General
Material
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5

Recursive predicate definitions

If you have not already done so, do the exercise about family relationships.

Extend the family tree that you defined in that exercise by adding great-grandparents for Harry.

Now, define a predicate ancestor_of/2. ancestor_of(X,Y) should be true if X is an ancestor of Y. Your predicate definition should work correctly even if you add Harry's great-great-grandparents, his great-great-great-grandparents, his great-great-... to the knowledge base.

Ask queries to test your definition. For example:

  • Is Albert an ancestor of Harry?
  • Who are the ancestors of Harry?
  • Is Dudley an ancestor of Harry?
  • Who are the descendants of james?

Hint

If Prolog does not come back with an answer, it has probably gone off into an endless loop. Stop it by pressing Ctrl-c. Then type a to abort.

Back to the practical session of day 1.