Sie sind auf Seite 1von 12

RADHA GOVIND ENGINEERING COLLEGE,

MEERUT

ARTIFICIAL INTELLIGENCE LAB FILE

UTTAR PRADESH TECHNICAL UNIVERSITY,


LUCKNOW

Submitted to:

Submitted by:

INDEX
S.NO

TOPICS

DATE

REMARKS

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.

LISP
LISP: List processing is an A.I. programming language developed by John M.C. Carthy
in the late of 1950s.LISP is a symbolic processing language that represents the
Information in list & manipulates these lists to derive the information. LISP language is
exclusively used for manipulating the list.The major characteristic is that the basic
elements are treated as symbols irrespective of whether they are numeric or
alphanumeric.
The basic data elements of LISP is an atom (a single word or number that
stands for some object or value)
LISP has two basic types of atoms1) Numbers 2) Symbols
1) Numbers: Represents a numeric value of any type of nos such as positive or
negative integers, floating or decimal are acceptable.
2) Symbols: Represents alphanumeric characteristics. It can be a combination of an
alphabets and numerals. A collection of nos or symbols constitute a list.
LISP Function:
A LISP program is a collection of small routines which define symbol function. In order
that complex function called primitives. These primitives serve commonly required
operation.
The basic primitives of LISP are:
1)Arithmetic primitives: The arithmetic primitive corresponds to the basic arithmetic
operation of addition, subtraction, multiplication & division. Since LISP used prefix
representation. All the arithmetic representation is carried out on data represented in the
prefix form.
Examples: To add two nos say 10 & 20.The prefix notation is +10 20
2) Boolean: The primitives provide a result which is Boolean in nature i.e. true or false
some such primitives are
(I) Atom: The purpose is to find out whether the element is atom or not.
Ex. (atom_xyz)
(II) Number: Determines atom is no. or not
Ex. (Number_20)
(III) List: Determines if i/p is list or not.
Ex. (List (5 10 15 20))

(IV) Odd: To find out whether the given i/p no. is odd.
Ex. (Odd_65)
(V) Even: Find out i/p is even or not.
Ex. (Even_20)
List Manipulation Primitive:
The purposes are
i)
Creating a new list.
ii)
Modifying the position of list.
iii)
Extracting the position of list.
In LISP the values are assigned to a variable by

SETQ primitive.

The primitive has two arguments:


a) Being the variable.
b) The value to be assigned to the variable
Ex. (SETQ a 20)
Output > 20

FUNCTION:
The function name DEFUN is used to define the function it requires the three argument.
1) The new function name.
2) The parameter for the function.
3) The function body or list code which performs the desired function operation.
The format is (DEFUN Name (parameter 1 Parameter 2Parameter n) Body)
Basic list manipulation function:
S.NO
1

Function Call
(CAR(A B C))

Value Return
A

(CDR(A B C))

BC

(CONSA(B C))

ABC

(LISTA(B C))

(A (B C))

Remarks
CAR takes one argument a list
and returns the first element.
CDR takes one argument list &
returns the first element
remove.
CONS take the two arguments
an element & a list and return a
list with the element inserted at
the beginning.
List takes any no. of arguments
& returns a list with the
argument as elements.

Additional basic manipulation functions are:


S.NO

Function Call

Value Return

Remarks

(APPEND(A)(B C))

ABC

Merges two or more


list in a single list.

(LAST(A B C D))

(REVERSE(A(B C)D))

(D(B C )A)

Returns a list
containing the last
element.
Returns list with top
element in the
reverse order.

Programs:

1) Write a program to find the average of three numbers.


(DEFUN AVERAGE (A B C)
(/ (+ A B C) 3))
AVERAGE
(AVERAGE 10 20 30)
OUTPUT:
20

2) Write a program to find the average of two numbers.


(DEFUN AVERAGE (A B )
(/ (+ A B ) 2))
AVERAGE
(AVERAGE 10 20)
OUTPUT:
15

3) Write a program to find the max of two numbers.


(DEFUN MAX(A B))
(COND (( > A B)A)
(T B)))
MAX
(MAX 3 4)
OUTPUT:
4

4) Write a program to find the maximum of three numbers.


(DEFUN MAX(A B C))
(COND (( > A B)A)
(T (COND ((> B C))B)
(T C)))))
MAX
(MAX 3 4 5)
OUTPUT:
5

5) Write a program to find the minimum of two numbers.


(DEFUN MIN (A B))
(COND ((< A B) A)
(T B))
MIN
(MIN 3 5)
OUTPUT:
3

6) Write a program to find the minimum of three numbers.


(DEFUN MIN (A B C))
(COND ((< A B)A)
(T (COND((< B C) B)
(T C)))))
MIN
(MIN 3 4 5)
OUTPUT:
3

7) Write a program to find the maximum of four numbers.


(DEFUN MAX(A B C D))
(COND (( > A B)A)
(T (COND ((> B C))B)
(T (COND ((> C D)C)
(T D)))))
MAX
(MAX 3 4 5 8)
OUTPUT:
8

8) Write a program to find the minimum of four numbers.


(DEFUN MIN(A B C D)
(COND ((< A B) A)
(T (COND ((< B C) B)
(T (COND ((< C D) C)
(T D)))))))
MIN
(MIN 8 5 4 3)
OUTPUT:
3

9) Write a program to find the area of square.


(DEFUN SQAREA(X) (* X X))
SQAREA
(SQAREA 5)
OUTPUT:
25

10) Write a program to find the area of rectangle.


(DEFUN RECT(L B) (* L B))
RECT
(RECT 5 10)
OUTPUT:
50

11) Write a program to find the area of triangle.


(DEFUN TRIANGLE(B H) (* .5 (* B H)))
TRIANGLE
(TRIANGLE 5 10)
OUTPUT:
25

10

12) Write a program to find the area of circle.


(DEFUN CIRCLE(R) (*3.14 (* R R)))
CIRCLE
(CIRCLE 5)
OUTPUT:
78.5

13) Write a program to convert Fahrenheit into Celsius.( C=(F+40)*(5/9)-40 )


(DEFUN TEMP(F)
(- (* (+ F 40) (/ 5 9)) 40))
TEMP
(TEMP 5)
OUTPUT:
-15

14) Write a program to convert C Celsius into Fahrenheit.( F=(C+40)*(9/5)-40 )


(DEFUN TEMP(C)
(- (* (+ C 40) (/ 9 5)) 40))
TEMP
(TEMP -15)
OUTPUT:

11

5
15) Write a program to find the factorial of a number.
(DEFUN FACT(X)
(COND ((ZEROP X) 1)
(T (* X (FACT (- X 1))))))
FACT
(FACT 5)
OUTPUT:
120

16) Write a program to take temperature as a parameter and return HOT if the
temperature is greater than 100, COLD if it is less than 0 and OK otherwise.
(DEFUN TEMP (X)
(COND ((> X 100) HOT)
(T (COND ((< X 0) COLD)
(T OK)))))
TEMP
(TEMP 120)
OUTPUT:
HOT

12

Das könnte Ihnen auch gefallen