0% found this document useful (0 votes)
5 views3 pages

Prolog Facts and Rules Example

The document outlines a set of facts and rules related to relationships and attributes among individuals, including familial ties and ownership. It includes queries to test the existence of certain facts and to bind variables based on the defined relationships. Additionally, it presents rules for determining relationships such as father, mother, and siblings based on the existing facts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Prolog Facts and Rules Example

The document outlines a set of facts and rules related to relationships and attributes among individuals, including familial ties and ownership. It includes queries to test the existence of certain facts and to bind variables based on the defined relationships. Additionally, it presents rules for determining relationships such as father, mother, and siblings based on the existing facts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SAMUEL KARANJA PO4/o665/2023

a)Key at least 30 facts (with one, two and three atoms

helps(john,peter,gray).
female(mary).
barks(dog).
flies(birds).
cries(baby).
delicious(food).
eaten(food).
sings(musician).
male(john).
shaves(kevin).
sleeping(mark).
female(brooke,tracy).
owns(abel,car2).
cooks(brain,ian).
drunk(kevin,ian).
mother(joy,vance).
brother(john,kevin).
sisters(joy,bianca).
parent(john,susan).
wife(joy,peter).
owns(john,van).
parent(john,peter,mark).
brothers(grey,jean,vaze).
sisters(eve,joy,evelyne).
friends(yeat,scott,travis).
mother(joyan,pete,kay).
cousins(kev,jay,wik).
foes(levin,twizz,leas).
pals(tee,geeh,zeak).

siblings(mary,alex,lisa).hree atoms)

b) run a number of queries to test for the following: -

i) Existence of some facts (at least 3runs)

?- pals(tee,geeh,zeak).
true.

?- sisters(joy,bianca).
true.

?- male(john).
true.

ii) Facts binding (solution of some facts i.e. father (X, Y)) at least 3 queries

?- parent(X,susan). % Find who is susans's parent


?- sisters(joy, X, giana). % Find giana’s sibling
?- wife(joy, Y). % Who is joy wife to?

c) Add at least 6 rules that are in line with the facts (example father(X,Y):-

parent(X,Y),male(X)) and perform the following: -: -

% Rule 1: Father(X, Y) if X is a parent of Y and X is male


father(X, Y) :- parent(X, Y), male(X).

% Rule 2: Mother(X, Y) if X is a parent of Y and X is female


mother(X, Y) :- parent(X, Y), female(X).

% Rule 3: Sibling rule (if two people share a parent)


are_siblings(X, Y) :- parent(Z, X), parent(Z, Y), X \= Y.

% Rule 4: sister’s rule (if X is a parent of Y's parent)


sisters(X, Y) :- sisters(X, Y), female(X, Y).

% Rule 5:parents rule (if X is the parent of Y)


parent(X, Y) :- parent of(X, C).
% Rule 6:owns(X, Y ) :- owns(X, Y).
i) Test for the existence of the rules
?- parent(john, susan).
?- mother(joy, kevin).
?- sisters(joy, bianca).
?- girlfriend(giana, brian).
?- wife(joy, john).
?- helps(john,brian, kevin).
ii) Run at least two queries for each of the 6 rules.
?- parent(X, susan). % Find susan's parent
?- parent(john, Y). % Find all children of John

?- mother(X, kevin). % Find Kevin's mother


?- mother(joy, Y). % Find children of Joy

?- are_sisters(joy, X). % Find Joy’s sister’s


?- are_sisters(joy, bianca). % Check if Joy and bianca are sisters

?- girlfriend(X, brian). % Find Brian’s girlfriend


?- girlfriend(Giana, Y). % Find Giana's boyfriend

?- wife(X, Y). % Find people working together


?- wife(joy, john). % Check if Joy is John’s wife

?-helps(john, X, kevin). % Find who john helps


?- helps(john, brian, Y). % Find who John helps

You might also like