0% found this document useful (0 votes)
6 views5 pages

Practical 02

This is Ai lab manual part 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Practical 02

This is Ai lab manual part 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of: Subject of:

Information Technology Artificial Intelligence

Quaid-e-Awam University of Year 4TH Semester 8TH


Engineering, Science &
Technology Batch 19IT Duration 03
Hours
Nawabshah

PRACTICAL 02
TO BECOME FAMILIAR WITH DEFINING RELATIONS BY FACTS, BY
RULES AND RECURSIVE RULES
----------------------------------------------------------
OBJECTIVES

• Define relationship by facts


• Define relationship by Rules
• Family Tree program

REQUIREMENTS

• PC with windows
• SWI Prolog
2.1 An Example of a Procedure

2.1.1 DEFINING RELATIONSHIP BY FACTS:


% pam is a parent of bob
We will write the above declarative sentence in prolog as:
• Parent(pam, bob).
• Parent(tom, bob).
• Parent(tom, liz).
• Parent(bob, ann).
• Parent(bob, pat). Parent(pat, jim).

2.1.2 DEFINING RELATIONSHIP BY RULES:


Rules have two parts:
• A condition part (body) i-e, left hand side of the rule
• A conclusion part (head) i-e, right hand side of the rule Defining
Offspring Rule
offspring( Y, X) :- parent( X, Y).
For all X and Y,
Y is an offspring of X if
X is a parent of Y.
Defining Mother Rule

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


For all X and Y,
X is the mother of Y if
X is a parent of Y and X is a female
Defining Grandparent Rule

grandparent( X, Z) :- parent( X, Y), parent( Y, Z).


For all X and Z,
X is grandparent of Z if,
X is Parent of Y and Y is parent of Z
2.2 The Family Tree Program

2.3 ASKING QUESTIONS


To answer a question, Prolog tries to satisfy all the goals.
To satisfy a goal means to demonstrate that the goal istrue, assuming that the
relations in the program is true.
Example.
sister(X,Y). % who is sister of
whom.
mother(X,Y). % X is mother of Y.
EXERCISE

1. Find all the sisters relations in the above programs?


2. Write a rule for UNCLE/Aunty relationship.
3. Make a family tree of own and find relationships for brother, sister,
mother, father, uncle, grandparent.
4. Do you know these wooden Russian dolls (Matryoshka dolls) where the
smaller ones are contained in bigger ones? Here is a schematic picture:

First, write a knowledge base using the predicate


directlyIn/2 which encodes which doll is directly
contained in which other doll. Then, define a
recursive predicate in/2 , that tells us which doll is
(directly or indirectly) contained in which other dolls.
For example, the query in(katarina,natasha) should
evaluate to true, while in(olga, katarina)
should fail.

You might also like