0% found this document useful (0 votes)
97 views21 pages

Artificial Intelligence: Instructor

The document discusses the Lisp programming language. It provides a brief history of Lisp's development from 1958-1992. It then covers key Lisp concepts like atoms, lists, functional programming, recursion, and garbage collection. The document also discusses Lisp features, applications in AI, syntax using prefix notation, data types of atoms and lists, functions, iterations, and basic functions like CAR and CDR.

Uploaded by

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

Artificial Intelligence: Instructor

The document discusses the Lisp programming language. It provides a brief history of Lisp's development from 1958-1992. It then covers key Lisp concepts like atoms, lists, functional programming, recursion, and garbage collection. The document also discusses Lisp features, applications in AI, syntax using prefix notation, data types of atoms and lists, functions, iterations, and basic functions like CAR and CDR.

Uploaded by

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

Artificial Intelligence

Instructor

Rana Muhammad Ashfaq


Lecture # 5

QUIZ
Q1: What is relationship between Natural intelligence and AI

Q2: AI Objective
Q3: Write Name of Different Type of Agent Program
2

Assignment Q 5
A: Explain Steps in Problem Solving B: What is State Transition Diagrams (STD's)

LISP
Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT). McCarthy published its design in a paper in Communications of the ACM in 1960, entitled "Recursive Functions of Symbolic Expressions and Their Computation by Machine,
It was at the 1958 Research Project on Artificial Intelligence that John McCarthy first developed the basics behind Lisp. His motivation was to develop a list processing language for Artificial Intelligence. By 1965 the primary dialect of Lisp was created (version 1.5). By 1970 specialpurpose computers known as Lisp Machines, were designed to run Lisp programs. 1980 was the year that object-oriented concepts were integrated into the language. By 1986, the X3J13 group formed to produce a draft for ANSI Common Lisp standard. Finally in 1992, X3J13 group published the American National Standard for Common Lisp.
4

Significant Language Features


The term Lisp itself originally stood for LISt Processing.
Atoms & Lists - Lisp uses two different types of data structures, atoms and lists. Atoms are similar to identifiers, but can also be numeric constants Lists can be lists of atoms, lists, or any combination of the two Functional Programming Style - all computation is performed by applying functions to arguments. Variable declarations are rarely used. Uniform Representation of Data and Code - example: the list (A B C D) a list of four elements (interpreted as data) Reliance on Recursion - a strong reliance on recursion has allowed Lisp to be successful in many areas, including Artificial Intelligence. Garbage Collection - Lisp has built-in garbage collection, so programmers do not need to explicitly free dynamically allocated memory.

LISP: LISt Processing language


Special focus on symbolic processing and symbol manipulation Linked list structures Also programs, functions are represented as lists At one point special LISP computers with basic LISP functions implemented directly on hardware were available (Symbolics Inc., 80s) LISP today: Many AI programs now are written in C,C++, Java List manipulation libraries are available

LISP keeps its dominance among high level (AI) programming languages Common Lisp Interpreter and compiler object oriented programming
6

Advantages of LISP
Recursion: A program can call itself a sub routine Garbage Collector: Data storage is automatically recycled Uniform Representation: Program and data look the same Program can execution other program Interaction: User can combine program writing, compilation,testing,debugging,running in a single interacting session

Application of LISP
Artificial Intelligence Symbolical Algebraic Manipulation Natural Language Understanding Machine Translation Expert System Diagnosis System Automatic Programming (Robotics) Perception(Vision, Speech Understanding)

LISP Syntax
Syntax: Prefix notation Operator first, arguments follow E.g. (+ 3 2) adds 3 and 2 A lot of parentheses These define lists and also programs Examples: (a b c d) is a list of 4 elements (atoms) a,b,c,d (defun factorial (num) (cond ((<= num 0) 1) (t (* (factorial (- num 1)) num)) ))
9

LISP Data Types


There are two: atoms and lists. 1 Atoms:
Integer, Float ,String, Character, symbol, Boolean etc a, 7, tom, my-age, nil, T Evaluate an atom gives the value assigned that atom. Numbers are special--they always evaluate to themselves. (setq my-age 24) => 24 my-age => 24 Reserved: nil and T nil => nil t => t Case insensitive: aBc and ABC are the same atom
10

Data Types: Lists

Lists: (a), (+ 6 7), (a (e f g) h), (), nil Evaluating a list always invokes a function. (function-name arg1 argn) (+ 6 7) => 13 (foo 17 18 19) => Error (function not defined) (+ my-age 4) => 28

Lists are chains of pairs Can make other trees, etc as well

11

LISP Expressions
(+ (* ((/ Numeric Functions x1 x2 ... xn) x1 x2 ... xn) x y) x y) Meaning The sum of x1, x2, ..., xn The product of x1, x2, ..., xn Subtract y from x Divide x by y The remainder of dividing x by y The absolute value of x The maximum of x1, x2, ..., xn The minimum of x1, x2, ..., xn
12

(rem x y) (abs x) (max x1 x2 ... xn) (min x1 x2 ... xn)

function definition
Definition of a function (defun <name> <documentation-string> (<arguments>) <body>) (defun square computes square (x) (* x x))

Lisp includes many built-in functions: +, *, -, /, max, min, sqrt


Once a list is built, how do we access its members? first and car give you the first element of a list. (first (1 2 3)) => 1 (first ((a b) 2 3)) => (a b) (length (a b c)) => 3
13

Relational Operators
Relational Operators Meaning (= x y) x is equal to y (/= x y) x is not equal to y (< x y) x is less than y (> x y) x is greater than y (<= x y) x is no greater than y (>= x y) x is no less than y

14

Logical Operators Logical Operators Meaning (or x1 x2 ... Logical or xn) (and x1 x2 ... Logical and xn) (not x) Logical negation

15

Many ways to define iterations Commands: loop dolist dotimes do, do*

Iterations: loop
> (setq a 4) 4 > (loop (setq a (+ a 1)) (when (> a 7) (return a))) ;; return exists the loop 8 > (loop (setq a (- a 1)) (when (< a 3) (return))) NIL
16

Iterations: dolist > (dolist (x '(1 2 3 4)) (print x)) 1 2 3 4 NIL ;; NIL is returned by dolist
Iterations: dotimes > (dotimes (i 4) (print i)) ;; starts from 0 and continues till limit 4 0 1 2 3 4 NIL ;; returns NIL

17

Basic Functions

CAR returns the head of a list CDR returns the tail of a list CONS inserts a new head into a list EQ compares two atoms for equality ATOM tests if its argument is an atom

18

Other useful Functions

(NULL S) tests if S is the empty list (LISTP S) tests if S is a list LIST makes a list of its (evaluated) arguments

(LIST 'A '(B C) 'D) returns (A (B C) D) (LIST (CDR '(A B)) 'C) returns ((B) C) (APPEND '(A B) '((X) Y) ) returns (A B (X) Y)

APPEND concatenates two lists

19

CAR

The CAR of a list is the first thing in the list CAR is only defined for nonempty lists
Then (CAR L) is
A (X Y) () undefined
20

If L is
(A B C) ( (X Y) Z) (()()) ()

CDR examples
If L is (A B C) ( (X Y) Z) (X) (()()) ()

Then (CDR L) is (B C) (Z) () (()) undefined

First Program
(defun hello () (write-string "Hello, World!"))
21

You might also like