Assignment 2

Note: use halt. to exit prolog and <ctrl c> to interrupt processing.

1. pam is the parent of bob, 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.

Using prolog, create the data and 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 relations female and male. For example, female(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.

    b) Define a rule for grandparent using parent_of.

    c) Define aunt in terms of parent and sister_of.

    d) Define predecessor, the transitive closure of parent_of.

After adding the rules above, re-enter prolog and reload the family data and rules and use Prolog to answer the following questions.

    e) Who is ann's sister?

    f) Who is the grandparent of ann?

    g) Who is the mother of jim?

    h) Who is the aunt of jim?

    i) Who are the predecessors of jim?

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

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

X = tom

Y = mary

Yes

 

3. a) Express the following story as sentences in predicate calculus. Convert the sentences to clause form and then use resolution refutation to answer the posed question. Then, b) develop a PROLOG program for the solution.

Anyone passing his PROLOG exams and winning the lottery is happy. But anyone who studies or is lucky can pass all his exams. John did not study but he is lucky. Anyone who is lucky wins the lottery. Is John happy?

Note: you will need to add a statement such as the following to your code:

:- dynamic study/1.

This means that the predicate study has 1 argument and it is dynamic. If predicate study is not made dynamic, then if no study facts are asserted and a query ?- study(X) is posed, Prolog will return an exception because the predicate study is not defined. If the predicate is made dynamic, non-existence of study facts or rules then means failure, that is, do not try to represent "facts that are not true" in the Prolog database but rather employ the closed-world assumption in that something is false if it is not a fact or if it cannot be proven from the facts and rules that make up the Prolog program.