SlideShare uma empresa Scribd logo
1 de 43
ARTIFICIAL INTELLIGENCE
LISP and PROLOG
Submitted to : Submitted by:
Dr.arpana chaturvedi Arti kumari
S No. CONTENT REMARK
LISP
1 To print “hello world” in LISP
2 program To find the area of circle
3 to print odd number form 1-20
4 to print the average of number 10,20,30,40
5 defining macro
OPERATORS
6 Arithmetic operator
7 Comparision operator
8 Logical operator
DECISIONS CONSTRUCT
9 Cond
10 If
11 When
12 case
LOOPS
13 Loop
14 Loop for
15 Do
16 dotimes
17 dolist
18 Predicate
29 Factorial of a number
20 Array
21 String
22 Sequence
23 list
24 Exiting from block
25 Let function
26 Prog function
27 Formatted output
PROLOG
28 Print hello world using prolog. In console
29 prolog program to print hello world..
30 Priya, Tiyasha, and Jaya are three girls, among
them, Priya can cook
31 some rules. Rules contain some information that
are conditionally true about the domain of
interest.
32 Priya, Tiyasha, and Jaya are three girls, among
them, Priya can cook.
;use of variable in our query
33 Prolog program, that can find the minimum of
two numbers and the maximum of two numbers.
34 write a prolog program that will help us find the
equivalent resistance
35 program to show working of Arithmetic operator
in prolog
36 prolog program to print values from 1 to10 using
loop
37 Example of decision making in Prolog.
38 prolog program to find the length of the list
39 prolog program to concatenate two list
40 Backtracking.
41 prolog program to find the cube of a number
LISP
Q1)To print “hello world” in LISP
CODE:
(write-line "Hello World")
(write-line "I am at 'Online class' !-
Learning LISP" )
Q2) LISP program To find the area of circle ..
CODE:
(defconstantp13.141592)
(defunarea-circle(rad)
(terpri)
(formatt " Radius:~5f"rad)
(formatt "~%area:~10f" (* p1 rad rad)))
(area-circle 10)
Q3)LISP program to print odd number form 1-20 ?
CODE:
(loopfor x from 1 to 20
if(oddpx)
do (printx)
)
Q4)LISP program to print the average of number 10,20,30,40
CODE:
;write a LISP program to find the average of numbers
(defunaveragenum(n1 n2 n3 n4)
( / ( + n1 n2 n3 n4) 4)
)
(write(averagenum10 20 30 40))
Q5.defining macro
CODE:
(defmacro setTo10(num)
(setq num 10)(print num))
(setq x 25)
(print x)
(setTo10 x)
Q6)Arithmetic operators
(setq a 10)
(setq b 20)
(format t "~% A + B = ~d" (+ a b))
(format t "~% A - B = ~d" (- a b))
(format t "~% A x B = ~d" (* a b))
(format t "~% B / A = ~d" (/ b a))
(format t "~% Increment A by 3 = ~d" (incf a 3))
(format t "~% Decrement A by 4 = ~d" (decf a 4))
Q7) Comparison operator
(setq a 10)
(setq b 20)
(format t "~% A = B is ~a" (= a b))
(format t "~% A /= B is ~a" (/= a b))
(format t "~% A > B is ~a" (> a b))
(format t "~% A < B is ~a" (< a b))
(format t "~% A >= B is ~a" (>= a b))
(format t "~% A <= B is ~a" (<= a b))
(format t "~% Max of A and B is ~d" (max a b))
(format t "~% Min of A and B is ~d" (min a b))
Q8) logical operator
(setq a 10)
(setq b 20)
(format t "~% A and B is ~a" (and a b))
(format t "~% A or B is ~a" (or a b))
(format t "~% not A is ~a" (not a))
(terpri)
(setq a nil)
(setq b 5)
(format t "~% A and B is ~a" (and a b))
(format t "~% A or B is ~a" (or a b))
(format t "~% not A is ~a" (not a))
(terpri)
(setq a nil)
(setq b 0)
(format t "~% A and B is ~a" (and a b))
(format t "~% A or B is ~a" (or a b))
(format t "~% not A is ~a" (not a))
(terpri)
(setq a 10)
(setq b 0)
(setq c 30)
(setq d 40)
(format t "~% Result of and operation on 10, 0, 30, 40 is ~a"
(and a b c d))
(format t "~% Result of and operation on 10, 0, 30, 40 is ~a"
(or a b c d))
(terpri)
(setq a 10)
(setq b 20)
(setq c nil)
(setq d 40)
(format t "~% Result of and operation on 10, 20, nil, 40 is ~a"
(and a b c d))
(format t "~% Result of and operation on 10, 20, nil, 40 is ~a"
(or a b c d))
Q9) cond construct
(setq a 10)
(cond ((> a 20)
(format t "~% a is greater than 20"))
(t (format t "~% value of a is ~d " a)))
Q10) If construct
(setq a 10)
(if (> a 20)
(format t "~% a is less than 20"))
(format t "~% value of a is ~d " a)
Q11)When construct
(setq a 100)
(when (> a 20)
(format t "~% a is greater than 20"))
(format t "~% value of a is ~d " a)
Q12)Case construct
(setq day 4)
(case day
(1 (format t "~% Monday"))
(2 (format t "~% Tuesday"))
(3 (format t "~% Wednesday"))
(4 (format t "~% Thursday"))
(5 (format t "~% Friday"))
(6 (format t "~% Saturday"))
(7 (format t "~% Sunday")))
Q13)Loop construct
(setq a 10)
(loop
(setq a (+ a 1))
(write a)
(terpri)
(when (> a 17) (return a))
)
Q14)Loop for
(loop for x from 1 to 20
if(evenp x)
do (print x)
)
Q15)Do construct
(do ((x 0 (+ 2 x))
(y 20 ( - y 2)))
((= x y)(- x y))
(format t "~% x = ~d y = ~d" x y)
)
Q16)dotimes
(dotimes (n 11)
(print n) (prin1 (* n n))
)
Q17)dolist
(dolist (n '(1 2 3 4 5 6 7 8 9))
(format t "~% Number: ~d Square: ~d" n (* n n))
)
Q18)predicate
(write (atom 'abcd))
(terpri)
(write (equal 'a 'b))
(terpri)
(write (evenp 10))
(terpri)
(write (evenp 7 ))
(terpri)
(write (oddp 7 ))
(terpri)
(write (zerop 0.0000000001))
(terpri)
(write (eq 3 3.0 ))
(terpri)
(write (equal 3 3.0 ))
(terpri)
(write (null nil ))
Q19)To find the factorial of a number
(defun factorial (num)
(cond ((zerop num) 1)
(t ( * num (factorial (- num 1))))
)
)
(setq n 6)
(format t "~% Factorial ~d is: ~d" n (factorial n))
Q20)Array
(write (setf my-array (make-array '(10))))
(terpri)
(setf (aref my-array 0) 25)
(setf (aref my-array 1) 23)
(setf (aref my-array 2) 45)
(setf (aref my-array 3) 10)
(setf (aref my-array 4) 20)
(setf (aref my-array 5) 17)
(setf (aref my-array 6) 25)
(setf (aref my-array 7) 19)
(setf (aref my-array 8) 67)
(setf (aref my-array 9) 30)
(write my-array)
Q21)String
(write-line "Hello World")
(write-line "Welcome to JAGANNATH INSTITUTE OF MANAGEMENT
SCIENCES")
;escaping the double quote character
(write-line "Welcome SIXTH SEMESTER")
Q22) sequence
(write (count 7 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (remove 5 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (delete 5 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (substitute 10 7 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (find 7 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (position 5 '(1 5 6 7 8 9 2 7 3 4 5)))
Q23)lists
(write (cons 1 2))
(terpri)
(write (cons 'a 'b))
(terpri)
(write (cons 1 nil))
(terpri)
(write (cons 1 (cons 2 nil)))
(terpri)
(write (cons 1 (cons 2 (cons 3 nil))))
(terpri)
(write (cons 'a (cons 'b (cons 'c nil))))
(terpri)
(write ( car (cons 'a (cons 'b (cons 'c nil)))))
(terpri)
(write ( cdr (cons 'a (cons 'b (cons 'c nil)))))
Q24)exiting from the block
Q25) let function
(let((x 'a)(y'b) (z'c))
(formatt "x= ~a y= ~a z= ~a" x y z))
Q26)prog function
(prog((x'(abc))(y'(12 3))(z'(pq10)))
(formatt"x=~a y=~a z=~a" x y z))
Q27)Formatted output
(setqx 10)
(setqy20)
(formatt"x=~2d y=~2d ~%" x y)
(setqx 100)
(setqy200)
(formatt"x=~2d y=~2d" x y)
PROLOG
Q28) Print hello world using prolog..
CODE:
write('Hello World').
Q29)prolog program to print hello world..
CODE:
main :- write('This is sample Prolog program'),
write(' This program is written into hello_world.pl file').
Q30) Priya, Tiyasha,and Jaya are three girls, among them,Priya can cook.
CODE:
girl(priya).
girl(tiyasha).
girl(jaya).
can_cook(priya).
Q31) some rules. Rules contain some informationthat are conditionally true about the
domain of interest.
CODE:
sing_a_song(ananya).
listens_to_music(rohit).
listens_to_music(ananya):- sing_a_song(ananya).
happy(ananya):- sing_a_song(ananya).
happy(rohit) :- listens_to_music(rohit).
playes_guitar(rohit):- listens_to_music(rohit).
Q32) Priya, Tiyasha,and Jaya are three girls, among them,Priya can cook.
;use of variable in our query
CODE:
can_cook(priya).
can_cook(jaya).
can_cook(tiyasha).
likes(priya,jaya) :- can_cook(jaya).
likes(priya,tiyasha) :- can_cook(tiyasha).
Q33) Prolog program,that can find the minimum of two numbers and the maximum
of two numbers.
CODE:
find_max(X,Y,X) :- X >= Y, !.
find_max(X,Y,Y) :- X < Y.
find_min(X,Y, X) :- X =< Y, !.
find_min(X,Y, Y) :- X > Y.
Q34) write a prolog program that will help us find the equivalent resistance.
 If R1 and R2 are in Series, then equivalent resistor Re = R1 + R2.
 If R1 and R2 are in Parallel, then equivalent resistor Re = (R1 * R2)/(R1 +
R2).
Q35)programto show working of Arithmetic operatorin prolog
+ Addition
- Subtraction
* Multiplication
/ Division
** Power
// Integer Division
mod Modulus
Q36)prolog program to print values from 1 to10 using loop
CODE:
count_to_10(10):- write(10),nl.
count_to_10(X) :-
write(X),nl,
Y is X + 1,
count_to_10(Y).
Q37) Example of decision making in Prolog.
CODE:
% If-Then-Else statement
gt(X,Y) :- X >= Y,write('X is greateror equal').
gt(X,Y) :- X < Y,write('X is smaller').
% If-Elif-Else statement
gte(X,Y) :- X > Y,write('X is greater').
gte(X,Y) :- X =:= Y,write('X and Y are same').
gte(X,Y) :- X < Y,write('X is smaller').
Q38)prolog program to find the length of the list ;?
CODE:
list_length([],0).
list_length([_|TAIL],N) :- list_length(TAIL,N1),N is N1 + 1.
Q39)prolog program to concatenatetwo list
CODE:
list_concat([],L,L).
list_concat([X1|L1],L2,[X1|L3]) :- list_concat(L1,L2,L3).
Q40)Backtracking.
CODE:
boy(tom).
boy(bob).
girl(alice).
girl(lili).
pay(X,Y) :- boy(X), girl(Y).
Q41)prolog program to find the cube of a number
CODE:
cube :-
write('Write a number:'),
read(Number),
process(Number).
process(stop) :- !.
process(Number) :-
C is Number* Number* Number,
write('Cube of '),write(Number),write(': '),write(C),nl,cube.

Mais conteúdo relacionado

Mais procurados

0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
Mrunal Patil
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
Ankita Goyal
 

Mais procurados (20)

Concept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithmConcept learning and candidate elimination algorithm
Concept learning and candidate elimination algorithm
 
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
0/1 DYNAMIC PROGRAMMING KNAPSACK PROBLEM
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
 
NLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit DistanceNLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit Distance
 
Multi dimensional turing machine
Multi dimensional turing machineMulti dimensional turing machine
Multi dimensional turing machine
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
First order logic
First order logicFirst order logic
First order logic
 
First order logic
First order logicFirst order logic
First order logic
 
Fuzzy Logic
Fuzzy LogicFuzzy Logic
Fuzzy Logic
 
RECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSINGRECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSING
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Tsp is NP-Complete
Tsp is NP-CompleteTsp is NP-Complete
Tsp is NP-Complete
 
Job sequencing with Deadlines
Job sequencing with DeadlinesJob sequencing with Deadlines
Job sequencing with Deadlines
 
Frames
FramesFrames
Frames
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
Production system in ai
Production system in aiProduction system in ai
Production system in ai
 
asymptotic notation
asymptotic notationasymptotic notation
asymptotic notation
 

Semelhante a Lisp and prolog in artificial intelligence

CL metaprogramming
CL metaprogrammingCL metaprogramming
CL metaprogramming
dudarev
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
Damian T. Gordon
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
guesta3202
 

Semelhante a Lisp and prolog in artificial intelligence (20)

Class 10: Abstracting Procedures
Class 10: Abstracting ProceduresClass 10: Abstracting Procedures
Class 10: Abstracting Procedures
 
Frsa
FrsaFrsa
Frsa
 
Procesos
ProcesosProcesos
Procesos
 
Functional Concepts for OOP Developers
Functional Concepts for OOP DevelopersFunctional Concepts for OOP Developers
Functional Concepts for OOP Developers
 
Scala @ TomTom
Scala @ TomTomScala @ TomTom
Scala @ TomTom
 
CL metaprogramming
CL metaprogrammingCL metaprogramming
CL metaprogramming
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
Eta
EtaEta
Eta
 
Hadoop I/O Analysis
Hadoop I/O AnalysisHadoop I/O Analysis
Hadoop I/O Analysis
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Monadologie
MonadologieMonadologie
Monadologie
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Vcs16
Vcs16Vcs16
Vcs16
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpy
 
C PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAMC PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAM
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
 
R meets Hadoop
R meets HadoopR meets Hadoop
R meets Hadoop
 
Class 16: Making Loops
Class 16: Making LoopsClass 16: Making Loops
Class 16: Making Loops
 

Último

Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
karishmasinghjnh
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
JoseMangaJr1
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
amitlee9823
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
amitlee9823
 

Último (20)

Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
hybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptxhybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptx
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 

Lisp and prolog in artificial intelligence

  • 1. ARTIFICIAL INTELLIGENCE LISP and PROLOG Submitted to : Submitted by: Dr.arpana chaturvedi Arti kumari
  • 2. S No. CONTENT REMARK LISP 1 To print “hello world” in LISP 2 program To find the area of circle 3 to print odd number form 1-20 4 to print the average of number 10,20,30,40 5 defining macro OPERATORS 6 Arithmetic operator 7 Comparision operator 8 Logical operator DECISIONS CONSTRUCT 9 Cond 10 If 11 When 12 case LOOPS 13 Loop 14 Loop for 15 Do 16 dotimes 17 dolist 18 Predicate 29 Factorial of a number 20 Array 21 String 22 Sequence 23 list 24 Exiting from block 25 Let function 26 Prog function 27 Formatted output
  • 3. PROLOG 28 Print hello world using prolog. In console 29 prolog program to print hello world.. 30 Priya, Tiyasha, and Jaya are three girls, among them, Priya can cook 31 some rules. Rules contain some information that are conditionally true about the domain of interest. 32 Priya, Tiyasha, and Jaya are three girls, among them, Priya can cook. ;use of variable in our query 33 Prolog program, that can find the minimum of two numbers and the maximum of two numbers. 34 write a prolog program that will help us find the equivalent resistance 35 program to show working of Arithmetic operator in prolog 36 prolog program to print values from 1 to10 using loop 37 Example of decision making in Prolog. 38 prolog program to find the length of the list 39 prolog program to concatenate two list 40 Backtracking. 41 prolog program to find the cube of a number
  • 4. LISP Q1)To print “hello world” in LISP CODE: (write-line "Hello World") (write-line "I am at 'Online class' !- Learning LISP" )
  • 5. Q2) LISP program To find the area of circle .. CODE: (defconstantp13.141592) (defunarea-circle(rad) (terpri) (formatt " Radius:~5f"rad) (formatt "~%area:~10f" (* p1 rad rad))) (area-circle 10)
  • 6. Q3)LISP program to print odd number form 1-20 ? CODE: (loopfor x from 1 to 20 if(oddpx) do (printx) )
  • 7. Q4)LISP program to print the average of number 10,20,30,40 CODE: ;write a LISP program to find the average of numbers (defunaveragenum(n1 n2 n3 n4) ( / ( + n1 n2 n3 n4) 4) ) (write(averagenum10 20 30 40))
  • 8. Q5.defining macro CODE: (defmacro setTo10(num) (setq num 10)(print num)) (setq x 25) (print x) (setTo10 x)
  • 9. Q6)Arithmetic operators (setq a 10) (setq b 20) (format t "~% A + B = ~d" (+ a b)) (format t "~% A - B = ~d" (- a b)) (format t "~% A x B = ~d" (* a b)) (format t "~% B / A = ~d" (/ b a)) (format t "~% Increment A by 3 = ~d" (incf a 3)) (format t "~% Decrement A by 4 = ~d" (decf a 4))
  • 10. Q7) Comparison operator (setq a 10) (setq b 20) (format t "~% A = B is ~a" (= a b)) (format t "~% A /= B is ~a" (/= a b)) (format t "~% A > B is ~a" (> a b)) (format t "~% A < B is ~a" (< a b)) (format t "~% A >= B is ~a" (>= a b)) (format t "~% A <= B is ~a" (<= a b)) (format t "~% Max of A and B is ~d" (max a b)) (format t "~% Min of A and B is ~d" (min a b))
  • 11. Q8) logical operator (setq a 10) (setq b 20) (format t "~% A and B is ~a" (and a b)) (format t "~% A or B is ~a" (or a b)) (format t "~% not A is ~a" (not a)) (terpri) (setq a nil) (setq b 5) (format t "~% A and B is ~a" (and a b)) (format t "~% A or B is ~a" (or a b)) (format t "~% not A is ~a" (not a)) (terpri) (setq a nil) (setq b 0) (format t "~% A and B is ~a" (and a b)) (format t "~% A or B is ~a" (or a b)) (format t "~% not A is ~a" (not a)) (terpri) (setq a 10) (setq b 0) (setq c 30) (setq d 40) (format t "~% Result of and operation on 10, 0, 30, 40 is ~a" (and a b c d)) (format t "~% Result of and operation on 10, 0, 30, 40 is ~a" (or a b c d)) (terpri) (setq a 10) (setq b 20) (setq c nil) (setq d 40) (format t "~% Result of and operation on 10, 20, nil, 40 is ~a" (and a b c d)) (format t "~% Result of and operation on 10, 20, nil, 40 is ~a" (or a b c d))
  • 12.
  • 13. Q9) cond construct (setq a 10) (cond ((> a 20) (format t "~% a is greater than 20")) (t (format t "~% value of a is ~d " a))) Q10) If construct (setq a 10) (if (> a 20) (format t "~% a is less than 20")) (format t "~% value of a is ~d " a)
  • 14. Q11)When construct (setq a 100) (when (> a 20) (format t "~% a is greater than 20")) (format t "~% value of a is ~d " a)
  • 15. Q12)Case construct (setq day 4) (case day (1 (format t "~% Monday")) (2 (format t "~% Tuesday")) (3 (format t "~% Wednesday")) (4 (format t "~% Thursday")) (5 (format t "~% Friday")) (6 (format t "~% Saturday")) (7 (format t "~% Sunday")))
  • 16. Q13)Loop construct (setq a 10) (loop (setq a (+ a 1)) (write a) (terpri) (when (> a 17) (return a)) )
  • 17. Q14)Loop for (loop for x from 1 to 20 if(evenp x) do (print x) )
  • 18. Q15)Do construct (do ((x 0 (+ 2 x)) (y 20 ( - y 2))) ((= x y)(- x y)) (format t "~% x = ~d y = ~d" x y) )
  • 19. Q16)dotimes (dotimes (n 11) (print n) (prin1 (* n n)) )
  • 20. Q17)dolist (dolist (n '(1 2 3 4 5 6 7 8 9)) (format t "~% Number: ~d Square: ~d" n (* n n)) )
  • 21. Q18)predicate (write (atom 'abcd)) (terpri) (write (equal 'a 'b)) (terpri) (write (evenp 10)) (terpri) (write (evenp 7 )) (terpri) (write (oddp 7 )) (terpri) (write (zerop 0.0000000001)) (terpri) (write (eq 3 3.0 )) (terpri) (write (equal 3 3.0 )) (terpri) (write (null nil ))
  • 22. Q19)To find the factorial of a number (defun factorial (num) (cond ((zerop num) 1) (t ( * num (factorial (- num 1)))) ) ) (setq n 6) (format t "~% Factorial ~d is: ~d" n (factorial n))
  • 23. Q20)Array (write (setf my-array (make-array '(10)))) (terpri) (setf (aref my-array 0) 25) (setf (aref my-array 1) 23) (setf (aref my-array 2) 45) (setf (aref my-array 3) 10) (setf (aref my-array 4) 20) (setf (aref my-array 5) 17) (setf (aref my-array 6) 25) (setf (aref my-array 7) 19) (setf (aref my-array 8) 67) (setf (aref my-array 9) 30) (write my-array)
  • 24. Q21)String (write-line "Hello World") (write-line "Welcome to JAGANNATH INSTITUTE OF MANAGEMENT SCIENCES") ;escaping the double quote character (write-line "Welcome SIXTH SEMESTER")
  • 25. Q22) sequence (write (count 7 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (remove 5 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (delete 5 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (substitute 10 7 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (find 7 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (position 5 '(1 5 6 7 8 9 2 7 3 4 5)))
  • 26. Q23)lists (write (cons 1 2)) (terpri) (write (cons 'a 'b)) (terpri) (write (cons 1 nil)) (terpri) (write (cons 1 (cons 2 nil))) (terpri) (write (cons 1 (cons 2 (cons 3 nil)))) (terpri) (write (cons 'a (cons 'b (cons 'c nil)))) (terpri) (write ( car (cons 'a (cons 'b (cons 'c nil))))) (terpri) (write ( cdr (cons 'a (cons 'b (cons 'c nil)))))
  • 28. Q25) let function (let((x 'a)(y'b) (z'c)) (formatt "x= ~a y= ~a z= ~a" x y z))
  • 30. Q27)Formatted output (setqx 10) (setqy20) (formatt"x=~2d y=~2d ~%" x y) (setqx 100) (setqy200) (formatt"x=~2d y=~2d" x y)
  • 31. PROLOG Q28) Print hello world using prolog.. CODE: write('Hello World'). Q29)prolog program to print hello world.. CODE: main :- write('This is sample Prolog program'), write(' This program is written into hello_world.pl file').
  • 32. Q30) Priya, Tiyasha,and Jaya are three girls, among them,Priya can cook. CODE: girl(priya). girl(tiyasha). girl(jaya). can_cook(priya). Q31) some rules. Rules contain some informationthat are conditionally true about the domain of interest. CODE: sing_a_song(ananya).
  • 33. listens_to_music(rohit). listens_to_music(ananya):- sing_a_song(ananya). happy(ananya):- sing_a_song(ananya). happy(rohit) :- listens_to_music(rohit). playes_guitar(rohit):- listens_to_music(rohit). Q32) Priya, Tiyasha,and Jaya are three girls, among them,Priya can cook. ;use of variable in our query CODE: can_cook(priya).
  • 34. can_cook(jaya). can_cook(tiyasha). likes(priya,jaya) :- can_cook(jaya). likes(priya,tiyasha) :- can_cook(tiyasha). Q33) Prolog program,that can find the minimum of two numbers and the maximum of two numbers. CODE: find_max(X,Y,X) :- X >= Y, !. find_max(X,Y,Y) :- X < Y. find_min(X,Y, X) :- X =< Y, !. find_min(X,Y, Y) :- X > Y.
  • 35. Q34) write a prolog program that will help us find the equivalent resistance.  If R1 and R2 are in Series, then equivalent resistor Re = R1 + R2.  If R1 and R2 are in Parallel, then equivalent resistor Re = (R1 * R2)/(R1 + R2).
  • 36.
  • 37. Q35)programto show working of Arithmetic operatorin prolog + Addition - Subtraction * Multiplication / Division ** Power // Integer Division mod Modulus
  • 38. Q36)prolog program to print values from 1 to10 using loop CODE: count_to_10(10):- write(10),nl. count_to_10(X) :- write(X),nl, Y is X + 1, count_to_10(Y). Q37) Example of decision making in Prolog. CODE: % If-Then-Else statement
  • 39. gt(X,Y) :- X >= Y,write('X is greateror equal'). gt(X,Y) :- X < Y,write('X is smaller'). % If-Elif-Else statement gte(X,Y) :- X > Y,write('X is greater'). gte(X,Y) :- X =:= Y,write('X and Y are same'). gte(X,Y) :- X < Y,write('X is smaller'). Q38)prolog program to find the length of the list ;? CODE: list_length([],0). list_length([_|TAIL],N) :- list_length(TAIL,N1),N is N1 + 1.
  • 40. Q39)prolog program to concatenatetwo list CODE: list_concat([],L,L). list_concat([X1|L1],L2,[X1|L3]) :- list_concat(L1,L2,L3).
  • 42. Q41)prolog program to find the cube of a number CODE: cube :- write('Write a number:'), read(Number), process(Number).
  • 43. process(stop) :- !. process(Number) :- C is Number* Number* Number, write('Cube of '),write(Number),write(': '),write(C),nl,cube.