ai-prolog4 - AI: Prolog Review of Prolog Rules and Facts...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 AI: Prolog Review of Prolog Rules and Facts Prolog Syntax Matching
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Prolog Basics - Revisited Prolog program consists of facts and rules. animal(lion). animal(sparrow). hasfeathers(sparrow). bird(X) :- animal(X), hasfeathers(X). “Run” by asking questions or queries. Or (using logic terminology) by setting a goal for Prolog to try to prove: To find out if something is true: ?- bird(sparrow). yes Or to find a value of a variable that makes it true: ?- bird(What). What = sparrow
Background image of page 2
3 Prolog Execution A Prolog rule consists of a head and a body. a(X) :- b(X), c(X). When Prolog tries to answer a query (prove a goal) it does so by trying to match the goal to the head of the rule. This might result in some variables getting bound. ?- a(thing). a(thing) MATCHES a(X) so X is bound to the value “thing”. Now it tries to prove the goals in the body of the rule, using these variable bindings:: b(thing) and c(thing) head body
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Example likes(mary, X) :- strong(X), handsome(X). strong(Y) :- tall(Y). tall(john). handsome(john). ?- likes(mary, john). MATCHES likes(mary, john) to head of rule 1, with X=john. Sets strong(john), handsome(john) as new goals. Tries to prove strong(john). MATCHES head of rule 2. Y=john. Tries to prove tall(john). MATCHES a fact. So proved. Tries to prove handsome(john). MATCHES a fact, So proved.
Background image of page 4
5 Example: Using Prolog Trace | ?- likes(mary, john). 1
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/20/2011 for the course CS 6810 taught by Professor Hecker during the Spring '10 term at CSU East Bay.

Page1 / 19

ai-prolog4 - AI: Prolog Review of Prolog Rules and Facts...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online