03.06.2013 Views

Turbo Prolog

Turbo Prolog

Turbo Prolog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

mother(marilyn,beverly).<br />

mother(alan,sally).<br />

father(alan,bob)<br />

father(beverly,charles).<br />

father(fay,bob).<br />

father(marilyn,alan).<br />

parent(X,Y) if mother(X,Y).<br />

parent(X,Y) if father(X,Y).<br />

brother(X,Y) if<br />

male(Y) and<br />

parent(X,P) and<br />

parent(Y,P) and<br />

X () Y.<br />

sister(X,Y) if<br />

female(Y) and<br />

parent(X,P) and<br />

parent(Y,P) and<br />

X () Y.<br />

uncle(X,U) if<br />

mother(X,P) and<br />

brother(P,U).<br />

uncle(X,U) if<br />

father(X,P) and<br />

brother(P,U).<br />

grandfather(X,G) if<br />

father(P,G) and<br />

mother(X,P).<br />

grandfather(X,G) if<br />

father(X,P) and<br />

father(p,G) .<br />

I*The brother of X is Y if *1<br />

I*Y is a male and *1<br />

I*the parent of X is P and *1<br />

I*the parent of Y is P and *1<br />

1* X and Yare not the same *1<br />

I*The sister of X is Y if *1<br />

I*Y is female and *1<br />

I*the parent of X is P and *1<br />

I*the parent of Y is P and *1<br />

I*X and Yare not the same *1<br />

I*The uncle of X is U if *1<br />

I*the mother of X is P and *1<br />

I*the brother of P is U. *1<br />

I*The uncle of X is U if *1<br />

I*the father of X is P and *1<br />

I*the brother of P is U *1<br />

I*The grandfather of X is G *1<br />

I*if the father of P is G *1<br />

I*and the mother of X is P. *1<br />

I*The grandfather of X is G *1<br />

I*if the father of X is P *1<br />

I*the father of Pis G *1<br />

Type and execute this program and, by formulating appropriate goals, use <strong>Turbo</strong> <strong>Prolog</strong><br />

to answer the following questions:<br />

I. Is alan ivan's brother?<br />

2. Who is marilyn's grandfather?<br />

3. Who is fay's sister?<br />

4. What is the relationship (if any) between marilyn and beverly?<br />

The relations uncle and grandfather are both described by two clauses, though only one<br />

is necessary. Try to rewrite uncle and grandfather using one clause for each.<br />

28 <strong>Turbo</strong> <strong>Prolog</strong> Owner's Handbook

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!