SlideShare une entreprise Scribd logo
1  sur  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.

Contenu connexe

Tendances

Tendances (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
 

Similaire à Lisp and prolog in artificial intelligence

Class 10: Abstracting Procedures
Class 10: Abstracting ProceduresClass 10: Abstracting Procedures
Class 10: Abstracting ProceduresDavid Evans
 
Frsa
FrsaFrsa
Frsa_111
 
Functional Concepts for OOP Developers
Functional Concepts for OOP DevelopersFunctional Concepts for OOP Developers
Functional Concepts for OOP Developersbrweber2
 
CL metaprogramming
CL metaprogrammingCL metaprogramming
CL metaprogrammingdudarev
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lispkyleburton
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian T. Gordon
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpyFaraz Ahmed
 
C PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAMC PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3guesta3202
 
Class 16: Making Loops
Class 16: Making LoopsClass 16: Making Loops
Class 16: Making LoopsDavid Evans
 

Similaire à 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
 

Dernier

Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
➥🔝 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
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramMoniSankarHazra
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteedamy56318795
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...amitlee9823
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...amitlee9823
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsJoseMangaJr1
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...amitlee9823
 
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
 

Dernier (20)

Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
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
 
➥🔝 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...
 
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
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
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...
 

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.