some prolog prolog is a logic programming language used for implementing logical representations and...
TRANSCRIPT
![Page 1: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/1.jpg)
Some Prolog Prolog is a logic programming
language Used for implementing logical
representations and for drawing inference
We will do: Some examples of Prolog for motivation Generalized Modus Ponens, Unification,
Resolution Wumpus World in Prolog
![Page 2: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/2.jpg)
Need to add new logic rules above those in Propositional Logic Universal Elimination
Existential Elimination
(Person1 does not exist elsewhere in KB) Existential Introduction
Inference in First-Order Logic
),(),( SemisonicLizLikesSemisonicxLikesx
),1(),( SemisonicPersonLikesSemisonicxLikesx
),(),( SemisonicxLikesxSemisonicGlennLikes
![Page 3: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/3.jpg)
Example of inference rules “It is illegal for students to copy
music.” “Joe is a student.” “Every student copies music.” Is Joe a criminal?
Knowledge Base:
),(
),()()(,
yxCopiesMusic(y)Student(x)yx
e)Student(Jo
)Criminal(x
yxCopiesyMusicxStudentyx
)3(
)2(
)1(
![Page 4: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/4.jpg)
Example cont...
),(
),( :From
yJoeCopiesMusic(y)e)Student(Joy
yxCopiesMusic(y)Student(x)yx
),( SomeSongJoeCopiesSong)Music(Somee)Student(Jo
oe)Criminal(J
Universal EliminationExistential Elimination
Example partially borrowed from http://sern.ucalgary.ca/courses/CPSC/533/W99/presentations/L1_9A_Chow_Low/main.html
Modus Ponens
![Page 5: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/5.jpg)
How could we build an inference engine?
Software system to try all inferences to test for Criminal(Joe) A very common behavior is to do:
And-Introduction Universal Elimination Modus Ponens
![Page 6: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/6.jpg)
Example of this set of inferences
Generalized Modus Ponens does this in one shot
4 & 5
![Page 7: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/7.jpg)
Substitution A substitution in a sentence binds
variables to particular values Examples:
)(
}/{
)(
CherylStudentp
Cherylx
xStudentp
)()(
}/,/{
)()(
GoodhueLivesrChristopheStudentq
GoodhueyrChristophex
yLivesxStudentq
![Page 8: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/8.jpg)
Unification A substitution unifies sentences
p and q if p = q.
p q
Knows(John,x) Knows(John,Jane)
Knows(John,x) Knows(y,Phil)
Knows(John,x) Knows(y,Mother(y))
![Page 9: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/9.jpg)
Unification
Use unification in drawing inferences: unify premises of rule with known facts, then apply to conclusion
If we know q, and Knows(John,x) Likes(John,x) Conclude
Likes(John, Jane) Likes(John, Phil) Likes(John, Mother(John))
p q
Knows(John,x) Knows(John,Jane) {x/Jane}
Knows(John,x) Knows(y,Phil) {x/Phil,y/John}
Knows(John,x) Knows(y,Mother(y)) {y/John, x/Mother(John)}
![Page 10: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/10.jpg)
Generalized Modus Ponens
Two mechanisms for applying binding to Generalized Modus Ponens Forward chaining Backward chaining
![Page 11: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/11.jpg)
Forward chaining Start with the data (facts) and draw
conclusions
When a new fact p is added to the KB: For each rule such that p unifies with a
premise if the other premises are known
add the conclusion to the KB and continue chaining
![Page 12: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/12.jpg)
Forward Chaining Example
![Page 13: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/13.jpg)
Backward Chaining Start with the query, and try to find
facts to support it When a query q is asked:
If a matching fact q’ is known, return unifier For each rule whose consequent q’ matches q
attempt to prove each premise of the rule by backward chaining
Prolog does backward chaining
![Page 14: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/14.jpg)
Backward Chaining Example
![Page 15: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/15.jpg)
Completeness in first-order logic
A procedure is complete if and only if every sentence entailed by KB can be derived using that procedure
Forward and backward chaining are complete for Horn clause KBs, but not in general
atoms nonnegated are and 21
QP
QPnPP
i
![Page 16: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/16.jpg)
Example
![Page 17: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/17.jpg)
Resolution Resolution is a complete inference
procedure for first order logic Any sentence entailed by KB can be
derived with resolution Catch: proof procedure can run for an
unspecified amount of time At any given moment, if proof is not done,
don’t know if infinitely looping or about to give an answer
Cannot always prove that a sentence is not entailed by KB
First-order logic is semidecidable
![Page 18: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/18.jpg)
Resolution
![Page 19: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/19.jpg)
Resolution Inference Rule
![Page 20: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/20.jpg)
Resolution Inference Rule
In order to use resolution, all sentences must be in conjunctive normal form bunch of sub-sentences connected by “and”
![Page 21: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/21.jpg)
Converting to Conjunctive Normal Form (briefly)
![Page 22: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/22.jpg)
Example: Using Resolution to solve problem
![Page 23: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/23.jpg)
Sample Resolution Proof
![Page 24: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/24.jpg)
What about Prolog? (10.3) Only Horn clause sentences
semicolon (“or”) ok if equivalent to Horn clause
Negation as failure: not P is considered proved if system failes to prove P
Backward chaining with depth-first search Order of search is first to last, left to right Built in predicates for arithmetic
X is Y*Z+3 Depth-first search could result in infinite
looping
![Page 25: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/25.jpg)
Some more Prolog Bounded depth first search Cut
![Page 26: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/26.jpg)
Theorem Provers (10.4) Theorem provers are different from
logic programming languages Handle all first-order logic, not just
Horn clauses Can write logic in any order, no
control issue
![Page 27: Some Prolog Prolog is a logic programming language Used for implementing logical representations and for drawing inference We will do: Some examples of](https://reader035.vdocuments.us/reader035/viewer/2022070306/5516d92b5503464c088b459d/html5/thumbnails/27.jpg)
Sample theorem prover: Otter
Define facts (set of support) Define usable axioms (basic background) Define rules (rewrites or demodulators) Heuristic function to control search
Sample heuristic: small and simple statements are better
OTTER works by doing best first search http://www-unix.mcs.anl.gov/AR/sobb/
Boolean algebras