SlideShare a Scribd company logo
INTRODUCTION TO TURBO PROLOG
1 | P a g e
Q-1. What is Prolog? Explain features, limitation and application of it.
Answer
It supports formal symbolic reasoning that can understand human language. It’s developed in 1972 by P.Roussell. It’s object-
oriented language which will use data about object and their relationship. It’s collection of data on facts and the relationship
among this fact.
Features:
(1). We can compile standalone program that will be executed on a machine that is not running in Turbo Prolog and it can
be distributed to the user.
(2). It’s a full complement of standard predicates for many functions such as string operation, random file access, cursor
control, graphics and sound.
(3). It’s a functional interface which will allow procedural support to be added in prolog system.
(4). We have to declare the variable which one used to provide more secure development control.
(5). Integer, floating point and real arithmetic values are provided.
(6). An integrated editor is provided making the program development, complication and debugging.
Limitations:
(1). It will reflect the structural aspects of procedural language. The variable declaration requirements and the division of
programming in 2 sections which will impose the some of the limitation in symbolic processing.
(2). The current version of turbo prolog doesn’t support virtual memory. In this memory the size of the program is limited
only by the disk space. So, it’s limited by the amount of memory so, we can use random file access to overcome the
limitation.
(3). All the prolog programs are inefficient for numerical processing.
Application:It’s useful for almost any application that requires the form of reasoning. This includes expert system, NLP,
Robotics, Game playing simulation.
(1). Expert System: This is the program that use inference technique which involves formal reasoning perform by a human
expert to solve a problem in a specific area of knowledge. It can diagnosis, analyze and categorize previously define
knowledge. So, it’s a collection of rules and facts.
(2). NLP(Natural Language Processing): It’s a part of expert system which permits non-tech user to describe the problem
and resolve them. It helps the computer to gain the knowledge about a human language which are expressed by rules
and facts.
(3). Robotics: It’s a branch of Computer Science which enables the computer to see and manipulate the objects in their
environment. It’s primarily involved in study and developing sensor system, manipulators and control the object and
space oriented problems.
(4). Game playing and simulation: Prolog is ideal for game playing and simulation because of formal reasoning. It implies
a set of logical rule that will control the action of many classical game like Tower of Hanoi, 8-puzzle, etc.
INTRODUCTION TO TURBO PROLOG
2 | P a g e
Program-1. Write a program to establish relation between 2 symbolic variables
Program-2. Write a program for medical symptoms example
INTRODUCTION TO TURBO PROLOG
3 | P a g e
Q-2. Define following terms:(a)predicates (b)clauses (c)Goal (d)fact (e)rule (f)domains
Answer
(a)predicates : A predicates will denote a property or a relationship between the objects
Ex. likes(person1,person2) ← predicate
(b)clauses: It’s a complete subset of first order predicate logic. A clause has a head which is known as
facts between name and arguments. It has a body which is known as rules. If the head is true then
only the body is executed.
Ex. likes(Aditya,Naina). ← fact (‘.’ shows the ending of fact)
(c)Goal: It will try to satisfy by finding the values of the variables that makes the goal successful.
The values are said to be bound to the variables. If prolog is unable to do this then goal fails.
Ex. Goal: likes(Aditya,Naina)
Yes
(d)fact: The fact must start with a predicate and ends with a full-stop(‘.’). The predicates may be followed
by one or more arguments which are enclosed by parenthesis. The arguments can be numbers, variables
or list and it’s separated by comma(‘,’).
Ex. symptoms(Flu,runnynose).
(e)rule: Rule can be viewed as an extension of fact with added condition that have to be satisfied for it to
be true. It consist of 2 part:
The first part is the fact, predicate with argument and the second part is other
clause(fact or rules separated by comma(‘,’)) both part is separated by
colon(‘:-’).
Ex. hypothesis(Charlie,cold):-
symptom(Charlie,fever).
(f)domains: In this we have to declare the objects which can be integer, real, string, char, symbol.
Ex. domains
x,y=integer
Q-3. What is variable in Prolog?
Answer
Variables are normally declared in the domains part.
There are 2 types of variable in Prolog:
1)Bound variable : If a variable has a value at a partition time it’s said ti be bound.
2)Free variable : If a variable doesn’t have a value at a particular time it’s said to be free.
INTRODUCTION TO TURBO PROLOG
4 | P a g e
Program-3. Demonstrate the program using the concept of rule.
Or
Write a prolog program to find the symptoms of patient data disease using the rules.
Q-4. Explain input and output predicate in prolog.
Answer
Input predicates- 4 types
1. readint: It can read the integer value
2. readreal: It can read the float value
3. readchar: It can read the char value
4. readln: It can read string value
Output predicates- 3 types
1. write: The output may be any number, char, string and more
2. writef: It’s a formatted output function. Example at last page
3. writedevice: It will give the output privately to the printer
INTRODUCTION TO TURBO PROLOG
5 | P a g e
Program-4. Demonstrate the use of readint and write predicate
Or
Write a prolog program to find out the age of patient.
 CODE :
 OUTPUT:
INTRODUCTION TO TURBO PROLOG
6 | P a g e
Program-5. Demonstrate a program for the use of readreal and write predicate.
Or
Write a program to find out the price of an item.
 CODE:
 OUTPUT:
INTRODUCTION TO TURBO PROLOG
7 | P a g e
Program-6. Demonstrate a program for the use of readln and write predicate.
Or
Write a prolog program to find whether a city belongs to a state or not?
 CODE:
 OUTPUT:
INTRODUCTION TO TURBO PROLOG
8 | P a g e
Program-7. Demonstrate a program for the use of readchar and write predicate.
Or
Write a prolog program to find whether a city belongs to a state or not?
 CODE:
 OUTPUT:
INTRODUCTION TO TURBO PROLOG
9 | P a g e
Program-8. Demonstrate a program for the use of go predicate.
 CODE:
 OUTPUT:
Program-9. Demonstrate a program for the use of go and other predicate.
 CODE: OUTPUT:
INTRODUCTION TO TURBO PROLOG
10 | P a g e
 writef predicate: If we want formatted output then we will use writef() predicate.
Syntax: writef(“format”,argument,argument(1),….,argument(n))
%-m.p (ex. %2.7f)
‘-‘ indicates left justification; right justification is the default.
‘m’ specifies the minimum field width
‘p’ field determines the precision of a floating-point image (or the maximum number of characters to be
printed from a string)
f - Reals in fixed decimal notation (default)
e - Reals in exponential notation
g - Use the shortest format.
Example at last page
 writedevice predicate : Reassigns the current writedevice to the file opened with the given SymbolicFileName,
which may be one of the predefined symbolic files (screen and printer) or any userdefined symbolic filename for a file
opened for writing or modifying.
writedevice(printer or screen)
 inkey predicate : This predicate will read a single character from the input
Syntax : inkey(char)
 keypressed predicate : It’s the predicate which will determine whether a key has been pressed without
a character being returned.
Syntax : keypressed
Define the following terms : (a)backtracking (b)unification
(a) Backtracking :
If any condition fails prolog backtracks to the previous condition and will try to prove it again with another variable
then it moves forward again to see if the fail condition will succeed with the newly one prolog moves forward and
backward direction through the condition and will try every attempt to get the goal to succeed as many as possible.
(b)Unification :
A term is said to be unify with another term.
1). Both the term appears in predicates that have same no. of argument and both term appear in the same position in
their predicate.
2). Both the terms appears as argument of the same type a symbol type can only unify with the symbol type only.
3). All sub terms unify with each other
These are the basic rules of unification :
(i) A variable that is free will unify with any term that satisfies the preceding condition
(ii) A free variable will unify with other free variable. After unifying the 2 variable will act as 1.
(iii) Predicates unify with each other if they have same relation same no of arguments.
INTRODUCTION TO TURBO PROLOG
11 | P a g e
Q-5. Explain Cut and Fail predicate with example.
Or
Explain controlling execution in prolog.
Answer
Cut predicate : It removes all the alternatives and then forbid the values otherwise it could be written by
method of binding.
It’s also very important for recursive process. The symbol of cut predicate is “!”. It always succeeds a statement.
It will block the backtracking based on a specific condition.
{There are two main uses of the cut:
• When you know in advance that certain possibilities will never give rise to meaningful solutions, so it is a waste of
time and storage space to backtrack over them. By using a cut in this situation, the resulting program will run
quicker and use less memory.
• When the logic of a program demands the cut. } Extra points
Ex. //Code snippet
a(X):-b(X),!,c(X).
a(X):-d(X).
b(1).
b(4).
c(1).
c(3).
d(4).
Explanation: After the cut predicate the whole statement will be going to be true.
First of all b(x). After that cut predicate indicates the value of b(x) can’t be changed that means a(x)=1 and the
whole statement is going to be true. So, the value of a(x)=1
Extra example given below for better understanding
Program Without cut predicate:
Program with cut predicate: (max out of two number)
INTRODUCTION TO TURBO PROLOG
12 | P a g e
Fail predicate: It means the whole statement is going to be false. It will force the backtracking in an attempt to
unify with another clause.
It’s very useful in recursion and other process.
Ex. //Code snippet
a(X):-b(X),c(X),fail.
a(X):-d(X).
b(1).
b(4).
c(1).
c(3).
d(4).
Explanation: As a(x)=b(x),c(x),fail. So, the fail statement makes b(x) and c(x) to be failed. So, the value of a(x)
can’t be b(1),b(4),c(1),c(3).
Statement 2 says a(x)=d(x). So, the value of a(x) will be d(4).
Extra example given below for better understanding
Program Without fail predicate:
Program With fail predicate:
INTRODUCTION TO TURBO PROLOG
13 | P a g e
Programs for cut and fail predicate.
In Exam if ask then you write any one with output
Program1:
Program2:
Program10 for cut predicate.
Program11 for fail predicate.
INTRODUCTION TO TURBO PROLOG
14 | P a g e
Q-6. What are the different types of cut predicates.
Or
Explain red cut and green cut in prolog.
Answer
There are two types of cuts. In Prolog, these are called the green and the red cuts.
Green cut: The green type of cut is used to force binding to be retained, once the right clause is reached. Green cuts are
used to express determinism. A program is nondeterministic if it is capable of generating multiple solutions on backtracking.
The red type of cut is used to omit explicit conditions. The use of any type of cut in a Prolog program is controversial. It
implies a type of procedural control, which is in sharp contrast to the declarative style of Prolog programming. If used with
caution, however, cuts improve the clarity and efficiency of most programs.
NOTE: Of the two types of cut, the green cut is the more acceptable type. One can often use the not predicate instead of the
red cut.
Program-12.Write a prolog to print the values between given range.
INTRODUCTION TO TURBO PROLOG
15 | P a g e
Program-13. Write a prolog program to find minimum no out of 2 numbers.
 For 5 or 7 mark then write this,
 For below 5 mark then write this,
INTRODUCTION TO TURBO PROLOG
16 | P a g e
Program-14. Write a prolog program to find maximum no out of 3 numbers.
 CODE: OUTPUT: For 5/7 marks
 For below 5 marks
INTRODUCTION TO TURBO PROLOG
17 | P a g e
Program-15. Write a prolog program to find sum of 3 numbers.
 For 5 or 7 mark then write this,
 For below 5 mark then write this,
Q-7. Define Recursion in prolog.
or
Explain repeat predicate in prolog
Answer
It’s a technique of using a clause to invoke a copy of itself.
The following predicate which is not bulletin will be used for recursion.
Repeat (‘Repeat’)
Syntax:
repeat.
repeat:-
repeat.
This predicate always succeed when it’s used in a rule. The repeat predicate is useful for forcing a program to generate
alternate solution through backtracking( go back to the initial position and recheck which one is better)
INTRODUCTION TO TURBO PROLOG
18 | P a g e
Program-16. Demonstrate a prolog program for the use of ‘repeat’ predicate.
Program-17. Write a prolog program to write numbers up to given range by use of recursion
without using repeat predicate.
Q-8. Define unwinding.
Answer
If we want to fix the program as previous example by adding new clause and modifying existing clause slightly.
We can compile and execute the above program with the goal count(1).
It defines the terminating condition. The recursion call will unify with the first and terminates from the loop.
INTRODUCTION TO TURBO PROLOG
19 | P a g e
Example of writef predicate
 CODE:
 OUTPUT:
Program-18. Write a prolog program to find whether the given input is a digit, number,
uppercase letter, lowercase letter or symbol.
INTRODUCTION TO TURBO PROLOG
20 | P a g e
Program-19. Write a prolog program whether a particular number is greater than 50 or not.
Program-20. Write a prolog program to find the answer of power function for a given value.
INTRODUCTION TO TURBO PROLOG
21 | P a g e
Program-21. Write a prolog program to find a factorial of given number.
• By 3 varialbles
INTRODUCTION TO TURBO PROLOG
22 | P a g e
Program-22. Write a prolog program to login with one username and password.
Q-9. Define Compound object.
Answer
We can create one object that contains another object. The resulting structure is called compound object.
Ex. Address(Name,Street,City,State,Zip)
The entire object can be treated as single object in predicate.
The first part of the compound object is the object’s name which is called functor.
The second part which is a argument list is called component.
Program-23. Write a prolog to demonstrate compound object.
INTRODUCTION TO TURBO PROLOG
23 | P a g e
Q-10. Define String in prolog.
Answer
A string is a list of character.
The properties of a string are as follows:
• All the character in the string must be same type.
• The length of the string can be of length.
• The length of the string can be of length.
• The order of the characters in a string is significant. Ex. “XYZ” is not the same string as “YXZ”.
• The string can be empty or null for Ex. write(“ ”)
Q-11. List out the various operations of string.
Answer
 Concatenation – The concat is a built-in predicate which will join 2 strings and will form 3rd
one.
Syntax: concat(String 1, String 2, ResultString)
Program-24. Write a prolog program which will demonstrate the concatenation operation
for 2 strings.
INTRODUCTION TO TURBO PROLOG
24 | P a g e
 frontstr predicate – This predicate will extract the number of characters from the front of a string.
Syntax: frontstr(NumberofCharacters, InputString, SelectedString, RestofString)
NumberofCharacters – Number of left characters to be extracted(Integer)
InputString – input string of charaters
SelectedString – extracted string
RestofString – rest of the input string after extraction process
Program-25. Write a program which will demonstrate frontstr predicate.
 fronttoken predicate – This predicate permits the extraction of token from a string the token can be a name, a
number or any non-space character in a sentence each word is token.
Syntax: fronttoken(InputString, Token, RestofString)
Where, InputString – any input string
Token – the first token in the input string(it can be a symbol or a string)
Restofstring – the input string after the token is extended
Program-26. Write a prolog program which will demonstrate the front token predicate.
INTRODUCTION TO TURBO PROLOG
25 | P a g e
 str_len – It’s used for to obtain a length of given string.
Syntax : str_len(InputString,len)
Where, InputString – any input string
Len – length of the InputString(in integer)
Program-27. Write a prolog program which will demonstrate the length of given string.
 upper_lower predicate – this predicate can be use to convert uppercase characters to lowercase characters or
lowercase characters to uppercase characters.
Syntax:upper_lower(UppercaseString,LowercaseString)
Program-28. Write a prolog program to convert lowercase to uppercase.
INTRODUCTION TO TURBO PROLOG
26 | P a g e
 isname predicate – this predicate is used to test whether a string is a name or not.
Syntax : isname(String)
Program-29. Write a prolog program for isname predicate.
Q-12. What is list in the prolog?
Answer
• A list is an ordered sequence of terms.
• The terms of list can be variables, simple object, compound object or any other list. So, a list can contain unlimited
number of terms.
• Each list is set of brackets.
• With the components of the list separated by commas for Ex. [a,b,c,d,e]
• The component of a list should be same domain type it can be integers, real numbers, string, single or compound
object.
• We can also indicate empty list as [].
Program-30. Write a prolog program which will demonstrate the declaring of list domain.
INTRODUCTION TO TURBO PROLOG
27 | P a g e
Program-31. Write a prolog program which will demonstrate writing a list.
Program-32. Write a prolog program which will perform append or concat element in list.
Program-33. Write a prolog program which will perform reverse operation in list.
INTRODUCTION TO TURBO PROLOG
28 | P a g e
Program-34. Prolog Program for Tower of Hanoi.
Program-35. Prolog Program for find vowel from list.
INTRODUCTION TO TURBO PROLOG
29 | P a g e
Program-36. Prolog program for find sum of integer list.
Program-37. Prolog program for check given character is a member of list or not?
INTRODUCTION TO TURBO PROLOG
30 | P a g e
Program-38. Prolog program for delete an element from list.
Program-39. Prolog program for find maximum from integer list.

More Related Content

PPTX
Compiler Chapter 1
PPT
Choosing a course and university
PPTX
Fragmentaton
PPT
Compiler Design Unit 1
PPTX
Malaria Detection Deep Learning Models.pptx
PPTX
Chapter 6 agent communications--agent communications
PDF
Cisco router-commands
PDF
4to grado - Computación
Compiler Chapter 1
Choosing a course and university
Fragmentaton
Compiler Design Unit 1
Malaria Detection Deep Learning Models.pptx
Chapter 6 agent communications--agent communications
Cisco router-commands
4to grado - Computación

What's hot (20)

PPT
BackTracking Algorithm: Technique and Examples
PPTX
Clipping
PPTX
N queen problem
PPTX
1.10. pumping lemma for regular sets
PPTX
Parallel projection
PPTX
Matching techniques
PPTX
0 1 knapsack using branch and bound
PPT
Composite transformations
PPTX
Water jug problem ai part 6
PPTX
Output primitives in Computer Graphics
PPTX
Frame buffer
PPTX
Huffman coding
PPTX
Boyer moore algorithm
PPTX
Realibity design
PDF
Ai lab manual
PPTX
04 Multi-layer Feedforward Networks
PPTX
2 d viewing computer graphics
PPTX
Attributes of Output Primitives
PPTX
Deep Learning - Convolutional Neural Networks - Architectural Zoo
BackTracking Algorithm: Technique and Examples
Clipping
N queen problem
1.10. pumping lemma for regular sets
Parallel projection
Matching techniques
0 1 knapsack using branch and bound
Composite transformations
Water jug problem ai part 6
Output primitives in Computer Graphics
Frame buffer
Huffman coding
Boyer moore algorithm
Realibity design
Ai lab manual
04 Multi-layer Feedforward Networks
2 d viewing computer graphics
Attributes of Output Primitives
Deep Learning - Convolutional Neural Networks - Architectural Zoo
Ad

Similar to Turbo prolog 2.0 basics (20)

PPTX
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit
DOCX
Python interview questions and answers
PPTX
Introduction To Programming with Python-1
PDF
Python interview questions and answers
DOCX
INTERNSHIP REPORT.docx
PPS
Learn C
PDF
Data Structure and Algorithms (DSA) with Python
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
PDF
data base nd analystics slybysss for the students to improbvr
DOCX
What is c language
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
PDF
Unit 1
PDF
GE3151_PSPP_All unit _Notes
PDF
Python Programming Course Presentations
PDF
Password protected diary
PPTX
program fundamentals using python1 2 3 4.pptx
PPTX
session-1_Design_Analysis_Algorithm.pptx
DOCX
Python Interview Questions For Experienced
DOC
C notes for exam preparation
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit
Python interview questions and answers
Introduction To Programming with Python-1
Python interview questions and answers
INTERNSHIP REPORT.docx
Learn C
Data Structure and Algorithms (DSA) with Python
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
data base nd analystics slybysss for the students to improbvr
What is c language
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
Unit 1
GE3151_PSPP_All unit _Notes
Python Programming Course Presentations
Password protected diary
program fundamentals using python1 2 3 4.pptx
session-1_Design_Analysis_Algorithm.pptx
Python Interview Questions For Experienced
C notes for exam preparation
Ad

More from Soham Kansodaria (9)

PPTX
Digital signature(Cryptography)
PPTX
Jdbc driver types
PPTX
DVWA(Damn Vulnerabilities Web Application)
PPT
Enviornmental Studies
PPT
Elements of Mechanical Engineering
PPT
Physics Dielectric
PPT
Slideshare Engineering Graphics
PPT
Full threded binary tree
PPTX
Dbms 4NF & 5NF
Digital signature(Cryptography)
Jdbc driver types
DVWA(Damn Vulnerabilities Web Application)
Enviornmental Studies
Elements of Mechanical Engineering
Physics Dielectric
Slideshare Engineering Graphics
Full threded binary tree
Dbms 4NF & 5NF

Recently uploaded (20)

PPTX
A Presentation on Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
KodekX | Application Modernization Development
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
A Presentation on Artificial Intelligence
NewMind AI Weekly Chronicles - August'25 Week I
MYSQL Presentation for SQL database connectivity
Mobile App Security Testing_ A Comprehensive Guide.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding
Reach Out and Touch Someone: Haptics and Empathic Computing
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.
KodekX | Application Modernization Development
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation_ Review paper, used for researhc scholars

Turbo prolog 2.0 basics

  • 1. INTRODUCTION TO TURBO PROLOG 1 | P a g e Q-1. What is Prolog? Explain features, limitation and application of it. Answer It supports formal symbolic reasoning that can understand human language. It’s developed in 1972 by P.Roussell. It’s object- oriented language which will use data about object and their relationship. It’s collection of data on facts and the relationship among this fact. Features: (1). We can compile standalone program that will be executed on a machine that is not running in Turbo Prolog and it can be distributed to the user. (2). It’s a full complement of standard predicates for many functions such as string operation, random file access, cursor control, graphics and sound. (3). It’s a functional interface which will allow procedural support to be added in prolog system. (4). We have to declare the variable which one used to provide more secure development control. (5). Integer, floating point and real arithmetic values are provided. (6). An integrated editor is provided making the program development, complication and debugging. Limitations: (1). It will reflect the structural aspects of procedural language. The variable declaration requirements and the division of programming in 2 sections which will impose the some of the limitation in symbolic processing. (2). The current version of turbo prolog doesn’t support virtual memory. In this memory the size of the program is limited only by the disk space. So, it’s limited by the amount of memory so, we can use random file access to overcome the limitation. (3). All the prolog programs are inefficient for numerical processing. Application:It’s useful for almost any application that requires the form of reasoning. This includes expert system, NLP, Robotics, Game playing simulation. (1). Expert System: This is the program that use inference technique which involves formal reasoning perform by a human expert to solve a problem in a specific area of knowledge. It can diagnosis, analyze and categorize previously define knowledge. So, it’s a collection of rules and facts. (2). NLP(Natural Language Processing): It’s a part of expert system which permits non-tech user to describe the problem and resolve them. It helps the computer to gain the knowledge about a human language which are expressed by rules and facts. (3). Robotics: It’s a branch of Computer Science which enables the computer to see and manipulate the objects in their environment. It’s primarily involved in study and developing sensor system, manipulators and control the object and space oriented problems. (4). Game playing and simulation: Prolog is ideal for game playing and simulation because of formal reasoning. It implies a set of logical rule that will control the action of many classical game like Tower of Hanoi, 8-puzzle, etc.
  • 2. INTRODUCTION TO TURBO PROLOG 2 | P a g e Program-1. Write a program to establish relation between 2 symbolic variables Program-2. Write a program for medical symptoms example
  • 3. INTRODUCTION TO TURBO PROLOG 3 | P a g e Q-2. Define following terms:(a)predicates (b)clauses (c)Goal (d)fact (e)rule (f)domains Answer (a)predicates : A predicates will denote a property or a relationship between the objects Ex. likes(person1,person2) ← predicate (b)clauses: It’s a complete subset of first order predicate logic. A clause has a head which is known as facts between name and arguments. It has a body which is known as rules. If the head is true then only the body is executed. Ex. likes(Aditya,Naina). ← fact (‘.’ shows the ending of fact) (c)Goal: It will try to satisfy by finding the values of the variables that makes the goal successful. The values are said to be bound to the variables. If prolog is unable to do this then goal fails. Ex. Goal: likes(Aditya,Naina) Yes (d)fact: The fact must start with a predicate and ends with a full-stop(‘.’). The predicates may be followed by one or more arguments which are enclosed by parenthesis. The arguments can be numbers, variables or list and it’s separated by comma(‘,’). Ex. symptoms(Flu,runnynose). (e)rule: Rule can be viewed as an extension of fact with added condition that have to be satisfied for it to be true. It consist of 2 part: The first part is the fact, predicate with argument and the second part is other clause(fact or rules separated by comma(‘,’)) both part is separated by colon(‘:-’). Ex. hypothesis(Charlie,cold):- symptom(Charlie,fever). (f)domains: In this we have to declare the objects which can be integer, real, string, char, symbol. Ex. domains x,y=integer Q-3. What is variable in Prolog? Answer Variables are normally declared in the domains part. There are 2 types of variable in Prolog: 1)Bound variable : If a variable has a value at a partition time it’s said ti be bound. 2)Free variable : If a variable doesn’t have a value at a particular time it’s said to be free.
  • 4. INTRODUCTION TO TURBO PROLOG 4 | P a g e Program-3. Demonstrate the program using the concept of rule. Or Write a prolog program to find the symptoms of patient data disease using the rules. Q-4. Explain input and output predicate in prolog. Answer Input predicates- 4 types 1. readint: It can read the integer value 2. readreal: It can read the float value 3. readchar: It can read the char value 4. readln: It can read string value Output predicates- 3 types 1. write: The output may be any number, char, string and more 2. writef: It’s a formatted output function. Example at last page 3. writedevice: It will give the output privately to the printer
  • 5. INTRODUCTION TO TURBO PROLOG 5 | P a g e Program-4. Demonstrate the use of readint and write predicate Or Write a prolog program to find out the age of patient.  CODE :  OUTPUT:
  • 6. INTRODUCTION TO TURBO PROLOG 6 | P a g e Program-5. Demonstrate a program for the use of readreal and write predicate. Or Write a program to find out the price of an item.  CODE:  OUTPUT:
  • 7. INTRODUCTION TO TURBO PROLOG 7 | P a g e Program-6. Demonstrate a program for the use of readln and write predicate. Or Write a prolog program to find whether a city belongs to a state or not?  CODE:  OUTPUT:
  • 8. INTRODUCTION TO TURBO PROLOG 8 | P a g e Program-7. Demonstrate a program for the use of readchar and write predicate. Or Write a prolog program to find whether a city belongs to a state or not?  CODE:  OUTPUT:
  • 9. INTRODUCTION TO TURBO PROLOG 9 | P a g e Program-8. Demonstrate a program for the use of go predicate.  CODE:  OUTPUT: Program-9. Demonstrate a program for the use of go and other predicate.  CODE: OUTPUT:
  • 10. INTRODUCTION TO TURBO PROLOG 10 | P a g e  writef predicate: If we want formatted output then we will use writef() predicate. Syntax: writef(“format”,argument,argument(1),….,argument(n)) %-m.p (ex. %2.7f) ‘-‘ indicates left justification; right justification is the default. ‘m’ specifies the minimum field width ‘p’ field determines the precision of a floating-point image (or the maximum number of characters to be printed from a string) f - Reals in fixed decimal notation (default) e - Reals in exponential notation g - Use the shortest format. Example at last page  writedevice predicate : Reassigns the current writedevice to the file opened with the given SymbolicFileName, which may be one of the predefined symbolic files (screen and printer) or any userdefined symbolic filename for a file opened for writing or modifying. writedevice(printer or screen)  inkey predicate : This predicate will read a single character from the input Syntax : inkey(char)  keypressed predicate : It’s the predicate which will determine whether a key has been pressed without a character being returned. Syntax : keypressed Define the following terms : (a)backtracking (b)unification (a) Backtracking : If any condition fails prolog backtracks to the previous condition and will try to prove it again with another variable then it moves forward again to see if the fail condition will succeed with the newly one prolog moves forward and backward direction through the condition and will try every attempt to get the goal to succeed as many as possible. (b)Unification : A term is said to be unify with another term. 1). Both the term appears in predicates that have same no. of argument and both term appear in the same position in their predicate. 2). Both the terms appears as argument of the same type a symbol type can only unify with the symbol type only. 3). All sub terms unify with each other These are the basic rules of unification : (i) A variable that is free will unify with any term that satisfies the preceding condition (ii) A free variable will unify with other free variable. After unifying the 2 variable will act as 1. (iii) Predicates unify with each other if they have same relation same no of arguments.
  • 11. INTRODUCTION TO TURBO PROLOG 11 | P a g e Q-5. Explain Cut and Fail predicate with example. Or Explain controlling execution in prolog. Answer Cut predicate : It removes all the alternatives and then forbid the values otherwise it could be written by method of binding. It’s also very important for recursive process. The symbol of cut predicate is “!”. It always succeeds a statement. It will block the backtracking based on a specific condition. {There are two main uses of the cut: • When you know in advance that certain possibilities will never give rise to meaningful solutions, so it is a waste of time and storage space to backtrack over them. By using a cut in this situation, the resulting program will run quicker and use less memory. • When the logic of a program demands the cut. } Extra points Ex. //Code snippet a(X):-b(X),!,c(X). a(X):-d(X). b(1). b(4). c(1). c(3). d(4). Explanation: After the cut predicate the whole statement will be going to be true. First of all b(x). After that cut predicate indicates the value of b(x) can’t be changed that means a(x)=1 and the whole statement is going to be true. So, the value of a(x)=1 Extra example given below for better understanding Program Without cut predicate: Program with cut predicate: (max out of two number)
  • 12. INTRODUCTION TO TURBO PROLOG 12 | P a g e Fail predicate: It means the whole statement is going to be false. It will force the backtracking in an attempt to unify with another clause. It’s very useful in recursion and other process. Ex. //Code snippet a(X):-b(X),c(X),fail. a(X):-d(X). b(1). b(4). c(1). c(3). d(4). Explanation: As a(x)=b(x),c(x),fail. So, the fail statement makes b(x) and c(x) to be failed. So, the value of a(x) can’t be b(1),b(4),c(1),c(3). Statement 2 says a(x)=d(x). So, the value of a(x) will be d(4). Extra example given below for better understanding Program Without fail predicate: Program With fail predicate:
  • 13. INTRODUCTION TO TURBO PROLOG 13 | P a g e Programs for cut and fail predicate. In Exam if ask then you write any one with output Program1: Program2: Program10 for cut predicate. Program11 for fail predicate.
  • 14. INTRODUCTION TO TURBO PROLOG 14 | P a g e Q-6. What are the different types of cut predicates. Or Explain red cut and green cut in prolog. Answer There are two types of cuts. In Prolog, these are called the green and the red cuts. Green cut: The green type of cut is used to force binding to be retained, once the right clause is reached. Green cuts are used to express determinism. A program is nondeterministic if it is capable of generating multiple solutions on backtracking. The red type of cut is used to omit explicit conditions. The use of any type of cut in a Prolog program is controversial. It implies a type of procedural control, which is in sharp contrast to the declarative style of Prolog programming. If used with caution, however, cuts improve the clarity and efficiency of most programs. NOTE: Of the two types of cut, the green cut is the more acceptable type. One can often use the not predicate instead of the red cut. Program-12.Write a prolog to print the values between given range.
  • 15. INTRODUCTION TO TURBO PROLOG 15 | P a g e Program-13. Write a prolog program to find minimum no out of 2 numbers.  For 5 or 7 mark then write this,  For below 5 mark then write this,
  • 16. INTRODUCTION TO TURBO PROLOG 16 | P a g e Program-14. Write a prolog program to find maximum no out of 3 numbers.  CODE: OUTPUT: For 5/7 marks  For below 5 marks
  • 17. INTRODUCTION TO TURBO PROLOG 17 | P a g e Program-15. Write a prolog program to find sum of 3 numbers.  For 5 or 7 mark then write this,  For below 5 mark then write this, Q-7. Define Recursion in prolog. or Explain repeat predicate in prolog Answer It’s a technique of using a clause to invoke a copy of itself. The following predicate which is not bulletin will be used for recursion. Repeat (‘Repeat’) Syntax: repeat. repeat:- repeat. This predicate always succeed when it’s used in a rule. The repeat predicate is useful for forcing a program to generate alternate solution through backtracking( go back to the initial position and recheck which one is better)
  • 18. INTRODUCTION TO TURBO PROLOG 18 | P a g e Program-16. Demonstrate a prolog program for the use of ‘repeat’ predicate. Program-17. Write a prolog program to write numbers up to given range by use of recursion without using repeat predicate. Q-8. Define unwinding. Answer If we want to fix the program as previous example by adding new clause and modifying existing clause slightly. We can compile and execute the above program with the goal count(1). It defines the terminating condition. The recursion call will unify with the first and terminates from the loop.
  • 19. INTRODUCTION TO TURBO PROLOG 19 | P a g e Example of writef predicate  CODE:  OUTPUT: Program-18. Write a prolog program to find whether the given input is a digit, number, uppercase letter, lowercase letter or symbol.
  • 20. INTRODUCTION TO TURBO PROLOG 20 | P a g e Program-19. Write a prolog program whether a particular number is greater than 50 or not. Program-20. Write a prolog program to find the answer of power function for a given value.
  • 21. INTRODUCTION TO TURBO PROLOG 21 | P a g e Program-21. Write a prolog program to find a factorial of given number. • By 3 varialbles
  • 22. INTRODUCTION TO TURBO PROLOG 22 | P a g e Program-22. Write a prolog program to login with one username and password. Q-9. Define Compound object. Answer We can create one object that contains another object. The resulting structure is called compound object. Ex. Address(Name,Street,City,State,Zip) The entire object can be treated as single object in predicate. The first part of the compound object is the object’s name which is called functor. The second part which is a argument list is called component. Program-23. Write a prolog to demonstrate compound object.
  • 23. INTRODUCTION TO TURBO PROLOG 23 | P a g e Q-10. Define String in prolog. Answer A string is a list of character. The properties of a string are as follows: • All the character in the string must be same type. • The length of the string can be of length. • The length of the string can be of length. • The order of the characters in a string is significant. Ex. “XYZ” is not the same string as “YXZ”. • The string can be empty or null for Ex. write(“ ”) Q-11. List out the various operations of string. Answer  Concatenation – The concat is a built-in predicate which will join 2 strings and will form 3rd one. Syntax: concat(String 1, String 2, ResultString) Program-24. Write a prolog program which will demonstrate the concatenation operation for 2 strings.
  • 24. INTRODUCTION TO TURBO PROLOG 24 | P a g e  frontstr predicate – This predicate will extract the number of characters from the front of a string. Syntax: frontstr(NumberofCharacters, InputString, SelectedString, RestofString) NumberofCharacters – Number of left characters to be extracted(Integer) InputString – input string of charaters SelectedString – extracted string RestofString – rest of the input string after extraction process Program-25. Write a program which will demonstrate frontstr predicate.  fronttoken predicate – This predicate permits the extraction of token from a string the token can be a name, a number or any non-space character in a sentence each word is token. Syntax: fronttoken(InputString, Token, RestofString) Where, InputString – any input string Token – the first token in the input string(it can be a symbol or a string) Restofstring – the input string after the token is extended Program-26. Write a prolog program which will demonstrate the front token predicate.
  • 25. INTRODUCTION TO TURBO PROLOG 25 | P a g e  str_len – It’s used for to obtain a length of given string. Syntax : str_len(InputString,len) Where, InputString – any input string Len – length of the InputString(in integer) Program-27. Write a prolog program which will demonstrate the length of given string.  upper_lower predicate – this predicate can be use to convert uppercase characters to lowercase characters or lowercase characters to uppercase characters. Syntax:upper_lower(UppercaseString,LowercaseString) Program-28. Write a prolog program to convert lowercase to uppercase.
  • 26. INTRODUCTION TO TURBO PROLOG 26 | P a g e  isname predicate – this predicate is used to test whether a string is a name or not. Syntax : isname(String) Program-29. Write a prolog program for isname predicate. Q-12. What is list in the prolog? Answer • A list is an ordered sequence of terms. • The terms of list can be variables, simple object, compound object or any other list. So, a list can contain unlimited number of terms. • Each list is set of brackets. • With the components of the list separated by commas for Ex. [a,b,c,d,e] • The component of a list should be same domain type it can be integers, real numbers, string, single or compound object. • We can also indicate empty list as []. Program-30. Write a prolog program which will demonstrate the declaring of list domain.
  • 27. INTRODUCTION TO TURBO PROLOG 27 | P a g e Program-31. Write a prolog program which will demonstrate writing a list. Program-32. Write a prolog program which will perform append or concat element in list. Program-33. Write a prolog program which will perform reverse operation in list.
  • 28. INTRODUCTION TO TURBO PROLOG 28 | P a g e Program-34. Prolog Program for Tower of Hanoi. Program-35. Prolog Program for find vowel from list.
  • 29. INTRODUCTION TO TURBO PROLOG 29 | P a g e Program-36. Prolog program for find sum of integer list. Program-37. Prolog program for check given character is a member of list or not?
  • 30. INTRODUCTION TO TURBO PROLOG 30 | P a g e Program-38. Prolog program for delete an element from list. Program-39. Prolog program for find maximum from integer list.