Artificial Intelligence Lab Manual
Artificial Intelligence Lab Manual
Artificial Intelligence Lab Manual
SSASIT
Laboratory Manual
for
Artificial Intelligence
B.E. (COMPUTER)
SEM VIII
January 2013
SSASIT
EXPERIMENT 1
AIM:TurboProlog features and format.
LOGIC:
Write a simple prolog program to study fact, verification, domain,
predicate and clauses section.(Refer book page no 41)
OUTPUT:
SSASIT
EXPERIMENT 2
AIM:WAPusing variables in Prolog.
Write a Prolog program containing facts related to following
predicates
1.Location (city, state)
2.Stays (person, city)
Display:
(i) list of person, state and city
(ii) Given person staying in which state.
LOGIC:
Write clauses Location (city, state) andStays (person, city)
OUTPUT:
(i)Person= ram City=anand State=Gujarat
Person= Lakshman City=anandState=Gujarat
Person= Seeta City=Baroda State=Gujarat
(ii)Person= ram State=Gujarat
SSASIT
EXPERIMENT 3
AIM:WAP for Usage of rules in Prolog.
Create a family tree program(of EXP2) to include following
rules
1. M is the mother of P if she is a parent of P and is
female
2. F is the father of P if he is a parent of P and is male
3. X is a sibling of Y if they both have the same parent.
4. Then add rules for grandparents,uncle-aunt,sister
and brother .
Based on the facts , define goals to answer questions related to
family tree
LOGIC:Consider this relation tree
Dhashrath-Kaushlya
Lakshaman-Urmila
Ram -Sita
Luv
Kush
OUTPUT:
Goal :-grandfather(Luv,X)
X=Dashrath
Goal:-uncle(Luv,X)
X=Lakshman
Goal:-father(Luv,X)
X=Ram
Goal:-sibling(Luv,X)
X=Kush
Goal:-aunt(Luv,X)
X=Urmila
EXPERIMENT 4
3
SSASIT
Solution(2):
4
SSASIT
Person
Luv
Ram
Lakshman
Ancestor
Ram ,Lakshman
Dashrath
Dashrath,
SSASIT
EXPERIMENT 5
AIM:Write programs for studying Usage of arithmetic operators in
Prolog.
(1)Accept name of the student, rollno, his/her subject name
,maximum marks and obtained marks in the subject. (Take
marks of atleast 6 subjects ). Compute the percentage of a
student. Display his result with other information.
(2) Accept department, designation, name, age, basic salary,
house rent allowance(HRA) of an employee . Compute dearness
allowance (DA) which is 15% of basic salary . Determine the
gross salary(basic salary+HRA+DA) of the employee. Display all
information of the employee(Generate Payslip).
LOGIC:
For making the program use variables, arithmetic operator, I/O predicates
appropriately.
OUTPUT:
Solution(1):
Example:
Enter name of student:- ram
Enter roll number of student-Cp1
Enter subject information for 6 subjects:Subject
Max marks Obtained
name
marks
DAA
150
120
OOPD
150
110
CN
150
100
DC
150
100
AMP
150
140
CPI
150
30
Student name:-ram Roll no-Cp1
Subject names-DAA, OOPD, CN, DC, AMP, CPI
Total max marks-.Total Obtained marks- .
%Percentage -
6
SSASIT
Solution(2):
Example:Enter employee name: - xyz
Enter department :-IT Enter age:-43
Enter basic salary-50,000
Enter HRA:- 2000
----------------------PAYSLIP
Employee Name is
xyz Department-IT
BA-50,000
DA - 7500
HRA-2000
Gross salary- 59500/-
SSASIT
EXPERIMENT 6
AIM:WAP to study usage of cut,not,fail predicates in Prolog.
Write a Prolog program having facts in clauses section for
predicate student(studentname,branchname).
Display:
(i)list of all students
(ii)list of students for given specific branch.
(iii)list of students excluding specific branch
LOGIC:
Use cut !, fail, not predicates for this program.
OUTPUT:
Example:***********MENU************
1)Display list of all students
2)Display list of students for given specific branch.
3)Display list of students excluding specific branch
Enter your choice3
Enter branch name to be excluded from result CE
List of all students except from CE branch are Student name- Department
Harsh -IT
Deep-EC
Heena-IC
SSASIT
EXPERIMENT 7
AIM:WAP to study usage of Recursion inProlog.
(1)Write program which finds and display factorial of a given
number.
(2)Write program which display Fibonacci series.
LOGIC:
For finding the factorial of a given number use function fact and for
displaying Fibonacci series use function fibo.
OUTPUT:
Solution(1):
Example:fact(5)
5 != 5*4*3*2*1= 120 .
OUTPUT:
Solution(2):
Example:Total number of numbers needed in output? 6
Fibonacci series of first 6 numbers:-1,1,2,3,5,8
SSASIT
EXPERIMENT 8
AIM:WAPto study usage of logical , arithmetic ,string operators in Prolog
(1)Write
a
program
which
finds
and
displays
maximumnumberand minimum number from three given
numbers.
(2)Write a program which accepts integer number as an input and displays
its square .It should also find its positive square root value ,if its
square root is integer, otherwise display NA.
(3)Write a program to find substring from a given string. The
substring should start from 1st location of source string and
should contain the entered number of characters from the source
string.
LOGIC:
Use appropriate function for finding minimum number ,maximum number
,square root and substring. Use logical operators.
OUTPUT:
Solution(1):
Example:Enter three numbers : 1 2 3
maximum is 3 , minimum is 1
Solution(2):
Example1 :Enter no. : 3
3(number) , 9 (square) ,NA(square root not possible)
Example2 :Enter no. 4
4 (number), 16 (square) , 2(square root)
Solution(3):
Example:
Enter source string: tested
Enter number of characters needed in substring: 4
Original String is : tested
Substring is :test
10
SSASIT
EXPERIMENT 9
AIM:WAP for studying usage of compound object and list in Prolog.
(1)Write a program to maintain inventory items using a
compoundobject:
(i) Accept from user the details of atleast 10 objects.
(ii)Display from user the details of objects entered by user
(2)Find and display odd and even numbers from a given input list.
LOGIC:
The format of compound object should be:
(item type, item (no, description, qty, cost))
Item-type can be Fg-finish good, Sf-semi finish good, Rm-raw material.
Do the following:
OUTPUT:
Solution(1):
Example:Enter information of 10 type:
Enter item type.
Enter item number.
Enter item..
Description.
Enter quantity of item
description quantity
keyboard
10
plasticbox 10
keypad
10
Solution(2):
Example:Enter list of 10 integer numbers
1,2,3,4,5,6,7,8,9,10
Even number -> 2,4,6,8,10
11
cost
2000
300
500
SSASIT
12
%
61
69