Ai Final Report
Ai Final Report
AI final report
LAB REPORT
ON
ARTIFICIAL INTELLIGENCE
By
Swastika Khatri
Roll: 23
Sec: B
Submitted to:
Department of Management
Minbhawan, Kathmandu
Date: 19Jan2023
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
Lab-2
Write a program to display your name in prolog.
Code:
name:-write('Swastika Khatri').
Output:
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:
Lab-4
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).
Output:
Lab-5
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.
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).
Lab-6
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
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
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
Output:
Lab-10
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
Write a program using C or java to implement AND, OR, NOT and XOR
gate.
Code:
package ai;
// 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);
Output: