120 likes | 130 Views
Prolog. CSE 473 – Autumn 2003. Today. First-order logic resolution proofs Answer extraction Resolution strategies Prolog The 5 th Generation Project. FOL Resolution Proofs. People who love happy people are happy. Rich people are happy. People love their spouse.
E N D
Prolog CSE 473 – Autumn 2003
Today • First-order logic resolution proofs • Answer extraction • Resolution strategies • Prolog • The 5th Generation Project
FOL Resolution Proofs • People who love happy people are happy. • Rich people are happy. • People love their spouse. • Mothers love their children. • Prove: Bill Gate’s mother-in-law is happy. happy(x), rich(x), loves(x,y)spouse(Melinda,Bill)mother(MIL,Melinda)mother(Mary,Bill)
Answer Extraction • Who is happy? • Who loves Bill Gates? • Who loves who?
Prolog Interpreter binding_list disprove(literal neglit){ choose (clause c) such that (binding = unify(head(c),neglit)) if (no choice possible){ backtrackto last choice;} for (each lit in body(c)){ binding = binding U disprove(substitute(lit,binding)); } return binding; }
Properties of Prolog Interpreter • Tree-shaped proofs • Efficient use of memory (just stack) • Builds tree depth-first – may enter infinite loop even on finite domains! • Free implementation: SWI Prolog http://www.swi-prolog.org/
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(mil,melinda). mother(mary,bill). rich(paul). mother(barbara,henry).
toohappy.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(mil,melinda). mother(mary,bill). rich(paul). mother(barbara,henry). loves(bill,melinda). loves(henry,barbara).
hanoi.pl move(1,X,Y,_) :- write('Move top disk from '), write(X), write(' to '), write(Y), nl. move(N,X,Y,Z) :- N>1, M is N-1, move(M,X,Z,Y), move(1,X,Y,_), move(M,Z,Y,X).
nlp.pl % Try: s([a,man,loves,a,woman],[]). s(S0,S) :- np(S0,S1), vp(S1,S). np(S0,S) :- det(S0,S1), n(S1,S). vp(S0,S) :- tv(S0,S1), np(S1,S). vp(S0,S) :- v(S0,S). det(S0,S) :- S0=[the|S]. det(S0,S) :- S0=[a|S]. det(S0,S) :- S0=[every|S]. n(S0,S) :- S0=[man|S]. n(S0,S) :- S0=[woman|S]. n(S0,S) :- S0=[park|S]. tv(S0,S) :- S0=[loves|S]. tv(S0,S) :- S0=[likes|S]. v(S0,S) :- S0=[walks|S].
Japanese 5th Generation Project • 1982 – 1992: $400M effort by Japanese corporate/government partnership to leapfrog the world in creating an “epoch-making computer” • Approach: hardware for parallel Prolog • In the end, few results • General purpose hardware evolved more rapidly • Most significant software R&D in Europe
Prolog Today • Natural language processing • Datalog – database query and integrity constraints • Function-free definite clauses + bottom-up resolution strategy • Expert systems – diagnosis, classification, … • http://www.amzi.com/AdventureInProlog/