Homework 07

Harry

To start, you should have a version of harry.pl that has working rules for grandparent and ancestor.

1) If your version of ancestor looks like this:

ancestor(A,D) :- parent(A,D).

ancestor(A,D) :- parent(A,P), ancestor(P,D).

It probably works fine, but if you wrote this:

ancestor(A,D) :- parent(A,D).

ancestor(A,D) :- ancestor(A,P), parent(P,D).

It works for true and crashes for false.

Which is the first indication that prolog is not completely magic.

What's wrong with the second version?

2) Write and test the following rules:

full_siblings(X,Y) if X and Y have the same pair of parents

siblings(X,Y) if X and Y have a parent in common

3) In the next few steps we will figure out a way to represent facts and rules that will establish the relationship between Harry Potter and Voldemort.

Figure out a way to add facts to the database so that ancestor(X,Y) works correctly even if one of the intervening ancestors is "Many generations".

.

The following should be true:

ancestor(ignotus_peverell, harry_potter).

ancestor(cadmus_peverell, tom_marvolo_riddle).

But make sure ancestor doesn't crash when you test something false!

4) Write and test a rule that checks whether two people are first cousins.

The following should be true:

cousins(harry_potter, dudley_dursley).

cousins(harry_potter, dudley_dursley).

You will have to think about the best way to represent the fact that Lily and Petunia Evans are sisters.

5) Write and test a rule that checks whether two people are related by blood.

The following should be true:

related(harry_potter, tom_marvolo_riddle).

related(harry_potter, cadmus_peverell).

But the following is false (as far as the database knows):

related(harry_potter, ginevra_weasley).