SlideShare a Scribd company logo
1 of 26
Artificial
Intelligence [LISP]
Presented by:-A.RAVINDRA KUMAR RAO
(B.TECH (C.E))
Madanapalle Institute Of Technology & Science
LISP
• Invented by John McCarthy (1958)
• Two simple data structure (atoms and lists)
• Heavy use of recursion
• Interpretive language
• Variations
– Scheme
– Common Lisp (de facto industrial standard)
• Most widely used AI programming language
• Functional Programming Paradigm
• Low maintenance overhead
• Atoms (Can’t be sub-divided) may be;
• Numbers: (real 1.0, integer 1)
• Symbols: a consecutive sequence of characters (no space)
e.g. a, x, price-of-beef
• Two special symbols: T and NIL for logical true and false
• Strings: a sequence of characters bounded by double
quotes e.g. "this is red"
Valid Objects
• Lists: A list of atoms and/or lists, bounded by ( and ). For
example
 (a b c)
 (a (b c))
• Top elements of a list – first level
Example:
 Top elements of list (a b c) are a, b, and c
 Top elements of list (a (b c)) are a and (b c)
 ‘nil’ stands for empty list, same as ()
Valid Objects
• Its also a list
• Uses prefix notation:
(function-name arg1,arg2 ... argN)
• It returns function value for the given list of arguments
• Functions are either provided by LISP function library or
defined by the user
Function Calls
• Examples:
> (+ 1 3 5)
9
> (/ 3 5)
3/5
> (/ 3.0 5)
0.59999999999999998
> (sqrt 4)
2
Function Calls
Command Line Prompt
1) Evaluating an atom
• Numerical and string atoms evaluate to themselves
• Symbols evaluate to their values if they are assigned
values, otherwise return Error
• The values of T and NIL are themselves
Evaluation of S-expression
• Examples :
> (sqrt x)
Error: The variable
X is unbound
> (+ (sqrt 4) 4.0)
6.0
> (+ (/ 3 5) 4)
23/5
Evaluation of S-expression
3/5+4
3) To assign a value to a symbol use: setq, set, setf
•‘setq’ is a special form of function (with two arguments)
 The first argument is a symbol which will not be evaluated
 The second argument is a S-expression, which will be
evaluated
 The value of the second argument is assigned to be the
value of the first argument
> (setq x 3.0)
3.0
> x
3.0
Evaluation of S-expression
> (setq y x)
3.0
> y
3.0
> (+ x y)
6.0
• To forbid evaluation of a symbol use: quote or ’
> (quote x)
x
> 'x
x
> (setq z 'x)
x
Functions
• Math functions
– +, -, *, /, exp, expt, log, sqrt, sin, cos, tan, max, min
• Functions for creating lists or ‘List Constructors’
– Cons, list and append
> (cons 'x L) ; insert symbol x at the front of list L
(X A B C) > (setq L '(A B C))
> (list 'a 'b 'c) ; making a list with the arguments as its elements
(A B C) ; if a, b, c have values A, B, C, then (list a b c)
; returns list (A B C)
> (append '(a b) '(c d)) ; appends one list in front of another
(A B C D)
L is a list containing elements
(A,B,C)X is inserted at the front/top of the list
Functions (cont’)
• Selectors
– first, rest, nth, car, cdr…
> (first '(a s d f)) ;returns the first element of a list
a
> (rest '((a s) d f)) ;deletes the first element from the
;list and returns the rest as a list
(d f)
> (first '((a s) d f))
(a s)
> (rest '((a s) (d f))
((d f))
> (setq L '(A B C))
(A B C)
> (car L)
; returns the first top level element of list L
A
> (cdr L)
; returns the rest of list L
(B C)
Functions
> (reverse L) ; reverses a list
(C B A)
> (length L) ; returns the length of list L
3
List has elements
(A B C)
• Conditional control:
– if, when and cond
(if <test> <then> <else>)
> (setq SCORE 78)
> 78
> (if (> score 85) ‘HIGH
(if (and (< score 84) (> score 65)) ‘MEDIUM ‘LOW))
> MEDIUM
Control Flow
score<84 and score>65
Predicates
• A special function which returns NIL if
the predicate is false, T or anything
other than NIL, otherwise
• We can use the following operators to
build the predicates
– =, >, <, >=, <= for numeric values
– eq or equal for others
– atom: test if x is an atom
– listp: test if x is a list
• A list can be viewed as a set whose members are the top
elements of the list
> (member 'b L)
(B C)
> (member ‘b (cons 'b L))
(B A B C)
> (member x L)
NIL ; if no, returns NIL
> (union L1 L2) ; returns the union of the two lists
> (intersection L1 L2) ; returns the intersection of the two lists
> (set-difference L1 L2) ; returns the difference of the two lists
Set Operations
Test if symbol b is a member (a top
element) of L; if yes, returns the sublist of L
starting at the first occurrence of symbol b
List L has elements (A B C)
Defining LISP functions
(defun func-name (arg-1 ... Arg-n) func-body)
Example:
> (defun y-plus (x) (+ x y)) ;definition of y-plus
> (setq y 2)
> (y-plus 23)
25
• Recursion
– Main tool used for iteration
– There is a limit to the depth of the recursion,
and it depends on the version of LISP
– Use trace to watch recursion
– Example:
(defun power (x y)
(if (= y 0) 1 (* x (power x (1- y)))))
examples:
(defun member (x L)
(cond ((null L) nil) ; base case 1: L is empty
((equal x (car L)) L) ; base case 2: x=first(L)
(t (member x (cdr L))) ; recursion: test if x is in rest(L)
))
(defun intersection (L1 L2)
(cond ((null L1) nil)
((null L2) nil)
((member (car L1) L2)
(cons (car L1) (intersection (cdr L1) L2)))
(t (intersection (cdr L1) L2))
))
> (intersection '(a b c) '(b a b c))
> (a b c)
> (intersection '(b a b c) '(a b c))
> (b a b c)
• Iteration: dotimes and dolist
– (dolist (x L result) body)
• for each top level element x in L, do body(x);
• x is not equal to an element of L in each iteration, but rather x
takes an element of L as its value;
– (dotimes (count n result) body)
• do body n times. count starts with 0, ends with n-1
– Note: result is optional, to be used to hold the computing
result. If result is given, the function will return the value of
result, returns NIL, otherwise. (may change global
variables as side effects.)
Arrays
• Data type to store expressions in places
identified by integer indexes.
• (setf linear-array (make-array ‘(4)))
• A single dimension array by the name of
linear-array with indices from 0 to 3.
• (setf linear-array (make-array 4))
• (setf chess-board (make-array ‘(8 8)))
• Other functions in LISP library
1) Predicates:zerop, plusp, evenp, oddp, integerp, floatp
2) Logical connector: and, or, not
3) Rounding: floor, ceiling, truncate, round
4) Others:
max, min, abs, sqrt, 1+ (add 1), 1- (minus 1)
(exp number) (base-e exponential)
(expt Base-number Power-Number)
(log number & Optional base-number)
(isqrt number) Returns the greater integer less than or equal to
the exact positive square-root of the number.
(signum number) Returns -1, zero, or 1 according if the
number is negative, zero, or positive.
Summary
• Atoms and lists
• Functions and function calls
setq, setf, set, quote, eval,
math functions (+, -, *, /, max, min, exp, sqrt, …)
list operations: list, cons, car, cdr, length, nth,
append, reverse
predicates (=, >, equal, eq, numberp, symbolp, …)
• Defining functions
(defun func_name (arg_list) func_body)
dolist, dotimes, cond, if, when, unless, mapcar
• Input/output: print, read, with-open-file, load
What made Lisp Different
• Conditionals: such as if-then-else construct.
• Function types: where functions are just like integers
and strings
• Recursion: first language to support it.
• Dynamic typing: all variable are pointers.
• Garbage-Collection.
• Programs composed of expressions.
• A symbol type.
• The whole program is a mathematical function

More Related Content

What's hot

Gentle Introduction To Lisp
Gentle Introduction To LispGentle Introduction To Lisp
Gentle Introduction To LispDamien Garaud
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming LangugeYaser Jaradeh
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISPDevnology
 
Contravariant functors in scala
Contravariant functors in scalaContravariant functors in scala
Contravariant functors in scalaPiotr Paradziński
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Piotr Paradziński
 
Chapter 10 Library Function
Chapter 10 Library FunctionChapter 10 Library Function
Chapter 10 Library FunctionDeepak Singh
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming FundamentalsShahriar Hyder
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsJohn De Goes
 
Stack and Queue (brief)
Stack and Queue (brief)Stack and Queue (brief)
Stack and Queue (brief)Sanjay Saha
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data scienceJohn Cant
 

What's hot (20)

Lisp
LispLisp
Lisp
 
Lisp
LispLisp
Lisp
 
Gentle Introduction To Lisp
Gentle Introduction To LispGentle Introduction To Lisp
Gentle Introduction To Lisp
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
 
Prolog & lisp
Prolog & lispProlog & lisp
Prolog & lisp
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Contravariant functors in scala
Contravariant functors in scalaContravariant functors in scala
Contravariant functors in scala
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
 
stack & queue
stack & queuestack & queue
stack & queue
 
Chapter 10 Library Function
Chapter 10 Library FunctionChapter 10 Library Function
Chapter 10 Library Function
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Haskell
HaskellHaskell
Haskell
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
 
Stack and Queue (brief)
Stack and Queue (brief)Stack and Queue (brief)
Stack and Queue (brief)
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
 

Similar to (Ai lisp)

Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 
Introduction to parallel and distributed computation with spark
Introduction to parallel and distributed computation with sparkIntroduction to parallel and distributed computation with spark
Introduction to parallel and distributed computation with sparkAngelo Leto
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scalaRaymond Tay
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptAnishaJ7
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functionsjoellivz
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To LispLISP Content
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1smruti sarangi
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In ScalaKnoldus Inc.
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with ScalaDenis
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHISowmya Jyothi
 
Python programming for Beginners - II
Python programming for Beginners - IIPython programming for Beginners - II
Python programming for Beginners - IINEEVEE Technologies
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaDaniel Cukier
 

Similar to (Ai lisp) (20)

Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to parallel and distributed computation with spark
Introduction to parallel and distributed computation with sparkIntroduction to parallel and distributed computation with spark
Introduction to parallel and distributed computation with spark
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scala
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.ppt
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Scheme language
Scheme languageScheme language
Scheme language
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In Scala
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
 
Python programming for Beginners - II
Python programming for Beginners - IIPython programming for Beginners - II
Python programming for Beginners - II
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
PARSING.ppt
PARSING.pptPARSING.ppt
PARSING.ppt
 
Mbd2
Mbd2Mbd2
Mbd2
 

Recently uploaded

Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 

Recently uploaded (20)

Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 

(Ai lisp)

  • 1. Artificial Intelligence [LISP] Presented by:-A.RAVINDRA KUMAR RAO (B.TECH (C.E)) Madanapalle Institute Of Technology & Science
  • 2. LISP • Invented by John McCarthy (1958) • Two simple data structure (atoms and lists) • Heavy use of recursion • Interpretive language • Variations – Scheme – Common Lisp (de facto industrial standard) • Most widely used AI programming language • Functional Programming Paradigm • Low maintenance overhead
  • 3. • Atoms (Can’t be sub-divided) may be; • Numbers: (real 1.0, integer 1) • Symbols: a consecutive sequence of characters (no space) e.g. a, x, price-of-beef • Two special symbols: T and NIL for logical true and false • Strings: a sequence of characters bounded by double quotes e.g. "this is red" Valid Objects
  • 4. • Lists: A list of atoms and/or lists, bounded by ( and ). For example  (a b c)  (a (b c)) • Top elements of a list – first level Example:  Top elements of list (a b c) are a, b, and c  Top elements of list (a (b c)) are a and (b c)  ‘nil’ stands for empty list, same as () Valid Objects
  • 5. • Its also a list • Uses prefix notation: (function-name arg1,arg2 ... argN) • It returns function value for the given list of arguments • Functions are either provided by LISP function library or defined by the user Function Calls
  • 6. • Examples: > (+ 1 3 5) 9 > (/ 3 5) 3/5 > (/ 3.0 5) 0.59999999999999998 > (sqrt 4) 2 Function Calls Command Line Prompt
  • 7. 1) Evaluating an atom • Numerical and string atoms evaluate to themselves • Symbols evaluate to their values if they are assigned values, otherwise return Error • The values of T and NIL are themselves Evaluation of S-expression
  • 8. • Examples : > (sqrt x) Error: The variable X is unbound > (+ (sqrt 4) 4.0) 6.0 > (+ (/ 3 5) 4) 23/5 Evaluation of S-expression 3/5+4
  • 9. 3) To assign a value to a symbol use: setq, set, setf •‘setq’ is a special form of function (with two arguments)  The first argument is a symbol which will not be evaluated  The second argument is a S-expression, which will be evaluated  The value of the second argument is assigned to be the value of the first argument > (setq x 3.0) 3.0 > x 3.0 Evaluation of S-expression
  • 10. > (setq y x) 3.0 > y 3.0 > (+ x y) 6.0
  • 11. • To forbid evaluation of a symbol use: quote or ’ > (quote x) x > 'x x > (setq z 'x) x
  • 12. Functions • Math functions – +, -, *, /, exp, expt, log, sqrt, sin, cos, tan, max, min • Functions for creating lists or ‘List Constructors’ – Cons, list and append > (cons 'x L) ; insert symbol x at the front of list L (X A B C) > (setq L '(A B C)) > (list 'a 'b 'c) ; making a list with the arguments as its elements (A B C) ; if a, b, c have values A, B, C, then (list a b c) ; returns list (A B C) > (append '(a b) '(c d)) ; appends one list in front of another (A B C D) L is a list containing elements (A,B,C)X is inserted at the front/top of the list
  • 13. Functions (cont’) • Selectors – first, rest, nth, car, cdr… > (first '(a s d f)) ;returns the first element of a list a > (rest '((a s) d f)) ;deletes the first element from the ;list and returns the rest as a list (d f) > (first '((a s) d f)) (a s) > (rest '((a s) (d f)) ((d f))
  • 14. > (setq L '(A B C)) (A B C) > (car L) ; returns the first top level element of list L A > (cdr L) ; returns the rest of list L (B C)
  • 15. Functions > (reverse L) ; reverses a list (C B A) > (length L) ; returns the length of list L 3 List has elements (A B C)
  • 16. • Conditional control: – if, when and cond (if <test> <then> <else>) > (setq SCORE 78) > 78 > (if (> score 85) ‘HIGH (if (and (< score 84) (> score 65)) ‘MEDIUM ‘LOW)) > MEDIUM Control Flow score<84 and score>65
  • 17. Predicates • A special function which returns NIL if the predicate is false, T or anything other than NIL, otherwise • We can use the following operators to build the predicates – =, >, <, >=, <= for numeric values – eq or equal for others – atom: test if x is an atom – listp: test if x is a list
  • 18. • A list can be viewed as a set whose members are the top elements of the list > (member 'b L) (B C) > (member ‘b (cons 'b L)) (B A B C) > (member x L) NIL ; if no, returns NIL > (union L1 L2) ; returns the union of the two lists > (intersection L1 L2) ; returns the intersection of the two lists > (set-difference L1 L2) ; returns the difference of the two lists Set Operations Test if symbol b is a member (a top element) of L; if yes, returns the sublist of L starting at the first occurrence of symbol b List L has elements (A B C)
  • 19. Defining LISP functions (defun func-name (arg-1 ... Arg-n) func-body) Example: > (defun y-plus (x) (+ x y)) ;definition of y-plus > (setq y 2) > (y-plus 23) 25
  • 20. • Recursion – Main tool used for iteration – There is a limit to the depth of the recursion, and it depends on the version of LISP – Use trace to watch recursion – Example: (defun power (x y) (if (= y 0) 1 (* x (power x (1- y)))))
  • 21. examples: (defun member (x L) (cond ((null L) nil) ; base case 1: L is empty ((equal x (car L)) L) ; base case 2: x=first(L) (t (member x (cdr L))) ; recursion: test if x is in rest(L) )) (defun intersection (L1 L2) (cond ((null L1) nil) ((null L2) nil) ((member (car L1) L2) (cons (car L1) (intersection (cdr L1) L2))) (t (intersection (cdr L1) L2)) )) > (intersection '(a b c) '(b a b c)) > (a b c) > (intersection '(b a b c) '(a b c)) > (b a b c)
  • 22. • Iteration: dotimes and dolist – (dolist (x L result) body) • for each top level element x in L, do body(x); • x is not equal to an element of L in each iteration, but rather x takes an element of L as its value; – (dotimes (count n result) body) • do body n times. count starts with 0, ends with n-1 – Note: result is optional, to be used to hold the computing result. If result is given, the function will return the value of result, returns NIL, otherwise. (may change global variables as side effects.)
  • 23. Arrays • Data type to store expressions in places identified by integer indexes. • (setf linear-array (make-array ‘(4))) • A single dimension array by the name of linear-array with indices from 0 to 3. • (setf linear-array (make-array 4)) • (setf chess-board (make-array ‘(8 8)))
  • 24. • Other functions in LISP library 1) Predicates:zerop, plusp, evenp, oddp, integerp, floatp 2) Logical connector: and, or, not 3) Rounding: floor, ceiling, truncate, round 4) Others: max, min, abs, sqrt, 1+ (add 1), 1- (minus 1) (exp number) (base-e exponential) (expt Base-number Power-Number) (log number & Optional base-number) (isqrt number) Returns the greater integer less than or equal to the exact positive square-root of the number. (signum number) Returns -1, zero, or 1 according if the number is negative, zero, or positive.
  • 25. Summary • Atoms and lists • Functions and function calls setq, setf, set, quote, eval, math functions (+, -, *, /, max, min, exp, sqrt, …) list operations: list, cons, car, cdr, length, nth, append, reverse predicates (=, >, equal, eq, numberp, symbolp, …) • Defining functions (defun func_name (arg_list) func_body) dolist, dotimes, cond, if, when, unless, mapcar • Input/output: print, read, with-open-file, load
  • 26. What made Lisp Different • Conditionals: such as if-then-else construct. • Function types: where functions are just like integers and strings • Recursion: first language to support it. • Dynamic typing: all variable are pointers. • Garbage-Collection. • Programs composed of expressions. • A symbol type. • The whole program is a mathematical function

Editor's Notes

  1. S-expression From Wikipedia, the free encyclopedia. An S-expression (S stands for symbolic) is a convention for representing data or an expression in a computer program in a text form. S-expressions are used in the Lisp programming language and Lisp-derived languages such as Scheme and DSSSL, and as mark-up in communications protocols like IMAP and John McCarthy&amp;apos;s CBCL. The details of the syntax and supported data types vary in the different languages, but the most common feature is the extensive use of prefix notation with explicit use of brackets (affectionately known as Cambridge Polish notation). S-expressions are used for both code and data in Lisp (see McCarthy Recursive Functions of Symbolic Expressions at http://www-formal.stanford.edu/jmc/recursive/recursive.html ). S-expressions were originally intended only as machine representations of human-readable M-expressions, but Lisp programmers soon started using S-expressions as the default notation. S-expressions can either be single objects such as numbers, LISP atoms including the special atoms nil and t, or cons pairs, written as (x . y). Longer lists are made up of nested cons pairs, for example (1 . (2 . (3 . nil))) which can also be written more intelligibly as (1 2 3). Program code can be written in S-expressions, using prefix notation. An extra piece of syntactic sugar for writing Lisp programs is that the common expression (quote x) can be written with the abbreviation &amp;apos;x. Example in Lisp: (defun factorial (x) (cond ((eq x 1) 1) (t (* x (factorial (- x 1)))))) Example in Scheme: (define (factorial x) (if (= x 1) 1 (* x (factorial (- x 1)))))
  2. Member (x) we check that x is member of L (list).. Cons is adding element in new list.
  3. Program composed of expression: Lisp programs are trees of expression, each of which returns a value. Symbol types: symbols are effectively pointer to strings stored in a hash table The whole langauge is there: there is no real distciton between read-time, compile-time and runtime. You can compile or run code while reading, read or run code while compiling , and read or compile code at runtime. That is, programs are expressed directly in the parse trees that get build behind the scenes when other languages are parsed, and these trees are make of lists, which are Lisp date structures. This provides a very powerful feature allowing the programmer to write programs that write programs. The most common way this is done in lisp is through Macros, which I will discuss later. Comments # re: The XML Conspiracy Rick Schaut I remember sitting around with a bunch of grad students talking about LISP, when one asked me, &amp;quot;You know what &amp;apos;LISP&amp;apos; stands for, don&amp;apos;t you?&amp;quot; &amp;quot;No,&amp;quot; I said. &amp;quot;Lots of Insipid, Stupid Parentheses!&amp;quot; he exclaimed. To which, another grad student replied, &amp;quot;Silly! The &amp;apos;S&amp;apos; stands for Silly!“ Lost In a Sea of Parentheses