Вы находитесь на странице: 1из 8

www.rgpvmca.blogspot.

in

ARTIFICIAL INTELLIGENCE MCA-401

INDEX

Sno. Topics
General Issues and Overview of AI
1 The AI problems
2 What is an AI technique
3 Characteristics of AI applications
Introduction to LISP Programming
4 Syntax
UNIT I 5 Numeric functions
6 Basic list manipulation functions
7 Predicates
8 Conditionals
9 Input output
10 local variables
11 Iteraction and recursion
12 Property lists
13 Arrays

UNIT I

The AI problems

An AI problem is simply a task that we might want an intelligent agent to solve the problem. It involves goal
possible actions and their results as well as data / percepts, cost / benefits and so on.

Example:

1. Find a book.
2. Find a way to got a book once it is found.
3. Find a way to move puzzle pieces to achieve a particular pattern.
4. Answer a question.
5. Interpret visual data.
And so on.

Some AI problems are:

1. Block-word problem.
2. Monkey and Bananas problem.
3. 8-puzzle problem.
www.rgpvmca.blogspot.in

What is AI technique?

Characteristics of AI system:

1. Learn new concept and tasks.


2. Remember complicated interrelated facts and draw conclusions from them.
3. Understand a natural language.
4. Plan sequence of action to complete a goal.
5. Capable of performing intelligent tasks effectively and efficiently.

Introduction of LISP programming

LISP means List programming.


It is a language of AI. It is easy to learn if you dont know more about programming.
For LISP programming CLISP S/W is used it is an interpreter.

Advantage of LISP

1. Recursion: A program can call itself as a subroutine.


2. Garbage collection: Data storage is automatically recycled.
3. Uniform representation :
Programs and data looks the same.
Programs can examine other program
Programs can write programs
Program can modify themselves.(learn)
Data structure can contain programs.
4. Interaction: User can combine program writing, compilation, testing, debugging, running in a single
interaction session.

Application of LISP

AI
Symbolic algebraic manipulation
Natural language understanding
Machine translation
Formal logical reasoning
Expert system
Automatic programming
Robotics
Perceptions (vision, speech, understanding)

LISP Data

1. Symbols (They are atomic symbol or atoms) range (upto 30 characters) followed by letters, numbers
and some special characters.
www.rgpvmca.blogspot.in

Note: special characters ( , . : ) are not include in atom names.

2. Numbers (numeric atoms) Integer / Floating no.


3. S-Expressions (symbolic expressions)
Atom
List (ex: [(x1,x2,x3,.xn)() empty list]

Computation in LISP

Example:

(+ 2 2)
(+ 3 ( * 4 5))
(-5(*45))
( PRINT (H1MOM))
( * 3.145926 (EXPT R 2))
(SQRT 2.0)
(SETQ X 2)
(SET X ( + 2 2))
( COND ( ( > X Y )

( SETQ Y 3)))

Variable value in LISP

Example:

( SET X 3 ) O/P X=3


( SET A X) O/P A=X
( SETQ X 3 ) O/P X=3

Constructing LIST

Syntax : (LIST X1,X2..Xn)

Example:

( SETQ man adam)


(SETQ woman eve)
(LIST man loves woman) O/P (adam love eve)
(LIST (LIST A B) (LIST C D)) O/P ((A B) (C D))

Extracting part of LIST

We can extract part of LIST by using two functions

1. CAR (extract first element of list)


2. CDR (return the rest of list after the first)
www.rgpvmca.blogspot.in

Example:

(Car (a b c)) o/p : a


(car ((a) b c) o/p: (a)
(car (car ((a) b c))) o/p: a
(car a) o/p: Error a is not a list
(cdr (a b c)) o/p: (b c)
(cdr ((a) b c) o/p: ( b c)
(cdr ((a) b c) o/p: (b c)
(cdr (cdr ((a) b c))) o/p: a
(cdr a) o/p: Error a is not a list

Combination of car and cdr:

We can use combination of car and cdr in the form of [C - - - - - - R]

Example:

(caar x) means (car ( car x))


(cadr x) means (car ( cdr x))
(caddr x) means (car (cdr (cdr X)))

Constructing list structure: (adding element in the front of list)

The basic function that constructs new list structure is the function of CONS.

Example:
(cons a (b)) o/p (a b)
(cons a nil) o/p (a)
(cons a ( )) o/p (a)
(cons (a) (b)) o/p ((a) (b))
(cons a b) o/p (a b)

Note:

(car (cons x y)) o/p: x


(cdr (cons x y)) o/p: y

List of Manipulation function:

APPEND : Makes a new list consisting of the members of its argument lists appended together. It takes any
number of arguments.

Example:
www.rgpvmca.blogspot.in

(APPEND (a) (B)) O/P: (a b)


(APPEND (a b) (c d)) O/P: (a b c d)

REVERSE : Make a new list that is the reverse of the list given as its argument.

Example:

(REVERSE (a b)) o/p: (b a)


(REVERSE ((a b) (c d)) o/p: ((c d) (a b))

LENGTH : Return an integer that is the list given as its argument.

Example:

(LENGTH (a)) o/p: 1


(LENGTH (a b)) o/p: 2
(LENGTH (a b)) o/p: 1

SUBSTITUTION : The function SUBST makes a new S-expression with a specified substitution

Example:

(SUBST x y z) means y=x and z=y o/p: x


(SUBST john name (Iam name)) O/P: Iam john

Defining New LISP Functions:

Syntax: (DEFUN <FUNCTION NAME> (<arg1><arg2>.<argn>) <code>)

Example:

(DEFUN sum(x y z) (* x (+y z)))

PREDICATES: A Predicates in LIPS is a function that returns either T (true) or NIL (false).

Note: predicate name often end in P

Some commonly used predicates are:

(atom x) true iff xis atom.

(null x)true iff x is null.

(number x).true iff x is number

(zerop x)true iff x is zero. Error if not a number.

(minusp x)..true iff x is negative. Error if x is not a number.

(equal x y)..true if x equal y

(>= x y).true if x >=y


www.rgpvmca.blogspot.in

(< x y)true if x<y

Logical Operators:

Predicates can be combined by the logical operators AND, OR and NOT.

NOT

(NOT x) return T iff x is NILL , otherwise. It return NIL , NOT is therefore the same as NULL.

Example:

( NOT (a b)) is nil

(NOT ( ))..is true

Condition resting:

(IF <test><then - form>)

(IF <test><then - form><else-form>)

Example: (if (<=3 2 )(* 3 9)(+ 4 2 3)) ...[if 3.2 then return 3*9 else return 4+2+3]

Global variables:

(setf x 4) ..x set globally.

Local variables:

(let ((x 3)))

Input / Output primitives:

1. Read :
Example : (+ 7 (read))
2. Print:
Example: (print good morning)
o/p : good morning
good morning
(print (x y z u)) ..o/p : (x y z u).
o/p : (x y z u)
(x y z u)

3. Prinl : It is same as print except that the new-line characters and space are not provided.
Example: (print left) (prinl right)
o/p: left right
(print left) (prinl right)
o/p: left
right
www.rgpvmca.blogspot.in

4. Princ: It is same as prinl .


Example: (princ good morning)
Good morning good morning

Iteration and Recursion:

Recursion: It is a function which calls itself repeatedly but each with a similar arguments than the argument
using in the preceding calls.

Example:

Logic: fact(1)=1

fact (n) =n* fact(n-1)

In Lisp:

(defun fact(n)

(cond

((= n 1) 1)

(t (* n fact (-n 1)))

For calling : (fact 5) o/p: 120

Example: Define a function LEN that return the number of top-most elements in a given list L:

(defun len(L)

(cond

( (null ) 0 )

( t (+1 (len (cdr l)))

)
www.rgpvmca.blogspot.in

Property List

By using property list we can associate property and values of object in LISP.

1. Putprop:
It return the attribute values LISP.

Syntax: (putprop <object_name_symbol> <attribute_values>< attribute_values >)

Example:
(putprop book rich & night Author) o/p: rich & night
(putpro book Tata McGrawHill Publisher)..o/p: Tata McGrawHill
(putprop book 1984 year) .o/p: 1984
2. GET:
It is used to retrieve the value of attribute or properties.
Syntax: (get <obj-name> <attribute>)
Example:
(get book year) o/p: 1984
(get book author) o/p: rich & knight
(get book publisher) o/p: Tata McGrawHill

Array: Lisp provide the primitive Make_Array to create array.

Syntax: (Make_array (<dim-1><dim-2>-------<dim-n>))

Dim dimension

Example : (setq matrix-3(make_array (2 2 3) & key:integer))

o/p matrix-3

Reference By :
1."Elaine Rich and Kevin Knight Artifical Intelligence - Tata McGraw Hill.
2. Artifical Intelligence 4 ed. Pearson.
3. Dan W. Patterson Introduction to Artifical Intelligence and Expert Systems, Prentice India.
4. Nils J. Nilson Principles of Artifical Intelligence, Narosa Publishing House.
5. Clocksin & C.S.Melish Programming in PROLOG, Narosa Publishing House.
6. M.Sasikumar,S.Ramani etc. Rule based Expert System, Narosa Publishing House.

Вам также может понравиться