Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* Facts */ parent(mary,tom). parent(john,tom). parent(mary,alice). parent(john,alice). sex(mary, female). sex(john, male). sex(tom, male). sex(alice, female). /* Rules */ mother(X):- sex(X,female), parent(X,_). father(X):- sex(X, male), parent(X,_).

/* Facts */ parent(mary,tom). parent(john,tom). parent(mary,alice). parent(john,alice). sex(mary, female). sex(john, male). sex(tom, male). sex(alice, female). /* Rules */ mother(X):- sex(X,female), parent(X,_). father(X):- sex(X, male), parent(X,_). sibling(X,Y):- parent(M,X), sex(M,female), parent(F,X), sex(F,male), parent(M,Y), parent(F,Y). sibling1(X,Y):- parent(M,X), sex(M,female), parent(F,X), sex(F,male), parent(M,Y), parent(F,Y), X \= Y. go:- nl, nl, write('Hello there .....'), nl, write('Testing on Prolog2.'), nl, write('End Job'), nl. 
% The family program. parent( pam, bob). % Pam is a parent of Bob parent( tom, bob). parent( tom, liz). parent( bob, ann). parent( bob, pat). parent( pat, jim). female( pam). % Pam is female male( tom). % Tom is male male( bob). female( liz). female( ann). female( pat). male( jim). offspring( Y, X) :- % Y is an offspring of X if parent( X, Y). % X is a parent of Y mother( X, Y) :- % X is the mother of Y if parent( X, Y), % X is a parent of Y and female( X). % X is female grandparent( X, Z) :- % X is a grandparent of Z if parent( X, Y), % X is a parent of Y and parent( Y, Z). % Y is a parent of Z sister( X, Y) :- % X is a sister of Y if parent( Z, X), parent( Z, Y), % X and Y have the same parent and female( X), % X is female and different( X, Y). % X and Y are different predecessor( X, Z) :- % Rule prl: X is a predecessor of Z parent( X, Z). predecessor( X, Z) :- % Rule pr2: X is a predecessor of Z parent( X, Y), predecessor( Y, Z). 
/****************************************/ /* Family tree example */ /****************************************/ parent(pam, bob). parent(tom, bob). parent(tom, liz). parent(bob, ann). parent(bob, pat). parent(tina, ann). parent(tina, pat). parent(pat, jim). parent(mary, jim). parent(ann, george). parent(michael, george). parent(ann, sophie). parent(ian, sophie). /* ------ */ parent(lou, kenny). parent(albert, kenny). parent(lou, pete). parent(lou, pauline). parent(albert, pauline). parent(pat, simon). parent(pete, simon). parent(kenny, simon). parent(kenny, elizabeth). parent(cath, ian). parent(pete, ian). parent(pauline, michelle). parent(arthur, michelle). parent(michelle, vicky). parent(den, vicky). parent(cath, donna). parent(kenny, elizabeth). /* ------ */ sex(pam, female). sex(tom, male). sex(bob, male). sex(tina, female). sex(liz, female). sex(ann, female). sex(pat, male). sex(mary, female). sex(michael, male). sex(george, male). sex(ian, male). sex(jim, male). sex(sophie, female). sex(lou, female). sex(pat, female). sex(elizabeth, female). sex(cath, female). sex(donna, female). sex(pauline, female). sex(michelle, female). sex(vicky, female). sex(angie, female). sex(sharon, female). sex(kenny, male). sex(simon, male). sex(pete, male). sex(ian, male). sex(arthur, male). sex(den, male). sex(lofty, male). sex(albert, male). /* ------ */ married(cath, pete). married(pauline, arthur). married(michelle, lofty). married(lou, albert). Lab Exercise #1 Instructions:  Use Program no. 3 (above) to answer the following basic questions.  Since program no. 3 contains no rules (at all), you are required to define a few rules that make use of the existing facts parent(Parent, Child). sex(Person, Sex). % where Sex is one of male or female married(Wife, Husband).  Examples of rules needed may be: mother(), father(), etc. [Think of it!]  You may need to use compound predicates when making queries (if there is no suitable rule to use). Basic questions: Construct queries at Prolog Listener to observe answers for each of the following: 1. Find all the married couples 2. Find out all married females in the KB 3. Find pats father 4. Find arthurs mother 5. Find all of bobs parents 6. Find out if simon is a parent of jim 7. Find out if donna is a parent of tina 8. Find all of cathys parents 9. Find michelles gender type 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago