SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Presented By –
Tandel Vishal P.
Prolog
● What is Prolog?
● Syntax of Prolog
● Prolog Control Strategy
● Interface architecture
● Prolog Query
● Programming Techniques
● Termination
● Rule Order
● Goal Order
● Redundancy
● Iteration in Prolog
● conclusion
● Prolog is acronym of PROgramming in LOGic.
● Prolog program is sequence of rules and facts.
● Prolog Rule for grandfather is defined as:
gfather(X, Y) :- father(X, Z), parent(Z, Y).
father(james, robert).
● The rules and facts in Prolog are terminated by full stop (.).
● Goal can be included in the program or given at the prompt.
● Goal can be single or conjunction of sub-goal(s) terminated by full stop.
● Constants are numerals and symbols such as, 4, mary, etc.
● String is a sequence of characters and is enclosed within single quotes e.g., 'This is
a string'.
● Predicate names must start with alphabet and are formed by using lower case
letters, numerals and underscore ( _ ).
● Variable names are formed similar to predicate names but it must start with
upper case letter. Normally, we use X, Y, Z, ... for variables.
● Prolog contains three basic control strategies.
− Forward movement
− Matching (Unification)
− Backward movement (Backtracking)
● Prolog uses depth first search strategy.
● Choose a rule by
− searching sequentially in the program from top to bottom whose
head matches with the goal with possible unifier.
− Remember the position of the matched rule.
− Join the rule body in front of the sequence of sub goals to be
solved.
● Repeat until either goal is satisfied or is failed.
● Consider the following query consisting of n sub-goals.
?- G1, ... , Gi-1, Gi, ... , Gn
● Starts executing or satisfying G1
− If G1 is satisfied using some rule, put a place marker so that next rule for G1 will
be searched after the marker.
− Continue in forward direction to satisfy G2 and if it is satisfied then continue with
common bindings of the variables in sub-goals so far satisfied.
− Such a movement is called forward
● Unification is a process of matching or finding the most general unifier.
− Constant matches with the same constant.
− A variable can match with any constant or any another variable.
● Examples
− love(X, sita) unifies with love(ram, sita) with mgu as {X / ram}.
− love(X, Y) unify with love(ram, sita) with mgu as {X/ram, Y/sita} respectively.
● Backtracking refers to backtrack in search process for a solution.
● In Prolog, backtracking takes place in two situations.
− First when a sub goal fails and
− Other when the last sub goal succeeds, it backtracks to find
alternative solutions.
● Prolog has two kinds of backtracking.
− Shallow and
− Deep backtracking
● Both backtrackings take place in conjunction with each other.
● Shallow backtracking occurs
− when alternative definition of the goal is tried.
− Suppose G1,.., Gi-1 have been satisfied with some common bindings
of the variables in sub-goals.
− While satisfying Gi., if it fails for some rule then try another rule of Gi
− This is called shallow backtracking to rules of the same sub-goal
● Deep backtracking occurs
− When sub-goal Gi fails for all rules of Gi then backtrack to Gi-1.
− This backtracking is called deep backtracking.
− Remove the bindings created earlier to satisfy Gi-1.
− Try to satisfy Gi-1 again by using an alternative rule, if it exists, from
last place marker of Gi-1. and continue the process.
− If sub goal Gi-1 is satisfied then move forward to Gi, else backtrack to
Gi-2.
− The process of backtracking continues till we reach G1.
− If G1 fails for all possible definitions, then entire query fails.
● If entire conjunction of sub-goals succeed, then the solution is
displayed.
● For alternative solution, the sub goal Gn is tried to be satisfied with
alternative rule, if it exist, after last place marker (Shallow backtracking)
of Gn .
● Otherwise it backtracks to previous sub goal Gn-1 (Deep backtracking).
● Process is repeated till all possible solutions are generated.
● Two types of query
− Ground query
 No variable in the argument
 Example:
? gfather(ram, shyam) – Is ram a grand father of shyam?
 Answer to ground queries are Yes or No
 Proof tree is generated while solving the query.
− Non ground query
 Atleast one argument is a variable
 Example:
? gfather(X, shyam) – Who is a grand father of shyam?
 Answer to such queries are the values bound to the variables in the query.
 Search tree is generated using DFS to find all possible solutions.
Ground query:
?- gfather(james, hency).
Proof tree: ?- gfather(james, hency).
(1)
?- father(james, Z), parent(Z, hency).
(4) { Z = robert }
?- parent(robert, hency).
(2)
?- father(robert, hency).
(7)
succeeds Answer: Yes
Non-Ground query:
?- gfather(william, X).
Search tree: ?- gfather(william, X).
(1)
?- father(william, Z), parent(Z, X).
(6) {Z = james}
?- parent(james, X).
(2) (3)
?- father(james, X). ?- mother(james, X).
(4) {X = robert}
succeeds fails
Answer: X = robert
● Recursion is one of the most important execution control techniques in
Prolog.
● Iteration is another important programming technique.
● Prolog does not support iteration.
● It can be achieved by
− making recursive call to be the last sub goal in the rule
− using the concept of accumulators which are special types of arguments used for
holding intermediate results.
● The issues of termination, rule order, goal order and redundancy are
also important.
● Consider a classical example of computing factorial using recursion.
● Recurrence relation or mathematical definition for computing factorial of positive
integer is:
1, if n = 0
FACTORIAL (n) =
n * FACTORIAL (n-1),
otherwise
● In Prolog, program for computing factorial of a positive number is written using
above definition.
● Factorial predicate contains two arguments; one as input and another as output.
/*fact(N, R) – succeeds if R is unified with the factorial of N */
factorial(0, 1). (1)
factorial(N, R) :- N1 is N–1, factorial(N1, R1), R is N * R1. (2)
● Rule (1) states that factorial of 0 is 1 which is a terminating clause.
● Rule (2) is a recursive rule which states that factorial of N is calculated
by multiplying N with factorial of (N-1).
Goal: ?- factorial(3, R).
 Depth first traversal of Prolog has a serious problem. If the search tree
of a goal with respect to a program contains an infinite branch, the
computation will not terminate.
 Prolog may fail to find a solution of a goal, even if the goal has a finite
computation.
 Non termination arises because of the following reasons:
− Left recursive rules: The rule having a recursive goal as the first sub
goal in the body.
● Consider acyclic directed graph
p
q
r s
t
● Graph G is represented by set of connected edges.
G = { edge(p, q), edge(q, r), edge(q, s), edge(s, t)}
● Write Prolog Program to check whether there is a route from one node to another
node.
● Route from node A to B is defined as follows:
− route from A to B if there is a root from A some node C and an edge from C to B.
− route from A to B if there is a direct edge from A to B.
● Prolog Program
route(A, B) :- route(A, C), edge(C, B). (1)
route(A, B) :- edge(A, B). (2)
edge(p, q).
edge(q, r).
edge(q, s).
edge(s, t).
Query: Check whether there exist a route between nodes p and t .
Goal: ?- route(p, t).
Proof tree:?- route(p, t).
(1)
?- route(p, X), edge(X, t)
(1)
?- route(p, Y), edge(Y, X), edge(X, t).
Non terminating
● Non terminating program because of left recursion.
● Better way of writing a rule is to write recursive call as the last call.
route(A, B) :- edge(A, C), route(C, B).
● A rule order is very important issue in Prolog.
● Change of the order of rules in a program, the branches in any search
tree for a goal to be solved with that program get permuted.
● It may affect the efficiency of executing goal.
● Since the search tree is traversed using depth first approach, the order
of solutions will be different.
● Goal order in Prolog is more significant than rule order.
● It may affect the termination because
− subsequent sub goals have different bindings and hence different search trees.
● Consider the following recursive rules.
ancester(X, Y) :- parent(X, Z), ancester(Z, Y).
route(X, Y) :- edge(X, Z), route(Z, Y).
● If the sub goals in the body of above rules are swapped, then the rules becomes left
recursive and all the computations will become non terminating.
● It also affects the amount of search the program does in solving a query .
● Redundancy of the solution to the queries is another important issue in Prolog
programs.
● In Prolog, each possible deduction means an extra branch in the search tree.
● The bigger the search tree, higher the computation time.
● It is desirable in general to keep the size of the search tree as small as possible.
● Redundant program at times may cause exponential increase in runtime in the
event of backtracking.
● There are various reasons by which redundancy gets introduced.
− The same case is covered by several rules
− Redundancy in computation appears in the program by not handling special
cases separately.
 Prolog does not have storage variables that can
− hold intermediate results of the computation
− be modified as the computation progress.
 To implement iterative algorithm one requires the storage of
intermediate results, Prolog predicates are augmented with additional
arguments called accumulators.
 These are similar to local variables in procedural languages.
 The programs written using accumulators are iterative in nature.
 In iterative form of a program, make the recursive call as the last call if
possible.
● Prolog has helped more than 6,000 organization reduce construction project risk, control project costs, and
provide complete transparency to project stakeholders, becoming the industry standard for construction project
control and visibility.
Prolog Enables you to Your Benefit
Automate Task and process Complete automation from project design to close-out
Streamline project Delivery Manage all construction projects in one system
Control cost Real-time cost management tools and budget tracking
Increase Productivity Real-time collaboration with geographically dispersed project teams
Reduce Legal Risk Audited access to data and documents in one central location
Monitor Project
performance
Access to real time metrics tracking and dashboards
Extend The value of your
Software investment
Integrating your construction project data with other technology system
and devices (accounting , Microsoft Office, BIM models, and handheld
devices)
Introduction on Prolog - Programming in Logic

Weitere ähnliche Inhalte

Was ist angesagt?

Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AIVishal Singh
 
Informed search (heuristics)
Informed search (heuristics)Informed search (heuristics)
Informed search (heuristics)Bablu Shofi
 
Knowledge Representation in Artificial intelligence
Knowledge Representation in Artificial intelligence Knowledge Representation in Artificial intelligence
Knowledge Representation in Artificial intelligence Yasir Khan
 
Lec 3 knowledge acquisition representation and inference
Lec 3  knowledge acquisition representation and inferenceLec 3  knowledge acquisition representation and inference
Lec 3 knowledge acquisition representation and inferenceEyob Sisay
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Artificial intelligence and knowledge representation
Artificial intelligence and knowledge representationArtificial intelligence and knowledge representation
Artificial intelligence and knowledge representationSajan Sahu
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Language Model (N-Gram).pptx
Language Model (N-Gram).pptxLanguage Model (N-Gram).pptx
Language Model (N-Gram).pptxHeneWijaya
 
Artificial Intelligence -- Search Algorithms
Artificial Intelligence-- Search Algorithms Artificial Intelligence-- Search Algorithms
Artificial Intelligence -- Search Algorithms Syed Ahmed
 
knowledge representation using rules
knowledge representation using rulesknowledge representation using rules
knowledge representation using rulesHarini Balamurugan
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)jehan1987
 
Knowledge representation and Predicate logic
Knowledge representation and Predicate logicKnowledge representation and Predicate logic
Knowledge representation and Predicate logicAmey Kerkar
 
Introduction to Machine Learning with Find-S
Introduction to Machine Learning with Find-SIntroduction to Machine Learning with Find-S
Introduction to Machine Learning with Find-SKnoldus Inc.
 
State Space Search in ai
State Space Search in aiState Space Search in ai
State Space Search in aivikas dhakane
 
Neural Networks: Multilayer Perceptron
Neural Networks: Multilayer PerceptronNeural Networks: Multilayer Perceptron
Neural Networks: Multilayer PerceptronMostafa G. M. Mostafa
 
Genetic Algorithms - Artificial Intelligence
Genetic Algorithms - Artificial IntelligenceGenetic Algorithms - Artificial Intelligence
Genetic Algorithms - Artificial IntelligenceSahil Kumar
 
Problem solving agents
Problem solving agentsProblem solving agents
Problem solving agentsMegha Sharma
 

Was ist angesagt? (20)

Knowledge representation in AI
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AI
 
Informed search (heuristics)
Informed search (heuristics)Informed search (heuristics)
Informed search (heuristics)
 
Knowledge Representation in Artificial intelligence
Knowledge Representation in Artificial intelligence Knowledge Representation in Artificial intelligence
Knowledge Representation in Artificial intelligence
 
AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)
 
Lec 3 knowledge acquisition representation and inference
Lec 3  knowledge acquisition representation and inferenceLec 3  knowledge acquisition representation and inference
Lec 3 knowledge acquisition representation and inference
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
First order logic
First order logicFirst order logic
First order logic
 
AI: Logic in AI
AI: Logic in AIAI: Logic in AI
AI: Logic in AI
 
Artificial intelligence and knowledge representation
Artificial intelligence and knowledge representationArtificial intelligence and knowledge representation
Artificial intelligence and knowledge representation
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Language Model (N-Gram).pptx
Language Model (N-Gram).pptxLanguage Model (N-Gram).pptx
Language Model (N-Gram).pptx
 
Artificial Intelligence -- Search Algorithms
Artificial Intelligence-- Search Algorithms Artificial Intelligence-- Search Algorithms
Artificial Intelligence -- Search Algorithms
 
knowledge representation using rules
knowledge representation using rulesknowledge representation using rules
knowledge representation using rules
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
Knowledge representation and Predicate logic
Knowledge representation and Predicate logicKnowledge representation and Predicate logic
Knowledge representation and Predicate logic
 
Introduction to Machine Learning with Find-S
Introduction to Machine Learning with Find-SIntroduction to Machine Learning with Find-S
Introduction to Machine Learning with Find-S
 
State Space Search in ai
State Space Search in aiState Space Search in ai
State Space Search in ai
 
Neural Networks: Multilayer Perceptron
Neural Networks: Multilayer PerceptronNeural Networks: Multilayer Perceptron
Neural Networks: Multilayer Perceptron
 
Genetic Algorithms - Artificial Intelligence
Genetic Algorithms - Artificial IntelligenceGenetic Algorithms - Artificial Intelligence
Genetic Algorithms - Artificial Intelligence
 
Problem solving agents
Problem solving agentsProblem solving agents
Problem solving agents
 

Andere mochten auch

Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog LanguageREHMAT ULLAH
 
Logic Programming and Prolog
Logic Programming and PrologLogic Programming and Prolog
Logic Programming and PrologSadegh Dorri N.
 
PROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG CONTENT
 
PROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologPROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologDataminingTools Inc
 
PROLOG: Arithmetic Operations In Prolog
PROLOG: Arithmetic Operations In PrologPROLOG: Arithmetic Operations In Prolog
PROLOG: Arithmetic Operations In PrologDataminingTools Inc
 
Expert Systems
Expert SystemsExpert Systems
Expert Systemsosmancikk
 
Expert Systems & Prolog
Expert Systems & PrologExpert Systems & Prolog
Expert Systems & PrologFatih Karatana
 
Hubot and Playbook - Oct 2016 ChatbotsAU meetup
Hubot and Playbook - Oct 2016 ChatbotsAU meetupHubot and Playbook - Oct 2016 ChatbotsAU meetup
Hubot and Playbook - Oct 2016 ChatbotsAU meetupTim Kinnane
 
Introduccion a prolog
Introduccion a prologIntroduccion a prolog
Introduccion a prologJeffoG92
 
Prolog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb PirzadaProlog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb PirzadaShahzeb Pirzada
 
Prolog programming
Prolog programmingProlog programming
Prolog programmingHarry Potter
 
Prolog: Arithmetic Operations In Prolog
Prolog: Arithmetic Operations In PrologProlog: Arithmetic Operations In Prolog
Prolog: Arithmetic Operations In PrologPROLOG CONTENT
 

Andere mochten auch (20)

Prolog basics
Prolog basicsProlog basics
Prolog basics
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog Language
 
Introduction to Prolog
Introduction to PrologIntroduction to Prolog
Introduction to Prolog
 
Logic Programming and Prolog
Logic Programming and PrologLogic Programming and Prolog
Logic Programming and Prolog
 
PROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In Prolog
 
Prolog & lisp
Prolog & lispProlog & lisp
Prolog & lisp
 
Prolog 7-Languages
Prolog 7-LanguagesProlog 7-Languages
Prolog 7-Languages
 
PROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologPROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In Prolog
 
PROLOG: Arithmetic Operations In Prolog
PROLOG: Arithmetic Operations In PrologPROLOG: Arithmetic Operations In Prolog
PROLOG: Arithmetic Operations In Prolog
 
Expert Systems
Expert SystemsExpert Systems
Expert Systems
 
Expert Systems & Prolog
Expert Systems & PrologExpert Systems & Prolog
Expert Systems & Prolog
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 
Introdução ao Prolog
Introdução ao PrologIntrodução ao Prolog
Introdução ao Prolog
 
Hubot and Playbook - Oct 2016 ChatbotsAU meetup
Hubot and Playbook - Oct 2016 ChatbotsAU meetupHubot and Playbook - Oct 2016 ChatbotsAU meetup
Hubot and Playbook - Oct 2016 ChatbotsAU meetup
 
Ai入門 in prolog
Ai入門 in prologAi入門 in prolog
Ai入門 in prolog
 
Introduccion a prolog
Introduccion a prologIntroduccion a prolog
Introduccion a prolog
 
Prolog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb PirzadaProlog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb Pirzada
 
Ch10 Recursion
Ch10 RecursionCh10 Recursion
Ch10 Recursion
 
Prolog programming
Prolog programmingProlog programming
Prolog programming
 
Prolog: Arithmetic Operations In Prolog
Prolog: Arithmetic Operations In PrologProlog: Arithmetic Operations In Prolog
Prolog: Arithmetic Operations In Prolog
 

Ähnlich wie Introduction on Prolog - Programming in Logic

Machine Learning Applications in Subsurface Analysis: Case Study in North Sea
Machine Learning Applications in Subsurface Analysis: Case Study in North SeaMachine Learning Applications in Subsurface Analysis: Case Study in North Sea
Machine Learning Applications in Subsurface Analysis: Case Study in North SeaYohanes Nuwara
 
A brief introduction to Searn Algorithm
A brief introduction to Searn AlgorithmA brief introduction to Searn Algorithm
A brief introduction to Searn AlgorithmSupun Abeysinghe
 
Vjai paper reading201808-acl18-simple-and_effective multi-paragraph reading c...
Vjai paper reading201808-acl18-simple-and_effective multi-paragraph reading c...Vjai paper reading201808-acl18-simple-and_effective multi-paragraph reading c...
Vjai paper reading201808-acl18-simple-and_effective multi-paragraph reading c...Dat Nguyen
 
Python Revision Tour 1 Class XII CS
Python Revision Tour 1 Class XII CSPython Revision Tour 1 Class XII CS
Python Revision Tour 1 Class XII CSclass12sci
 
Real Time Systems - Deferred pre-emption
Real Time Systems - Deferred pre-emptionReal Time Systems - Deferred pre-emption
Real Time Systems - Deferred pre-emptionValentino Baraldo
 
recursive problem_solving
recursive problem_solvingrecursive problem_solving
recursive problem_solvingRajendran
 
Lec7 deeprlbootcamp-svg+scg
Lec7 deeprlbootcamp-svg+scgLec7 deeprlbootcamp-svg+scg
Lec7 deeprlbootcamp-svg+scgRonald Teo
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02mansab MIRZA
 
Asymptotic Notations.pptx
Asymptotic Notations.pptxAsymptotic Notations.pptx
Asymptotic Notations.pptxSunilWork1
 
On Applying Or-Parallelism and Tabling to Logic Programs
On Applying Or-Parallelism and Tabling to Logic ProgramsOn Applying Or-Parallelism and Tabling to Logic Programs
On Applying Or-Parallelism and Tabling to Logic ProgramsLino Possamai
 
Answer Span Correction in Machine Reading Comprehension
Answer Span Correction in Machine Reading ComprehensionAnswer Span Correction in Machine Reading Comprehension
Answer Span Correction in Machine Reading ComprehensionEfsun Kayi
 
Functional Programming Principles & Patterns
Functional Programming Principles & PatternsFunctional Programming Principles & Patterns
Functional Programming Principles & Patternszupzup.org
 
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...Kenshi Abe
 
DGraph: Introduction To Basics & Quick Start W/Ratel
DGraph: Introduction To Basics & Quick Start W/RatelDGraph: Introduction To Basics & Quick Start W/Ratel
DGraph: Introduction To Basics & Quick Start W/RatelKnoldus Inc.
 
Explaining the Basics of Mean Field Variational Approximation for Statisticians
Explaining the Basics of Mean Field Variational Approximation for StatisticiansExplaining the Basics of Mean Field Variational Approximation for Statisticians
Explaining the Basics of Mean Field Variational Approximation for StatisticiansWayne Lee
 
Stochastic Definite Clause Grammars
Stochastic Definite Clause GrammarsStochastic Definite Clause Grammars
Stochastic Definite Clause GrammarsChristian Have
 
L05 language model_part2
L05 language model_part2L05 language model_part2
L05 language model_part2ananth
 

Ähnlich wie Introduction on Prolog - Programming in Logic (20)

Machine Learning Applications in Subsurface Analysis: Case Study in North Sea
Machine Learning Applications in Subsurface Analysis: Case Study in North SeaMachine Learning Applications in Subsurface Analysis: Case Study in North Sea
Machine Learning Applications in Subsurface Analysis: Case Study in North Sea
 
A brief introduction to Searn Algorithm
A brief introduction to Searn AlgorithmA brief introduction to Searn Algorithm
A brief introduction to Searn Algorithm
 
Vjai paper reading201808-acl18-simple-and_effective multi-paragraph reading c...
Vjai paper reading201808-acl18-simple-and_effective multi-paragraph reading c...Vjai paper reading201808-acl18-simple-and_effective multi-paragraph reading c...
Vjai paper reading201808-acl18-simple-and_effective multi-paragraph reading c...
 
Python Revision Tour 1 Class XII CS
Python Revision Tour 1 Class XII CSPython Revision Tour 1 Class XII CS
Python Revision Tour 1 Class XII CS
 
Real Time Systems - Deferred pre-emption
Real Time Systems - Deferred pre-emptionReal Time Systems - Deferred pre-emption
Real Time Systems - Deferred pre-emption
 
recursive problem_solving
recursive problem_solvingrecursive problem_solving
recursive problem_solving
 
Lec7 deeprlbootcamp-svg+scg
Lec7 deeprlbootcamp-svg+scgLec7 deeprlbootcamp-svg+scg
Lec7 deeprlbootcamp-svg+scg
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02
 
Asymptotic Notations.pptx
Asymptotic Notations.pptxAsymptotic Notations.pptx
Asymptotic Notations.pptx
 
On Applying Or-Parallelism and Tabling to Logic Programs
On Applying Or-Parallelism and Tabling to Logic ProgramsOn Applying Or-Parallelism and Tabling to Logic Programs
On Applying Or-Parallelism and Tabling to Logic Programs
 
Answer Span Correction in Machine Reading Comprehension
Answer Span Correction in Machine Reading ComprehensionAnswer Span Correction in Machine Reading Comprehension
Answer Span Correction in Machine Reading Comprehension
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
Functional Programming Principles & Patterns
Functional Programming Principles & PatternsFunctional Programming Principles & Patterns
Functional Programming Principles & Patterns
 
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
 
DGraph: Introduction To Basics & Quick Start W/Ratel
DGraph: Introduction To Basics & Quick Start W/RatelDGraph: Introduction To Basics & Quick Start W/Ratel
DGraph: Introduction To Basics & Quick Start W/Ratel
 
Explaining the Basics of Mean Field Variational Approximation for Statisticians
Explaining the Basics of Mean Field Variational Approximation for StatisticiansExplaining the Basics of Mean Field Variational Approximation for Statisticians
Explaining the Basics of Mean Field Variational Approximation for Statisticians
 
Chap05
Chap05Chap05
Chap05
 
Stochastic Definite Clause Grammars
Stochastic Definite Clause GrammarsStochastic Definite Clause Grammars
Stochastic Definite Clause Grammars
 
L05 language model_part2
L05 language model_part2L05 language model_part2
L05 language model_part2
 

Mehr von Vishal Tandel

Case study on Physical devices used in Computer forensics.
Case study on Physical devices used in Computer forensics.Case study on Physical devices used in Computer forensics.
Case study on Physical devices used in Computer forensics.Vishal Tandel
 
honey pots introduction and its types
honey pots introduction and its typeshoney pots introduction and its types
honey pots introduction and its typesVishal Tandel
 
Introduction of Windows azure and overview
Introduction of Windows azure and overviewIntroduction of Windows azure and overview
Introduction of Windows azure and overviewVishal Tandel
 
Mobile transport layer - traditional TCP
Mobile transport layer - traditional TCPMobile transport layer - traditional TCP
Mobile transport layer - traditional TCPVishal Tandel
 
Case Study on Google.
Case Study on Google.Case Study on Google.
Case Study on Google.Vishal Tandel
 
Cluster analysis for market segmentation
Cluster analysis for market segmentationCluster analysis for market segmentation
Cluster analysis for market segmentationVishal Tandel
 

Mehr von Vishal Tandel (7)

Case study on Physical devices used in Computer forensics.
Case study on Physical devices used in Computer forensics.Case study on Physical devices used in Computer forensics.
Case study on Physical devices used in Computer forensics.
 
honey pots introduction and its types
honey pots introduction and its typeshoney pots introduction and its types
honey pots introduction and its types
 
Introduction of Windows azure and overview
Introduction of Windows azure and overviewIntroduction of Windows azure and overview
Introduction of Windows azure and overview
 
Mobile transport layer - traditional TCP
Mobile transport layer - traditional TCPMobile transport layer - traditional TCP
Mobile transport layer - traditional TCP
 
Route maps
Route mapsRoute maps
Route maps
 
Case Study on Google.
Case Study on Google.Case Study on Google.
Case Study on Google.
 
Cluster analysis for market segmentation
Cluster analysis for market segmentationCluster analysis for market segmentation
Cluster analysis for market segmentation
 

Kürzlich hochgeladen

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 

Kürzlich hochgeladen (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 

Introduction on Prolog - Programming in Logic

  • 1. Presented By – Tandel Vishal P. Prolog
  • 2. ● What is Prolog? ● Syntax of Prolog ● Prolog Control Strategy ● Interface architecture ● Prolog Query ● Programming Techniques ● Termination ● Rule Order ● Goal Order ● Redundancy ● Iteration in Prolog ● conclusion
  • 3. ● Prolog is acronym of PROgramming in LOGic. ● Prolog program is sequence of rules and facts. ● Prolog Rule for grandfather is defined as: gfather(X, Y) :- father(X, Z), parent(Z, Y). father(james, robert).
  • 4. ● The rules and facts in Prolog are terminated by full stop (.). ● Goal can be included in the program or given at the prompt. ● Goal can be single or conjunction of sub-goal(s) terminated by full stop. ● Constants are numerals and symbols such as, 4, mary, etc. ● String is a sequence of characters and is enclosed within single quotes e.g., 'This is a string'. ● Predicate names must start with alphabet and are formed by using lower case letters, numerals and underscore ( _ ). ● Variable names are formed similar to predicate names but it must start with upper case letter. Normally, we use X, Y, Z, ... for variables.
  • 5. ● Prolog contains three basic control strategies. − Forward movement − Matching (Unification) − Backward movement (Backtracking) ● Prolog uses depth first search strategy.
  • 6. ● Choose a rule by − searching sequentially in the program from top to bottom whose head matches with the goal with possible unifier. − Remember the position of the matched rule. − Join the rule body in front of the sequence of sub goals to be solved. ● Repeat until either goal is satisfied or is failed.
  • 7. ● Consider the following query consisting of n sub-goals. ?- G1, ... , Gi-1, Gi, ... , Gn ● Starts executing or satisfying G1 − If G1 is satisfied using some rule, put a place marker so that next rule for G1 will be searched after the marker. − Continue in forward direction to satisfy G2 and if it is satisfied then continue with common bindings of the variables in sub-goals so far satisfied. − Such a movement is called forward
  • 8. ● Unification is a process of matching or finding the most general unifier. − Constant matches with the same constant. − A variable can match with any constant or any another variable. ● Examples − love(X, sita) unifies with love(ram, sita) with mgu as {X / ram}. − love(X, Y) unify with love(ram, sita) with mgu as {X/ram, Y/sita} respectively.
  • 9. ● Backtracking refers to backtrack in search process for a solution. ● In Prolog, backtracking takes place in two situations. − First when a sub goal fails and − Other when the last sub goal succeeds, it backtracks to find alternative solutions.
  • 10. ● Prolog has two kinds of backtracking. − Shallow and − Deep backtracking ● Both backtrackings take place in conjunction with each other. ● Shallow backtracking occurs − when alternative definition of the goal is tried. − Suppose G1,.., Gi-1 have been satisfied with some common bindings of the variables in sub-goals. − While satisfying Gi., if it fails for some rule then try another rule of Gi − This is called shallow backtracking to rules of the same sub-goal
  • 11. ● Deep backtracking occurs − When sub-goal Gi fails for all rules of Gi then backtrack to Gi-1. − This backtracking is called deep backtracking. − Remove the bindings created earlier to satisfy Gi-1. − Try to satisfy Gi-1 again by using an alternative rule, if it exists, from last place marker of Gi-1. and continue the process. − If sub goal Gi-1 is satisfied then move forward to Gi, else backtrack to Gi-2. − The process of backtracking continues till we reach G1. − If G1 fails for all possible definitions, then entire query fails.
  • 12. ● If entire conjunction of sub-goals succeed, then the solution is displayed. ● For alternative solution, the sub goal Gn is tried to be satisfied with alternative rule, if it exist, after last place marker (Shallow backtracking) of Gn . ● Otherwise it backtracks to previous sub goal Gn-1 (Deep backtracking). ● Process is repeated till all possible solutions are generated.
  • 13.
  • 14. ● Two types of query − Ground query  No variable in the argument  Example: ? gfather(ram, shyam) – Is ram a grand father of shyam?  Answer to ground queries are Yes or No  Proof tree is generated while solving the query. − Non ground query  Atleast one argument is a variable  Example: ? gfather(X, shyam) – Who is a grand father of shyam?  Answer to such queries are the values bound to the variables in the query.  Search tree is generated using DFS to find all possible solutions.
  • 15. Ground query: ?- gfather(james, hency). Proof tree: ?- gfather(james, hency). (1) ?- father(james, Z), parent(Z, hency). (4) { Z = robert } ?- parent(robert, hency). (2) ?- father(robert, hency). (7) succeeds Answer: Yes
  • 16. Non-Ground query: ?- gfather(william, X). Search tree: ?- gfather(william, X). (1) ?- father(william, Z), parent(Z, X). (6) {Z = james} ?- parent(james, X). (2) (3) ?- father(james, X). ?- mother(james, X). (4) {X = robert} succeeds fails Answer: X = robert
  • 17. ● Recursion is one of the most important execution control techniques in Prolog. ● Iteration is another important programming technique. ● Prolog does not support iteration. ● It can be achieved by − making recursive call to be the last sub goal in the rule − using the concept of accumulators which are special types of arguments used for holding intermediate results. ● The issues of termination, rule order, goal order and redundancy are also important.
  • 18. ● Consider a classical example of computing factorial using recursion. ● Recurrence relation or mathematical definition for computing factorial of positive integer is: 1, if n = 0 FACTORIAL (n) = n * FACTORIAL (n-1), otherwise ● In Prolog, program for computing factorial of a positive number is written using above definition. ● Factorial predicate contains two arguments; one as input and another as output.
  • 19. /*fact(N, R) – succeeds if R is unified with the factorial of N */ factorial(0, 1). (1) factorial(N, R) :- N1 is N–1, factorial(N1, R1), R is N * R1. (2) ● Rule (1) states that factorial of 0 is 1 which is a terminating clause. ● Rule (2) is a recursive rule which states that factorial of N is calculated by multiplying N with factorial of (N-1). Goal: ?- factorial(3, R).
  • 20.  Depth first traversal of Prolog has a serious problem. If the search tree of a goal with respect to a program contains an infinite branch, the computation will not terminate.  Prolog may fail to find a solution of a goal, even if the goal has a finite computation.  Non termination arises because of the following reasons: − Left recursive rules: The rule having a recursive goal as the first sub goal in the body.
  • 21. ● Consider acyclic directed graph p q r s t ● Graph G is represented by set of connected edges. G = { edge(p, q), edge(q, r), edge(q, s), edge(s, t)} ● Write Prolog Program to check whether there is a route from one node to another node.
  • 22. ● Route from node A to B is defined as follows: − route from A to B if there is a root from A some node C and an edge from C to B. − route from A to B if there is a direct edge from A to B. ● Prolog Program route(A, B) :- route(A, C), edge(C, B). (1) route(A, B) :- edge(A, B). (2) edge(p, q). edge(q, r). edge(q, s). edge(s, t). Query: Check whether there exist a route between nodes p and t .
  • 23. Goal: ?- route(p, t). Proof tree:?- route(p, t). (1) ?- route(p, X), edge(X, t) (1) ?- route(p, Y), edge(Y, X), edge(X, t). Non terminating ● Non terminating program because of left recursion. ● Better way of writing a rule is to write recursive call as the last call. route(A, B) :- edge(A, C), route(C, B).
  • 24. ● A rule order is very important issue in Prolog. ● Change of the order of rules in a program, the branches in any search tree for a goal to be solved with that program get permuted. ● It may affect the efficiency of executing goal. ● Since the search tree is traversed using depth first approach, the order of solutions will be different.
  • 25. ● Goal order in Prolog is more significant than rule order. ● It may affect the termination because − subsequent sub goals have different bindings and hence different search trees. ● Consider the following recursive rules. ancester(X, Y) :- parent(X, Z), ancester(Z, Y). route(X, Y) :- edge(X, Z), route(Z, Y). ● If the sub goals in the body of above rules are swapped, then the rules becomes left recursive and all the computations will become non terminating. ● It also affects the amount of search the program does in solving a query .
  • 26. ● Redundancy of the solution to the queries is another important issue in Prolog programs. ● In Prolog, each possible deduction means an extra branch in the search tree. ● The bigger the search tree, higher the computation time. ● It is desirable in general to keep the size of the search tree as small as possible. ● Redundant program at times may cause exponential increase in runtime in the event of backtracking. ● There are various reasons by which redundancy gets introduced. − The same case is covered by several rules − Redundancy in computation appears in the program by not handling special cases separately.
  • 27.  Prolog does not have storage variables that can − hold intermediate results of the computation − be modified as the computation progress.  To implement iterative algorithm one requires the storage of intermediate results, Prolog predicates are augmented with additional arguments called accumulators.  These are similar to local variables in procedural languages.  The programs written using accumulators are iterative in nature.  In iterative form of a program, make the recursive call as the last call if possible.
  • 28. ● Prolog has helped more than 6,000 organization reduce construction project risk, control project costs, and provide complete transparency to project stakeholders, becoming the industry standard for construction project control and visibility. Prolog Enables you to Your Benefit Automate Task and process Complete automation from project design to close-out Streamline project Delivery Manage all construction projects in one system Control cost Real-time cost management tools and budget tracking Increase Productivity Real-time collaboration with geographically dispersed project teams Reduce Legal Risk Audited access to data and documents in one central location Monitor Project performance Access to real time metrics tracking and dashboards Extend The value of your Software investment Integrating your construction project data with other technology system and devices (accounting , Microsoft Office, BIM models, and handheld devices)