SlideShare a Scribd company logo
1 of 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.

More Related Content

What's hot

Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in cBUBT
 
Pumping lemma for regular set h1
Pumping lemma for regular set h1Pumping lemma for regular set h1
Pumping lemma for regular set h1Rajendran
 
Introduction to design and analysis of algorithm
Introduction to design and analysis of algorithmIntroduction to design and analysis of algorithm
Introduction to design and analysis of algorithmDevaKumari Vijay
 
Bresenham's line algorithm
Bresenham's line algorithmBresenham's line algorithm
Bresenham's line algorithmPooja Dixit
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and ComplexityRajandeep Gill
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ pptKumar
 
C mcq practice test 4
C mcq practice test 4C mcq practice test 4
C mcq practice test 4Aman Kamboj
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaPriyanka Rana
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsSwapnil Agrawal
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory Rajendran
 

What's hot (20)

Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Pumping lemma for regular set h1
Pumping lemma for regular set h1Pumping lemma for regular set h1
Pumping lemma for regular set h1
 
Introduction to design and analysis of algorithm
Introduction to design and analysis of algorithmIntroduction to design and analysis of algorithm
Introduction to design and analysis of algorithm
 
Bresenham's line algorithm
Bresenham's line algorithmBresenham's line algorithm
Bresenham's line algorithm
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Theta notation
Theta notationTheta notation
Theta notation
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
C mcq practice test 4
C mcq practice test 4C mcq practice test 4
C mcq practice test 4
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
CP Handout#4
CP Handout#4CP Handout#4
CP Handout#4
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Intro automata theory
Intro automata theory Intro automata theory
Intro automata theory
 
chapter 1
chapter 1chapter 1
chapter 1
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 

Similar to 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
 

Similar to 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
 

Recently uploaded

Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxfirstjob4
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...shivangimorya083
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxolyaivanovalion
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girlCall Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girlkumarajju5765
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxolyaivanovalion
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxMohammedJunaid861692
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
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
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Delhi Call girls
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 

Recently uploaded (20)

Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptx
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptx
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girlCall Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
Call Girls 🫤 Dwarka ➡️ 9711199171 ➡️ Delhi 🫦 Two shot with one girl
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
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...
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 

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.