Math 156
Discrete Mathematics for Computer Science
Fall 1999

Toy Prolog Examples

This page contains several example programs:

Grandparents and Siblings


Aunts and Uncles -- First Attempt


Notice that this examples fails to get uncles and aunts by marriage. We'll add them in in the next example.

Aunts and Uncles -- Second Attempt


Oops. This still isn't correct. chriss should be an aunt of andrew since she is married to mark. The problem is that we have not made married symetric.

Aunts and Uncles -- Third Attempt


Now what?!? We have an infinite loop! Why? The program goes back and forth figuring out that, for example, mark and chriss are married over and over. ( married(mirk,chriss) => married(chriss,mark) => married(mark, chriss) , etc.) Actually, it gets stuck even sooner when it is figuring out about mike and julie. One fix is given in the next attempt.

Aunts and Uncles -- Fourth Attempt


Is she a witch?



The example above is based on Scene 5 of Monty Python's Search for the Holy Grail. If you are interested in the Monty Python sketch, here are links to the text and audio

Last modified: Monday, 30-Apr-2001 03:11:49 EDT