Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logical Foundations of AI Logic Programming. Making FOL Practical Barriers to using FOL: Choice of clauses to resolve Huge amount of memory to store DAG.

Similar presentations


Presentation on theme: "Logical Foundations of AI Logic Programming. Making FOL Practical Barriers to using FOL: Choice of clauses to resolve Huge amount of memory to store DAG."— Presentation transcript:

1 Logical Foundations of AI Logic Programming

2 Making FOL Practical Barriers to using FOL: Choice of clauses to resolve Huge amount of memory to store DAG Getting useful answers to queries (not just “yes” or “no”) PROLOG’s answers: Simple backward-chaining resolution strategy – left/right, first to last clause Tree-shaped proofs – no need to store entire proof in memory at one time Extract answers to queries by returning variable bindings

3 happy.pl happy(X) :- rich(X). happy(X) :- loves(X,Y),happy(Y). loves(X,Y) :- spouse(X,Y). loves(X,Y) :- mother(X,Y). rich(bill). spouse(melinda,bill). mother(elaine,melinda). mother(mary,bill). rich(paul). mother(barbara,henry). QUERIES: ?- happy(bill). YES ?- happy(henry). NO ?- happy(Z).

4 PROLOG Examples Happy Ancestor Lists Genesis

5 Lists Terms in Prolog can be used as data structures Lists: can be built using a 2-place function symbol "list" and a constant "nil" list(a,list(b,list(c,nil))) (note: most implementations call the list function symbol ".") Prolog provides shorthand: [a,b,c] Notation: [a, b, | R] is a list where R is the "rest of the list" (also a list). Suppose variable R is bound to [c,d] Then [a,b|R] is [a,b,c,d]

6 Unifying Lists [a,b,c] and X X=[a,b,c] [a,b,c] and [a,X,Y] X=b,Y=c [a,b,c] and [X|Y] X=a, Y=[b,c] [X,b,Y] and [a,Z,Z] X=a, Z=b, Y=b

7 PROLOG Examples Lists Genesis

8 Prolog Limitations Only handles definite clauses (exactly one positive literal per clause) Cannot express e.g. happy(bill) v happy(henry) Tree-shaped proofs means some sub-steps may be repeatedly derived DATALOG: does forward-chaining inference and caches derived unit clauses Interpreter can get into an infinite loop if care is not taken in form & order of clauses

9 Exercise You have just been hired by snacks.com, an Internet startup that provides snacking recommendations. Your first assignment is to create an expert system that will recommend snacks according to the following rules: Every snack should contain one beverage and one munchie. Sweet beverages are good with salty munchies. Bitter beverages are good with sweet munchies or salty munchies. Define a predicate snack(X,Y) that makes such recommendations.

10 Procedural Control Order of clauses cousin(jane,sam). cousin(X,Y):- granparent(Z,X),grandparent(Z,Y) Order of literals within a clause americanCousin(X,Y):- american(X,Y),cousin(X). americanCousin(X,Y):- cousin(X,Y),american(X) Cut (commit) operator ! americanCousin(X,Y):- cousin(X,Y),!,american(X).


Download ppt "Logical Foundations of AI Logic Programming. Making FOL Practical Barriers to using FOL: Choice of clauses to resolve Huge amount of memory to store DAG."

Similar presentations


Ads by Google