0% found this document useful (0 votes)
3 views

Ai Final Report

Uploaded by

olikeshab527
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)
3 views

Ai Final Report

Uploaded by

olikeshab527
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/ 17

lOMoARcPSD|55196816

AI final report

Artificial Intelligence (Tribhuvan Vishwavidalaya)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Keshab Oli ([email protected])
lOMoARcPSD|55196816

LAB REPORT

ON

ARTIFICIAL INTELLIGENCE

By

Swastika Khatri

BIM 7th semester

Roll: 23

Sec: B

Submitted to:

Mr. Arjun Lamichhane

Department of Management

Nepal Commerce Campus

Minbhawan, Kathmandu

In partial fulfillment of the requirements for the Course Artificial Intellegence

Date: 19Jan2023

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Lab-1
What is prolog? Describe its history and current uses in brief.
Prolog is a logic programming language. It has important role in artificial
intelligence. Unlike many other programming languages, Prolog is intended
primarily as a declarative programming language. In prolog, logic is expressed as
relations (called as Facts and Rules). Core heart of prolog lies at the logic being
applied. Formulation or Computation is carried out by running a query over these
relations.
History of Prolog:
The heritage of prolog includes the research on theorem provers and some other
automated deduction system that were developed in 1960s and 1970s. The
Inference mechanism of the Prolog is based on Robinson’s Resolution Principle,
that was proposed in 1965, and Answer extracting mechanism by Green (1968).
These ideas came together forcefully with the advent of linear resolution
procedures.
The explicit goal-directed linear resolution procedures, gave impetus to the
development of a general purpose logic programming system. The first Prolog was
the Marseille Prolog based on the work by Colmerauer in the year 1970. The
manual of this Marseille Prolog interpreter (Roussel, 1975) was the first detailed
description of the Prolog language.
Prolog is also considered as a fourth generation programming language supporting
the declarative programming paradigm. The well-known Japanese Fifth-Generation
Computer Project, that was announced in 1981, adopted Prolog as a development
language, and thereby grabbed considerable attention on the language and its
capabilities.
Some Applications of Prolog:
Prolog is used in various domains. It plays a vital role in automation system.
Following are some other important fields where Prolog is used −
 Intelligent Database Retrieval
 Natural Language Understanding
 Specification Language
 Machine Learning
 Robot Planning
 Automation System
 Problem Solving

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Lab-2
Write a program to display your name in prolog.

Code:

name:-write('Swastika Khatri').

Output:

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Lab- 3

Write a prolog program to represent few basic facts and perform queries (eg
elephant is an animal. Elephant is bigger than horse etc.)

Code:
animal(Rhino).
animal(donkey).
animal(cat).
animal(dog).
bird(Pigeon).
bird(crow).
bird(parrot).

bigger_than(Rhino,donkey).
bigger_than(donkey,dog).
bigger_than(dog,cat).
bigger_than(cat,crow).
bigger_than(X,Y):-bigger_than(X,Z),bigger_than(Z,Y).
smaller_than(X,Y):-bigger_than(Y,X).

Output:

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Lab-4

For the above family tree:


i. Represent all members of family with their gender as property.
ii. Represent all parent relationship of the family. (i.e. all fact of form parent
(X, Y))
iii. Is tom parent of jim?
iv. Is angela male?
v. Is bob parent of pat?
vi. Is liz parent of pat?

Code:
female(pam).
female(ann).
female(liz).
female(angela).
female(sue).
female(mary).
male(pat).
male(bob).
male(tom).
male(jim).
male(dave).

parent(bob,mary).
parent(bob,ann).
parent(bob,pat).
parent(bob,sue).
parent(tom,liz).
parent(tom,bob).

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

parent(pam,bob).
parent(sue,dave).
parent(sue,angela).
parent(pat,jim).

Output:

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Lab-5

For above family tree list following:


i. List all male family members
ii. List all female family members.
iii. Who is liz’s parent?
iv. Who are bob’s children?
v. Find all parent children relationship. (find all X and Y such that X is
parent of Y).
vi. Who is grand parent of jim?
vii. Who are tom’s granddaughters?
viii. Does ann and pat have common parent?
ix. Who are the siblings of ann?
x. List all the sisters of pat.
xi. List all the uncles of Angela.

Code:
female(pam).
female(ann).
female(liz).
female(angela).
female(sue).
female(mary).
male(pat).
male(bob).
male(tom).
male(jim).
male(dave).
parent(bob,mary).
parent(bob,ann).
parent(bob,pat).
parent(bob,sue).
parent(tom,liz).
parent(tom,bob).
parent(pam,bob).
parent(sue,dave).
parent(sue,angela).
parent(pat,jim).
mother(X,Y):- parent(X,Y),female(X).
father(X,Y):- parent(X,Y),male(X).
brother(X,Y) :- parent(Z,X), parent(Z,Y),male(X),X\==Y.
sister(X,Y) :- parent(Z,X), parent(Z,Y),female(X),X\==Y.

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

grandparent(X,Y):-parent(Z,Y),parent(X,Z).
uncle(X,Z) :- brother(X,Y), parent(Y,Z).
commonparent(X,Y):-parent(Z,X),parent(Z,Y).
children(X,Y):-parent(Y,X).
granddaughter(X,Y):-parent(Z,X),parent(Y,Z),female(X).
sibling(X,Y):-parent(Z,Y),parent(Z,X).

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Lab-6

Write a program to display factorial of a user defined number using


recursion.
Code:
factorial(0,1).

factorial(N,F):-
N>0,
N1 is N-1,
factorial(N1,F1),
F is N*F1.
findfactorial:-
write('\n Enter a number '),
read(Num),
factorial(Num,F),
write('\n Factorial of '),write(Num),write(' is '),write(F).

Output:

Lab-7

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Write a program to display Fibonacci sequence up to user defined number


using recursion.
Code:
fibonacciSequence:-
write('Enter the position upto which you want to print Fibonacci
Sequence : '),read(N),nl,
write('Fibonacci sequence upto '),write(N),write(' th term
is : '),nl,
A is 0,
B is 1,
write(A),write(' '),write(B),write(' '),
Num is N-1,
fibonacci(Num,A,B).

fibonacci(N,A,B):-
N<2, write(' \n All numbers generated ! Thank You');
C is A+B,
write(C),write(' '),
D is B,
E is C,
N1 is N-1,
fibonacci(N1,D,E).

Output:

Lab-8

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Write a program to implement monkey banana problem.


Code:
on(monkey,floor).
on(box,floor).
in(monkey,room).
in(box,room).
in(banana,room).
at(banana,ceiling).

strong(monkey).
grasp(monkey).
climb(monkey,box).

push(monkey,box):-strong(monkey).
under(box,banana):-push(monkey,box).

canreach(monkey,banana):-
on(box,floor),
at(banana,ceiling),
under(box,banana),
climb(monkey,box).
canget(monkey,banana):-
canreach(monkey,banana),
grasp(monkey).

Output:

Lab-9

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Write a program to implement Tower of Hanoi problem.


Code:
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).

Output:

Lab-10

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Represent following facts using prolog:


If a student studies they will pass the exam.
If the student pass their exam they will be happy.
Radha studied for the exam.
Rakesh studied for the exam.
Anish studied for the exam.
Rekha did not study for her exam.
Bibek did not study for the exam
Using the facts, answer following:
i. Did Anish pass?
ii. List all the students that passed.
iii. Did Rekha study?
iv. List all the students that did not study.

Code:
pass(X):-study(X).
happy(X):-pass(X).
notstudy(rekha).
notstudy(bibek).

study(radha).
study(rakesh).
study(anish).
fail(X):-notstudy(X).
umhappy(X):-fail(X).
Output:

Lab-11

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Write a program using C or java to implement AND, OR, NOT and XOR
gate.
Code:
package ai;

public class operators {


public static void main(String[] args) {
// Initial values
int a = 5;
int b = 7;

// bitwise and
// 0101 & 0111=0101 = 5
System.out.println("a&b = " + (a & b));

// bitwise or
// 0101 | 0111=0111 = 7
System.out.println("a|b = " + (a | b));

// bitwise xor
// 0101 ^ 0111=0010 = 2
System.out.println("a^b = " + (a ^ b));

// bitwise not
// ~00000000 00000000 00000000 00000101=11111111 11111111
11111111 11111010
// will give 2's complement (32 bit) of 5 = -6
System.out.println("~a = " + ~a);

// can also be combined with


// assignment operator to provide shorthand
// assignment
// a=a&b
a &= b;
System.out.println("a= " + a);
System.out.println("b= " + b);
System.out.println("Swastika,23,B");
}
}

Downloaded by Keshab Oli ([email protected])


lOMoARcPSD|55196816

Output:

Downloaded by Keshab Oli ([email protected])

You might also like