You are on page 1of 2

Praktikum 1: 1. Copy famtree.pl into your program. parent(A,B):father(A,B). parent(A,B):mother(A,B). son(A,B):parent(B,A),male(A). daughter(A,B):parent(B,A),female(A). male(bob). male(tom). male(jim). male(pat). female(ann).

female(liz). female(pam). father(tom,bob). father(tom,liz). father(bob,ann). father(bob,pat). father(pat,jim). mother(pam,bob). mother(pam,liz). Consult. Listing. Test by asking: - mother(pam, bob). - father(tom, ann). - male(jim). - father(tom, Who). - mother(Mother, bob). - mother(X, Y). - parent(tom, bob). - daughter(liz, Who). - son(What, How). How would you ask the following? - Is Tom the father of Bob and of Ann? - Is there anyone who has a son and is themselves the son of someone? - Do Bob and Liz have the same mother? Write grandparent rule into program: grandparent(Grandparent, Grandchild) :parent(Grandparent, Parent), parent(Parent, Grandchild). Add rules for sister, brother, aunt and uncle.

2. 3. 4.

5.

6.

7.

8. How would you add facts and rules to the database to give information about peoples ages, and to be able to answer questions like Is Fred older than Jim? or How old is Sue? - Add a clause age with two arguments, one for a persons name and the other for that persons age, for example: age(cecil, 30) age(mary, 72) - Compare age using > which means greater than, for example by asking: age(cecil, X), age(mary, Y), Y > X. 9. Add a rule is_older(OldPerson, YoungPerson) which is true when the OldPerson is older than the YoungPerson. The whole rule, if we were comparing Mary and Cecils ages, would be: Mary is older than Cecil if we know Marys age and we know Cecils age and Marys age is greater than Cecils age. 10. We could have different rules for cases where we dont know everyones age, but we know that if Fred is the parent of Cecil then Fred must be older than Cecil. Write the rule. 11. Write a rule looks like this: Mary is older than Cecil if Mary is older than someone and that someone is older than Cecil.

You might also like