0% found this document useful (0 votes)
52 views42 pages

Artificial Intelligence

The document discusses the LISP programming language. LISP stands for LISt Processing and was one of the earliest programming languages invented in the late 1950s. It is well-suited for artificial intelligence due to its ability to process symbolic information. The basic building blocks of LISP are atoms, lists, and strings. It also covers numeric functions, list manipulation functions, function definition, predicates, and conditionals in LISP.

Uploaded by

Keertana R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views42 pages

Artificial Intelligence

The document discusses the LISP programming language. LISP stands for LISt Processing and was one of the earliest programming languages invented in the late 1950s. It is well-suited for artificial intelligence due to its ability to process symbolic information. The basic building blocks of LISP are atoms, lists, and strings. It also covers numeric functions, list manipulation functions, function definition, predicates, and conditionals in LISP.

Uploaded by

Keertana R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

ARTIFICIAL INTELLIGENCE (AI) UNIT 4

MCA
Sem II- Even Sem
Academic Year 2021-22

Course: Artificial Intelligence

Course Code: M21DES221

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


1
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Contents

Sl. No Topic Page No.


1. LISP 3
2. Prolog 15
3. Fuzzy Logic System 24
4. Perception and Action 32
5. Parallel and distributed AI 40

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


2
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

LISP
LISP stands for LISt Processing. It is one of the oldest programming Languages. It was invented by
McCarthy during late 1950’s. It is particularly suited for AI programs because of its ability to process
symbolic information effectively. It is a language with a simple syntax, with little or no data typing
and dynamic memory management.

Syntax

The basic building blocks of LISP are as follows:

1. Atom – An atom is a number or string of contiguous characters, including numbers and special
characters.
2. List – A list is a sequence of atoms and/or other lists enclosed within parenthesis.
3. String – A string is a group of characters enclosed in double quotation marks.

Following are examples of some valid atoms −

hello-from-tutorials-point
name
123008907
*hello*
Block#221
abc123

Following are examples of some valid lists −

( i am a list)
(a ( a b c) d e fgh)
(father tom ( susan bill joe))
(sun mon tue wed thur fri sat)
()

Following are examples of some valid strings −

" I am a string"
"a ba c d efg #$%^&!"
"Please enter the following details :"
"Hello from 'Tutorials Point'! "

o A list may contain atom or other lists.

o The basic unit members of List is called top elements.

Example:

List = (a b (c d) e (f))

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


3
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Top Elements = a, b, (c d), e and (f).


o Atoms, lists and strings are the only valid objects in LISP.
o They are called symbolic-expression or s-expressions.
o Any s-expression is potentially a valid program.

Numeric Functions

 LISP programs run either on an interpreter or as compiled code.


 The interpreter examines source programs in a repeated loop, called the read-evaluate-print loop.
 This loop reads the program code, evaluates it, and prints the value returned by the program.
 The interpreter signals its readiness to accept code for execution by printing a prompt such as ->
symbol.
 Example: To find the sum of 3 numbers 5, 6 and 9
-> (+ 5 6 9)
20
->

LISP uses prefix notation.

Predefined Numeric Functions

Basic List Manipulation Functions

Sometimes we wish to take atoms or lists literally and not have them evaluated or treated as function
calls, when the list represents data. To accomplish this we precede the atom or list with a singlequotation
mark.

Example: ‘man, ‘(a b c d)

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


4
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Assignment in LISP

 Variables in LISP are symbolic (nonnumeric) atoms.


 They may be assigned values using function setq.
 Setq takes two arguments, the first of which must be a variable. It is never evaluated and should not
be in quotation marks.
 The second argument is evaluated (unless in quotation marks) and the result is bound to the first
argument.
 The variable retains this value until a new assignment is made.
 When variables are evaluate, they return the last value bound to them.
 Trying to evaluate an undefined variable results in an error.

Example

-> (setq x 10)


10
-> x
10
-> (setq x (+ 3 5))
8
-> (setq x ‘(+ 3 5))
(+ 3 5)
-> y
Unbound variable: y

Some Basic Symbol Processing Functions

Note: The quotation marks preceding the arguments in the function calls of the above table. An error
will result if they are not there because the interpreter will try to evaluate each argument before
evaluating the function.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


5
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Notice the difference in results with and without the quotation marks.

Function Call

The syntax of a function call is

(function-name arg1 arg2 …)

Where any number of arguments may be used. When a function is called, the arguments are evaluated
first from left to right (unless within quotation marks) and then the function is executed using the
evaluated argument values.

Additional List manipulation functions

Functions, Predicates and Conditionals


Function Definition

The function named defun is used to define functions. It requires 3 arguments:


1. The new function name
2. The parameters for the function
3. The function body or LISP code which performs desired operations.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


6
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

The format is
(defun name (parm1 parm2 …) body)
Defun does not evaluate its arguments. It simply builds a function which may be called like any other
function.

Example
-> (defun averagethree (n1 n2 n3)
(/ (+ n1 n2 n3) 3))
AVERAGETHREE
->
When a function is called, the arguments supplied in the call are evaluated unless they are in quotation
marks and bound to (assigned) the function parameters. The argument values are bound to the
parameters in the same order they were given in the definition.

Predicate Function

Predicates are functions that test their arguments for some specific condition. Predicates return true (t)
or false (nil) depending on the arguments. The most common predicates are:

1. atom = takes one argument. It returns t if the argument is an atom and nil otherwise.
2. equal = takes 2arguments and returns t it they evaluate to the same value, and nil otherwise.
3. evenp, number, oddp, zerop = are tests on a single numeric argument. They return t if their
argument evaluates to an even number, a number, an odd number, or zero respectively. Otherwise
they each return nil.
4. greaterp and lessp = each take one or more arguments. If there is only one argument, each returns
t. If more than one argument is used, greaterp returns t if the arguments, from left to right, are
successively larger; otherwise nil is returned. Lessp requires that the arguments be successively
smaller from left to right to return t. Otherwise it returns nil.
5. >= and <= have same meaning as greaterp and lessp, except they return t if successive elemnets
are also equal.
6. listp and null = both take a single argument. Listp returns t if its argument evaluates to a list, and
nil otherwise. Null returns t if its argument evaluates to nil; otherwise it returns nil.

Examples:

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


7
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

The Conditional

To make use of predicates, we need some construct to permit branching. Cond (for conditional) is like
if…then…else construct.

The syntax for cond is


(cond (<test1> <action1>)
(<test2> <action2>)
. .
. .

. .
(<testk> <actionk>))
Each (<testi> <actioni>), i=1, …,k, is called a clause. Each clause consists of a test protion and an
action or result portion. The first clause following the cond is executed by evaluating <test1>. If this
evaluates to non-nil, the <action1> portion is evaluated, its value is returned, and the remaining clauses
are skipped over. If<test1> evaluates to nil, control passes to the second clause without evaluating
<action1> and the procedure is repeated, If all tests evaluate to nil, cond returns nil.
Example:
-> (defun maximum2 (a b)
(cond ((> a b) a)
(t b)))
MAXIMUM2
->

When maximum2 is executed, it starts with the first clause following the cond. The test sequence is as
follows: if (the argument bound to) a is greater than (that bound to) b, return a else return b. Note the t
in the second clause preceding b. This forces the last clause to be evaluated when the first clause is not

-> (maximum2 234 320)


320
->

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


8
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Example: Find the maximum of three numbers:

-> (defun maximum3 (a b c)


(cond ((> a b) (cond ((> a c) a)
(t c)))
((> b c) b)
(t c)))
MAXIMUM3
->
-> (maximum3 20 30 50)
50
->

Logical Functions

Like predicates, logical functions may also be used for flow of control. The basic logical operators are
and, or and not. Not is the simplest. It takes one argument and returns t if the argument evaluates to nil;
returns nil if its argument evaluates to non-nil. The functions and and or both take any number of
arguments. For both the arguments are evaluated from left to right. In case of and, if all arguments
evaluate to non-nil, the value of the last argument is returned; otherwise nil is returned. The arguments
of or are evaluated until one evaluates to non-nil, in which case it returns the argument value; otherwise
it returns nil.

Examples:

Input, Output and Local Variables

The most commonly used I/O functions are read, print, prinl, princ, terpri and format.

Read takes no argument. When read appears in a procedure, processing halts until a single s-expression
is entered from the keyboard. The s-expression is then returned as the value of read and processing
continues.

Example:

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


9
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

If we include read in an arithmetic expression, an appropriate value should be entered when the
interpreter halts.
->(+ 5 (read))
6
11
->

Print takes one argument. It prints the argument as it is received, and then returns the argument. When
print is used to print an expression, its argument is preceded by the carriage-return and line feed
characters and is followed by a space.
-> (print ‘(a b c))
(A B C)
(A B C)
->(print “hello there”)
“hello there”
“hello there”
Notice that print even prints the double quotation marks defining the string.

Prinl is the same as print except that the new-line characters and space are not provided
-> ((prinl ‘(hello))(prinl ‘(hello)))
(HELLO)(HELLO)
->

Princ – used to avoid double quotation marks in the output. It is the same as prinl except it does not
print the unwanted quotation marks.
Example
-> (princ “hello there”)
hello there “hello there”
Princ eliminated the quotes, but the echo still remains. This is because princ returned its argument and
since that was the last thing returns, it was printed by the read-evaluate-print loop.

Terpri The primitive function terpri takes no arguments. It introduces a new-line (carriage return and
line feed) wherever it appears and then returns nil.

-> (defun circle-area ()


(terpri)
(princ “Please enter the radius: “)
(setq radius (read))
(princ “The area of the circle is: “)
(princ (* 3.1416 radius radius))
(terpri))
CIRCLE-AREA
-> (circle-area)
Please enter the radius: 4
The area of the circle is: 50.2656
->

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


10
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Format
 The format function permits us to create cleaner output than is possible with just the basic printing
functions.
 It has the form (format <destination> <string> arg1 arg2 …).
 Destination specifies where the output is to be directed, like to the monitor or some other external
file. By default its monitor.
 String is the desired output string, but intermixed with format directives which specify how each
argument is to be represented.
 Directives appear in the string in the same order the arguments are to be printed.
 The most common directives are given below:
-
A - The argument is printed as though princ were used.
-
S - The argument is printed as though prinl were used.
-
D – The argument which must be an integer is printed as a decimal number
-
F - The argument which must be a floating point number is printed as a decimal floating-point
number
-
C – The argument is printed as character output.
-
% - A new-line is printed.
The field widths for appropriate argument values are specified with an integer immediately following
the tilde symbol.

-> (format t “Circle radius = -2F-%Circle area = -3F” X Y)


“Circle radius = 3.0
Circle area = 9.42”
->

Constructs for Local Variables

The values they are assigned within the function are accessible only within that function.

Example:

The variable x in the defun is local in scope. It reverts back to its previous value after the function local-
var is exited. The variable y, on the other hand, is global. It is accessible from any procedure and retain
its value unless with setq.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


11
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

The let and prog constructs also permit the creation of local variables.

Let function
 The syntax of the let function is (let ((var1 val1 ) ((var2 val2 )…) <s-expression>)
 Where each vari , is a different variable name and vali is an initial value assigned to each vari
respectively. When let is executed, each vali is evaluated and assigned to the corresponding var i ,
and the s-expression which follow are then evaluated in order.
 The value of the last expression evaluated is then returned.
 If an initial value is not included with a vari, it is assigned nil, and the parenthesis enclosing it may
be omitted.
-> (let ((x ‘a)
(y ‘b)
(z ‘c)
(cons x (cons y (list z))))
(A B C)
->

Prog Function
 The prog function is similar to let in that the first arguments following it are a list of local variables
where each element is either a variable name or a list containing a variable name and its initial
value.
 This is followed by the body of the prog, and any no. of s-expressions.
 Prog executes list s-expressions in sequence and returns nil unless it encounters a function named
return.
 In this case a single argument of return is evaluated and returned.
-> (defun memb (e1 1st)
(Prog ()
Start
(cond ((equal el (car 1st)) (return 1st)))
(setq 1st (cdr 1st))
(go start)))
MEMB
->

Iteration and Recursion

Iteration Constructs

We introduce a structured form of iteration with the do construct, which is similar to while loop in
Pascal.

The do statement has the form

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


12
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

(do (<var1 val1> <var-update1>)


(<var2 val2> <var-update2>)
-
-
-
(<test> <return-value>)
(s-expression>))

 The vali are initial values which are all evaluated and then bound to the corresponding variables
vari in parallel.
 Following each such statements are optional update statements which define how the vari are to be
updated with each iteration.
 After the variables are updated during an iteration, the test is evaluated , and if it returns non-
nil(true), the return-value is evaluated and returned.
 The s-expressions forming the body of the construct are optional.
 If present, they are executed each iteration until an exit test condition is encouneterd.
Example:
-> (defun factorial (n)
(do ((count n (- count 1))
(Product n (* product (-count 1))
((equal 0 count) product)))
FACTORIAL
->

Recursion

A recursive function is one calls itself successively to reduce a problem to a sequence of simpler steps.
Recursion requires a stopping condition and a recursive step.

Example : Factorial

The recursive step in factorial is the product of n and factorial (n-1). The stopping condition is reached
when n= 0.

-> (defun factorial (n)


(cond ((zerop n) 1)
(t (* n (factorial (- n 1))))))
FACTORIAl
-> (factorial 6)
720
->

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


13
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Property Lists and Arrays

Property Lists

 The function putprop assigns properties to an atom. It takes 3 arguments: an object name (an atom)
, a property or attribute name and property or attribute value.
 For example: to assign properties to a car, we can assign properties such as make, year, color and
style with the following statements.

 The object car will retain these properties until they are replaced with the new ones or until
removed with the remprop function.
 Remprop function takes two arguments, the object and its attribute.
 To retrieve a property value, such as color of car , we use function get, which also takes two
argments object and attribute.

Arrays

 Single or multiple-dimension arrays may be defined in LISP using the make-array function.
 The items stored in the array may be any LISP object.
 To create an array with 10 cells named myarray, we bind the unquoted name to an array using setf
(or setq) with the make-array function and a specification of the number of cells.
-> (setf myarray (make-array ‘(10)))
#A(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)
->
 The function returns the pound sign (#) followed by an A and the array representation with its cells
initially set to nil.
 To access the contents of cells, we use the function aref which takes two arguments, the name of
the array and the index value. Since the cells are indexed starting zero, an index value of 9 must
be used to retieve the contents of the tenth cell.
 -> (aref myarray 9)
NIL
->
 To store the items in the array, we use the function setf.
 -> (setf (aref( myarray 0) 25)
25
-> (setf (aref myarray 1) ‘red)

RED

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


14
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Prolog
Introduction

 Prolog stands for programming in logic.


 It has important role in artificial intelligence.
 Unlike many other programming languages, Prolog is intended primarily as a declarative
programming
 language, which means that a program consists of data based on the facts and rules (Logical
relationship) rather than computing how to find a solution.
 In prolog, logic is expressed as relations (called as Facts and Rules).
 To obtain the solution, the user asks a question rather than running a program. When a user asks
a question, then to determine the answer, the run time system searches through the database of
facts and rules.
 Core heart of prolog lies at the logic being applied.

Applications of Prolog

The applications of prolog are as follows:

o Specification Language
o Robot Planning
o Natural language understanding
o Machine Learning
o Problem Solving
o Intelligent Database retrieval
o Expert System
o Automated Reasoning

Prolog language basically has three different elements −


o Facts − The fact is predicate that is true, for example, if we say, “Tom is the son of Jack”, then
this is a fact.
o Rules − Rules are extinctions of facts that contain conditional clauses. To satisfy a rule these
conditions should be met. For example, if we define a rule as −
grandfather(X, Y) :- father(X, Z), parent(Z, Y)
This implies that for X to be the grandfather of Y, Z should be a parent of Y and X should be
father of Z.
o Questions − And to run a prolog program, we need some questions, and those questions can be
answered by the given facts and rules.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


15
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Converting English to Prolog Facts and Rules

English Prolog
Dog is barking barking(dog)
Sun rises in east rises(sun)
Pickles are spicy spicy(pickles)
Priya like food if they are delicious likes(priya, Food):-delicious(Food)
Prakash likes food if they are spicy and delicious likes(prakash,Food):-
and spicy spicy(Food),delicious(Food)

While the first three statements are called facts and last two statements are called rules.

Note: Variable like Food’s whose first letter is capital because value of it came from the previous fact.
whereas the constants like priya, pickles are written in small letters. The predicates here are barking,
rises, spicy, likes etc. Who initialize the relation of subject to another? Or define what a subject do. First
three statement are called because they are declarative and doesn’t depends on any other statements,
they are just told. Where as in the last two statement first part is fact and another part is also fact and
the first part is depended on another part after “:-” symbol. That means priya likes food if the food is
delicious. prakash likes food if it is spicy and delicious too.

Note: Here (,) comma operator is applied for the And operator.

Goals

A goal is a statement starting with a predicate and probably followed by its arguments. In a valid goal,
the predicate must have appeared in at least one fact or rule in the consulted program, and the number
of arguments in the goal must be the same as that appears in the consulted program. Also, all the
arguments (if any) are constants.

The purpose of submitting a goal is to find out whether the statement represented by the goal is true
according to the knowledge database (i.e. the facts and rules in the consulted program). This is similar
to proving a hypothesis - the goal being the hypothesis, the facts being the axioms and the rules being
the theorems.

A program describes the relationships of the members in a family

father(jack, susan). /* Fact 1 */


father(jack, ray). /* Fact 2 */
father(david, liza). /* Fact 3 */
father(david, john). /* Fact 4 */
father(john, peter). /* Fact 5 */
father(john, mary). /* Fact 6 */
mother(karen, susan). /* Fact 7 */
mother(karen, ray). /* Fact 8 */

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


16
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

mother(amy, liza). /* Fact 9 */


mother(amy, john). /* Fact 10 */
mother(susan, peter). /* Fact 11 */
mother(susan, mary). /* Fact 12 */

parent(X, Y) :- father(X, Y). /* Rule 1 */


parent(X, Y) :- mother(X, Y). /* Rule 2 */
grandfather(X, Y) :- father(X, Z), parent(Z, Y). /* Rule 3 */
grandmother(X, Y) :- mother(X, Z), parent(Z, Y). /* Rule 4 */
grandparent(X, Y) :- parent(X, Z), parent(Z, Y). /* Rule 5 */
yeye(X, Y) :- father(X, Z), father(Z, Y). /* Rule 6 */
mama(X, Y) :- mother(X, Z), father(Z, Y). /* Rule 7 */
gunggung(X, Y) :- father(X, Z), mother(Z, Y). /* Rule 8 */
popo(X, Y) :- mother(X, Z), mother(Z, Y). /* Rule 9 */

Take Rule 3 as an example. It means that "granfather(X, Y)" is true if both


"father(X, Z)" and "parent(Z, X)" are true. The comma between the two
conditions can be considered as a logical-AND operator.

Prolog Variables

A variable in Prolog is a string of letters, digits, and underscores (_) beginning either with a capital
letter or with an underscore. Examples:

X, Sister, _, _thing, _y47, First_name, Z2

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


17
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

The variable _ is used as a "don't-care" variable, when we don't mind what value the variable has. For
example:

is_a_parent(X) :- father_of(X, _).


is_a_parent(X) :- mother_of(X, _).

That is, X is a parent if they are a father or a mother, but we don't need to know who they are the
father or mother of, to establish that they are a parent.

Variables are used in more than one way:

 to express constraints in parts of a rule:


likes(A,B) :- dog(B), feeds(A,B).
Note that both A and B appear on both sides of the neck symbol - the appearance of the same
variable in two (or more places) in effect says that when the variable is bound to a value, it
must be bound to the same value in all the places that it appears in a given rule.
Note that if the same variable appears in two or more different rules, it might be bound to
different values in the different rules. This is achieved by Prolog renaming the variables
internally, when it comes to use the rule - usually the names are things like _1, _2, _3, etc.
This is why variables with names like these sometimes turn up in error messages when your
Prolog program goes wrong.
 to formulate queries, as in the following example:
?- studies(X, 9311). Prolog responds by finding all the values for X for
which studies(X, 9311) is true, and successively listing them, e.g.
 X = fred ;
 X = jane ;
 X = abdul ;
 X = maria ;

Arithmetic Operators

 Prolog provides the facility for arithmetic operations.


 As per the requirement of the user, arithmetic operations can be divided into some special purpose
integer predicates and a series of general predicates for integer, floating point and rational
arithmetic.
 The general arithmetic predicates are handled by the expressions.
 An expression is either a function or a simple number.
 Prolog arithmetic is slightly different than other programming languages.

For example:
?- X is 2 + 1.
X=3?
yes

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


18
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

The basic arithmetic operators are given in the following table:

Sr. No Operator Explanation

1 X+Y The sum of 'X' and 'Y'

2 X-Y the difference of 'X' and 'Y'

3 X*Y The product of 'X' and 'Y'

4 X/Y The quotient of 'X' and 'Y'

5 X^Y 'X' to the power of 'Y'

6 -X Negation of 'X'

7 abs(X) Absolute value of 'X'

8 sqrt(X) The square root of X

9 sin(X) The sine of X

10 cos(X) The cos of X

Operator precedence
 If there is more than one operator in the arithmetic expression such as A-B*C+D, then the prolog
decides an order in which the operator should be applied.
 Prolog gives numerical value for each operator, operators with high precedence like '*' and '/' are
applied before operators with relatively low precedence values like '+' and '-'.
 Operator with same precedence value ('*' or '/') and ('+' or '-') should be applied from left to right.
 So, the expression A-B*C+D can be written as A-(B*C)+D

Matching

Definition: The two terms are said to be matched, if they are equal or if they consist of variables
representing the resulting equal terms.

Prolog matches expressions in structural way.

So,
?- 3 + 2= 5
no
Note: In prolog '=' means matches with.

Consider the following example,?- X + 3 = 2 * Y

But the following expressions will match because they have same structure.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


19
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Expression 1:
?- X + Y = 2 + 3
X=2
Y=3

Expression 2:
?- 2 + Y = X + 3
X=2
Y=3

Unification

The pattern matching part of Prolog is formally known as unification. The idea is simple. The
pattern color(X, Y) matches with color(rose, red) with the binding X=rose, Y=red. The pattern color(X,
X) does not match with the same predicate. (This requires a predicate of the form color(rose,rose).)

Control Structures

Loops

Loop statements are used to execute the code block multiple times. Code block is executed multiple
times using recursive predicate logic. There are no direct loops in some other languages, but we can
simulate loops with few different techniques.

Program

count_to_10(10) :- write(10),nl.
count_to_10(X) :-
write(X),nl,
Y is X + 1,
count_to_10(Y).

Output

| ?- [loop].
compiling D:/TP Prolog/Sample_Codes/loop.pl for byte code...
D:/TP Prolog/Sample_Codes/loop.pl compiled, 4 lines read - 751 bytes written, 16 ms

(16 ms) yes


| ?- count_to_10(3).
3
4
5
6
7

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


20
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

8
9
10

true ?
yes
| ?-

Decision Making
The decision statements are If-Then-Else statements. So when we try to match some condition, and
perform some task, then we use the decision making statements. The basic usage is as follows −
If <condition> is true, Then <do this>, Else
In some different programming languages, there are If-Else statements, but in Prolog we have to define
our statements in some other manner. Following is an example of decision making in Prolog.

Program

% If-Then-Else statement

gt(X,Y) :- X >= Y,write('X is greater or 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').

Output

| ?- [test].
compiling D:/TP Prolog/Sample_Codes/test.pl for byte code...
D:/TP Prolog/Sample_Codes/test.pl compiled, 3 lines read - 529 bytes written, 15 ms

yes
| ?- gt(10,100).
X is smaller

yes
| ?- gt(150,100).
X is greater or equal

true ?

yes
| ?- gte(10,20).
X is smaller

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


21
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

(15 ms) yes


| ?- gte(100,20).
X is greater

true ?

yes
| ?- gte(100,100).
X and Y are same

true ?

yes
| ?-

Back Tracking

Backtracking is a procedure, in which prolog searches the truth value of different predicates by checking
whether they are correct or not. The backtracking term is quite common in algorithm designing, and in
different programming environments. In Prolog, until it reaches proper destination, it tries to backtrack.
When the destination is found, it stops.

Suppose A to G are some rules and facts. We start from A and want to reach G. The proper path will be
A-C-G, but at first, it will go from A to B, then B to D. When it finds that D is not the destination, it
backtracks to B, then go to E, and backtracks again to B, as there is no other child of B, then it backtracks
to A, thus it searches for G, and finally found G in the path A-C-G. (Dashed lines are indicating the
backtracking.) So when it finds G, it stops.

Recursion
Recursion is a technique in which one predicate uses itself (may be with some other predicates) to find
the truth value.
Let us understand this definition with the help of an example −
 is_digesting(X,Y) :- just_ate(X,Y).
 is_digesting(X,Y) :-just_ate(X,Z),is_digesting(Z,Y).

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


22
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

So this predicate is recursive in nature. Suppose we say that just_ate(deer, grass), it


means is_digesting(deer, grass) is true. Now if we say is_digesting(tiger, grass), this will be true
if is_digesting(tiger, grass) :- just_ate(tiger, deer), is_digesting(deer, grass), then the
statement is_digesting(tiger, grass) is also true.
There may be some other examples also, so let us see one family example. So if we want to express the
predecessor logic, that can be expressed using the following diagram −

So we can understand the predecessor relationship is recursive. We can express this relationship using
the following syntax −
 predecessor(X, Z) :- parent(X, Z).
 predecessor(X, Z) :- parent(X, Y),predecessor(Y, Z).

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


23
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Fuzzy Logic System


The term fuzzy refers to things that are not clear or are vague.

Introduction

 In the real world many times we encounter a situation when we can’t determine whether the state
is true or false, their fuzzy logic provides very valuable flexibility for reasoning.
 In this way, we can consider the inaccuracies and uncertainties of any situation.
 In the boolean system truth value, 1.0 represents the absolute truth value and 0.0 represents the
absolute false value.
 But in the fuzzy system, there is no logic for the absolute truth and absolute false value.
 But in fuzzy logic, there is an intermediate value too present which is partially true and partially
false.

Architecture

Fuzzy Architecture contains four parts :

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


24
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

 RULE BASE: It contains the set of rules and the IF-THEN conditions provided by the experts to
govern the decision-making system, on the basis of linguistic information. Recent developments
in fuzzy theory offer several effective methods for the design and tuning of fuzzy controllers.
Most of these developments reduce the number of fuzzy rules.
 FUZZIFICATION: It is used to convert inputs i.e. crisp numbers into fuzzy sets. Crisp inputs are
basically the exact inputs measured by sensors and passed into the control system for processing,
such as temperature, pressure, rpm’s, etc.
 INFERENCE ENGINE: It determines the matching degree of the current fuzzy input with respect
to each rule and decides which rules are to be fired according to the input field. Next, the fired
rules are combined to form the control actions.
 DEFUZZIFICATION: It is used to convert the fuzzy sets obtained by the inference engine into a
crisp value. There are several defuzzification methods available and the best-suited one is used
with a specific expert system to reduce the error.

Advantages of Fuzzy Logic System

 This system can work with any type of inputs whether it is imprecise, distorted or noisy input
information.
 The construction of Fuzzy Logic Systems is easy and understandable.
 Fuzzy logic comes with mathematical concepts of set theory and the reasoning of that is quite
simple.
 It provides a very efficient solution to complex problems in all fields of life as it resembles human
reasoning and decision-making.
 The algorithms can be described with little data, so little memory is required.

Disadvantages of Fuzzy Logic Systems

 Many researchers proposed different ways to solve a given problem through fuzzy logic which
leads to ambiguity. There is no systematic approach to solve a given problem through fuzzy logic.
 Proof of its characteristics is difficult or impossible in most cases because every time we do not
get a mathematical description of our approach.
 As fuzzy logic works on precise as well as imprecise data so most of the time accuracy is
compromised.

Applications

 It is used in the aerospace field for altitude control of spacecraft and satellites.
 It has been used in the automotive system for speed control, traffic control.
 It is used for decision-making support systems and personal evaluation in the large company
business.
 It has application in the chemical industry for controlling the pH, drying, chemical distillation
process.
 Fuzzy logic is used in Natural language processing and various intensive applications in Artificial
Intelligence.
 Fuzzy logic is extensively used in modern control systems such as expert systems.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


25
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

 Fuzzy Logic is used with Neural Networks as it mimics how a person would make decisions, only
much faster. It is done by Aggregation of data and changing it into more meaningful data by
forming partial truths as Fuzzy sets.

Crisp Sets

Crisp set is a collection of unordered distinct elements, which are derived from Universal set.
Universal set consists of all possible elements which take part in any experiment. Set is quite useful and
important way of representing data.

Let X represents a set of natural numbers, so

X = {1, 2, 3, 4, …}

Sets are always defined with respect to some universal set. Let us derive two sets A and B from this
universal set X.

A = Set of even numbers = {2, 4, 6, …}

B = Set of odd number = {1, 3, 5, …}

Examples of crisp set

Consider X represents class of students which acts as Universe of discourse. If you ask a question, “who
does have a driving license?” Obviously, all students might not have driving license. So those students
who have driving license will have membership value 1 for this particular set and rest of all will have
membership value zero.
We can define set A is equal to set of students having driving license and A will be definitely subset of
universal set X.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


26
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Crisp set is very convenient to represent and process the data. Many programing languages including
Python, R etc. supports the creation and manipulation of sets.

Fuzzy Sets

Fuzzy set is a natural way to deal with the imprecision. Many real world representation relies on
significance rather than precision. Fuzzy logic is the best way to deal with them. Fuzzy set is an
extension of crisp set.

For example if some heavy object is approaching to your friend from the top and you say that “hey
friend, 1500 kg mass is approaching to you at the speed of 45.3 m/s”. This statement is quite precise
but before your friend Interpret it, the object might have fallen on him.

But if you simply shout “hello friend, lookout” then probably statement is not so precise but it convey
quick information to your friend and he may move away from his place. In real world, we may be
looking for significance rather than precision. Fuzzy logic helps us to model imprecision into data for
many real world problems.

Advantages of fuzzy set


Fuzzy sets are quite useful in many industrial and hand hold device design due to its simplicity and
interpretability. Some of the most prevailing advantages are listed here:

 Conceptually easy to understand as it is built upon “natural” mathematics


 Tolerant to imprecise data
 Universal approximation: It can model arbitrary nonlinear functions
 Intuitive
 Based on linguistic terms
 Convenient way to express expert and common sense knowledge

Limitations of fuzzy set


 How do we define the membership functions? For the same range of inputs, different person can
use different membership function, which results into different result.
 There is no proper way of learning in fuzzy logic. Membership function is to be chosen from the
experience of the domain expert.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


27
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

 What if we have membership functions provided from two different people E.g. What a 6’11”
Basketball player defines as tall will differ from a 4’10” Gymnast. A guy having height 6.11 may
not be considered tall in case of Basketball, but a player with height 4.10 is considered as tall in
Gymnast. Thus, there might be ambiguity in interpretation of membership function, that is, domain
changes, interpretation also changes.
 Defuzzification can produce undesired results. Different defuzzification techniques can produced
different crisp output for same fuzzy value. The produced crisp value might have large variations
in them, this creates lots of ambiguity in selection of defuzzification method.
 Crisp/precise models can be more efficient and even convenient
 Membership values begin to move away from expectations when chains of logic are lengthy so
this approach is not suitable for many KBS problems (e.g., medical diagnosis)

Example

If we have three linguistic representation for the temperature – called cool, nominal and warm, then
depending upon value, temperature ‘t’ has different membership in all three sets. The temperature
value t = 5 might have membership value 0.7 in cool set, 0.3 in nominal set and 0 in warm set. Because,
5 degree is considered quite cool but its not warm at all, so its membership value in cool set would be
high, where is it will be very low in warm set.

Example – 2:

Let us consider age is to be represented using fuzzy set. We will be using two fuzzy
sets Young and Very Young to represent different age range .
A = {young} ∈ [0, 90]

B = {Very Young} ∈ [0, 60]

Let us see, how the membership value is affected by two different functions. As of now, the
mathematical description of both fuzzy sets is not important, but as a human, we can easily map that if
the range of young set is from 0 to 90, then as we move away from 0, they youngness will keep
decreasing and become 0 at the age 90. The age 30 is in upper half of the entire range and hence it has
higher membership value for being considered as young.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


28
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

For set Very Young, the range is from 0 to 60, so age 30 is at the center and hence its obvious it takes
membership value 0.5.

Difference Between Crisp Set and Fuzzy Set

1 Crisp set defines the value is either 0 or Fuzzy set defines the value between 0 and 1
1. including both 0 and 1.
2 It is also called a classical set. It specifies the degree to which something is true.

3 It shows full membership It shows partial membership.

4 Eg1. She is 18 years old. Eg1. She is about 18 years old.

Eg2. Rahul is 1.6m tall Eg2. Rahul is about 1.6m tall.

5 Crisp set application used for digital Fuzzy set used in the fuzzy controller.
design.
6 It is bi-valued function logic. It is infinite valued function logic

7 Full membership means totally Partial membership means true to false, yes to no,
true/false, yes/no, 0/1. 0 to 1.

Fuzzy Terminologies

Visit the following link for content

https://codecrucks.com/fuzzy-terminologies-all-you-need-to-know/

Fuzzy Logic Control

 The basic architecture of a fuzzy logic controller is shown in Figure.


 The principal components of an FLC system is a fuzzifier, a fuzzy rule base, a fuzzy knowledge
base, an inference engine, and a defuzzifier.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


29
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

 It also includes parameters for normalization.


 When the output from the defuzzifier is not a control action for a plant, then the system is a fuzzy
logic decision system.
 The fuzzifier present converts crisp quantities into fuzzy quantities.
 The fuzzy rule base stores knowledge about the operation of the process of domain expertise.
 The fuzzy knowledge base stores the knowledge about all the input-output fuzzy relationships.
 It includes the membership functions defining the input variables to the fuzzy rule base and the
out variables to the plant under control.
 The inference engine is the kernel of an FLC system, and it possesses the capability to simulate
human decisions by performing approximate reasoning to achieve the desired control strategy.
The defuzzifier converts the fuzzy quantities into crisp quantities from an inferred fuzzy control
action by the inference engine.

The various steps involved in designing a fuzzy logic controller are as follows:
Step 1: Locate the input, output, and state variables of the plane under consideration. I
Step 2: Split the complete universe of discourse spanned by each variable into a number of fuzzy
subsets, assigning each with a linguistic label. The subsets include all the elements in the universe.
Step 3: Obtain the membership function for each fuzzy subset.
Step 4: Assign the fuzzy relationships between the inputs or states of fuzzy subsets on one side and
the output of fuzzy subsets on the other side, thereby forming the rule base.
Step 5: Choose appropriate scaling factors for the input and output variables for normalizing the
variables between [0, 1] and [-1, I] interval.
Step 6: Carry out the fuzzification process.
Step 7: Identify the output contributed from each rule using fuzzy approximate reasoning.
Step 8: Combine the fuzzy outputs obtained from each rule.
Step 9: Finally, apply defuzzification to form a crisp output.

Applications:

FLC systems find a wide range of applications in various industrial and commercial products and
systems. In several applications- related to nonlinear, time-varying, ill-defined systems and also
complex systems – FLC systems have proved to be very efficient in comparison with other
conventional control systems. The applications of FLC systems include:

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


30
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

1. Traffic Control
2. Steam Engine
3. Aircraft Flight Control
4. Missile Control
5. Adaptive Control
6. Liquid-Level Control
7. Helicopter Model
8. Automobile Speed Controller
9. Braking System Controller
10. Process Control (includes cement kiln control)
11. Robotic Control
12. Elevator (Automatic Lift) control;
13. Automatic Running Control
14. Cooling Plant Control
15. Water Treatment
16. Boiler Control;
17. Nuclear Reactor Control;
18. Power Systems Control;
19. Air Conditioner Control (Temperature Controller)
20. Biological Processes
21. Knowledge-Based System
22. Fault Detection Control Unit
23. Fuzzy Hardware implementation and Fuzzy Computers

Design of Room Cooler using Fuzzy Logic Control System

Visit the following links:

1. https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.740.479&rep=rep1&type=pdf
2. http://www.jctjournal.com/gallery/30-sep2019.pdf

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


31
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Perception and Action

Introduction

Perception involves interpreting sights, sounds, smell, and touch. Action includes the ability to navigate
through the world and manipulate objects.

Design for Autonomous Robot

Figure shows a design for a complete autonomous robot.

 Most of AI is concerned only with cognition, the idea being that when intelligent programs are
developed, we will simply add sensors and effectors to them.
 But problems in perception and action are substantial in their own right and are being tackled by
researchers in the field of robotics.

Difference between AI and Robotics

In the past, robotics and AI have been largely independent endeavors, and they have developed different
techniques to solve different problems.

Sl. No AI Robotics
AI programs usually operate in Robots must operate in the physical
1.
computer-simulated worlds. world.
A complete chess-playing robot,
Example: Chess, An AI program can
must be capable of grasping pieces,
search millions of nodes in a game tree
2. visually interpreting board
without ever having to sense or touch
positions, and carrying on a host of
anything in the real world.
other actions.
The input to an AI program is symbolic. The input to a robot is typically an
3. Eg., an 8-puzzle configuration or a analog signal, such as 2D video
typed English sentence. image or a speech waveform.
AI programs require only general- Robots require special hardware for
4.
purpose computers. perceiving and affecting the world.
Robots sensors are inaccurate, and
5. AI sensors are accurate. their effectors are limited in
precision.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


32
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

6. Because robots must operate in the


An AI program can come up with
real world, searching and
optimal plan by best-first search.
backtracking can be costly.

Perception

We perceive our environment through many channels: sight, sound, touch, smell and taste. Two
extremely important sensory channels for humans are vision and spoken language. It is through these
two faculties that we gather almost all of the knowledge that drives our problem-solving behaviors.

Vision

Machine vision applications include mobile robot navigation, complex manufacturing tasks, analysis
of satellite images, and medical image processing. We investigate how we can transform raw camera
images into useful information about the world.

A video camera provides a computer with an image represented as a 2D grid of intensity levels. Each
grid element, or pixel, may store a single bit of information (black/white) or many bits (Color). A visual
image is composed of thousands of pixels. The operations that can be performed on these images are:
1. Signal Processing: Enhancing the image, either for human consumption or as input to another
program.
2. Measurement Analysis: For images containing a single object, determining the 2D extent of the
object depicted.
3. Pattern Recognition: For single object images, classifying the object into a category drawn from
finite set of possibilities.
4. Image Understanding: For images containing many objects, locating the objects in the image,
classifying them and binding a three-dimensional model of the scene.

Sometimes the problems remain unsolved because of the difficulties that include the following:
1. An image is 2D, while the world is 3D. Some information is lost when an image is created.
2. One image can contain several objects, and some objects may partially occlude others.
3. The value of a single pixel is affected by many different phenomena, including the color of the
object, the source of the light, the angle and distance of the camera, the pollution in the air, etc.

Given a single image, we could construct any number of 3D worlds that would give rise to the image.
For example consider the following image.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


33
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

It is impossible to decide what 3D solid it portrays. In order to determine the most likely interpretation
of a scene, we have to apply several types of knowledge.

Knowledge can be at two level

1. Low Level Knowledge


2. High Level Knowledge

1. Low Level Knowledge

 We may invoke knowledge about low-level image features, such as shadows and textures.
 Figure shows how such knowledge can help to disambiguate the image.
 Having multiple images of the same object can also be useful for recovering 3D structure.
 The use of two or more cameras to acquire multiple simultaneous view of of the object is
called stereo vision.
 Moving objects (or moving camera) also supply multiple views.
 More information can be gathered with a laser rangefinder, a device that returns an array of
distance measures much like sonar does.

2. High Level Knowledge

 High level knowledge is also important for interpreting visual data.


 Consider the example in the figure(a)

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


34
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

 The objects surroundings provide us with the top down expectations.


 Consider the figure (b)
 All objects in this scene are ambiguous; the same shape might be interpreted as amoeba, logs
in a fire place and a basketball.
 There are no clear cut top down expectations.
 The preferred interpretation of egg, bacon and plate reinforce each other mutually, providing
the necessary expectations.

One possible architecture for vision is as shown in the figure:

Speech Recognition

Spoken language is a more natural form of communication in many human computer interfaces. Below
are five major design issues in speech systems.

1. Speaker Dependence v/s Speaker Independence: A speaker independent system can listen to any
speaker and translate the sounds in to written text. Speaker independence is hard to achieve because

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


35
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

of the wide variations in pitch and accent. It is easier to build a speaker dependent system, which
can be trained on the voice patterns of a single speaker. The system will only work for that single
speaker.
2. Continuous v/s Isolated word speech: Interpreting isolated word speech, in which the speaker
pauses between each word, is easier than interpreting continuous speech. This is because boundary
effects cause words to be pronounced differently in different context. Example “Could u” contains
a j sound.
3. Real Time v/s Offline Processing: Highly interactive applications require that a sentence be
translated into text as it is being spoken, while in other situations, it is permissible to spend minutes
in computation. Real-Time speeds are hard to achieve, especially when higher-level knowledge is
involved.
4. Large v/s small vocabulary: Recognizing utterances that are confined to small vocabularies is
easier than working with large vocabularies.
5. Broad v/s Narrow Grammar: An example of a narrow grammar is phone number: S- XXXX –
XXXX , where X is any number between zero and nine.

Action

Mobility and intelligence seem to have evolved together. We study the mobility in terms of how robots
navigate through the world and manipulate objects:

Navigation

Navigation means moving around the world; planning routes, reaching desired destinations without
bumping into things.

Many classic AI planning problems involve navigation.

The STRIPS system, for example, gave high level instructions to robot moving through a set of rooms,
carrying objects from one to another. Plans to solve goals like “move box A into room X” contained
operations like MOVE(Y,X). The planner did not concern itself with how this movement was to be
realized in the world.

Navigational Problems are surprisingly complex. For example, suppose that there are obstacles in the
robot’s path as shown in fig

The problem of path planning is to plot a continuous set of points connecting the initial position of the
robot to its desired position.

If the robot is so small as to be considered a point, the problem can be solved straight forwardly by
constructing a visibility graph.

Let S be the set consisting of the initial and final positions as well as the vertices of all obstacles. To
form the visibility graph, we connect every pair of points in S that are visible from one another. We can
then search an optimal path for the robot.

Most robots have bulky extent, we must take this into account when we plan paths.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


36
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Consider the problem shown in fig 21.8 where the robot has a pentagonal shape. The algorithm is as
follows: First choose a point P on the surface of the robot, then increase the size of the obstacles so that
they cover all points that P cannot enter, because of the physical size and shape of the robot. Now,
simply construct and search a visibility graph based on P and the vertices of the new obstacle.

Manipulation

Robot manipulators are able to perform simple repetitive tasks, such as bolting and fitting automobile
parts, but these robots are highly task specific. It is a long standing goal in robotics to build robots that
can be programmed to carry out a wide variety of tasks.

A manipulator is composed of a series of links and joints, usually terminating in an end-effector, which
can take the form of a two-pronged gripper, a human like hand or any of a variety of tools. One general
manipulation problem is pick-and-place., in which a robot must grasp an object and move it to a specific
location.

For example, Consider the fig below where the goal is to place a peg in a hole.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


37
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

There are 2 main subtasks here.

1. The first is to design a robot motion that ends with the object stably grasped between the two
fingers of the robot.
Clearly, some form of path planning can be used to move the arm toward the object. Here,
uncertainty is a critical problem. Even with the vision techniques, a robot can never be sure of the
precise location of the peg or the arm.
Therefore it would be a mistake to plan a grasp motion in which the gripper is spread only wide
enough to permit the peg to pass.
A better strategy is to open the gripper wide, then close gradually as the gripper gets near the peg.
As shown in fig 21.11

2. After the peg is stably grasped, the robot must place it in the hole.
This subtask resembles the path planning problem.
Fig 21.12 (a) shows a naïve strategy for placing the peg. Failure will result from even a slight
positioning error, because the peg will jam flatly on the outer surface. A better strategy is shown
in fig. 21.12(b) we slide the peg along the surface, applying downward pressure so that the peg
enters the hole at an angle. After this happens, we straighten the peg gradually and push it down
into the hole.

Robot Architectures

There are many decisions involved in designing an architecture that integrates perception, cognition,
and action.

 What range of tasks is supported by the architecture?


 What type of environment (indoor, outdoor, space) is supported?
 How are complex behaviours turned into sequences of low-level actions?

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


38
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

 Is control centralized or distributed?


 How are numeric and symbolic representations merged?
 How does the architecture represent the state of the world?
 How quickly can the architecture react to changes in the environment?
 How does the architecture decide when to plan and when to act?
Few Existing Robot architectures:

1. CODGER: is an architecture for controlling vehicles in out-door road-following tasks. It uses a


blackboard structure to organize incoming perceptual data. The system’s control is centralized and
hierarchical. The model is represented symbolically. CODGER has been used to build a system for;
driving the experimental NAVLAB vehicle, a commercial van that has been altered for computer
control via electric and hydraulic servos.
2. Brooks: for building autonomous robots for indoor navigation and manipulation. Behaviors are built
up from layers of simple, numeric finite state machines. Bottom layers consist of reactive, instinctual
behaviors such as obstacle avoidance and wandering. Upper layers consist of behaviors like object
identification and reasoning about object motions. The various behaviors operate in a decentralized
fashion, computing independently and suppressing or informing one another.
3. TCA: is an architecture that combines the idea of of reactive systems with traditional AI planning.
It is a distributed system with centralized control, designed to control autonomous robots forlong
periods in unstructured environments, such as surface of the Mars. TCA particularly addresses issues
that arrive in the context of multiple goals and limited resources.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


39
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Parallel and Distributed AI


There are three main areas in which parallel and distributed architectures can contribute to the study of
intelligent systems:

1. Psychological Modeling
2. Improving Efficiency
3. Helping to organize systems in a modular fashion.

Psychological Modeling

The psychological modelling can be done using two types of models:

1. Using Production Rules


2. Using human brain itself.

1. Using Production Rules

 The production system was originally proposed as a model of human information


processing, and it continues to play a role in psychological modelling.
 Some production system models stress the sequential nature of production system, i.e., the
manner in which the short-term memory is modified over time by the rules.
 Other models stress the parallel aspect, in which all productions match and fire
simultaneously, no matter how many there are.
 SOAR is a production system architecture for building integrated AI systems. It has two
phases. In the elaboration phase of the processing cycle, productions fire in parallel. In the
decision phase, operators and states are chosen, and working memory is modified.

2. Using Human Brain

 While individual neurons is quite slow compared to digital computer circuits, there are vast
numbers of these richly interconnected components, and they all operate concurrently.
 If we wish to model the brain or use it as a source of idea for AI, we must consider the
powers and constraints imposed by the brain’s architecture at the neural level.

Parallelism in Reasoning Systems

AI programs consume significant time and space resources. It is therefore important that Ai algorithms
make use of advances in parallel computation. This can be done at 3 levels:

i. Parallelizing AI architecture
ii. Parallelizing AI Programming Languages
iii. Parallelizing AI Algorithms

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


40
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Parallelizing AI Architecture

Production system have both sequential and parallel aspects. The question arises, how much speedup
can we expect from parallel processing. There are several sources of parallel speed up in production
systems:

 Match-level Parallelism, in which multiple processors are used to speed up the handling of
individual match-resolve-act cycles.
o Production-level parallelism, in which all of the productions match themselves against
working memory in parallel.
o Condition-level Parallelism, in which all of the conditions of a single production are
matched in parallel.
 Task-level Parallelism, in which several cycles are executed simultaneously.

Parallelizing AI Programming Languages

Frequently used interpreters in AI include programming languages LIPS and PROLOG.

 Parallel LISP models include


i. Multilisp
ii. QLISP
iii. Puralation Model
 Parallel PROLOG models include
i. Concurrent PROLOG
ii. PARLOG
iii. Guarded Horn Clauses

PROLOG suggest two types of parallelism:

1. OR-Parallelism: multiple paths for the same goal are taken in parallel.
Example:
Consider the following clauses

Uncle (X, Y):- mother (Z, Y), sibling (X, Z)


Uncle (X, Y) :- father (Z, Y) , sibling (X, Z)

Then the query


?- uncle (John, Bill)

Could be satisfied in two different ways since john could be the sibling of Bill’s mother or of
Bill’s father. A sequential implementation would try to satisfy the first condition, and then if
failed, try the second condition.

2. AND-Parallelism : The protions of a conjunctive goal are pursued in parallel.


Example:
Consider the clause

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


41
REVA UNIVERSITY, BENGALURU.
ARTIFICIAL INTELLIGENCE (AI) UNIT 4

Infieldfly (X) :- fly (X), infiledcatchable (X),


Occupiedbase (first), outs (zero).
Here, four conditions can be checked in parallel, leading to a four fold speedup in processing
the queries.

Parallelizing AI Algorithms

 Throwing more processors at an AI problem may not bring the desired benefits.
 Many problems can be solved efficiently by parallel methods, but it is not always a simple matter
to convert a sequential algorithm into an efficient parallel one.
 Some AI algorithms whose parallel aspects have been studied are best-first search, constraint
satisfaction, natural language parsing, and resolution theorem proving and property inheritance.

Distributed Reasoning Systems

A distributed reasoning system is composed of a set of separate modules (called agents) and a set of
communication paths between them. It is a control mechanism and a shared knowledge base to ones in
which both control and knowledge are fully distributed.

The advantages of distributed systems over monolithic systems are:

1. System Modularity: It is easier to build and maintain a collection of quasi-independent modules than
one huge one.
2. Efficiency: Not all knowledge is needed for all tasks. By modularizing it, we gain the ability to focus
the problem-solving system’s efforts in ways that are most likely to pay off.
3. Fast Computer Architecture: As problem-solvers get more complex, they need more and more
cycles. Although machines continue to get faster, the real speed-ups are beginning to come not from
a single processor with a huge associated memory, but from clusters of smaller processors, each with
its own memory. Distributed systems are better able to exploit such architectures.
4. Heterogeneous Reasoning: The problem-solving techniques and knowledge representation
formalisms that are best for working on one part of a problem may not be the best for working on
another part.
5. Multiple Perspectives: The knowledge required to solve a problem may not reside in the head of a
single person. It is very difficult to get many diverse people to build a single, coherent, knowledge
base and sometimes it is impossible because their models of the domain are actually inconsistent.
6. Distributed Problems: Some problems are inherently distributed. For example, there may be
different data available in each of several distinct physical locations.
7. Reliability: If a problem is distributed across agents on different systems, problem-solving can
continue even if one system fails.

SHREETHA BHAT, ASSISTANT PROFESSOR, SCHOOL OF CSA,


42
REVA UNIVERSITY, BENGALURU.

You might also like