0% found this document useful (0 votes)
172 views8 pages

Artificial Intelligence Project Lab: Iec College of Engineering & Tecnology

The document contains implementations of various artificial intelligence algorithms and techniques in Lisp and Prolog. It includes programs to find the maximum of three numbers, convert between Celsius and Fahrenheit temperatures, and implementations of best first search, hill climbing, the water jug problem, modeling grandfather and sister relationships, and depth first search using Prolog. It also lists some built-in functions in Prolog like arg, functor, integer, concat, date, time, and files.

Uploaded by

Upwan Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
172 views8 pages

Artificial Intelligence Project Lab: Iec College of Engineering & Tecnology

The document contains implementations of various artificial intelligence algorithms and techniques in Lisp and Prolog. It includes programs to find the maximum of three numbers, convert between Celsius and Fahrenheit temperatures, and implementations of best first search, hill climbing, the water jug problem, modeling grandfather and sister relationships, and depth first search using Prolog. It also lists some built-in functions in Prolog like arg, functor, integer, concat, date, time, and files.

Uploaded by

Upwan Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

IEC COLLEGE OF ENGINEERING &

TECNOLOGY

ARTIFICIAL INTELLIGENCE
PROJECT LAB

Submitted to:: Submitted by::


Ms. Megha Shah Upwan Gupta
IT-2,4th year
0709013115
Serial No. Program description Signature
1. Program to find max. of three numbers.

2. Program to convert Celsius to Fahrenheit temp.

3. Implementation of BEST FIRST SEARCH.

4. Implementation of HILL CLIMBING METHOD.

5. Implementation of WATER JUG PROBLEM.

6. Implementation of grandfather relationship in


PROLOG.
7. Implementation of sister relationship in PROLOG.

8. Implementation of DEPTH FIRST SEARCH in


PROLOG.
9. Built in functions in PROLOG.

Program to find maximum of three numbers


->(defun maximum-3(a b c)
(cond ((>a b) (cond ((> a c ) a) (t c )))
MAXIMUM-3
->(MAXIMUM-3 123 234 3)
((>b c) b)(t c )))

Program to convert a temperature in degree Fahrenheit to degree centigrade

->(defun convert (f))


(+(*(/ 9 5) f) 32)
CONVERT
->(convert 50)

Implementation of BEST FIRST SEARCH in LISP.

- >(defun best_search (start finish & optional(queue(list(list start))))


(cond ((endp queue) nil) ;queue empty
((eq finish (first (first queue))) ;finish found?
(reverse ( first queue ))) ;return path
(t ( best _first ;try again
Start
Finish
(sort(append(extend(first queue))
(rest queue))
# ‘ (lambda(p1 p2) (closerp p1 p2 finish)))))
)
)

- >(defun closerp (path-1 path-2 target-node)


(< (straight-line-distance(first-path1)target)
Straight-line-distance(first-path2)target))
)
> (defun straight-line-distance (node-1 node-2)
(let ((coordinates-1(get node-1 ‘coordinates))
((coordinates-2 (get node-2 ‘coordinates))
)
(sqrt (+ (expt (- (first-1) (first-2)) 2)
(expt(second-1) (second-2)) 2))))
)

Implementation of HILL CLIMBING METHOD in LISP.

- >(defun hill_climbing (start first & optional(queue(list(list start))))


(cond ((endp queue) nil) ;queue empty
((eq finish (first (first queue))) ;finish found?
(reverse ( first queue ))) ;return path
(t ( hill_climbing ;try again
Start
Finish
(append(sort (extend(first queue))
# ‘ (lambda(p1 p2) (closerp p1 p2 finish)))
(rest queue))))
)
)

- >(defun closerp (path-1 path-2 target-node)


(< (straight-line-distance(first-path1)target)
Straight-line-distance(first-path2)target))
)

> (defun straight-line-distance (node-1 node-2)


(let ((coordinates-1(get node-1 ‘coordinates))
((coordinates-2 (get node-2 ‘coordinates))
)
(sqrt (+ (expt (- (first-1) (first-2)) 2)
(expt(second-1) (second-2)) 2))))
)

Implementation of WATER JUG PROBLEM in LISP.

- > (defun water_crook(a b c)


(cond ((and (> c a) (> c b))
(format t “^%^ a is too long” c))
((not (zerop (rem c (gcd a b))))
((format t “^%^ sorry I can not produce” c))
(t (transfer 0 0 a b c))
)
)

> (defun transfer (x y a b c)


(cond((= x c) ;Right amount in A
(format t “~%~ I can produce ~a units in A” c)
Nil )
((= y c)
(format t “~%~ I can produce ~a units in B” c)
Nil )
;;if crook A is full ,empty it
((= x a ) (cons ‘(empty a) (transfer 0 y a b c)))
;;if crook B is empty,fill it
((= y 0) (cons ‘ (fill b) (transfer x b a b c)))
;;will what is in B fit into A?
;;if yes,empty B into A
((>(-a x )y) (cons ‘ (empty b into a)
(transfer (+ x y )0 a b c)))
;;otherwisevfill A from B
(t (cons ‘ (fill a from b)
(transfer a (~y(~a x)) a b c ))))
)

Implementation of grandfather relationship in PROLOG

Father(ram.raj)
Father(shyam,ram)
Grandfather(X,Y):- father(X,Z),father(Z,Y)
Grandfather (shyam,X)

Implementation of sister relationship in PROLOG

Parent(sue,mue)
parent(sue,kay)
sister(X,Y):-parent(Z,X),parent(Z,Y),female(X),X\=Y

Program to depth first search in PROLOG

a(X,Y):-a(X,Y,Z)
go(X,Y):-a(Y,Z),go(Z,Y)
go(X,Y,T):-a(X,Z),legal(Z,T),go(Z,X,[Z|T])
legal(X,[H|T]):-X\=H,legal(X,T)

Built in functions in PROLOG

*arg(N,TERM,ARG) FUNCTION

arg (2,f(X,t(a),t(b)),Y)
*FUNCTOR FUNCTION
functor(D,date,3)
arg(3,D,1997).
D=date(17,april,1997)

*integer(term)

*CONCAT FUNCTION

Concat(“this”,”is an apple”,X)
X=this is an apple

*DATE FUNCTION

Y=2007,M=4,D=10

*TIME FUNCTION

H=12,M=44,S=34,T=49

*files(Wildcad,Filist)

files(“*.pro”,L)
L=[“FILE1.PRO”,FILE2.PRO”]

You might also like