15.08.2013 Views

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Definition 632 A query is a list of ProLog terms called goals. Write as ?- A1, . . ., An.,<br />

if Ai are terms.<br />

Problem: Knowledge bases can be big and even infinite.<br />

Example 633 The the knowledge base induced by the program<br />

nat(zero).<br />

nat(s(X)) :- nat(X).<br />

is the set {nat(zero), nat(s(zero)), nat(s(s(zero))), . . .}.<br />

Idea: interpret this as a search problem.<br />

state = tuple of goals; goal state = empty list (of goals).<br />

next(〈G, R1, . . . Rl〉) := 〈σ(B1), . . ., σ(Bm, R1, . . . , Rl)〉 (backchaining) if there is a rule<br />

H:-B1,. . ., Bm. and a substitution σ with σ(H) = σ(G).<br />

Example 634 (Continuing Example 633) ?- nat(s(s(zero))).<br />

?- nat(s(zero)).<br />

?- nat(zero).<br />

Yes<br />

c○: Michael Kohlhase 506<br />

This search process has as action the backchaining rule, which is really just a clever combination<br />

of the inference rules from Definition 630 applied backwards.<br />

The backchaining rule takes the current goal G (the first one) and tries to find a substitution<br />

σ and a head H in a program clause, such that σ(G) = σ(H). If such a clause can be found, it<br />

replaces G with the body of the rule instantiated by σ.<br />

But we can extend querying from simple yes/no answers to programs that return values by simply<br />

using variables in queries. In this case, the ProLog interpreter returns a substitution.<br />

Querying the Knowledge base (continued)<br />

If a query contains variables, then ProLog will return an answer substitution.<br />

has_wheels(mybmw,4).<br />

has_motor(mybmw).<br />

car(X):-has_wheels(X,4),has_motor(X).<br />

?- car(Y)<br />

?- has_wheels(Y,4),has_motor(Y).<br />

Y = mybmw<br />

?- has_motor(mybmw).<br />

Y = mybmw<br />

Yes<br />

If no instance of the statement in a query can be derived from the knowledge base, then the<br />

ProLog interpreter reports failure.<br />

?- nat(s(s(0))).<br />

?- nat(s(0)).<br />

?- nat(0).<br />

FAIL<br />

No<br />

c○: Michael Kohlhase 507<br />

With this, we can already do the “fallible Greeks” example from the introduction.<br />

266

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!