Assignment 3

Note: use halt. to exit Prolog and <ctrl c> to interrupt processing.  Please format and comment your Prolog code and tests of your code as shown in example.  You must turn in printouts of your source code and examples of testing your source code based on the provided example!  Be sure to label each problem and/or subproblem so the solution can be found quickly by the grader.

1. Express the following as Prolog facts:  pam is the parent of bob, pam is the parent of larry, tom is the parent of bob, tom is the parent of liz, bob is the parent of ann, bob is the parent of pat, pat is the parent of jim, larry is the parent of betty, betty is the parent of joe, betty is the parent of jane, betty is the parent of lucy, bob is the parent of mary, mary is the parent of lois, mary is the parent of bertha.

Write Prolog rules to answer the following questions. Turn in the listing of your data and rules, as well as the answers to the following questions.

    a) Do ann and pat have a common parent? If so, who?

    b) Who is pat's parent?

    c) Does liz have a child?

    d) Who is pat's grandparent.

2. Extend your conceptual scheme of the family tree above by introducing the unary facts female and male for all the people. For example, female(pam) also add the fact married(tom, pam). Exit prolog and enter the new facts corresponding to female and male along with the rules specified below.

    a) Define a rule for sister_of(X,Y) and mother_of(X,Y) using parent_of and female.  Then test: Who is ann's sister? Who is the mother of jim?

    b) Define a rule for grandparent using parent_of.  Then test: Who is the grandparent of ann?

    c) Define aunt in terms of parent and sister_of. Then test: Who is the aunt of jim?

    d) Define predecessor, the transitive closure of parent_of.  Then test" Who are the predecessors of jim?

Hint: built-in predicate \== can be used as follows:

Please note:  For the previous problems, the Prolog built in "\==" may be useful.  See below:

?- X = tom, Y=mary, X\==Y.

X = tom

Y = mary

Yes

3. Write a predicate same_generation(Person1, Person2) which is True if Person1 and Person2 are the same numbers of generations away from some common ancestor.  Note that a person is considered to be the same generation as him/herself.

4.  Write a predicate great_grandparent(Ancestor, Child) which is true if Ancestor is a great grandparent of Child.

5.  Write a predicate second_cousin(Person1, Person2) which is true if Person2 and Person2 share a great grandparent but no nearer ancestors.  Note that a person is not his/her own second cousin.

6.  Write predicates mother_has_all_same_sex_children(Woman) which is true if Woman is female and has more than one child, and all of these children are the same sex.