AI 170170107080
PRACTICAL - 1
AIM(1.1) - Write a prolog program to implement different kinds of knowledge
bases.
teaches(aakash,science).
teaches(arjun,maths).
teaches(aryan,physics).
teaches(akshay,biology).
teaches(aditi,chemistry).
teaches(arman,hindi).
studies(harsh,science).
studies(harsh,maths).
studies(harsh,physics).
studies(malay,biology).
studies(malay,chemistry).
studies(malay,hindi).
guide(Teacher,Student):-teaches(aakash,science),studies(harsh,science).
guide(Teacher,Student):-teaches(arjun,maths),studies(harsh,maths).
guide(Teacher,Student):-teaches(aryan,physics),studies(harsh,physics).
guide(Teacher,Student):-teaches(akshay,biology),studies(malay,biology).
guide(Teacher,Student):-teaches(aditi,chemistry),studies(malay,chemistry).
guide(Teacher,Student):-teaches(arman,hindi),studies(malay,hindi).
AI 1
AI 170170107080
Output:
AI 2
AI 170170107080
AIM(1.2) - write a program which contains three
predicates:male,female,parent.Make rules for following family
relations:father,mother,grandfather,grandmother,brother,sister,uncle
,aunt,nephew and niece.
/* Facts */
male(jack).
male(oliver).
male(ali).
male(james).
male(simon).
male(harry).
female(helen).
female(sophie).
female(jess).
female(lily).
parent_of(jack,jess).
parent_of(jack,lily).
parent_of(helen, jess).
parent_of(helen, lily).
parent_of(oliver,james).
parent_of(sophie, james).
parent_of(jess, simon).
AI 3
AI 170170107080
parent_of(ali, simon).
parent_of(lily, harry).
parent_of(james, harry).
/* Rules */
father_of(X,Y):- male(X),
parent_of(X,Y).
mother_of(X,Y):- female(X),
parent_of(X,Y).
grandfather_of(X,Y):- male(X),
parent_of(X,Z),
parent_of(Z,Y).
grandmother_of(X,Y):- female(X),
parent_of(X,Z),
parent_of(Z,Y).
sister_of(X,Y):- %(X,Y or Y,X)%
female(X),
father_of(F, Y), father_of(F,X),X \= Y.
sister_of(X,Y):- female(X),
mother_of(M, Y), mother_of(M,X),X \= Y.
AI 4
AI 170170107080
aunt_of(X,Y):- female(X),
parent_of(Z,Y), sister_of(Z,X),!.
brother_of(X,Y):- %(X,Y or Y,X)%
male(X),
father_of(F, Y), father_of(F,X),X \= Y.
brother_of(X,Y):- male(X),
mother_of(M, Y), mother_of(M,X),X \= Y.
uncle_of(X,Y):-
parent_of(Z,Y), brother_of(Z,X).
ancestor_of(X,Y):- parent_of(X,Y).
ancestor_of(X,Y):- parent_of(X,Z),
ancestor_of(Z,Y).
AI 5
AI 170170107080
Output:
AI 6
AI 170170107080
PRACTICAL - 2
Aim: (A)Write a PROLOG program to implement Tower Of Hanoi Problem
(B) Write a program to solve Water-Jug Problem.
(A) Tower of Hanoi
move(1,X,Y,) :-
write('move top disk from '),
write ('X'),
write(' to '),
write ('Y'),
nl.
move(N,X,Y,Z) :-
N>1,
M is N-1,
move(M,X,Z,Y),
move(1,X,Y, ),
move(M,Z,Y,X).
AI 7
AI 170170107080
Output:
AI 8
AI 170170107080
(B) Water-Jug problem
database
visited_state(integer,integer)
predicates
state(integer,integer)
clauses
state(2,0).
state(X,Y):- X < 4,
not(visited_state(4,Y)),
assert(visited_state(X,Y)),
write("Fill the 4-Gallon Jug: (",X,",",Y,") --> (", 4,",",Y,")\n"),
state(4,Y).
state(X,Y):- Y < 3,
not(visited_state(X,3)),
assert(visited_state(X,Y)),
write("Fill the 3-Gallon Jug: (", X,",",Y,") --> (", X,",",3,")\n"),
state(X,3).
state(X,Y):- X > 0,
not(visited_state(0,Y)),
AI 9
AI 170170107080
assert(visited_state(X,Y)),
write("Empty the 4-Gallon jug on ground: (", X,",",Y,") --> (", 0,",",Y,")\n"),
state(0,Y).
state(X,Y):- Y > 0,
not(visited_state(X,0)),
assert(visited_state(X,0)),
write("Empty the 3-Gallon jug on ground: (", X,",",Y,") --> (", X,",",0,")\n"),
state(X,0).
state(X,Y):- X + Y >= 4,
Y > 0,
NEW_Y = Y - (4 - X),
not(visited_state(4,NEW_Y)),
assert(visited_state(X,Y)),
write("Pour water from 3-Gallon jug to 4-gallon until it is full: (", X,",",Y,") --> (",
4,",",NEW_Y,")\n"),
state(4,NEW_Y).
state(X,Y):- X + Y >=3,
X > 0,
NEW_X = X - (3 - Y),
not(visited_state(X,3)),
assert(visited_state(X,Y)),
write("Pour water from 4-Gallon jug to 3-gallon until it is full: (", X,",",Y,") --> (",
NEW_X,",",3,")\n"),
AI 10
AI 170170107080
state(NEW_X,3).
state(X,Y):- X + Y <=4,
Y > 0,
NEW_X = X + Y,
not(visited_state(NEW_X,0)),
assert(visited_state(X,Y)),
write("Pour all the water from 3-Gallon jug to 4-gallon: (", X,",",Y,") --> (", NEW_X,",",0,")\n"),
state(NEW_X,0).
state(X,Y):- X+Y<=3,
X > 0,
NEW_Y = X + Y,
not(visited_state(0,NEW_Y)),
assert(visited_state(X,Y)),
write("Pour all the water from 4-Gallon jug to 3-gallon: (", X,",",Y,") --> (", 0,",",NEW_Y,")\n"),
state(0,NEW_Y).
state(0,2):- not(visited_state(2,0)),
assert(visited_state(0,2)),
write("Pour 2 gallons from 3-Gallon jug to 4-gallon: (", 0,",",2,") --> (", 2,",",0,")\n"),
state(2,0).
state(2,Y):- not(visited_state(0,Y)),
assert(visited_state(2,Y)),
AI 11
AI 170170107080
write("Empty 2 gallons from 4-Gallon jug on the ground: (", 2,",",Y,") --> (", 0,",",Y,")\n"),
state(0,Y).
goal
makewindow(1,2,3,"4-3 Water Jug Problem",0,0,25,80),
state(0,0).
Output:
AI 12
AI 170170107080
PRACTICAL-3
Aim: (A)Write a program to input user name and password from user and repeatedly
asking if any one of them is wrong.
(B)Write a program that list four addresses in a label form, each address should list a name,
one-line address, city,state and pincode.
(A)
/*program to check user name & password (repeat predicate)*/
domains
name,password=symbol.
predicates
getinput(name,password)
logon
user(name,password)
repeat
clauses
repeat.
repeat:-
repeat.
logon:-
clearwindow,
getinput (name,password),
write("sucessful login"),nl.
logon :-
AI 13
AI 170170107080
repeat,
write("sorry try logon"),
getinput(name,password).
getinput(name,password) :-
write("Enter user name :- "),
readln(name),
write("Enter Password"),
readln(password),
user(name,password).
user(xyz,abc).
user(vaishali,mastermind).
Output:
AI 14
AI 170170107080
(B)
Write a Turbo PROLOG program that list four address in a label form, each address should list a name,
one-line address, city, state &ZIP code.
domains
person = address(name, street, city, state, zip)
name, street, city, state, zip = string
predicates
readaddress(person)
go
clauses
go:-readaddress(Address), nl,
write(Address), nl, nl,
write("Accept (y/n) ? ")
,readchar(Reply), Reply = 'y', !.
go:-
nl, write("Please reenter"), nl,
go.
readaddress(address(Name, Street, City, State, Zip)) :-
write("Name : "), readln(Name),
write("Street : "), readln(Street),
write("City : "), readln(City),
write("State : "), readln(State),
AI 15
AI 170170107080
write("Zip : "), readln(Zip).
Output:
AI 16
AI 170170107080
PRACTICAL-4
Aim: Convert the given PROLOG predicates into Semantic Net.
cat(tom).
cat(cat1).
mat(mat1).
sat_on(cat1,mat1).
bird(bird1).
caught(tom,bird1).
like(X,cream) :– cat(X).
mammal(X) :– cat(X).
has(X,fur) :– mammal(X).
animal(X) :– mammal(X).
animal(X) :– bird(X).
owns(john,tom).
is_coloured(tom,ginger).
AI 17
AI 170170107080
AI 18
AI 170170107080
Practical – 5
Aim: Write the Conceptual Dependency for the given statement.
John gives Mary a book.
John gave Mary the book yesterday.
Description/Algorithm:
This representation is used in natural language processing in order to represent
them earning of the sentences in such a way that inference we can be made from the
sentences. It is independent of the language in which the sentences were originally
stated. CD representations of a sentence is built out of primitives , which are not
words belonging to the language but are conceptual , these primitives are combined
to form the meaning s of the words. As an example consider the event represented
by the sentence.
yesterday
AI 19