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

What's hot (20)

PPTX
Software myths | Software Engineering Notes
Navjyotsinh Jadeja
 
PPT
Quadric surfaces
Ankur Kumar
 
PPTX
Dempster shafer theory
Dr. C.V. Suresh Babu
 
PPTX
Matching techniques
Nagpalkirti
 
PDF
Ai lab manual
Shipra Swati
 
PPTX
Vision of cloud computing
gaurav jain
 
PPTX
Advanced topics in artificial neural networks
swapnac12
 
PDF
Lab report for Prolog program in artificial intelligence.
Alamgir Hossain
 
PPTX
Third party cloud services cloud computing
SohailAliMalik
 
PPTX
Syntax-Directed Translation into Three Address Code
sanchi29
 
PPTX
Problem solving agents
Megha Sharma
 
PPTX
Knowledge representation and Predicate logic
Amey Kerkar
 
PPTX
First order logic
Megha Sharma
 
PDF
AI_ 3 & 4 Knowledge Representation issues
Khushali Kathiriya
 
PDF
Daa notes 3
smruti sarangi
 
PPT
Symbol table management and error handling in compiler design
Swati Chauhan
 
PPTX
And or graph
Ali A Jalil
 
PPTX
Tree pruning
Shivangi Gupta
 
PPT
2D transformation (Computer Graphics)
Timbal Mayank
 
Software myths | Software Engineering Notes
Navjyotsinh Jadeja
 
Quadric surfaces
Ankur Kumar
 
Dempster shafer theory
Dr. C.V. Suresh Babu
 
Matching techniques
Nagpalkirti
 
Ai lab manual
Shipra Swati
 
Vision of cloud computing
gaurav jain
 
Advanced topics in artificial neural networks
swapnac12
 
Lab report for Prolog program in artificial intelligence.
Alamgir Hossain
 
Third party cloud services cloud computing
SohailAliMalik
 
Syntax-Directed Translation into Three Address Code
sanchi29
 
Problem solving agents
Megha Sharma
 
Knowledge representation and Predicate logic
Amey Kerkar
 
First order logic
Megha Sharma
 
AI_ 3 & 4 Knowledge Representation issues
Khushali Kathiriya
 
Daa notes 3
smruti sarangi
 
Symbol table management and error handling in compiler design
Swati Chauhan
 
And or graph
Ali A Jalil
 
Tree pruning
Shivangi Gupta
 
2D transformation (Computer Graphics)
Timbal Mayank
 

Similar to Turbo prolog 2.0 basics (20)

PPTX
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit
ManishYadav243888
 
DOCX
Python interview questions and answers
RojaPriya
 
PPTX
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
PDF
Python interview questions and answers
kavinilavuG
 
DOCX
INTERNSHIP REPORT.docx
21IT200KishorekumarI
 
PPS
Learn C
kantila
 
PDF
Data Structure and Algorithms (DSA) with Python
epsilonice
 
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
cargillfilberto
 
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
drandy1
 
PDF
data base nd analystics slybysss for the students to improbvr
unitycircledyd
 
DOCX
What is c language
Kushaal Singla
 
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
monicafrancis71118
 
PDF
Unit 1
Sowri Rajan
 
PDF
GE3151_PSPP_All unit _Notes
Guru Nanak Technical Institutions
 
PDF
Python Programming Course Presentations
DreamerInfotech
 
PDF
Password protected diary
SHARDA SHARAN
 
PPTX
program fundamentals using python1 2 3 4.pptx
ibrahimsoryjalloh91
 
PPTX
session-1_Design_Analysis_Algorithm.pptx
chandankumar364348
 
DOCX
Python Interview Questions For Experienced
zynofustechnology
 
DOC
C notes for exam preparation
Lakshmi Sarvani Videla
 
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit
ManishYadav243888
 
Python interview questions and answers
RojaPriya
 
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Python interview questions and answers
kavinilavuG
 
INTERNSHIP REPORT.docx
21IT200KishorekumarI
 
Learn C
kantila
 
Data Structure and Algorithms (DSA) with Python
epsilonice
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
cargillfilberto
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
drandy1
 
data base nd analystics slybysss for the students to improbvr
unitycircledyd
 
What is c language
Kushaal Singla
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
monicafrancis71118
 
Unit 1
Sowri Rajan
 
GE3151_PSPP_All unit _Notes
Guru Nanak Technical Institutions
 
Python Programming Course Presentations
DreamerInfotech
 
Password protected diary
SHARDA SHARAN
 
program fundamentals using python1 2 3 4.pptx
ibrahimsoryjalloh91
 
session-1_Design_Analysis_Algorithm.pptx
chandankumar364348
 
Python Interview Questions For Experienced
zynofustechnology
 
C notes for exam preparation
Lakshmi Sarvani Videla
 
Ad

More from Soham Kansodaria (9)

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

Recently uploaded (20)

PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 

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.