SlideShare une entreprise Scribd logo
1  sur  48
Télécharger pour lire hors ligne
Chapter 10: Logic Programming Languages 
Principles of Programming Languages
Contents 
•Predicate Calculus and Proving Theorems 
•The Basic Elements of Prolog 
•Simple Arithmetic and List in Prolog 
•Deficiencies of Prolog 
•Applications of Logic Programming
•Another programming methodology: 
–Express programs in a form of symbolic logic 
–Use a logical inferencing process to produce results 
•Prolog 
Introduction
•Proposition: a statement that may or may not be true 
–James I is a male 
–Catherine is a female 
–James I is parent of Charles I 
–Catherine is parent of Sophia 
•Compound term: functor + parameter lists 
male(james1) 
female(catherine) 
parent(james1, charles1) 
parent(catherine, sophia) 
•Two modes: facts or queries 
Proposition
Logic Operators 
¬ a 
negation 
a ˄ b 
conjunction 
a ˅ b 
disjunction 
a → b 
implication 
a ↔ b 
equivalence 
•Examples: 
(a ˄ b) → c
Predicates 
•When we employ variables, the truth value of a statement is unknown until the variable has a specific value 
–X is a male 
–male(X) 
•Predicates turn into propositions if they have quantifiers 
∀X (woman(X) → human(X)) 
∃X (mother(mary, X) ˄ male(X))
Clausal Form 
•A standard form for propositions 
B1 ˅ B2 ˅ …˅ Bn ← A1 ˄ A2 ˄ … ˄ Am 
•Examples 
mother(catherine, sophia) ← parent(catherine, sophia) ˄ female(catherine) 
father(louis, al) ˅ father(louis, violet) ← father(al, bob) ˄ mother(violet, bob) ˄ grandfather(louis, bob) 
•RHS = antecedent 
•LHS = consequent
Automatic Theorem Proving 
•Resolution: if we have 
older(joanne, jake) ← mother(joanne, jake) 
wiser(joanne, jake) ← older(joanne, jake) 
•Using resolution, we can construct 
wiser(joanne, jake) ← mother(joanne, jake) 
•Mechanics: 
1.AND two LHS to make the new LHS 
2.AND two RHS to make the new RHS 
3.Remove any terms that appear in the both sides
Questions 
father(bob, jake) ˅ mother(bob, jake) ← parent(bob, jake) 
grandfather(bob, fred) ← father(bob, jake) ˄ father(jake, fred) 
What can we infer?
Horn Clauses 
•When propositions are used for resolution, only a restricted kind of clausal form can be used 
•There are two forms of Horn clauses: 
–Headed: They have single atomic proposition on the LHS 
likes(bob, trout) ← likes(bob, fish) ˄ fish(trout) 
–Headless: Empty LHS 
father(bob, jake)
Resolution 
•Ability to detect any inconsistency in a given set of propositions 
•Theorem is proved by 
–We are given a set of pertinent propositions 
–Negation of theorem as a new proposition 
–Resolution is used to find inconsistency 
•Hypotheses: a set of original propositions 
•Goal: negation of theorem stated as a proposition
An Overview of Logic Programming 
•Declarative, rather that procedural or functional 
•Specify relation between objects 
–larger(3, 2) 
–father(tom, jane) 
•Separate logic from control: 
–Programmer declares what facts and relations are true 
–System determines how to use facts to solve problems 
–System instantiates variables in order to make relations true
Example: Sorting a List 
•Describe the characteristics of a sorted list, not the process of rearranging a list 
sort(old_list, new_list) ← permute (old_list, new_list) ˄ 
sorted (new_list) 
sorted (list) ← j such that 1 j < n, list(j)  list (j+1)
The Origins of Prolog 
•Alain Colmerauer at Marseille in 1970s 
–Natural language processing 
•University of Edinburgh 
–Automated theorem proving 
•1981, Japanese Fifth Generation Computing Systems choose Prolog as the basis 
•Despite the great assumed potential of logic programming and Prolog, little great significance had been covered
Facts 
male(charlie). 
male(bob). 
female(alice). 
female(eve). 
parent(charlie, bob). 
parent(eve, bob). 
parent(charlie, alice). 
parent(eve, alice). 
•Headless Horn clauses 
•Every Prolog statement is terminated by a period
Rules 
•Headed Horn clauses 
mother(X, Y) ← female(X) ˄ parent(X, Y) 
mother(X, Y) :- female(X), parent(X, Y).
Queries 
•Let the computer know the facts, then ask it some questions – queries 
•Ask the system to prove or disprove a theorem 
?- mother(sophia, george1). 
true 
•Ask the system to identify the instantiation of variables that make the query true 
?- mother(X, sophia). 
X = Elizabeth 
false
Some Prolog Syntax 
•Layer 0: constants and variables 
•Constants are: 
–Atoms: any string consisting of alphanumeric characters and underscore (_) that begins with a lowercase letter 
–Numbers 
•Variables are strings that begin with “_” or an uppercase letter
Some Prolog Syntax 
const -> atom | number 
var -> ucase string | _ string 
atom -> lcase string 
letter -> ucase | lcase 
string -> epsilon | letter string 
| number string | _ string 
ucase -> A | ... | Z 
lcase -> a | ... | z 
number -> ...
Some Prolog Syntax 
•Layer 1: terms 
•These are inductively defined: 
–Constants and variables are terms 
–Compound terms – applications of any n-ary functor to any n terms – are terms 
–Nothing else is a term
Some Prolog Syntax 
•Layer 2: atomic formulae 
•These consist of an n-ary relation (also called predicate) applied to n terms 
•Formulae are either true or false; terms denote entities in the world 
•In Prolog, atomic formulae can be used in three ways: 
–As facts: in which they assert truth 
–As queries: in which they enquire about truth 
–As components of more complicated statements
Some Prolog Syntax 
term -> const | var | 
functor “(“ term (“,” term)* “)” 
pred -> pname “(“ term (“,” term)* “)”
Prolog Queries 
•A query is a proposed fact that is to be proven 
–If the query has no variables, returns true/false 
–If the query has variables, returns appropriate values of variables (called a substitution) 
?- male(charlie). 
true 
?- male(eve). 
false 
?- female(Person). 
Person = alice; 
Person = eve; 
false
Terms 
•Horn Clause = Clause 
•Consequent = Goal = Head 
•Antecedents = Subgoals = Tail 
•Horn Clause with No Tail = Fact 
•Horn Clause with Tail = Rule
Some Prolog Syntax 
clause-> pred . | 
pred :- pred (“,” pred)* . 
term -> const | var | 
functor “(“ term (“,” term)* “)” 
pred -> pname “(“ term (“,” term)* “)” 
const -> ... 
var -> ...
Variables 
•Variables may appear in the LHS or RHS of a clause. Prolog interprets free variables of a rule universally 
mother(X) :- female(X), parent(X, Y). 
In first-order logic: 
∀X mother(X) ← ∃Y parent(X, Y) ˄ female(X) 
•Note that the Prolog query 
?-q(X1, ..., Xn) 
means 
∃X1,...,Xn q(X1, …, Xn)
Execution of Prolog Programs 
•Unification: variable bindings 
•Backward Chaining/Top-Down Reasoning/Goal Directed Reasoning: reduces a goal to one or more subgoals 
•Backtracking: systematically searches for all possible solutions that can be obtained via unification and backchaining.
Unification 
•Two atomic formulae unify iff they can be made syntactically identical by replacing their variables by other terms 
•For example: 
–parent(bob,Y) unifies with parent(bob,sue) by replacing Y by sue 
?-parent(bob,Y)=parent(bob,sue) 
Y = sue ; 
false 
–parent(bob,Y) unifies with parent(X,sue) by replacing Y by sue and X by bob 
?-parent(bob,Y)=parent(X,sue). 
Y = sue 
X = bob ; 
false
Unification Algorithm 
Equation 
Action 
f(s1, ..., sn) = f(t1, ..., tn) 
Replace with s1 = t1, ..., sn = tn 
f(s1, ..., sn) = g(t1, ..., tn) where f ≠ g 
Halt with failure 
X = X 
Delete the equation 
t = X where t is not a variable 
Replace with X = t 
X = t where X does not occur in t and it occurs elsewhere 
Apply the substitution X = t to all other terms 
X = t where X occurs in t (but t ≠ X) 
Halt with failure
Prolog Search Trees 
•Encapsulate unification, backward chaining, and backtracking 
–Internal nodes are ordered list of subgoals 
–Leaves are success nodes or failures, where computation can proceed no further 
–Edges are labeled with variable bindings that occur by unification 
•Describe all possible computation paths 
–There can be many success nodes 
–There can be infinite branches
Prolog Search Tree 
/* program P clause # */ 
p(a). /* #1 */ 
p(X) :- q(X), r(X). /* #2 */ 
p(X) :- u(X). /* #3 */ 
q(X) :- s(X). /* #4 */ 
r(a). /* #5 */ 
r(b). /* #6 */ 
s(a). /* #7 */ 
s(b). /* #8 */ 
s(c). /* #9 */ 
u(d). /* #10 */ 
?- p(X)
[trace] ?- p(X). 
Call: (7) p(_G312) ? creep 
Exit: (7) p(a) ? creep 
X = a ; 
Redo: (7) p(_G312) ? creep 
Call: (8) q(_G312) ? creep 
Call: (9) s(_G312) ? creep 
Exit: (9) s(a) ? creep 
Exit: (8) q(a) ? creep 
Call: (8) r(a) ? creep 
Exit: (8) r(a) ? creep 
Exit: (7) p(a) ? creep 
X = a ; 
Redo: (9) s(_G312) ? creep 
Exit: (9) s(b) ? creep 
Exit: (8) q(b) ? creep 
Call: (8) r(b) ? creep 
Exit: (8) r(b) ? creep 
Exit: (7) p(b) ? creep 
X = b ; 
Redo: (9) s(_G312) ? creep 
Exit: (9) s(c) ? creep 
Exit: (8) q(c) ? creep 
Call: (8) r(c) ? creep 
Fail: (8) r(c) ? creep 
Redo: (7) p(_G312) ? creep 
Call: (8) u(_G312) ? creep 
Exit: (8) u(d) ? creep 
Exit: (7) p(d) ? creep 
X = d ; 
No
Approaches 
•Prolog implementations use backward chaining 
•Top-down resolution, backward chaining 
–Begin with goal and attempt to find sequence that leads to set of facts in database 
–Works well with a small set of possibly correct answers 
•Bottom-up resolution, forward chaining 
–Begin with facts and rules of database and attempt to find sequence that leads to goal 
–Works well with a large set of possibly correct answers
Subgoal Strategies 
•When goal has more than one subgoal, can use either 
–Depth-first search: find a complete proof for the first subgoal before working on others 
–Breadth-first search: work on all subgoals in parallel 
•Prolog uses depth-first search 
–Can be done with fewer computer resources
Backtracking 
•With a goal with multiple subgoals, if fail to show truth of one of subgoals, reconsider previous subgoal to find an alternative solution: backtracking 
•Begin search where previous search left off 
•Can take lots of time and space because may find all possible proofs to every subgoal
Trace 
•Built-in structure that displays instantiations at each step 
•Tracing model of execution - four events: 
–Call (beginning of attempt to satisfy goal) 
–Exit (when a goal has been satisfied) 
–Redo (when backtrack occurs) 
–Fail (when goal fails)
Example 
likes(jake,chocolate). 
likes(jake,apricots). 
likes(darcie,licorice). 
likes(darcie,apricots). 
trace. 
likes(jake,X), 
likes(darcie,X).
Simple Arithmetic 
•Prolog supports integer variables and integer arithmetic 
•is operator: takes an arithmetic expression as right operand and variable as left operand 
A is B / 17 + C 
•Not the same as an assignment statement!
Example 
speed(ford,100). 
speed(chevy,105). 
speed(dodge,95). 
speed(volvo,80). 
time(ford,20). 
time(chevy,21). 
time(dodge,24). 
time(volvo,24). 
distance(X,Y) :- speed(X,Speed), 
time(X,Time), 
Y is Speed * Time.
List Structures 
•List is a sequence of any number of elements 
•Elements can be atoms, atomic propositions, or other terms (including other lists) 
[apple, prune, grape, kumquat] 
[] (empty list) 
[H | T] (head H and tail T)
Append Example 
append([], List, List). 
append([Head | List_1], List_2, [Head | List_3]) :- 
append (List_1, List_2, List_3).
Another Example 
whatisme([], []). 
whatisme([Head | Tail], List) :- 
whatisme(Tail, Result), 
append(Result, [Head], List). 
•Try to write member rule to check if an element is a member of a list
Deficiencies of Prolog 
•Resolution order control 
–Prolog always matches in the same order – user can control the ordering 
–Prolog allows explicit control of backtracking via cut operator -- “!”, which is actually a goal, not an operator 
•Always succeed but cannot be resatisfied through backtracking 
a, b, !, c, d 
–It is detrimental to one of the important advantages of logic programming – programs do not specify how solutions are to be found.
Deficiencies of Prolog 
•The closed-world assumption 
–In Prolog, the truths are those that can be proved using its database 
–If there is insufficient information in the database to prove a query, it is not actually false, it fails 
–It relates to negation problem
Deficiencies of Prolog 
•The negation problem 
–Stating that two atoms are not equal is not straightforward in Prolog 
–Bad solution: adding facts stating that they are not the same 
–Alternative: state in the goal that X must not be the same as Y 
sibling(X, Y) :- parent(M, X), parent(M, Y), not(X=Y) 
–However, not operator is not logical NOT, not(not(some_goal)) is not equivalent to some_goal 
–Reason: the use of Horn clause form prevents any negative conclusions
Deficiencies of Prolog 
•Intrinsic limitations 
–Prolog has no idea of how to sort, other than simply to enumerate all permutations of the given list until it happens to create the one that has the list in sorted order 
–We must specify the details of how that sorting can be done – not logic programming any more 
–Resolution is not capable of doing this sorting
Applications of Logic Programming 
•Relational database management systems 
–Logic programming is a natural match to the needs of implementing a RDBMS 
SQL is goal, tables are facts 
•Expert systems 
–Computer systems designed to emulate human expertise in some particular domain 
–In addition to the initial knowledge base, ES can learn from the process of being used 
•Natural language processing
Summary 
•Symbolic logic provides basis for logic programming 
•Logic programs should be nonprocedural 
•Prolog statements are facts, rules, or goals 
•Resolution is the primary activity of a Prolog interpreter 
•Although there are a number of drawbacks with the current state of logic programming it has been used in a number of areas

Contenu connexe

Tendances

L03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicL03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicManjula V
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prologsaru40
 
knowledge representation using rules
knowledge representation using rulesknowledge representation using rules
knowledge representation using rulesHarini Balamurugan
 
Prolog example explanation(Family Tree)
Prolog example explanation(Family Tree)Prolog example explanation(Family Tree)
Prolog example explanation(Family Tree)Gayan Geethanjana
 
Prolog Programming Language
Prolog Programming  LanguageProlog Programming  Language
Prolog Programming LanguageReham AlBlehid
 
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologDataminingTools Inc
 
Propositional And First-Order Logic
Propositional And First-Order LogicPropositional And First-Order Logic
Propositional And First-Order Logicankush_kumar
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AIMegha Sharma
 
First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)chauhankapil
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)Nitesh Singh
 
Introduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicIntroduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicVishal Tandel
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introductionwahab khan
 
Boyer moore algorithm
Boyer moore algorithmBoyer moore algorithm
Boyer moore algorithmAYESHA JAVED
 
Predicate calculus
Predicate calculusPredicate calculus
Predicate calculusRajendran
 

Tendances (20)

L03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicL03 ai - knowledge representation using logic
L03 ai - knowledge representation using logic
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
knowledge representation using rules
knowledge representation using rulesknowledge representation using rules
knowledge representation using rules
 
Prolog example explanation(Family Tree)
Prolog example explanation(Family Tree)Prolog example explanation(Family Tree)
Prolog example explanation(Family Tree)
 
Prolog Programming Language
Prolog Programming  LanguageProlog Programming  Language
Prolog Programming Language
 
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In Prolog
 
Propositional And First-Order Logic
Propositional And First-Order LogicPropositional And First-Order Logic
Propositional And First-Order Logic
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
 
Propositional Logic and Pridicate logic
Propositional Logic and Pridicate logicPropositional Logic and Pridicate logic
Propositional Logic and Pridicate logic
 
First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
 
Introduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicIntroduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in Logic
 
Rule based system
Rule based systemRule based system
Rule based system
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Backtracking
BacktrackingBacktracking
Backtracking
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
 
Boyer moore algorithm
Boyer moore algorithmBoyer moore algorithm
Boyer moore algorithm
 
Predicate calculus
Predicate calculusPredicate calculus
Predicate calculus
 
Problem Solving
Problem Solving Problem Solving
Problem Solving
 
String matching, naive,
String matching, naive,String matching, naive,
String matching, naive,
 

En vedette

Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
How to build a news website use CMS wordpress
How to build a news website use CMS wordpressHow to build a news website use CMS wordpress
How to build a news website use CMS wordpressbaran19901990
 
09 implementing+subprograms
09 implementing+subprograms09 implementing+subprograms
09 implementing+subprogramsbaran19901990
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentationbaran19901990
 
Nhập môn công tác kỹ sư
Nhập môn công tác kỹ sưNhập môn công tác kỹ sư
Nhập môn công tác kỹ sưbaran19901990
 
Config websocket on apache
Config websocket on apacheConfig websocket on apache
Config websocket on apachebaran19901990
 
Memory allocation
Memory allocationMemory allocation
Memory allocationsanya6900
 
Chapter 9 & chapter 10 solutions
Chapter 9 & chapter 10 solutionsChapter 9 & chapter 10 solutions
Chapter 9 & chapter 10 solutionsSaeed Iqbal
 
Penyederhanaan Karnaugh Map
Penyederhanaan Karnaugh MapPenyederhanaan Karnaugh Map
Penyederhanaan Karnaugh MapCheria Asyifa
 
Aljabar boolean
Aljabar booleanAljabar boolean
Aljabar booleanfarhan2000
 
Lecture # 2
Lecture # 2Lecture # 2
Lecture # 2Mr SMAK
 

En vedette (20)

Unit 5
Unit 5Unit 5
Unit 5
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Introduction to Prolog
Introduction to PrologIntroduction to Prolog
Introduction to Prolog
 
Hadoop
HadoopHadoop
Hadoop
 
How to build a news website use CMS wordpress
How to build a news website use CMS wordpressHow to build a news website use CMS wordpress
How to build a news website use CMS wordpress
 
09 implementing+subprograms
09 implementing+subprograms09 implementing+subprograms
09 implementing+subprograms
 
Introduction to HBase
Introduction to HBaseIntroduction to HBase
Introduction to HBase
 
08 subprograms
08 subprograms08 subprograms
08 subprograms
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Datatype
DatatypeDatatype
Datatype
 
Chapter2
Chapter2Chapter2
Chapter2
 
Nhập môn công tác kỹ sư
Nhập môn công tác kỹ sưNhập môn công tác kỹ sư
Nhập môn công tác kỹ sư
 
Config websocket on apache
Config websocket on apacheConfig websocket on apache
Config websocket on apache
 
Control structure
Control structureControl structure
Control structure
 
Memory allocation
Memory allocationMemory allocation
Memory allocation
 
Chapter 9 & chapter 10 solutions
Chapter 9 & chapter 10 solutionsChapter 9 & chapter 10 solutions
Chapter 9 & chapter 10 solutions
 
Penyederhanaan Karnaugh Map
Penyederhanaan Karnaugh MapPenyederhanaan Karnaugh Map
Penyederhanaan Karnaugh Map
 
Aljabar boolean
Aljabar booleanAljabar boolean
Aljabar boolean
 
Lecture # 2
Lecture # 2Lecture # 2
Lecture # 2
 
Chapter 17 dccn
Chapter 17 dccnChapter 17 dccn
Chapter 17 dccn
 

Similaire à 10 logic+programming+with+prolog

Knowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and ReasoningKnowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and ReasoningSagacious IT Solution
 
#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logicSharif Omar Salem
 
17 1 knowledge-based system
17 1 knowledge-based system17 1 knowledge-based system
17 1 knowledge-based systemTianlu Wang
 
Otter 2014-12-01-01-slideshare-2
Otter 2014-12-01-01-slideshare-2Otter 2014-12-01-01-slideshare-2
Otter 2014-12-01-01-slideshare-2Ruo Ando
 
Stochastic Processes Homework Help
Stochastic Processes Homework HelpStochastic Processes Homework Help
Stochastic Processes Homework HelpExcel Homework Help
 
Predlogic
PredlogicPredlogic
Predlogicsaru40
 
Challenge@RuleML2015 Datalog+, RuleML and OWL 2 - Formats and Translations f...
Challenge@RuleML2015  Datalog+, RuleML and OWL 2 - Formats and Translations f...Challenge@RuleML2015  Datalog+, RuleML and OWL 2 - Formats and Translations f...
Challenge@RuleML2015 Datalog+, RuleML and OWL 2 - Formats and Translations f...RuleML
 
Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingFilip De Sutter
 

Similaire à 10 logic+programming+with+prolog (20)

Prolog
PrologProlog
Prolog
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
Knowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and ReasoningKnowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and Reasoning
 
chapter9.ppt
chapter9.pptchapter9.ppt
chapter9.ppt
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
 
#8 formal methods – pro logic
#8 formal methods – pro logic#8 formal methods – pro logic
#8 formal methods – pro logic
 
17 1 knowledge-based system
17 1 knowledge-based system17 1 knowledge-based system
17 1 knowledge-based system
 
Otter 2014-12-01-01-slideshare-2
Otter 2014-12-01-01-slideshare-2Otter 2014-12-01-01-slideshare-2
Otter 2014-12-01-01-slideshare-2
 
artficial intelligence
artficial intelligenceartficial intelligence
artficial intelligence
 
AI IMPORTANT QUESTION
AI IMPORTANT QUESTIONAI IMPORTANT QUESTION
AI IMPORTANT QUESTION
 
Prolog2 (1)
Prolog2 (1)Prolog2 (1)
Prolog2 (1)
 
1. Logic and Proofs.ppt
1. Logic and Proofs.ppt1. Logic and Proofs.ppt
1. Logic and Proofs.ppt
 
PropositionalLogic.ppt
PropositionalLogic.pptPropositionalLogic.ppt
PropositionalLogic.ppt
 
Stochastic Processes Homework Help
Stochastic Processes Homework Help Stochastic Processes Homework Help
Stochastic Processes Homework Help
 
Stochastic Processes Homework Help
Stochastic Processes Homework HelpStochastic Processes Homework Help
Stochastic Processes Homework Help
 
Predlogic
PredlogicPredlogic
Predlogic
 
Challenge@RuleML2015 Datalog+, RuleML and OWL 2 - Formats and Translations f...
Challenge@RuleML2015  Datalog+, RuleML and OWL 2 - Formats and Translations f...Challenge@RuleML2015  Datalog+, RuleML and OWL 2 - Formats and Translations f...
Challenge@RuleML2015 Datalog+, RuleML and OWL 2 - Formats and Translations f...
 
Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional Programming
 
AI Lesson 17
AI Lesson 17AI Lesson 17
AI Lesson 17
 
Module_5_1.pptx
Module_5_1.pptxModule_5_1.pptx
Module_5_1.pptx
 

Plus de baran19901990

Plus de baran19901990 (15)

Tìm đường đi xe buýt trong TPHCM bằng Google Map
Tìm đường đi xe buýt trong TPHCM bằng Google MapTìm đường đi xe buýt trong TPHCM bằng Google Map
Tìm đường đi xe buýt trong TPHCM bằng Google Map
 
How to install nginx vs unicorn
How to install nginx vs unicornHow to install nginx vs unicorn
How to install nginx vs unicorn
 
Subprogram
SubprogramSubprogram
Subprogram
 
Lexical
LexicalLexical
Lexical
 
Introduction
IntroductionIntroduction
Introduction
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
 
How to install git on ubuntu
How to install git on ubuntuHow to install git on ubuntu
How to install git on ubuntu
 
Ruby notification
Ruby notificationRuby notification
Ruby notification
 
Rails notification
Rails notificationRails notification
Rails notification
 
Linux notification
Linux notificationLinux notification
Linux notification
 
Lab4
Lab4Lab4
Lab4
 
Lab5
Lab5Lab5
Lab5
 
09
0909
09
 
Báo cáo mô hình quản lý khách sạn
Báo cáo mô hình quản lý khách sạnBáo cáo mô hình quản lý khách sạn
Báo cáo mô hình quản lý khách sạn
 
MDA Framework
MDA FrameworkMDA Framework
MDA Framework
 

Dernier

best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...kajalverma014
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiMonica Sydney
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirtrahman018755
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查ydyuyu
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...kumargunjan9515
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsMonica Sydney
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfJOHNBEBONYAP1
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge GraphsEleniIlkou
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Balliameghakumariji156
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsMonica Sydney
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Roommeghakumariji156
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制pxcywzqs
 

Dernier (20)

best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 

10 logic+programming+with+prolog

  • 1. Chapter 10: Logic Programming Languages Principles of Programming Languages
  • 2. Contents •Predicate Calculus and Proving Theorems •The Basic Elements of Prolog •Simple Arithmetic and List in Prolog •Deficiencies of Prolog •Applications of Logic Programming
  • 3. •Another programming methodology: –Express programs in a form of symbolic logic –Use a logical inferencing process to produce results •Prolog Introduction
  • 4. •Proposition: a statement that may or may not be true –James I is a male –Catherine is a female –James I is parent of Charles I –Catherine is parent of Sophia •Compound term: functor + parameter lists male(james1) female(catherine) parent(james1, charles1) parent(catherine, sophia) •Two modes: facts or queries Proposition
  • 5. Logic Operators ¬ a negation a ˄ b conjunction a ˅ b disjunction a → b implication a ↔ b equivalence •Examples: (a ˄ b) → c
  • 6. Predicates •When we employ variables, the truth value of a statement is unknown until the variable has a specific value –X is a male –male(X) •Predicates turn into propositions if they have quantifiers ∀X (woman(X) → human(X)) ∃X (mother(mary, X) ˄ male(X))
  • 7. Clausal Form •A standard form for propositions B1 ˅ B2 ˅ …˅ Bn ← A1 ˄ A2 ˄ … ˄ Am •Examples mother(catherine, sophia) ← parent(catherine, sophia) ˄ female(catherine) father(louis, al) ˅ father(louis, violet) ← father(al, bob) ˄ mother(violet, bob) ˄ grandfather(louis, bob) •RHS = antecedent •LHS = consequent
  • 8. Automatic Theorem Proving •Resolution: if we have older(joanne, jake) ← mother(joanne, jake) wiser(joanne, jake) ← older(joanne, jake) •Using resolution, we can construct wiser(joanne, jake) ← mother(joanne, jake) •Mechanics: 1.AND two LHS to make the new LHS 2.AND two RHS to make the new RHS 3.Remove any terms that appear in the both sides
  • 9. Questions father(bob, jake) ˅ mother(bob, jake) ← parent(bob, jake) grandfather(bob, fred) ← father(bob, jake) ˄ father(jake, fred) What can we infer?
  • 10. Horn Clauses •When propositions are used for resolution, only a restricted kind of clausal form can be used •There are two forms of Horn clauses: –Headed: They have single atomic proposition on the LHS likes(bob, trout) ← likes(bob, fish) ˄ fish(trout) –Headless: Empty LHS father(bob, jake)
  • 11. Resolution •Ability to detect any inconsistency in a given set of propositions •Theorem is proved by –We are given a set of pertinent propositions –Negation of theorem as a new proposition –Resolution is used to find inconsistency •Hypotheses: a set of original propositions •Goal: negation of theorem stated as a proposition
  • 12. An Overview of Logic Programming •Declarative, rather that procedural or functional •Specify relation between objects –larger(3, 2) –father(tom, jane) •Separate logic from control: –Programmer declares what facts and relations are true –System determines how to use facts to solve problems –System instantiates variables in order to make relations true
  • 13. Example: Sorting a List •Describe the characteristics of a sorted list, not the process of rearranging a list sort(old_list, new_list) ← permute (old_list, new_list) ˄ sorted (new_list) sorted (list) ← j such that 1 j < n, list(j)  list (j+1)
  • 14. The Origins of Prolog •Alain Colmerauer at Marseille in 1970s –Natural language processing •University of Edinburgh –Automated theorem proving •1981, Japanese Fifth Generation Computing Systems choose Prolog as the basis •Despite the great assumed potential of logic programming and Prolog, little great significance had been covered
  • 15. Facts male(charlie). male(bob). female(alice). female(eve). parent(charlie, bob). parent(eve, bob). parent(charlie, alice). parent(eve, alice). •Headless Horn clauses •Every Prolog statement is terminated by a period
  • 16. Rules •Headed Horn clauses mother(X, Y) ← female(X) ˄ parent(X, Y) mother(X, Y) :- female(X), parent(X, Y).
  • 17. Queries •Let the computer know the facts, then ask it some questions – queries •Ask the system to prove or disprove a theorem ?- mother(sophia, george1). true •Ask the system to identify the instantiation of variables that make the query true ?- mother(X, sophia). X = Elizabeth false
  • 18. Some Prolog Syntax •Layer 0: constants and variables •Constants are: –Atoms: any string consisting of alphanumeric characters and underscore (_) that begins with a lowercase letter –Numbers •Variables are strings that begin with “_” or an uppercase letter
  • 19. Some Prolog Syntax const -> atom | number var -> ucase string | _ string atom -> lcase string letter -> ucase | lcase string -> epsilon | letter string | number string | _ string ucase -> A | ... | Z lcase -> a | ... | z number -> ...
  • 20. Some Prolog Syntax •Layer 1: terms •These are inductively defined: –Constants and variables are terms –Compound terms – applications of any n-ary functor to any n terms – are terms –Nothing else is a term
  • 21. Some Prolog Syntax •Layer 2: atomic formulae •These consist of an n-ary relation (also called predicate) applied to n terms •Formulae are either true or false; terms denote entities in the world •In Prolog, atomic formulae can be used in three ways: –As facts: in which they assert truth –As queries: in which they enquire about truth –As components of more complicated statements
  • 22. Some Prolog Syntax term -> const | var | functor “(“ term (“,” term)* “)” pred -> pname “(“ term (“,” term)* “)”
  • 23. Prolog Queries •A query is a proposed fact that is to be proven –If the query has no variables, returns true/false –If the query has variables, returns appropriate values of variables (called a substitution) ?- male(charlie). true ?- male(eve). false ?- female(Person). Person = alice; Person = eve; false
  • 24. Terms •Horn Clause = Clause •Consequent = Goal = Head •Antecedents = Subgoals = Tail •Horn Clause with No Tail = Fact •Horn Clause with Tail = Rule
  • 25. Some Prolog Syntax clause-> pred . | pred :- pred (“,” pred)* . term -> const | var | functor “(“ term (“,” term)* “)” pred -> pname “(“ term (“,” term)* “)” const -> ... var -> ...
  • 26. Variables •Variables may appear in the LHS or RHS of a clause. Prolog interprets free variables of a rule universally mother(X) :- female(X), parent(X, Y). In first-order logic: ∀X mother(X) ← ∃Y parent(X, Y) ˄ female(X) •Note that the Prolog query ?-q(X1, ..., Xn) means ∃X1,...,Xn q(X1, …, Xn)
  • 27. Execution of Prolog Programs •Unification: variable bindings •Backward Chaining/Top-Down Reasoning/Goal Directed Reasoning: reduces a goal to one or more subgoals •Backtracking: systematically searches for all possible solutions that can be obtained via unification and backchaining.
  • 28. Unification •Two atomic formulae unify iff they can be made syntactically identical by replacing their variables by other terms •For example: –parent(bob,Y) unifies with parent(bob,sue) by replacing Y by sue ?-parent(bob,Y)=parent(bob,sue) Y = sue ; false –parent(bob,Y) unifies with parent(X,sue) by replacing Y by sue and X by bob ?-parent(bob,Y)=parent(X,sue). Y = sue X = bob ; false
  • 29. Unification Algorithm Equation Action f(s1, ..., sn) = f(t1, ..., tn) Replace with s1 = t1, ..., sn = tn f(s1, ..., sn) = g(t1, ..., tn) where f ≠ g Halt with failure X = X Delete the equation t = X where t is not a variable Replace with X = t X = t where X does not occur in t and it occurs elsewhere Apply the substitution X = t to all other terms X = t where X occurs in t (but t ≠ X) Halt with failure
  • 30. Prolog Search Trees •Encapsulate unification, backward chaining, and backtracking –Internal nodes are ordered list of subgoals –Leaves are success nodes or failures, where computation can proceed no further –Edges are labeled with variable bindings that occur by unification •Describe all possible computation paths –There can be many success nodes –There can be infinite branches
  • 31. Prolog Search Tree /* program P clause # */ p(a). /* #1 */ p(X) :- q(X), r(X). /* #2 */ p(X) :- u(X). /* #3 */ q(X) :- s(X). /* #4 */ r(a). /* #5 */ r(b). /* #6 */ s(a). /* #7 */ s(b). /* #8 */ s(c). /* #9 */ u(d). /* #10 */ ?- p(X)
  • 32. [trace] ?- p(X). Call: (7) p(_G312) ? creep Exit: (7) p(a) ? creep X = a ; Redo: (7) p(_G312) ? creep Call: (8) q(_G312) ? creep Call: (9) s(_G312) ? creep Exit: (9) s(a) ? creep Exit: (8) q(a) ? creep Call: (8) r(a) ? creep Exit: (8) r(a) ? creep Exit: (7) p(a) ? creep X = a ; Redo: (9) s(_G312) ? creep Exit: (9) s(b) ? creep Exit: (8) q(b) ? creep Call: (8) r(b) ? creep Exit: (8) r(b) ? creep Exit: (7) p(b) ? creep X = b ; Redo: (9) s(_G312) ? creep Exit: (9) s(c) ? creep Exit: (8) q(c) ? creep Call: (8) r(c) ? creep Fail: (8) r(c) ? creep Redo: (7) p(_G312) ? creep Call: (8) u(_G312) ? creep Exit: (8) u(d) ? creep Exit: (7) p(d) ? creep X = d ; No
  • 33. Approaches •Prolog implementations use backward chaining •Top-down resolution, backward chaining –Begin with goal and attempt to find sequence that leads to set of facts in database –Works well with a small set of possibly correct answers •Bottom-up resolution, forward chaining –Begin with facts and rules of database and attempt to find sequence that leads to goal –Works well with a large set of possibly correct answers
  • 34. Subgoal Strategies •When goal has more than one subgoal, can use either –Depth-first search: find a complete proof for the first subgoal before working on others –Breadth-first search: work on all subgoals in parallel •Prolog uses depth-first search –Can be done with fewer computer resources
  • 35. Backtracking •With a goal with multiple subgoals, if fail to show truth of one of subgoals, reconsider previous subgoal to find an alternative solution: backtracking •Begin search where previous search left off •Can take lots of time and space because may find all possible proofs to every subgoal
  • 36. Trace •Built-in structure that displays instantiations at each step •Tracing model of execution - four events: –Call (beginning of attempt to satisfy goal) –Exit (when a goal has been satisfied) –Redo (when backtrack occurs) –Fail (when goal fails)
  • 37. Example likes(jake,chocolate). likes(jake,apricots). likes(darcie,licorice). likes(darcie,apricots). trace. likes(jake,X), likes(darcie,X).
  • 38. Simple Arithmetic •Prolog supports integer variables and integer arithmetic •is operator: takes an arithmetic expression as right operand and variable as left operand A is B / 17 + C •Not the same as an assignment statement!
  • 39. Example speed(ford,100). speed(chevy,105). speed(dodge,95). speed(volvo,80). time(ford,20). time(chevy,21). time(dodge,24). time(volvo,24). distance(X,Y) :- speed(X,Speed), time(X,Time), Y is Speed * Time.
  • 40. List Structures •List is a sequence of any number of elements •Elements can be atoms, atomic propositions, or other terms (including other lists) [apple, prune, grape, kumquat] [] (empty list) [H | T] (head H and tail T)
  • 41. Append Example append([], List, List). append([Head | List_1], List_2, [Head | List_3]) :- append (List_1, List_2, List_3).
  • 42. Another Example whatisme([], []). whatisme([Head | Tail], List) :- whatisme(Tail, Result), append(Result, [Head], List). •Try to write member rule to check if an element is a member of a list
  • 43. Deficiencies of Prolog •Resolution order control –Prolog always matches in the same order – user can control the ordering –Prolog allows explicit control of backtracking via cut operator -- “!”, which is actually a goal, not an operator •Always succeed but cannot be resatisfied through backtracking a, b, !, c, d –It is detrimental to one of the important advantages of logic programming – programs do not specify how solutions are to be found.
  • 44. Deficiencies of Prolog •The closed-world assumption –In Prolog, the truths are those that can be proved using its database –If there is insufficient information in the database to prove a query, it is not actually false, it fails –It relates to negation problem
  • 45. Deficiencies of Prolog •The negation problem –Stating that two atoms are not equal is not straightforward in Prolog –Bad solution: adding facts stating that they are not the same –Alternative: state in the goal that X must not be the same as Y sibling(X, Y) :- parent(M, X), parent(M, Y), not(X=Y) –However, not operator is not logical NOT, not(not(some_goal)) is not equivalent to some_goal –Reason: the use of Horn clause form prevents any negative conclusions
  • 46. Deficiencies of Prolog •Intrinsic limitations –Prolog has no idea of how to sort, other than simply to enumerate all permutations of the given list until it happens to create the one that has the list in sorted order –We must specify the details of how that sorting can be done – not logic programming any more –Resolution is not capable of doing this sorting
  • 47. Applications of Logic Programming •Relational database management systems –Logic programming is a natural match to the needs of implementing a RDBMS SQL is goal, tables are facts •Expert systems –Computer systems designed to emulate human expertise in some particular domain –In addition to the initial knowledge base, ES can learn from the process of being used •Natural language processing
  • 48. Summary •Symbolic logic provides basis for logic programming •Logic programs should be nonprocedural •Prolog statements are facts, rules, or goals •Resolution is the primary activity of a Prolog interpreter •Although there are a number of drawbacks with the current state of logic programming it has been used in a number of areas