Professional Documents
Culture Documents
(2017-2021)
Examiner 1:
Examiner 2:
INDEX
S.NO. PROGRAM DATE. SIGN.
1 Prolog program to find the rules for parent, child, male, female,
son, daughter, brother, sister, uncle, aunt, ancestor.
Solution:
parent(rr,sam).
parent(ar,rr).
parent(shahwar,sami).
male(rr).
male(ar).
female(sam).
female(shahwar).
female(sami).
grandparent(GRANDPARENT,CHILD):-
parent(GRANDPARENT,PARENT),parent(PARENT,CHILD).
daughter(X,Y):-parent(X,Y),female(Y).
son(X,Y):-parent(X,Y),male(Y).
1
Output:
?- (X,sam).
X = rr.
?-parent(X,Y).
X = rr,
Y = sam ;
X = ar,
Y = rr ;
X = shahwar,
Y = sami.
?- parent(rr,sam).
true.
Result: The program to find the rules for parent, child, male, female, son, daughter, brother,
sister, uncle, aunt, ancestor is successfully compiled and executed.
2
3
EX NO: 2 Demonstrate the use of various list operations in prolog.
DATE:
Solution:
delete([1,2,3,1,2],1,X).
X = [2, 3, 2].
proper_length([1,2,3,4,5,1],X).
X = 6.
?- sort([1,3,2,5,4,9,7,8,3],S).
S = [1, 2, 3, 4, 5, 7, 8, 9].
?- subset([1,2],[1,2,3,5]).
true.
?- union([1,2,3,4],[1,a,b,4],A).
A = [2, 3, 1, a, b, 4].
?-intersection([1,2],[2,3],L).
L = [2].
min_member(X,[1,2,3,4]).
X = 1.
Output:
?- member(X,[1,2,3,4]).
X=1;
X=2;
X=3;
X = 4.
?- append([1,2,3],[4,5,6],X).
X = [1, 2, 3, 4, 5, 6].
Result: The program to demonstrate the use of various list operations in prolog is successfully
compiled and executed.
4
5
EX NO: 3 Write a program given the knowledge base.
DATE:
Solution:
Knowledge Base:
If x is on the top of y, y supports x. If x is above y and they are touching each other, x is on top
of y. A cup is above a book. The cup is touching that book. Convert the following into wff’s,
clausal form; Is it possible to deduce that `The book supports the cup’.
Solution:
above(table,cup).
above(floor,book).
above(plate,cup).
touch(plate,cup).
touch(floor,book).
touch(table,cup).
on_top(X,Y):-above(X,Y),touch(X,Y).
supports(X,Y):-touch(X,Y),above(X,Y).
Output-?-on_top(X,Y).
X = (table),
Y = cup ;
X = floor,
Y = book ;
X = plate,
Y = cup.
Output:
?- supports(X,Y).
X = plate,
Y = cup ;
X = floor,
Y = book ;
X = (table),
Y = cup.
6
Result: The program based on given the knowledge base is successfully compiled and executed.
EX NO: 4 Write a prolog program for DFS.
DATE:
Solution:
Solution:
Output:
7
Result: The prolog program for DFS is successfully compiled and executed.
DATE:
Solution:
8
Result: The program to implement following facts and rules is successfully compiled and
executed.
9
EX NO: 6 WAP to compute cube of a number.
DATE:
Solution:
cube(N,C) :- C is N*N*N.
Output:
?- cube(2,X).
X=8
10
Result: The program to perform cube of a number is successfully compiled and executed.
11
EX NO: 7 Discuss various arithmetic operators used in prolog.
DATE:
Solution:
Addition: ?- X is 10 - 5.
X = 5
yes
Subtraction:?- X is 10 * 5.
X = 50
yes
Division:?- X is 10 / 5.
X = 2
yes
Multipe operators:?- X is 10 + 5 * 6 / 3.
X = 20
yes
Result: The program to perform various arithmetic operators is successfully compiled and
12
executed.
13
EX NO: 8 WAP to implement BFS algorithm.
DATE:
Solution:
14
EX NO: 9 WAP to create your own chat database implementing natural
language processing through wit.ai. Also write python program
DATE: to check the text match score.
Solution:
15
16
Python program:
Result: The prolog program to create own chat database implementing natural language
processing through wit.ai is successfully compiled and executed.
17
EX NO: 10 Write a program to solve crypt-arithmetic problem.
DATE:
CROSS
+ ROADS
DANGER
:-use_module(library(clpfd)).
crossroadsdanger(Vars) :-
Vars = [C, R, O, S, A, N, D, G, E ],
Vars ins 0..9,
S #\= 0,
M #\= 0,
all_different(Vars),
10000*C + 1000*R + 100*O +10*S+S
+ 10000*R + 1000*O + 100*A +10*D+S
#= 100000*D + 10000*A + 1000*N + 100*G +10* E+R.
Output:
Result: The prolog program to solve crypt-arithmetic problem is successfully compiled and
executed.
18