Lab Manual: Experiment NO: Name of Experiment
Lab Manual: Experiment NO: Name of Experiment
EXPERIMENT
NO: NAME OF EXPERIMENT
1 Write a program showing use of LISP arithmetic functions.
13 Write a program in PROLOG showing the use of predicate facts and rules.
15 Write a program in PROLOG, which contains facts about the names and ages of
some of the pupils in a class.
16 Write a program in PROLOG, which contains facts about the names and ages of
some of the pupils in a class.
EXPERIMENT: 1
Objective: Write a program showing use of LISP arithmetic functions.
(+ 3 5 8 4) 20
(- 10 12) -2
(* 2 3 4) 24
(/ 25 2) 12.5
EXPERIMENT: 2
Objective: - Write a program for implementation of LISP manipulation functions.
EXPERIMENT NO: 3
Objective: - Write a program for implementation of LISP Boolean function.
(Atom ‘aabb) t
(Evenp 3) nil
(Oddp 3) t
(Greater 2 4 27) t
(Lessp 5 3 1 2) nil
(Listp ‘(a)) t
(Null nil) t
Experiment No: 4
Objective: - Write a LISP Program calculating average of three numbers.
AVERAGETHREE
OUTPUT
(Averagethree 10 20 30)
20
EXPERIMENT NO: 5
Objective: - Write a program in LISP showing implementation of condition.
MAXIMUM2
OUTPUT
:-> 320
( defun maximum3(a b c)(cond(( > a b)(cond(( > a c)a)(t c)))( ( > b c)b)(t c)))
MAXIMUM3
OUTPUT
( maximum3 20 30 25)
:-> 30
EXPERIMENT: 6
Objective:- Write a LISP program to implement factorial of a number.
FACTORIAL OF A NUMBER
FACTORIAL
:-> (factorial 6)
720
EXPERIMENT NO: 7
Objective: - Write a LISP program for declaring property list and assigning values to them.
PUTPROP
TO ASSIGN PROPERTY
->(putprop ‘car ‘ford ‘make)
FORD
EXPERIMENT NO: 8
Objective: -. Write a LISP program to retrieve a property value.
PUTPROP
->(putprop ‘car ‘ford ‘make)
FORD
RETRIEVE A PROPERTY
EXPERIMENT NO: 9
PUTPROP
->(putprop ‘car ‘ford ‘make)
FORD
EXPERIMENT: 10
Theory:- Single or multidimensional arrays may be defined in LISP using the make-array
function .The items stored in array may be any LISP object. For example ,to create an array with
ten cells named myarray we bind the unquoted name to an array using setf(or setq) with the
make array function and specification of the number of cells.
Note that the function returns the pound sign(#) followed by an A and the array representation
withits cells initially set to nil.
To access the contents of cells,we use the function aref which takes two arguments, the name of
the array and the index value.since the cells are indexed starting at zero ,an index value of 9 must
be used to retrieve the contents of the tenth cell.
->(aref myarray 9)
NIL
EXPERIMENT: 11
Theory:-
To store items in the arrays,we use the function setf as to store properties on a property list .So to
store the items 25,red,and (sam sue linda) in the first,second,and the third cells of myarray.
:->( setf (aref myarray 0)25)
25
EXPERIMENT: 12
For eg:-
Add 1 to each element of the list (5 10 15 20 25)
(6 11 16 21 26)
:->
If we wish to add the corresponding elements of two lists(even of unequal length),use the +
function with the list to obtain the sum of the first four elements.
:->(2 4 6 8)
EXPERIMENT: 13
Objective:-Write a program in PROLOG showing the use of predicate facts and rules.
domains
person, activity = symbol
predicates
likes(person, activity)
clauses
likes(rakesh, tennis).
likes(vivek, football).
likes(rupali, baseball).
likes(rohan, swimming).
likes(shruti, tennis).
likes(akash, X) if likes(rupali, X).
Type the above program into your computer and Run it. When the system responds in the dialog
window.
Goal :
likes(akash, baseball).
True
likes(akash, tennis).
False
likes(Individual, tennis).
Individual = rakesh
Individual = shurti
2 Solutions
EXPERIMENT: 14
domains
brand, color = symbol
age, price = integer
mileage = real
predicates
car(brand, mileage, age, color, price)
clauses
car(audi, 130000, 3, red, 12000).
car(ford, 90000, 4, gray, 25000).
car(honda, 8000,1,red, 30000).
Goal:
EXPERIMENT: 15
Objective:-Write a program in PROLOG, which contains facts about the names and ages
of some of the pupils in a class.
domains
child = symbol
age = integer
predicates
pupil(child, age)
clauses
pupil(akansha, 9).
pupil(arjun, 10).
pupil(amit, 9).
pupil(susan, 9).
Goal:
pupil(Person1, 9) and
pupil(Person2, 9) and
Person1 <> Person2.
Person1=akansha, Person2=amit
Person1=akansha, Person2=susan
Person1=amit, Person2=akansha
Person1=amit, Person2=susan
Person1=susan, Person2=akansha
Person1=susan, Person2=amit
6 Solutions
EXPERIMENT: 16
Objective:-Write a program in PROLOG, which contains facts about the names and ages
of some of the pupils in a class.
domains
person = symbol
predicates
male(person)
smoker(person)
vegetarian(person)
ritika_could_marry(person)
goal
ritika_could_marry(X) and
write("a possible person for ritika is ",X) and nl.
clauses
male(nitin).
male(karan).
male(raju).
smoker(ramesh).
smoker(raju).
vegetarian(nitin).
vegetarian(raju).
ritika_could_marry(X) if male(X) and not(smoker(X)).
ritika_could_marry(X) if male(X) and vegetarian(X).
EXPERIMENT: 17
domains
person = symbol
predicates
male(person)
female(person)
father(person, person)
mother(person, person)
parent(person, person)
sister(person, person)
brother(person, person)
uncle(person, person)
grandfather(person, person)
clauses
male(salmaan).
male(shahrukh).
male(amir).
male(ajay).
female(anuskha).
female(vidya).
female(katrina).
female(rekha).
mother(katrina, anuskha).
mother(salmaan, rekha).
father(salmaan, amir).
father(anuskha, shahrukh).
father(vidya, amir).
father(katrina, salmaan).
brother(X,Y) if
male(Y) and
parent(X,P) and
parent(Y,P) and
X<> Y.
sister(X,Y) if
female(Y) and
parent(X,P) and
parent(Y,P) and
X<> Y.
uncle(X,U) if
mother(X,P) and
brother(P, U).
uncle(X, U) if
father(X,P) and
brother(P,U).
grandfather(X,G) if
father(P,G) and
mother(X,P).
grandfather(X,G) if
father(X,P) and
father(P,G).