第二次

advertisement
邏輯語言程式設計
學號:
第二次課堂作業
姓名:
1. Given the following facts, please answer the questions.
parent( pam, bob).
parent( tom, bob).
parent( tom, liz).
parent( bob, ann).
parent( bob, pat).
parent( pat, jim).
% Pam is a parent of Bob
(a) Please define a rule “grandchild(X, Y)”. It means that X is a grandchild of Y.
(b) Here shows a procedure of predecessor relation.
predecessor( X, Z) :- parent( X, Z).
predecessor( X, Z) :- predecessor( Y, Z), parent( X, Y).
Can this procedure work correctly? Why or why not?
(c) Please draw the corresponding derivation diagrams using the correct predecessor procedure
and the facts defined above.
(1) ?- grandparent( tom, ann).
(2) ?- predecessor( pam, jim).
Download