Presentation is loading. Please wait.

Presentation is loading. Please wait.

The portion of a Prolog interpreter that executes queries (goals) is known as the inference engine. An inference engine is a kind of theorem prover, using.

Similar presentations


Presentation on theme: "The portion of a Prolog interpreter that executes queries (goals) is known as the inference engine. An inference engine is a kind of theorem prover, using."— Presentation transcript:

1 The portion of a Prolog interpreter that executes queries (goals) is known as the inference engine. An inference engine is a kind of theorem prover, using three concepts:

2 Assume two rules of the following form : f :- a 1, a 2, …, a N g :- f, b 1, b 2, …, b N note f These two separate rules can be resolved to the following: g :- a 1, a 2, …, a N, b 1, b 2, …, b N Resolution & Facts Every single predicate is in fact a Horn clause. pred. pred :- true. means Therefore… pred. g :- pred, b 1, b 2, …, b N resolve to g :- b 1, b 2, …, b N When can the inference engine can answer “Yes”?

3 In attempting to satisfy a goal, the inference engine must replace (bind) variables to atomic values. Such binding is called unification. Example ?- child(sam, sue). child(C,P) :- parent(P,C). parent(P,C) :- mother(P,C). Unification is directed by goals. When a variable is unified, the binding extends to an entire rule. The goal suggests that C be bound to sam and P bound to sue. mother(sue, sam). child(sam,sue) :- mother(sue,sam). Assume the following fact: Together these last two assertions resolve as shown below. resolve to Yes

4 Unification is found in two ways: Goal is headed Horn clause ( search for rule that can resolve ) connected(A, B) :- connected(A, C), neighbors(C, B). If the second rule is unified (X  A and Y  C) then resolution can occur. connected(X, Y) :- neighbors(X, Y). connected(A, C) :- neighbors(A, C). resolve to Goal is headless Horn clause ( search for rule with matching left side ) ?-greenish(Z). greenish(W) :- hasBlue(W), hasYellow(W). Unify the second rule via (W  Z). greenish(Z) :- hasBlue(Z), hasYellow(Z). to subgoal

5 public boolean solve( Goal g) { for each (rule/fact: f that has been compiled) { if (f can resolve with g) { resolve f with g to yield subgoal s; if (s is something :- true) return true; else return solve(s); } else if (f suggests a unification for variables of g) { unify g using f to yield subgoal s; return solve(s); } backtrack } } left side of horn clause match?

6 family.pl file mother(sue, sam). mother(sue, mae). mother(mia, sue). mother(kay, jim). mother(kay, max). mother(mia, joe). mother(mia, bob). father(jim, sam). father(jim, mae). father(ed, sue). father(moe, jim). father(moe, max). father(ed, joe). father(ed, bob). child(C, P) :- parent(P, C). parent(P, C) :- mother(P, C). parent(P, C) :- father(P, C). siblings(A,B) :- parent(P,A), parent(P,B), A \= B. ?- siblings(sam, W).

7 use siblings(A,B) :- parent(P,A), parent(P,B), A \= B. to unify A  sam B  W ?- siblings(sam, W) :- parent(P,sam), parent(P,W), sam \= W. resolve/unify with parent(P, C) :- mother(P, C). P  P C  sam ?- siblings(sam, W) :- mother(P,sam), parent(P,W), sam \= W. unify using mother(sue, sam). P  sue ?- siblings(sam, W) :- mother(sue,sam), parent(sue,W), sam \= W. resolve with mother(sue, sam). ?- siblings(sam, W) :- parent(sue,W), sam \= W. resolve/unify with parent(P, C) :- mother(P, C). P  sue C  W ?- siblings(sam, W) :- mother(sue,W), sam \= W. unify using mother(sue, sam). W  sam ?- siblings(sam, sam) :- mother(sue,sam), sam \= sam. resolve with mother(sue, sam). ?- siblings(sam, sam) :- sam \= sam. fail and backtrack to unify using mother(sue, mae). W  mae ?- siblings(sam, mae) :- mother(sue,mae), sam \= mae.


Download ppt "The portion of a Prolog interpreter that executes queries (goals) is known as the inference engine. An inference engine is a kind of theorem prover, using."

Similar presentations


Ads by Google