You are on page 1of 21

LABORATORY RECORD NOTE BOOK

AMITY UNIVERSITY CHHATTISGARH


AMITY UNIVERSITY CHHATTISGARH

AMITY SCHOOL OF ENGINEERING AND TECHNOLOGY

(2017-2021)

Enrollment Number: A80105217013

This is to certify that this is a bonafide record of the work done by

Ms.: TAMANNA BAID Enrollment Number: A80105217013

of the year 2020 B.E/B.TECH Department of COMPUTER SCIENCE

Engineering in the AI Laboratory in the 7 th semester.

University Examination held on --------------------------------

Facultyin-charge Director ASET

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.

2 Demonstrate the use of various list operations in prolog

3 Write a program given the 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’

4 WAP to implement DFS algorithm

5 WAP to implement following facts and rules

6 WAP to compute cube of a number.

7 Discuss various arithmetic operators used in prolog.

8 WAP to implement BFS algorithm.

9 WAP to create your own chat database implementing natural


language processing through wit.ai. Also write python program to
check the text match score.

10 Program to solve crypt-arithmetic problem.


EX NO: 1 Write a prolog program to find the rules for parent, child, male,
female, son, daughter, brother, sister, uncle, aunt, ancestor.
DATE:

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:

dfs(S, Path, Path) :- goal(S).

dfs(S, Checked, Path) :-


% try a move
move(S, S2),
% ensure the resulting state is new
\+member(S2, Checked),
% and that this state leads to the goal
dfs(S2, [S2|Checked], Path).

Output:

?-dfs([1,2,3, 0,4,5, 6,7,8], [], Path).


Path = [[1, 2, 3, 4, 0, 5, 6, 7|...]] .

7
Result: The prolog program for DFS is successfully compiled and executed.

EX NO: 5 WAP to implement following facts and rules.

DATE:

Solution:

The bindings for ?x is-a horse:


?x -> Comet,
?x -> Prancer,
?x -> Thunder, and
?x -> Dasher

The bindings for ?y is fast


?y -> Prancer and
?y -> Thunder
The bindings for ?x and ?y in ?x is-a-parent-of ?y are:
?x -> Comet,?y -> Dasher; ?x -> Comet,?y -> Prancer; and
?x -> Dasher,?y -> Thunder
I.e., "Comet is-a horse" matches "?x is-a horse" but
"Aslan is-a lion" does not match "?x is-a horse"
Rule applicable with bindings
?x -> Comet,?y -> Prancer and ?x -> Dasher,?y -> Thunder
That is new facts that can be derived are:
valuable(Comet) and valuable(Dasher)

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

Equality operator:?- 6+4=:=6*3-8.


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:

breadth_first(Goal, Goal, _,[Goal]).


breadth_first(Start, Goal, Visited, Path) :-
findall(X,
(connected2(X,Start,_),not(member(X,Visited))),
[T|Extend]),
write(Visited), nl,
append(Visited, [T|Extend], Visited2),
append(Path, [T|Extend], [Next|Path2]),
breadth_first(Next, Goal, Visited2, Path2).
?- breadth_first(1, 28, [1], []).

Result: The program to perform BFS is successfully compiled and executed.

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:

?- Vars=[ C, R, O, S, A, N, D, G, E ], crossroadsdanger(Vars), label(Vars).


Vars = [9, 6, 2, 3, 5, 8, 1,7, 4],
C = 9,
R = 6,
O = 2,
S = 3,
A = 5,
N = 8,
D = 1,
G = 7,
E =4.

Result: The prolog program to solve crypt-arithmetic problem is successfully compiled and
executed.

18

You might also like