You are on page 1of 76

UNIVERSITY OF TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE















2010

. :
.
10/6/2010
Artificial Intelligence and its
Programming Language (Prolog)
Artificial Intelligence and its Programming Language (Prolog)
2

1.1 What is Prolog?
Prolog (programming in logic) is one of the most widely used programming languages in
artificial intelligence research.
Programming languages are of two kinds:
Procedural (BASIC, ForTran, C++, Pascal, Java);
Declarative (LISP, Prolog, ML).
In procedural programming, we tell the computer how to solve a problem, but in declarative
programming, we tell the computer what problem we want solved. One makes statements about
facts and relations among objects, and provides a set of rules (as predicate calculus implications)
for making inference.
1.2 What is Prolog used for?
Good at
Grammars and Language processing,
Knowledge representation and reasoning,
Unification,
Pattern matching,
Planning and Search.
By following this course, you will learn how to use Prolog as a programming language to solve
practical problems in computer science and artificial intelligence. You will also learn how the
Prolog interpreter actually works. The latter will include an introduction to the logical
foundations of the Prolog language.
1.3 Prolog Terms
The central data structure in Prolog is that of a term. There are terms of four kinds: atoms,
numbers, variables, and compound terms. Atoms and numbers are sometimes grouped together
and called atomic terms.
Everything in a Prolog program both the program and the data it manipulates is build from
Prolog terms.


Artificial Intelligence and its Programming Language (Prolog)
3

1.3.1 Constants
Integers, real numbers, or an atom. Any name that starts with a lowercase letter (followed by
zero or more additional letters, digits, or underscores) is an atom. Atoms look like variables of
other languages, but are treated as constants in Prolog. Sequences of most non-alphanumeric
characters (+, *, -, etc.) are also atoms.
1.3.2 Variables
A variable is any name beginning with an uppercase later or an underscore, followed by zero or
more additional letters, digits, or underscores.
For example:
X, Y, Variable, _tag, X_526, and List, List24, _head, Tail, _input and Output are all Prolog
variables.
1.4 Basic Elements of Prolog
There are only three basic constructs in Prolog: Facts, Rules, and Queries. A collection of facts
and rules is called a knowledge base (or a database) and Prolog programming is all about writing
knowledge bases. That is, Prolog programs simply are knowledge bases, collections of facts and
rules which describe some collection of relationships that we find interesting.
Some are always true (facts):
father( john, jim).
Some are dependent on others being true (rules):
parent( Person1, Person2 ) :- father( Person1, Person2 ).
To run a program, we ask questions about the database.
1.4.1 Example of Facts Database:
John is the father of Jim. father(john, jim).
Jane is the mother of Jim. mother(jane, jim).
Jack is the father of John. father(jack, john).
1.4.2 Example of Rules Database:
Person 1 is a parent of Person 2 if Person 1 is the father of Person 2 or Person 1 is the
mother of Person 2.
Artificial Intelligence and its Programming Language (Prolog)
4

parent(Person1, Person2):- father(Person1, Person2).
parent(Person1, Person2):- mother(Person1, Person2).

Person 1 is a grandparent of Person 2 if some Person 3 is a parent of Person 2 and
Person 1 is a parent of Person 3.
grandparent( Person1, Person2 ):- parent( Person3, Person2 ), parent( Person1,
Person3 ).
1.4.3 Example questions:
Who is Jim's father? ?- father( Who, jim ).
Is Jane the mother of Fred? ?- mother( jane, fred ).
Is Jane the mother of Jim? ?- mother( jane, jim ).
Does Jack have a grandchild? ?- grandparent( jack, _ )
1.5 Clauses
Predicate definitions consist of clauses. It is an individual definition (whether it be a fact or rule).

mother(jane,alan). = Fact

parent(P1,P2):- mother(P1,P2). = Rule

A clause consists of a head and sometimes a body. Facts dont have a body because they are
always true.
A predicate head consists of a predicate name and sometimes some arguments contained within
brackets and separated by commas.

mother(jane, alan).


Artificial Intelligence and its Programming Language (Prolog)
5

1.6 Arithmetic Operators
Operators for arithmetic and value comparisons are built-in to Prolog.
Comparisons: <, >, <=, >=, = (equals),< > (not equals)
Mathematical precedence is preserved: /, *, +, - Can make compound sums using round
brackets for example X = (5+4)*2 then X=18.
1.7 Tests within clauses
These operators can be used within the body of a clause to manipulate values:
sum(X,Y,Sum):- Sum = X+Y.
Goal: sum(3,5,S)
Output: S=8
sum(X,Y):-Sum=X+Y, write(Sum).
Goal: sum(3,5)
Output: 8
We can write the rule without arguments for example:
Sum:-readint(X),readint(Y),Sum=X+Y, write(Sum).
Goal: sum
Output: 8
Also, these operators can be used to distinguish between clauses of a predicate definition:
bigger(N,M):- N < M, write(The bigger number is ), write(M).
bigger(N,M):- N > M, write(The bigger number is ), write(N).
bigger(N,M):- N = M, write(Numbers are the same).
Goal: bigger(6,7)
Output: The bigger number is 7
2.1 Recursion
The recursion in any language is a function that can call itself until the goal has been succeed.
In Prolog, recursion appears when a predicate contain a goal that refers to itself. There are two
types of recursion.
Artificial Intelligence and its Programming Language (Prolog)
6

1. Tail Recursion: is recursion in which the recursive call is the last subgoal of the last
clause. That is, in tail recursion the recursive call is always made just before the
procedure exits: the last step. For example:

tail_recursion(X):- b, c, tail_recursion(Y).

2. Non Tail Recursion: when a recursive call is not last we don't have tail recursion. If you
think about it, tail recursive calls can be implemented very efficiently because they can
reuse the current stack frame or activation record rather than pushing a new one, filling it
with data, doing some computation, and popping it. So tail recursion is often a fast
option. For example:

nontail_recursion(X):- b, nontail_recursion(X), c.
2.2 Pattern Matching
Prolog uses unification to match variables to values. An expression that contains variables like
X+Y*Z describes a pattern where there are three blank spaces to fill in named X, Y, and Z. The
expression 1+2*3 has the same structure (pattern) but no variables. If we input this query

X+Y*Z=1+2*3.

then Prolog will respond that X=1, Y=2, and Z=3! The pattern matching is very powerful
because you can match variables to expressions like this

X+Y=1+2*3.

and get X=1 and Y=2*3! You can also match variable to variables:

X+1+Y=Y+Z+2.

This sets X=Y=2 and Z=1!
Artificial Intelligence and its Programming Language (Prolog)
7

Example 1:
a(1).
a(2).
a(4).
b(2).
b(3).
d(X,Y):-a(X),b(Y), X=4.
Goal: d(X,Y)
X=1, Y=2, 1=4 Fail
X=1, Y=3, 1=4 Fail
X=2, Y=2, 2=4 Fail
X=2, Y=3, 2=4 Fail
X=4, Y=2, 4=4 True
X=4, Y=3, 4=4 True
Output: 2 solutions X=4, Y=2 and X=4 Y=3.
Goal: d(A,2)
X=1, Y=2, 1=4 Fail
X=2, Y=2, 2=4 Fail
X=4, Y=2, 4=4 True
Output: 1solution A=4.
Goal: d(2,2)
Output: no solution.
2.3 Backtracking
2.3.1 Cut
Up to this point, the Prolog cut adds an 'else' to Prolog, we have worked with Prolog's
backtracking. Sometimes it is desirable to selectively turn off backtracking. Prolog provides a
predicate that performs this function. It is called the cut, represented by an exclamation point (!).
The cut effectively tells Prolog to freeze all the decisions made so far in this predicate. That is, if
required to backtrack, it will automatically fail without trying other alternatives.

Artificial Intelligence and its Programming Language (Prolog)
8

Example 1:
a(1).
a(2).
a(4).
b(2).
b(3).
d(X,Y):-a(X),b(Y), X=4,!.
Goal: d(X,Y)
X=1, Y=2, 1=4 Fail
X=1, Y=3, 1=4 Fail
X=2, Y=2, 2=4 Fail
X=2, Y=3, 2=4 Fail
X=4, Y=2, 4=4 True
Output: 1 solutions X=4, Y=2.
Example 2:
a(1).
a(2).
a(4).
b(2).
b(3).
d(X,Y):-a(X),!,b(Y), X=4.
Goal: d(X,Y)
X=1, Y=2, 1=4 Fail
X=1, Y=3, 1=4 Fail
Output: no solutions found.
2.3.2 Fail
The fail predicate is provided by Prolog. When it is called, it causes the failure of the rule. And
this will be forever; nothing can change the statement of this predicate.


Artificial Intelligence and its Programming Language (Prolog)
9


Example of using fail in the program.
clauses
a(1).
a(2).
a(3).
a(4).
Begin:-a(X),write(X),fail.
Goal: Begin
Output: 1234 NO

2.3.3 Passing Back Answers
To report back answers we need to put an un instantiated variable in the query, and then,
instantiate the answer to that variable when the query succeeds, Finally, pass the variable all the
way back to the query.
bigger(X,Y,Answer):- X>Y, Answer = X.
bigger(X,Y,Answer):- X=<Y, Answer = Y.
Goal: bigger(6,4,Answer),bigger(Answer,5,New_answer).
Output: New_answer=6
Built-in mathematical functions
Prolog has a full range of built-in mathematical functions and predicates that operate on integral
and real values.
X mod Y Returns the remainder (modulos) of X divided by Y.
X div Y Returns the quotient of X divided by Y.
abs(X) If X is bound to a positive value val, abs(X) returns that value; otherwise, it returns -1
* val.
cos(X) The trigonometric functions require that X be bound to
sin(X) a value representing an angle in radians.
tan(X) Returns the tangent of its argument.
arctan(X) Returns the arc tangent of the real value to which X is bound.
exp(X) e raised to the value to which X is bound.
ln(X) Logarithm of X, base e.
log(X) Logarithm of X, base 10.
sqrt(X) Square root of X.
Artificial Intelligence and its Programming Language (Prolog)
10

random(X) Binds X to a random real; 0 <= X < 1.
random(X, Y) Binds Y to a random integer; 0 <= Y < X.
round(X) Returns the rounded value of X. The result still being a real
trunc(X) Truncates X. The result still being a real
val(domain,X) Explicit conversion between numeric domains.









3.1 Complete Prolog Programs
domains
i=integer
predicates
counter(i)
sum(i,i,i).
sum_int(i,i,i).
fact(i,i,i).
power(i,i,i,i).
clauses
/* counter from 1-10*/
counter(10):-!.
counter(X):-write(X), X1=X+1, counter(X1).
Goal: counter(1)
Output: 1 2 3 4 5 6 7 8 9

/*summation of 10 numbers*/
sum(10,S,S):-!.
Artificial Intelligence and its Programming Language (Prolog)
11

sum(X,Y,S):-Y1=Y+X,X1=X+1,sum(X1,Y1,S),!.
Goal: sum(1,0,M)
Output: ?

/* summation of 10 given integer numbers*/
sum_int(10,S,S):-!.
sum_int(X,Y,S):-readint(Z),Z>0, X1=X+1,Y1=Y+Z,sum_int(X1,Y1,S),!.
sum_int(X,Y,S):-X1=X+1,sum_int(X1,Y,S),!.
Goal: sum_int(1,0,M)
Output: ?

/* factorial program*/
fact(0,_,1):-!.
fact(1,F,F):-!.
fact(X,Y,F):-Y1=X*Y,X1=X-1,fact(X1,Y1,F),!.
Goal: fact(3,1,F)
Output: F=6

/*power program*/
power(_,0,P,P):-!.
power(X,Y,Z,P):-Z1=Z*X,Y1=Y-1,power(X,Y1,Z1,P),!.
Goal: power(5,2,1,P)
Output: P=25







Artificial Intelligence and its Programming Language (Prolog)
12





4.1 Lists in Prolog
Lists are ordered sequences of elements that can have any length. Lists can be represented as a
special kind of tree. A list is either empty, or it is a structure that has two components: the head
H and tail T. List notation consists of the elements of the list separated by commas, and the
whole list is enclosed in square brackets.
For example:
[a] and [a,b,c], where a, b and c are symbols type.
[1], [2,3,4] these are a lists of integer.
[] is the atom representing the empty list.
Lists can contain other lists. Split a list into its head and tail using the operation [X|Y].
4.2 Examples about Lists
1. p([1,2,3]).
p([the,cat,sat,[on,the,hat]]).
Goal: p([X|Y]).
Output:
X = 1 Y = [2,3] ;
X = the Y = [cat,sat,[on,the,hat]].
2. p([a]).
Goal: p([H | T]).
Output:
H = a, T = [].
3. p([a, b, c, d]).
Goal: p([X, Y | T]).
Output:
X = a, Y = b, T = [c, d].
Artificial Intelligence and its Programming Language (Prolog)
13

4. P([[a, b, c], d, e]).
Goal: p(H,T)
Output:
H = [a, b, c], T = [d, e].

4.3 List Membership
Member is possibly the most used user-defined predicate (i.e. you have to define it every
time you want to use it!).
It checks to see if a term is an element of a list.
it returns yes if it is.
and fails if it isnt.
member(X,[X|_]).
member(X,[_|Y]) :- member(X,Y).

It 1st checks if the Head of the list unifies with the first argument.
If yes then succeed.
If no then fail first clause.
The 2nd clause ignores the head of the list (which we know doesnt match) and recourses
on the Tail.

Goal: member(a, [b, c, a]).
Output: Yes
Goal: member(a, [c, d]).
Output: No.
4.4 Print the contents of the list.
print([]).
print([i(X,Y)|T]):-write(X,Y),print(T).
Goal: print([3,4,5])
Output: 3 4 5
Artificial Intelligence and its Programming Language (Prolog)
14

4.5 Find the maximum value of the list
list([H],H).
list([H1,H2|T],H1):-H1>H2,list([H1|T],_).
list([_,H2|T],H2):-list([H2|T],H2).
Goal: list([3,9,4,5],M)
Output: M=9
4.6 Append two lists
app([],L,L).
app([X|L1],L2,[X|L3]) :-app(L1,L2,L3).
Goal: app([3,4,5],[6,7,8],L)
Output: L=[3,4,5,6,7,8]
4.7 Write the contents of list inside at the given list
list([[]]).
list([[H|T]]):-write(H),list([T]).
list([H|T]):-list([H]),list(T).
Goal: list([[3,4,5],[6,7,8]])
Output: 3 4 5 6 7 8
4.8 Reveres the contents of the given list.
app([],X,X).
app([H|T1],X,[H|T]):-app(T1,X,T).
rev([X],[X]).
rev([H|T],L):-rev(T,L1),app(L1,[H],L).
Goal: rev([a,b,c,d],R)
Output: R=[d,c,b,a]




Artificial Intelligence and its Programming Language (Prolog)
15






5.1 Tail and non tail Recursive Programs.
In general, tail-recursive programs are more efficient than non-tail-recursive programs.
Non-tail Summation of 10 integer number.

Sum-nontail(11,0).
Sum-nontail(X,S):-X1=X+1, Sum-nontail(X1,S1),S=S1+X.

Trace the above program with the goal ? Sum-nontail(4,S)

Sum-nontail(1,S):-X1=2, Sum-nontail(2,S1),S=S1+1.
Sum-nontail(2,S):-X1=3, Sum-nontail(3,S1),S=S1+2.
Sum-nontail(3,S):-X1=4, Sum-nontail(4,S1),S=S1+3.
Then ? Sum-nontail(4,S)
S=6.
Non-tail Factorial program.
Fact(0,1).
Fact(1,1).
Fact(X,Y):-X1=X-1,fact(X1,Y1),Y=X*Y1.
Non-tail Power program.
Power(_,0,1).
Power(X,Y,Z):-Y1=Y-1,power(X,Y1,Z1),Z=Z1+X.





Artificial Intelligence and its Programming Language (Prolog)
16

Standard String Predicates
Prolog provides several standard predicates for powerful and efficient string manipulations. In
this section, we summarize the standard predicates available for string manipulating and type
conversion.

1. str_len (String,Length) (string,integer) (i,o): Determines the length of String. Succeeds if the
length could be matched with Len.

str_len(prolog,X)
X=6.

2. str_char (String,Char) (string,char) (i,o) (o,i): Converts a string into a character or vice
versa. If string is bound, it must have length 1 for the predicate to succeed.

str_char(A,X)
X=A.

3. str_int (String,Int) (string,integer) (i,o) (o,i): Converts a string of one character to ASCII
code or vice versa. If string is bound, it must contain a single number for the predicate to
succeed.

str_int(A,X)
X=65 .

4. char_int (Char,Int) (char,integer) (i,o) (o,i): Converts a character to ASCII code or vice
versa.

char_int(A,X)
X=65.

5. isname (String) (string) (i): Tests whether a string would match a prolog symbol.

isname(s2) return YES.
isname(4r) return NO.

6. frontchar (String,FrontChar,RestString) (string,char,string) (i,x,x) (x,i,i): Extracts the first
character from a string, the remainder is matched with RestString.

frontchar (prolog,C,R)
C=p, R=rolog.
Artificial Intelligence and its Programming Language (Prolog)
17

7. fronttoken (String,Token,Rest) (string,string,string) (i,o,o) (i,i,o) (o,i,i): Skips all white
space characters (blanks,tabs) and separates from the resulting string the first valid token.
The remainder is matched with RestString. A valid token is either a variable or name
'A'...'Z','a'...'z','','0'...'9', a number '0'...'9' or a single character. It fails if String was
empty or contained only whitespace.

fronttoken (complete prolog program,T,R)
T=complete, R=prolog program.

8. frontstr (StrLen,String,FrontStr,RestStr) (i,i,o,o): Extracts the first n characters from a
string. This establishes a relation between String, Count, FronStr, and RestString, thus that String
= FrontStr+RestString and str_len(FronStr,Count) is true. The String and Count arguments must
be initalized.

frontstr(3,cdab 2000,T,R)
T=cda, R=b 2000.

9. concat (Str1,Str2,ResStr) (string,string,string) (i,i,o): Merges to strings to one by appending
the second argument to the first.
concat (prolog,2011,R)
R=prolog2011.
Examples: Write prolog program to do the following:
1. Convert the string of words into a list of words:
split("",[]).
split(S,[H|T]):-fronttoken(S,H,R),split(R,T).
2. Count the number of words in the given string.
counts("",0).
counts(S,C):-fronttoken(S,_,R), counts(R,C1),C=C1+1.
3.Count the number of characters in the given string.
counts("",0).
counts(S,C):-frontchar(S,_,R), counts(R,C1),C=C1+1.
4. Reverse the given string.
rev("","").
rev(Str,R_Str):-frontstr(1,Str,C,RemStr),rev(RemStr,L1),concat(L1,C,R_Str).
con([],"").
Artificial Intelligence and its Programming Language (Prolog)
18

con([H|T],Str):-con(T,Str1),concat(H,Str1,Str).
5. Count the number of words that contain tion in the given list.
count(S):-frontstr(4,S,X,_),X="tion".
count(S):-frontchar(S,_,R),count(R).
set([],0).
set([H|T],L):-count(H),set(T,L1),L=L1+1,!.
set([_|T],L):-set(T,L).

Prolog Database
It uses to retrieve information from the database. The database predicate retrieves information
from the database by matching its argument with any term stored in the database. Until the
DATABASE keyword is implemented, we have to use this or clause to make a non-destructive
database query. The database contains related predicates such
as: asserta, assertz, retract, retractall, these predicates are standard prolog built-in as shown
below:
1. asserta() adds Term to the beginning of the database. Term must should bound to an
atom or a struct, but may contain free variables. The database entry is not removed
upon backtracking. Database entries can only be removed by the use of the.
2. assertz() adds Term to the end of the database. Term must should bound to an atom
or a struct, but may contain free variables. The database entry is not removed upon
backtracking. Database entries can only be removed by the use of the retract()
predicate.
3. retract(): it retrieves information from the database by matching its argument with
any term stored in the database. If it matches, the database entry is removed. Upon
backtracking multiple solutions may occur. You may invoke indefinite loops by using
retract(X),...,assertz(X),fail.construct.
Different from standard prolog we may use this with an uninstantiated variable to
remove all entries.
Artificial Intelligence and its Programming Language (Prolog)
19

4. retractall(): It succeeds once and remove all database entries that match Term on the
way. Different from standard prolog we may use this with an uninstantiated variable
to remove all entries.
To load and save dos file, the predicates consult() and save() are used as shown below:
1- consult (FileName): is used to read and parse the file given by FileName. The file may
contain clauses and facts, separated by the dots. The current operator declarations are used. For
example consult("data.dat"), where data.dat is dos file name.
2- save(FileName): is used to save information the file given by FileName. For example
save("data.dat"), where data.dat is dos file name.

Examples: Write prolog program to perform the following:
1- Read persons name S1, gender S2 and age I then save them into file p.dat.
Solution:
repeat.
repeat:-repeat.
a:-repeat,consult(a1.dat),readln(S1),readln(S2),readint(I),assertz(Per(S1,I,S2)),
I<=18,save(p.dat).

2-Read cars name S, owner N and cars model M then save them into file c.dat.
repeat.
repeat:-repeat.
b:-repeat,consult(a2.dat),readln(S),readln(N),readint(M),assertz(car(S,N,M)),
M<=1980,save(c.dat).

3- Count how many cars with VOLVO name?
c:-consult("c.dat"),findall(X,car(X,_,_),L),count(L,C),write(C).
count([],0).
count([H|T],X):-H="volvo",count(T,X1),X=X1+1.
count([_|T],X):-count(T,X).


Artificial Intelligence and its Programming Language (Prolog)
20

4- Count how many cars with car name TOYOTA and owner name ALI?
d:-consult("c.dat"),findall(X,car("toyota",X,_),L),count(L,C),write(C).
count([],0).
count([H|T],X):-H="ali",count(T,X1),X=X1+1.
count([_|T],X):-count(T,X).




What are Knowledge Representation Schemes ?
In Al, there are four basic categories of representational schemes: logical,
procedural, network and structured representation schemes.
1) Logical representation uses expressions in formal logic to represent its
knowledge base. Predicate Calculus is the most widely used
representation scheme.
2) Procedural representation represents knowledge as a set of instructions for
solving a problem. These are usually if-then rules we use in rule-based systems.
3) Network representation captures knowledge as a graph in which the nodes
represent objects or concepts in the problem domain and the arcs -represent relations or
associations between them.
4) Structured representation extends network representation schemes by allowing each
node to have complex data structures named slots with attached values.
We will focus on logic representation schemes in this chapter.

2.1 The Propositional Calculus
2.1.1 Symbols and Sentences
The prepositional calculus and, in the next subsection, the predicate
calculus are first of all languages. Using their words, phrases, and sentences, we
can represent and reason about properties and relationships in the world. The
first step in describing a language is to introduce the pieces that make it up: ils set
of symbols.
DEFINTION
PROPOSITIONAL CALCULUS SYMBOLS
The symbols of prepositional Calculus are, the prepositional symbols:
P. Q. R,S,T....
truth symbols
true, false
and connectives:
A,v, , =, =
Prepositional symbols denote propositions of statements about the world that
may be either true or raise, such as "the car is red" or "water is wet."
Propositions are denoted by uppercase letters near the end of the English
alphabet. Sentences in the propoEitional calculus are formed from these atomic
symbols according to the following rules :
DEFINITION
PROPOSIONAL CALCULUS SENTENCES
Every prepositional symbol and truth symbol is a sentence.
For example: true, P, Q, and R are sentences.
The negation of a sentence is a sentence
for example: P and false are sentences
The conjunction or and two sentences : is a sentence
For example: P AP is a sentence.
The disjunction or of two sentences is a sentence.
For example P AP. is a sentence,
The implication of one sentence for another is a sentence.
For example P =Q is sentence.
The equivalence of two sentences Is a sentence.
For example: P v Q = R is a sentence.
Legal sentences are also called well-formed formulas 01 WFFs.
IN expressions of the form P A Q. P and Q are called the conjuncts In P v Q and
Q are referred to as disjuncts in an implication P = Q, P is the premise or antecedent
and Q, the conclusion or consequent .
In propositional calculus sentences. the symbols( ) and [ ] are used to group
symbols into subexpressions and so control their order of evaluation and meaning . for
example (P A Q )=R is quit different from P v (Q=R), as can be
demonstrated using truth tables ( section 2.1.2).
An expression is a sentence, or well-formed formula, of the prepositional calculus
if and only if it can be formed of legal symbols through some sequence of these rules . For
example .
P A Q =R = P v QvR
is a well-formed sentence in the in the propositions calculus because:
P, Q, and R are-proposition and .thus sentences.
P A Q, the conjunction of two sentences, is a sentence.
(P A Q) = R, the implication of a sentence for another, is a sentence.
P and Q, the negations of sentences, are sentences.
P v Q, the disjunction of two sentences, is a sentence.
P v Q v R, the disjunction of two sentences, is a sentence.
((P AQ) =R)= P v Q v R, the equivalence of two sentences, is a sentence.
This is our original sentence, which has been Constructed through a series of applications of
legal roles and is therefore well formed.
DEFINITION
PROPOSITIONAL CALCULUS SEMANTICS
An interpretation of a set of propositional is the assignment of a truth
value , either T or F , to each propositional symbol .
The symbol true is always assigned T, and the symbol false is assigned F .
The



F
e interpret
The tru
symbo
is F
The tru
have tru
The tru
truth val
The tru
symbol
symbol
The tru
expres
otherw





Figure 2.2
tation or tr
uth assign
ol , is F if th
uth assign
uth value T;
uth assign
lue F; otherw
uth assign
before the
after the im
uth assign
sslone hav
wise it is F

Figur
P Q
T. T
T F
F T
F F
2 Truth tab
ruth value
nment of n
he assignm
nment of c
otherwise i
nment of d
wise it is T.
nment of im
implication
mplication is
nment of e
e the same
.
P
re 2.1 trut
P pvQ
T F
F F
T T
F T
ble demon
e for senten
negation ,
ment to P i
onjunction
it is F.
disjunction

mplication
n is T and th
s F; otherwi
quivalenc
e assignm
Q PAQ
th table for

Q P=Q
T T
F F
T T
T T

nstrating th
(pvQ)
nce is dete
P, where
is T , and T
n A, is T on
n, v is F only
n , = is F o
he truth valu
ise it is T .
e , = is T
ment for all
Q
r the opera
(pvQ)=
T
T
T
T
he equival
ermined b
e P is any
T if the as
nly when bo
y when both
only when th
ue of the con

only when
l possible
ator A
( P=Q)
lence of (
by:
propositio
signment
oth conjunct
h disjuncts h
he premise
nsequent or
n both
interpreta

P=Q) and
onal
to P
ts
ave
or
r
tion
d

By demonstrating that they have identical truth tables, we can prove the following prepositional calculus
equivalences. For prepositional expressions P, Q, and R;

(P) = P
(P v Q)=( P =Q)
The contra positive law : (P=Q)=( Q=P)
De morgan's law : (P v Q)=( P A Q) and (P AQ)=( P v Q)
The commutative laws : (P A Q)=( Q A P) and ( P v Q ) = ( Q v P )
Associative law : (( P A Q) A R) = ( P A (Q A R))
Associative law : (( P v Q) v R) = ( P v (Q v R))
Distributive law : P v (Q A R) = ( P v Q) A (P v R)
Distributive law : P A (Q v R) = ( P A Q) v (P A R)

2.2 The Predicate Calculus
In prepositional calculus, each atomic symbol (P, Q, etc.) denotes a proposition of some complexity.
There is no way to access the components of an individual assertion. Predicate calculus provides this ability.
For example, instead pf letting a single prepositional symbol, P, denote
:
1he entire sentence "it rained on
Tuesday," we can create a predicate weather that describes a relationship between a date and the weather.
weather (Tuesday, rain) through inference rules we can manipulate predicate calculus expression accessing
their individual components and inferring new sentences.
Predicate calculus also allows expressions^ contain variables. Variables let us create general
assertions about classes of entities. For example, we could state that for
:
all values, of X, where X is a day of
the week , the statement weather ( X, rain ) is true ; I,e., it rains it rains everyday. As with propositional
calculus, we will first define the syntax of the language and then discuss its semantics.
Examples of English sentences represented in predicate calculus:
1- If it doesn't rain tomorrow, Tom will go to the mountains.
weather (rain, tomorrow) =go(tom, mountains).
2- Emma is a Doberman pinscher and a good dog. Good dog
(emma) A isa (emma, Doberman )
3. All basketball players are tall.
v X (basketball _ player(X) =tall (X))
4- Some people like anchovies.
+ X (person(X) A likes(X, anchovies)),
5- If wishes were horses, beggars would ride. equal(wishes,
horses) =ride(beggars).
6- Nobody likes taxes
+ X likes(X,taxes).


3-1 What is Resolution?
Resolution is a technique for theorem. proving in propositional and
predicate calculus which attempts to show that the negation of the
statement produces a contradiction with the known statements.
In the following expression, uppercase letters indicate variables
(W,X,Y,andZ); lowercase letters in the middle of the alphabet
indicate Constants or bound variables (I, m, and n); and early
alphabetic lowercase letters indicate the predicate names (a, b, c, d,
and e). To improve readability of the expressions, we use two types of
brackets: ( ) and [ ]. Where possible in the derivation, we remove
redundant brackets: The expression we will reduce to clause form is:

(i)(vX)(|o(X) A b(X)] - |c(X, I) A (+)(+Z)|c(, Z)] - J(X, ))]) v (vX)(c(X))

1. First we eliminate the by using: a b - a v b. This transformation
reduces the expression in (i) above:

(ii)(vX)(- | o(X) A b(X)]V|c(X, I) A (+)(-(+Z)|c(, Z)VJ(X, ))]V - J(X, ))]) v (vX)(c(X))

2. Next we reduce the scope of negation."This may be accomplished
using a number of the transformations that includes:
-(-o) o
-(+X)o(X) (vX)-o(X)
-(vX)b(X) (+X)-b(X)
-(o/b) -oV-b
-(oVb) -o/-b
Using the second and fourth equivalences (ii) becomes:

(iii)(vX) [- | o(X)Vb(X)]Vjc(X, I) A (+)((vZ)|-c(, Z)VJ(X, ])[ V(vX)(c(X))


3. Next we standardize by renaming all variables so that variables bound
by different quantifiers have unique names. Because variable names
are "dummies" or "place holders," the particular name chosen for a
variable does not affect either the truth value or the generality of the
clause. Transformations used at this step are of the form:
((vX)a(X) v (vX)b(X(vX)a(X) v (y)b(y)
Because {iii)bas two instances of the variable X, we rename:

(i:)(vX)(- o(X)V-b(X)]V|c(X, I) A (+)((vZ)|-c(, Z)VJ(X, ))]VJ(X, ))]) v (vw)(c(w))

4. Move all quantifiers to the left without changing their order. This is
possible. because step 3 has removed the possibility of any conflict
between variable names. (iv) now becomes:

(:)(vX)(+)(vZ)(vw)(- o(X)V-b(X)]V|c(X, I) A (|-c(, Z)VJ(X, ))]V c(w))]

After step 4 the clause is said to be in prenex normal form, because all
the quantifiers are in front as a prefix and the expression or matrix
follows after.
5. At this point all existential quantifiers are eliminated by a process called
skolemization. Expression (v) has an existential quantifier for Y.
When an expression contains an existentially quantified variable, for
example, ( +Z)(foo(...Z,...)), it may be concluded that there is an
assignment to Z under which foo is true. Skolemization identifies such a
value. Skolemization does not necessarily show how to produce such a
value; It is only a method for giving a name to an assignment that must
exist. If k represents that assignment, then we have foo(.K.).
Thus:

(vX)(Jog(X)moy bc rcploccJ by Jog (iJo)


where the name fido is picked from the domain of definition of X to

represent that individual X. fido is called a skolem constant. If the
prediCate has more than one argument and the existentially quantified
variable is within the scope of universally quantified variables, the
existential variable must be a function of those other variables. This is
represented in the skolemizatlon process:
(vX)(+)(motbcr(X, ))
This expression indicates that every person has' a mother. Every person is
an X and the existing mother will be a function of the particular person X
that is picked. Thus skolemization gives:
(vX)motbcr(X, m(X))
which indicates that each X has a mother (the m of that X). In another
example:
(vX)(v)(+Z)(vw)(oo(X, , Z, w))
Is skolemized to:
(vX)(v)(vw)(oo(X, ), w))

We note that the existentially quantified Z was. Within the scope (to the
right of) universally quantified X and Y Thus the skolemassignment is a
function of X and Y but not of W. With skolemization (v) becomes:

(:i)(vX)(vZ)(vw)(|-o(X)V-b(X)]V|c(X,I)/(| -c(f(X),Z)]Vd(X,f(X)))])Ve(W))

where f is the skolem function of X that replaces the existential Y. Once
the skolemization has occurred, step 6 can take place, which simply
drops the prefix.
6. Drop all universal quantification. By this point only universally
quantified variables exist (step 5) with no variable conflicts (step 3).
Thus all<quantifiers can be dropped, and any proof procedure employed
assumes all variables are universally quantified.
Formula (vi) now becomes:
(:ii)|-o(X)V-b(X)]V|c(X, I)/(-c((X), Z)VJ(X, (X)))]Vc(w)

7. Next we convert the expression to the conjunct of disjuncts form. This
requires using the associative and distributive properties of A and v.
Recall that
oV(bVc) = (oVb)Vc
o/(b/c) = (o/b)/c

which indicates that / or V may be grouped in any desired fashion. The
distributive property is also used, when necessary. Because
o/(bVc)
is already in clause form, A is not distributed However, V must be
distributed across / using:
oV(b/c) = (oVb)/(oVc)

The final form of (vii) is:
(:iii)|-o(X)V-b(X)Vc(X, I)Vc(w)/|-o(X)V-b(X)V-c((X), Z)VJ(X, (X))Vc(w)]

8. Now call each conjunct a separate clause. In the example (viii) above
there are two clauses:
(ixo)|-o(X) v c(X, I) v c(w)] A
(ixb)|-o(X) v -b(X) v c((X), Z) v J(X, (X)) v c(w)]
9. The final step is to standardize the variables apart again. This requires
giving. The variable in each clause generated by step 8 different names.
This procedure arises from the following equivalence:
(vX)(o(X) A b(X)) (vX)o(X) A (v)b()
Which follows from the nature of variable names as place holders. (ixa)
and (ixb) now become, using new-variable names U and V:
(xo)|-o(X) v -b(X) v c(X, I) v c(w)] A
(xo)|-o(u) v -b(u) v -c((u), Z) v J(u, (u)) v c(I)]
Ex (3): As a final example, suppose:
"All people who are not poor and are smart are hippy. Those people who'
read are not stupid. John can read are is wealthy. Happy people have
exciting lives. Can anyone be found with an exciting life?"
a) First change the sentences to predicate form:
We assume vX (smart (X) stupid (X) and vY (wealthy (Y) poor (Y)),
and get:
vX(-Pooi (X)A smort (X) = boppy(X))
v(rcoJ() = smort ())
read (john)A - poor (john)
vZ (happy (Z) = exciting (Z)
The negation of the conclusion is:
+W (exciting (W))
b) These predicate calculus expressions for the happy life problem are
transformed into the following clauses:
poor (X) v smart (X) v happy (X)
read (Y) v smart(Y)
......
read (john)
poor (john)
happy (Z) v exciting (Z)
exciting (W)
The resolution refutation for this example is found in Figure (3-4).














exciting(W) happy(Z) ) v exciting (Z)
(Z/W)

happy (Z) poor (X) v smart (X) v happy (X)

(X/Z)

poor (X) v smart (X) read (Y) v smart(Y)

(Y/X)

poor(john) poor(Y) read (Y)
(john/Y)

read(john) read (john)
( )



Figure (3-4):Resolution prove for the "exciting life" problem .

1IntelligentSearchMethodsandStrategies
Search is inherent to the problem and methods of artificial
intelligence (AI). This is because AI problems are intrinsically complex.
Efforts to solve problems with computers which human can routinely
innate cognitive abilities, pattern recognition, perception and
experience, invariably must turn to considerations of search. All search
methods essentially fall into one of two categories, exhaustive (blind)
methodsandheuristicorinformedmethods.
2StateSpaceSearch
The state space search is a collection of several states with
appropriate connections (links) between them. Any problem can be
represented as such space search to be solved by applying some rules
withtechnicalstrategyaccordingtosuitableintelligentsearchalgorithm.
What we have just said, in order to provide a formal description of a
problem,wemustdothefollowing:
1 Define a state space that contains all the possible configurations
of the relevant objects (and perhaps some impossible ones). It is,
of course, possible to define this space without explicitly
enumeratingallofthestatesitcontains.
2 Specify one or more states within that space that describe
possible situations from which the problemsolving process may
start.Thesestatesarecalledtheinitialstates.
3 Specify one or more states that would be acceptable as solutions
totheproblem.Thesestatesarecalledgoalstates.
4 Specify a set of rules that describe the actions (operators)
available. Doing this will require giving thought to the following
issues:
What unstated assumptions are present in the informal
problemdescription?
Howgeneralshouldtherulesbe?
How much of the work required to solve the problem
shouldbeprecomputedandrepresentedintherules?
The problem can then be solved by using rules, in combination
with an appropriate control strategy, to move through the problem
spaceuntilapathfromaninitialstatetoagoalstateisfound.Thusthe
process of search is fundamental to the problemsolving process. The
fact that search provides the basis for the process of problem solving
does not, however, mean that other, more direct approaches cannot
also be exploited. Whenever possible, they can be included as steps in
the search by encoding them rules. Of course, for complex problems,
more sophisticated computations will be needed. Search is a general
mechanismthatcanbeusedwhennomoredirectmethodsisknown.At
the same time, it provide the framework into which more direct
methodsforsolvingsubpartsofaproblemcanbeembedded.
Tosuccessfullydesignandimplementsearchalgorithms,aprogrammer
mustbeabletoanalyzeandpredicttheirbehavior.Questionsthatneed
tobeansweredinclude:
Istheproblemsolverguaranteedtofindasolution?
Willtheproblemsolveralwaysterminate,orcanitbecomecaught
inaninfiniteloop?
Whenasolutionisfound,isitguaranteedtobeoptimal?
What is the complexity of the search process in terms of time
usage?Memoryusage?
How can the interpreter most effectively reduce search
complexity?
How can an interpreter be designed to most effectively utilize a
representationlanguage?
Togetasuitableanswerforthesequestionssearchcanbestructured
into three parts. A first part presents a set of definitions and concepts
thatlaythefoundationsforthesearchprocedureintowhichinductionis
mapped. The second part presents an alternative approaches that have
beentakentoinductionasasearchprocedureandfinallythethirdpart
present the version space as a general methodology to implement
induction as a search procedure. If the search procedure contains the
principles of the above three requirement parts, then the search
algorithmcangiveaguaranteetogetanoptimalsolutionforthecurrent
problem.
3GeneralProblemSolvingApproaches
Thereexistquitealargenumberofproblemsolvingtechniquesin
AI that rely on search. The simplest among them is the
generateandtest method. The algorithm for the generateandtest
methodcanbefom1allystatedinthegure(1)follow.
It is clear from the above algorithm that the algorithm continues the
possibility of exploring a new state in each iteration of the repeatuntil
loop and exits only when the current state is equal to the goal. Most
importantpartinthealgorithmistogenerateanewstate.Thisisnotan
easytask.
ProcedureGenerate&Test
Begin
Repeat
Generateanewstateandcallitcurrentstate;
Untilcurrentstate=Goal;
End.
Figure(1)GenerateandTestAlgorithm
If generation of new states is not feasible, the algorithm should be
terminated. In our simple algorithm, we, however, did not include this
intentionallytokeepitsimplified.Buthowdoesonegeneratethestates
of a problem? To formalize this, we define a four tuple, called state
space,denotedby
{nodes,arc,goal,current},
where
nodesrepresentthesetofexistingstatesinthesearchspace;
an arc denotes an operator applied to an existing state to cause
transition to another state; goal denotes the desired state to be
identifiedinthenodes;andcurrentrepresentsthestate,nowgenerated
for matching with the goal. The state space for most of the search
problems takes the form of a tree or a graph. Graph may contain more
than one path between two distinct nodes, while for a tree it has
maximumvalueofone.
To build a system to solve a particular problem, we need to do four
things:
1. Definetheproblemprecisely.Thisdefinitionmustincludeprecise
specifications of what the initial situation(s) will be as well as
what final situations constitute acceptable solutions to the
problem.
2. Analyze the problem. A few very important features can have an
immense impact on the appropriateness of various possible
techniquesforsolvingtheproblem.
3. Isolate and represent the task knowledge that is necessary to
solvetheproblem.
4. Choosethebestproblemsolvingtechnique(s)andapplyit(them)
totheparticularproblem.
Measuring problemsolving performance is an essential matter in
termofanyproblemsolvingapproach.Theoutputofaproblemsolving
algorithmiseitherfailureorasolution.(Somealgorithmmightgetstuck
in an infinite loop and never return an output.) We will evaluate an
algorithm'sperformanceinfourways:
Completeness: Is the algorithm guaranteed to find a
solutionwhenthereisone?
Optimality:Doesthestrategyfindtheoptimalsolution?
Timecomplexity:Howlongdoesittaketondasoluon?1
Spacecomplexity:Howmuchmemoryisneededtoperform
thesearch?
4SearchTechnique
Having formulated some problems, we now need to solve them.
Thisisdonebyasearchthroughthestatespace.Therootofthesearch
treeisasearchnodecorrespondingtotheinitialstate.Thefirststepisto
testwhetherthisisagoalstate.Becausethisisnotagoalstate,weneed
to consider some other states. This is done by expanding the current
state; that is, applying the successor function to the current state,
thereby generating a new set of states. Now we must choose which of
thesepossibilitiestoconsiderfurther.Wecontinuechoosing,testingand
expanding either a solution is found or there are no more states to be
expanded. The choice of which state to expand is determined by the
search strategy. It is important to distinguish between the state space
and the search tree. For the route finding problem, there are only N
states in the state space, one for each city. But there are an infinite
numberofnodes.
There are many ways to represent nodes, but we will assume that a node is
a data structure with five components:
STATE: the state in the state space to which the node corresponds
PARENT-NODE: the node in the search tree that generated this
node
ACTION: the action that was applied to the parent to generate the
node
PATHCOST: the cost, traditionally denoted by g(n), of the path
from the initial state to the node, as indicated by the parent
pointers;and
DEPTH:thenumberofstepsalongthepathfromtheinitialstate.
As usual, we differentiate between two main families of search
strategies: systematic search and local search. Systematic search visits
eachstatethatcouldbeasolution,orskipsonlystatesthatareshownto
bedominatedbyothers,soitisalwaysabletofindanoptimalsolution.
Localsearchdoesnotguaranteethisbehavior.Whenitterminates,after
havingexhaustedresources(suchastimeavailableoralimitnumberof
iterations), it reports the best solution found so far, but there is no
guaranteethatitisanoptimalsolution.Toproveoptimality,systematic
algorithms are required, at the extra cost of longer running times with
respect to local search. Systematic search algorithms often scale worse
withproblemsizethanlocalsearchalgorithms.
5SearchTechniqueTypes
Usuallytypesofintelligentsearchareclassifiedintothreeclasses;
blind, heuristic and random search. Blind search is a technique to find
the goal without any additional information that help to infer the goal,
with this type there is no any consideration with process time or
memory capacity. In the other side the heuristic search always has an
evaluating function called heuristic function which guides and controls
the behavior of the search algorithm to reach the goal with minimum
cost, time and memory space. While random search is a special type of
search in which it begins with the initial population that is generated
randomly and the search algorithm will be the responsible for
generatingthenewpopulationbasesonsomeoperationsaccordingtoa
specialtypefunctioncalledfitnessfunction.Thefollowingsectionshave
detailsofeachtypeofsearchwithsimpleexamples.

5.1BlindSearch
There many search strategies that come under the heading of
blind search (also called uniformed search). The term means that they
havenoadditionalinformationaboutstatesbeyondthatprovidedinthe
problem definition. All they can do is generate successors and
distinguishagoalstatefromanongoalstate.
Thus blind search strategies have not any previous information
about the goal nor the simple paths lead to it. However blind search is
not bad, since more problems or applications need it to be solved; in
other words there are some problems give good solutions if they are
solvedbyusingdepthorbreadthfirstsearch.
Breadth first search is a simple strategy in which the root node is
expanded first, then all the successors of the root node are expanded
next, then their successors, and so on. In general all the nodes are
expanded at a given depth in the search tree before any nodes at the
next level are expanded. Breadth first search can be implemented by
calling TREESEARCH with any empty fringe that is a firstinfirstout
(FIFO) queue, assuring that the nodes that are visited first will be
expanded first. In other words, calling TREESEARCH (problem,
FIFOQUEUE) result in a breadth first search. The FIFO queue puts all
newly generated successors at the end of the queue, which means that
shallownodesareexpandedbeforedeepernodes.
Depth first search always expands the deepest node in the current
fringe of the search tree. The search proceeds immediately to the
deepestlevelofthesearchtree,wherethenodeshavenosuccessors.As
those nodes are expanded, they are dropped from the fringe, so then
the search backs up to the next shallowest node that still has
unexplored successors. This strategy can be implemented by
TREESEARCHwithalastinfirstout(LIFO)queue,alsoknownasastack.
As an alternative to the TREESEARCH implementation, it is common to
implementdepthfirstsearchwitharecursivefunctionthatcallsitselfon
eachofitschildreninturn.

Figure(2)BlindSearchTree

Thepathsfromtheinitialstate(A)tothegoalstate(H)are:
UsingBreadthfirstsearch ABCDEFGH
UsingDepthfirstsearch ABDGEH
A
C B
I
D
G
H
F
E
Initialstate
Goalstate
5.2HeuriscSearch
Classically heuristics means rule of thumb. In heuristic search, we
generally use one or more heuristic functions to determine the better
candidate states among a set of legal states that could be generated
from a known state. The heuristic function, in other words, measures
thefitnessofthecandidatestates.Thebettertheselectionofthestates,
the fewer will be the number of intermediate states for reaching the
goal.However;themostdifficulttaskinheuristicsearchproblemsisthe
selectionoftheheuristicfunctions.Onehastoselectthemintuitively,so
thatinmostcaseshopefullyitwouldbeabletoprunethesearchspace
correctly.
The search processes that will be described in this chapter build on
the fact that the search does not proceed uniformly outward from the
start node: instead, it proceeds preferentially through nodes that
heuristic, problemspecific information indicates might be on the best
pathtoagoal.Wecallsuchprocessesbestfirstorheuristicsearch.Here
isthebasicidea.
1. We assume that we have a heuristic (evaluation) function, f. to
help decide which node is the best one to expand next. This
function is based on information specific to the problem domain.
Itisrealvaluedfunctionofstatedescriptions.
2. Expand next that node, n, having the smallest value of f(n).
Resolvetiesarbitrarily.
3. Terminatewhenthenodetobeexpandednextisagoalnode.
A function which applies such an algorithm to nodes and assigns a
value to them accordingly is a heuristic function. Determining good
heuristics is very often the most difficult element involved in solving
complexproblemsinthesymbolicartificialintelligencetradition.
Therefore, heuristic can be defined as the study of the methods and
rulesofdiscoveryandinvention.
AIproblemssolversemployheuristicsintwobasicsituations:
1. A problem may not have an exact solution because of inherent
ambiguities in the problem statement or available data. A given
setofsymptomsmayhaveseveralpossiblecauses.
2. Aproblemmayhaveanexactsolution,butthecomputationalcost
of finding it may be prohibitive. In many problems state space
growth is combinatorially explosive, with the number of possible
statesincreasingexponentiallyorfactoriallywiththedepthofthe
search.
Inordertosolvemanyhardproblemsefficiently,itisoftennecessary
to compromise the requirements of mobility and systematicity and to
construct a control structure that is no longer guaranteed to find the
best answer but that will almost always find a very answer. Thus we
introducetheideaofaheuristic.Aheuristicisatechniquethatimproves
the efficiency of a search process, possibly by sacrificing claims of
completeness. Heuristics are like tour guides. They are good to the
extentthattheypointingenerallyinterestingdirections;theyarebadto
theextentthattheymaymisspointsofinteresttoparticularindividuals.
Some heuristics help to guide a search process without sacrificing any
claims to completeness that the process might previously have had.
Others (in fact, many of the best ones) may occasionally cause an
excellent path to be overlooked. But, on the average, they improve the
quality of the paths that are explored. Using good heuristics, we can
hope to get good (though possibly nonoptimal) solutions to hard
problems,suchasthetravelingsalesman,inlessthanexponentialtime.
There are some good generalpurpose heuristics that are useful in a
wide variety of problem domains. In addition, it is possible to construct
specialpurpose heuristics that exploit domainspecific knowledge to
solveparticularproblems.
Performance of the search can be drastically improved by using
specificknowledgeaboutasearchproblemtoguidethedecisionsmade
where to search. This knowledge can be presented in the form of
heuristicsrulesthatguidethedecisionmakingduringthesearch.This
gives us another class of heuristic search algorithms. It is quite obvious
thatheuristicswilldependverymuchontheclassofsolvableproblems.
The heuristic rules class is considered one of the more important and
complex way to guide the search procedure in which to reach the
solution (goal state) such class usually used in embedded system so to
formwhattodayknownassearchingwithheuristicembeddedinrules.
The search for plans is guided by heuristics that provide an estimate
of the cost (heuristic value) that are extracted automatically from the
problem encoding P. In order to simplify the definition of some of the
heuristics, we introduce in some cases a new dummy End action with
zerocost,whosepreconditionsG1,...,Gnarethegoalsoftheproblem,
and whose effect is a dummy atom G. In such cases, we will obtain the
heuristic estimate h(s) of the cost from state s to the goal, from the
estimateh(G;s)ofachievingthedummyatomGfroms.Inthesection
3.7adetaildescriptionabouttheheuristicsearchalgorithmswithsimple
examples.
5.3RandomSearch
Random Search is a method of searching with no planned
structure or memory. This method has the same intent of the typical
intuitive search, but the opposite strategy to achieve it. A random
technique may be preferred if it takes more time to devise a better
technique,ortheadditionalworkinvolvedisnegligible.
Random Search (RS) is a populationbased search algorithm. It is
first proposed by Price and also called Price's algorithm. RS first
randomlygeneratesapopulationofsamplesfromtheparameterspace,
andthenusesdownhillsimplexmethodtomovethepopulationtowards
the global optima. Suppose a ndimensional objective function is to be
optimized,thebasicRSalgorithmcanbedescribedasfollows:
1. Randomly generate a population of m points from the parameter
space.
2. Randomly select n+1 points from the population and make a
downhillsimplexmove.
3. If the new sample is better than the worst member in the
population, then the worst member is replaced with this new
sample.
4. Repeat the above process until a certain stopping criterion is
satisfied.
InRS,randomsamplingisusedforexplorationanddownhillsimplexfor
exploitation. Its balance strategy first executes exploration and then
switchescompletelytoexploitation.Sinceexplorationisonlyperformed
in the beginning of the search, the convergence to the global optima is
not guaranteed. The problem of getting trapped in a local extreme can
be alleviated by using a large population or introducing new members
intothepopulationwithrandomsamplingduringthesearch.Despiteof
this disadvantage, RS has proved to be very effective in practice and is
widelyused.Inaddition,sincethereisnolocalsearchmethodinvolved,
RSismorerobusttonoiseintheobjectivefunction.Besidesitsfailingto
provide the convergence guarantee, another disadvantage is its low
efficiency. Especially in the beginning, the population is composed of
randomsamples
andRSessentiallyperformslikeapurerandomsampling.Therefore,for
manysituationsinpracticewhereitisdesiredtoobtainagoodsolution
quickly,RSmaynotbeabletofulfilltheobjective.
To make sure that RS being with suitable solutions the algorithm
mustbeevolvedtodecidethefollowingfeatures:
High efficiency is required for the desired search algorithm. More
specifically,theemphasisofthesearchalgorithmshouldbeonfindinga
better operating point within the limited time frame instead of seeking
thestrictlyglobaloptimum.
High dimension is another feature in solve problems. Highdimensional
optimization problems are usually much more difficult to solve than
lowdimensionalproblemsbecauseofcurseofdimensionality.

6HeuristicSearchAlgorithms
In this section, we can saw that many of the problems that fall
withinthepurviewofartificialintelligencearetoocomplextobesolved
by direct techniques; rather they must be attacked by appropriate
searchmethodsarmedwithwhateverdirecttechniquesareavailableto
guide the search. These methods are all varieties of heuristic search.
They can be described independently any particular task or problem
domain.ButwhenappliedtoParticularproblems,theirefficacyishighly
dependent on the way they exploit domainspecific knowledge since in
and of themselves they are unable to overcome the combinatorial
explosion to which search processes are so vulnerable. For this reason,
thesetechniquesareoftencalledweakmethods.Althougharealization
of the limited effectiveness of these weak methods to solve hard
problems by themselves has been an important result that emerged
from the last decades of AI research, these techniques continue to
provide the framework into which domainspecific knowledge can be
placed,eitherbyhandorasaresultofautomaticlearning.
Hill climbing is a variant of generateandtest in which feedback from
thetest procedure isusedto helpthegenerator decidewhichdirection
tomoveinthesearchspace.Inapuregenerateandtestprocedure,the
test function responds with only a yes or no. but if the test function is
augmented with a heuristic function that provide an estimate of how
closeagivenistoagoalstate.Thisisparticularlynicebecauseoftenthe
computation of the heuristic function can be done at almost no cost at
the same time that the test for a solution is being performed. Hill
climbing is often used when a good heuristic function is available for
evaluating states but when no other useful knowledge is available. For
example, suppose you are in an unfamiliar city without a map and you
want to get downtown. You simply aim for the tall buildings. The
heuristic function is just distance between the current location and the
locationofthetallbuildingsandthe desirablestatesarethoseinwhich
thisdistanceisminimized.
Nowletusdiscussanewheuristicmethodcalledbestfirstsearch,which
is a way of combining the advantages of both depthfirst and
breadthfirstsearchintoasinglemethod.
Theactualoperationofthealgorithmisverysimple.Itproceedsinsteps,
expanding one node at each step, until it generates a node that
correspondstoagoalstate.Ateachstep,itpicksthemostpromisingof
the nodes that have so far been generated but not expanded. It
generates the successors of the chosen node, applies the heuristic
function to them, and adds them to the list of open nodes, after
checkingtoseeifanyofthemhavebeengeneratedbefore.Bydoingthis
check,wecanguaranteethateachnodeonlyappearsonceinthegraph,
althoughmanynodesmaypointtoitasasuccessors.Thenthenextstep
begins.
The gure (3) bellow illustrates the hill climbing steps algorithm as it
describedintreedatastructure.
Also the figure (4) bellow shows the steps of the best rst search
algorithmonagiventreeasanassumptionsearchspace.


























Figure (3) Hill Climbing Search Tree


Figure (3) Hill Climbing Search Tree

A
Step1
A
D
C
B
(3) (5) (1)
Step2
A
C D B
E
F
(3)
(5)
(7)
(6)
Step3
A
C D
B
E
F
(3)
(5)
(7)
Step4
E
F
(2) (1)




























Figure (4) Best First Search Tree
A
Step1
A
D C B
(3)
(5) (1)
Step2
A
C
D
B
E F
(3) (5)
(4)
(6)
Step3
A
C
D
B
E F
(5)
(4) (6)
Step4
G H
(6)
(5)
Step5
A
C D
B
E
F
(5)
(4) G H
(6)
(5)
I
J
(1)
(2)
The first advance approach to the best first search is known as
Asearch algorithm. A algorithm is simply define as a best first search
plusspecificfunction.Thisspecificfunctionrepresenttheactualdistance
(levels)betweentheinitialstateandthecurrentstateandisdenotedby
g(n).Anoticewillbementionedherethatthesamestepsthatareused
inthebestfirstsearchareusedinanAalgorithmbutinadditiontothe
g(n)asfollow;
F(n) h(n) + g(n) where h(n) is a heuristic function. The second
advance approach to the best first search is known as A*search
algorithm. A* algorithm is simply define as a best first search plus
specific function. This specific function represent the actual distance
(levels) between the current state and the goal state and is denoted by
h(n).Thisalgorithmwillbedescribedindetailinthenextsectionofthis
chapter.
But just as it was necessary to modify our search procedure
slightly to handle both maximizing and minimizing players, it is also
necessary to modify the branchandbound strategy to include two
bounds, one for each of players. This modified strategy is called
alphabeta pruning. It requires the maintenance of two threshold, one
representing a lower bound on the value that a maximizing node may
ultimately be assigned (we call this alpha) and another representing an
upper bound on the value that minimizing node may be assigned (this
wecallbeta).
Theeffectivenessofthealphabetaproceduredependsgreatlyon
theorderinwhichpathsareexamined.Iftheworstpathsareexamined
first,thennocutoffsatallwilloccur.But,ofcourse,ifthebestpathwere
known in advance so that it could be guaranteed to be examined first,
we would not need to bother with the search process. If, however, we
knew how effective the pruning technique is in the perfect case, we
wouldhaveanupperboundonitsperformanceinothersituations.Itis
possible to prove that if the nodes are perfectly ordered, then the
number of terminal nodes considered by a search to depth d using
alphabeta pruning is approximately equal to twice the number of
terminal nodes generated by a search to depth d/2 without alphabeta.
A doubling of the depth to which the search can be pursued is a
significantgain.Eventhoughallofthisimprovementcannottypicallybe
realized, the alphabeta technique is a significant improvement to the
minimaxsearchprocedure.
7A*Search:minimizingthetotalestimatedsolutioncost
The most widelyknown form of bestfirst search is called A*
search (pronounced "Astar search"). It evaluates nodes by combining
g(n),thecosttoreachthenode,andh(n),thecosttogetfromthenode
tothegoal:
f(n)=g(n)+h(n).
Sinceg(n)givesthepathcostfromthestartnodetonoden,andh(n)is
theestimatedcostofthecheapestpathfromntothegoal,wehave
f(n)=estimatedcostofthecheapestsolutionthroughn .
Thus,ifwearetryingtofindthecheapestsolution,areasonablethingto
tryfirstisthenodewiththelowestvalueofg(n)+h(n).Itturnsoutthat
this strategy is more than just reasonable: provided that the heuristic
function h(n) satisfies certain conditions, A* search is both complete
and optimal. The optimality of A* is straightforward to analyze if it is
used with TREESEARCH. In this case, A* is optimal if h(n) is an
admissible heuristicthat is, provided that h(n) never overestimates the
cost to reach the goal. Admissible heuristics are by nature optimistic,
becausetheythinkthecostofsolvingtheproblemislessthanitactually
is.Sinceg(n)istheexactcosttoreachn,wehasimmediateconsequence
thatf(n)neveroverestimatesthetruecostofasolutionthroughn.
7.1A*SearchAlgorithm
Aswementionedbefore,theA*algorithmtobediscussedshortly
is a complete realization of the best first algorithm that takes into
account these issues in detail. The following definitions, however, are
requiredforrepresentingtheA*algorithm.Theseareinorder.
Denion3.1:Anodeiscalledopenifthenodehasbeengeneratedand
theh'(x)hasbeenappliedoveritbutithasnotbeenexpandedyet.
Denion 3.2: A node is called closed if it has been expanded for
generatingoffsprings.
InordertomeasurethegoodnessofanodeinA*algorithm,werequire
twocostfunctions:
Heuristiccost.
Generationcost.
The heuristic cost measures the distance of the current node x
withrespecttothegoalandisdenotedbyh(x).Thecostofgeneratinga
node x, denoted by g(x), on the other hand measures the distance of
node x with respect to the starting node in the graph. The total cost
function at node x, denoted by f(x), is the sum of g(x) plus h(x). The
generation cost g(x) can be measured easily as we generate node x
through a few slate transitions. For instance, if node x was generated
from the starting node through m statetransitions, the costg(x) will be
proportionaltom(orsimplym).Buthowdoesoneevaluatetheh(x)?It
may be recollected that h(x) is the cost yet to be spent to reach the
goal from the current node x. Obviously, any cost we assign as h(x) is
through prediction. The predicted cost for h(x) is generally denoted by
h'(x).Consequently,thepredictedtotalcostisdenotedbyf(x),where:
f'(x)=g(x)+h'(x).
7.2A*Procedure
Here are the basic steps that are considered to implement the A*
proceduretosolveproblemsinanintelligentmanner:
1. Operations on states generate children of the state currently
underexamination.
2. Each new state is checked to see whether it has occurred before
therebypreventingloops.
3. Eachstatenisgivenanfvalueequaltothesumofitsdepthinthe
searchspaceg(n)andaheuristicestimateofitsdistancetoagoal
h(n).
4. Statesonopenaresortedbytheirfexaminedoragoal.
5. As an implementation point, the algorithms can be improved
throughmaintenanceofperhapsasheapsorleftisttrees.
8TheAlphaBetaSearchAlgorithm
Theideaforalphabetasearchissimple:ratherthansearchingthe
entire space to the ply depth, alphabeta search proceeds in a
depthfirst fashion. Two values, called alpha and beta, are created
during the search. The alpha value associated with MAX nodes, can
never decrease, and the beta value associated with MIN nodes, can
neverincrease.Tworulesforterminatingsearch,basedonalphaand
betavalues,are:
1. SearchcanbestoppedbelowanyMINnodehavingabetavalue
lessthanorequaltothealphavalueofanyofitsMAXancestors.
2. Search can be stopped below any MAX node having an alpha
value greater than or equal to the beta value of any of its MIN
nodeancestors.
Alphabetapruningthusexpressesarelationbetweennodesatplyn
andnodesatplyn+2underwhichenresubtreesrootedatleveln+
1 can be eliminated from consideraon. Note that the resulng
backedup value is identical to the minimax result and the search
saving over minimax is considerable. With fortuitous ordering states
in the search space, alphabeta can effectively double the depth of
the search considered with a fixed space/time computer
commitment.Ifthereisaparticularunfortunateordering,alphabeta
searches no more of the space than normal minimax; however, the
searchisdoneinonlyonepass.

8.1TheAlphaBetaCutoffProcedure(TreePruning)
c(n)=M(n)O(n)
WhereM(n)=numberofmypossiblewinninglines.
Now, we will discuss a new type of algorithm, which does not
require expansion of the entire space exhaustively. This algorithm is
referred to as alphabeta cutoff algorithm. In this algorithm, two extra
ply of movements are considered to select the current move from
alternatives. Alpha and beta denote two cutoff levels associated with
MAX and MIN nodes. As it is mentioned before the alpha value of MAX
nodecannotdecrease,whereasthebetavalueoftheMINnodescannot
increase.Buthowcanwecomputethealphaandbetavalues?Theyare
the backed up values up to the root like MINIMAX. There are a few
interestingpointsthatmaybeexploredatthisstage.Priortotheprocess
of computing MAX / MIN of the backed up values of the children, the
alphabeta cutoff algorithm estimates e(n) at' all fringe nodes n. Now,
the values are estimated following the MINIMAX algorithm. Now, to
prunetheunnecessarypathsbelowanode,checkwhether:

The beta value of any MIN node below a MAX node is less than or
equal to its alpha value. If yes. prune that path below the MIN node.
The alpha value of any MAX node below a MIN node exceeds the
beta value of the MIN node. if yes prune the nodes below the MAX
node.
Based on the above discussion, we now present the main steps in the -
search algorithm.

1. Create a new node, if it is the beginning move, c1seexpand the
existing tree by depth first manner. To make a decision about the
selection of a move at depth d, the tree should be expanded at least
up to a depth (d + 2).
2. Compute e(n) for all leave (fringe) nodes n in the tree.
3. Computer
min
(for max nodes) and
max
values (for min nodes) at the
ancestors of the fringe nodes by the following guidelines. Estimate
the minimum of the values (e or ) possessed by the children of a
MINIMIZER node N and assign it its
max
value. Similarly, estimate
the maximum of the values (e or ) possessed by the children of a
MAXIMIZER node N and assign it its
min
value.
4. If the MAXIMIZER nodes already possess
min
values, then their
current
min
value = Max (
min
value,
min,
); on tile other hand, if the
MANIMIZER nodes already possess
max
values, then their current

max
value = MIN (
max
value,
max
).
5. If the estimated
max
value of a MINIMIZER node N is less than the

min
value of its parent MAXIMIZER node N' then there is no need
to search below the node MINIMIZER node N. Similarly, if the
min

value of a MAXIMIZER node N is more than the
max
value of its
parent node N then there is no need to search below node N.


1. Introduction to Expert Systems
Expertsystemsarecomputerprogramsthatareconstructedtodo
the kinds of activities that human experts can do such as design,
compose, plan, diagnose, interpret, summarize, audit, give advice. The
worksuchasystemisconcernedwithistypicallyataskfromtheworlds
ofbusinessorengineering/scienceorgovernment.
Expertsystemprogramsareusuallysetuptooperateinamanner
that will be perceived as intelligent: that is, as if there were a human
expertontheothersideofthevideoterminal.
A characteristic body of programming techniques give these
programs their power. Expert systems generally use automated
reasoningandthesocalledweakmethods,suchassearchorheuristics,
to do their work. These techniques are quite distinct from the well
articulated algorithms and crisp mathematical procedures more
traditionalprogramming.

Figure(1)thevectorsofexpertsystemdevelopment

Expert
NewProgramming
Methodfor
AsshowninFigure(1),thedevelopmentofexpertsystemsisbased
ontwodistinct,yetcomplementary,vectors:
a.Newprogrammingtechnologiesthatallowustodealwithknowledge
andinferencewithease.
b. New design and development methodologies that allow us to
effectivelyusethesetechnologiestodealwithcomplexproblems.
The successful development of expert systems relies on a well
balancedapproachtothesetwovectors.
2. Expert System Using
Here is a short nonexhaustive list of some of the things expert
systemshavebeenusedfor:
To approve loan applications, evaluate insurance risks, and
evaluateinvestmentopportunitiesforthefinancialcommunity.
To help chemists find the proper sequence of reactions to create
newmolecules.
To configure the hardware and software in a computer to match
theuniquearrangementsspecifiedbyindividualcustomers.
To diagnose and locate faults in a telephone network from tests
andtroublereports.
Toidentifyandcorrectmalfunctionsinlocomotives.
To help geologists interpret the data from instrumentation at the
drilltipduringoilwelldrilling.
To help physicians diagnose and treat related groups of diseases,
suchasinfectionsofthebloodorthedifferentkindsofcancers.
To help navies interpret hydrophone data from arrays of
microphonesontheoceanfloorthatareusedt\uthesurveillance
ofshipsinthevicinity.
To figure out a chemical compound's molecular structure from
experiments with mass spectral data and nuclear magnetic
resonance.
Toexamineandsummarizevolumesofrapidlychangingdatathat
aregeneratedtoolastforhumanscrutiny,suchastelemetrydata
fromlandsatsatellites.
Mostoftheseapplicationscouldhavebeendoneinmoretraditional
ways as well as through an expert system, but in all these cases there
wereadvantagestocastingthemintheexpertsystemmold.
In some cases, this strategy made the program more human
oriented.Inothers,itallowedtheprogramtomakebetterjudgments.
In others, using an expert system made the program easier to
maintainandupgrade.
3. Expert Systems are Kind of AI Programs
Expert systems occupy a narrow but very important corner of the
entire programming establishment. As part of saying what they are, we
need to describe their place within the surrounding framework of
establishedprogrammingsystems.
Figure(2) shows the three programming styles that will most
concern us. Expert systems are part of a larger unit we might call AI
(artificial intelligence) programming. Procedural programming is what
everyone learns when they first begin to use BASIC or PASCAL or
FORTRAN. Procedural programming and A.I programming are quite
differentinwhattheytrytodoandhowtheytrytodoit.

Figure(2)threekindsofprogramming
In traditional programming (procedural programming), the
computerhastobetoldingreatdetailexactlywhattodoandhowtodo
it.Thisstylehasbeenverysuccessfulforproblemsthatarewelldefined.
They usually are found in data processing or in engineering or scientific
work.
AI programming sometimes seems to have been defined by
default, as anything that goes beyond what is easy to do in traditional
procedural programs, but there are common elements in most AI
programs.Whatcharacterizesthesekindsofprogramsisthattheydeal
with complex problems that are often poorly understood, for which
there is no crisp algorithmic solution, and that can benefit from some
sortofsymbolicreasoning.

Procedural
i
Expertsystems
programming
There are substantial differences in the internal mechanisms of
the computer languages used for these two sorts of problems.
Procedural programming focuses on the use of the assignment
statement("="or":")formovingdatatoandfromfixed,prearranged,
named locations in memory. These named locations are the program
variables.Italsodependsonacharacteristicgroupofcontrolconstructs
thattellthecomputerwhattodo.Controlgetsdonebyusing
ifthenelse goto
dowhile procedurecalls
repeatuntil sequentialexecution(asdefault)
AI programs are usually written in languages like Lisp and Prolog.
Program variables in these languages have an ephemeral existence on
the stack of the underlying computer rather than in fixed memory
locations. Data manipulation is done through pattern matching and list
building.Thelisttechniquesaredeceptivelysimple,butalmostanydata
structure can be built upon this foundation. Many examples of list
buildingwillbeseenlaterwhenwebegintouseProlog.AIprogramsalso
useadifferentsetofcontrolconstructs.Theyare:
procedurecalls
sequentialexecution
recursion

4. Expert System, Development Cycle


The explanation mechanism allows the program to explain its
reasoning to the user, these explanations include justification for the
system'sconclusions,explanationof whythesystemneedsa particular
pieceofdata.WhyquesonsandHowquesons.Figure(3)belowshows
theexploratorycycleforrulebasedexpertsystem.

Figure(3)Theexploratorycycleforexpertsystem
failed
Yes
No
No
Begin
Defineproblemsandgoals
Designandconstructprototype
Test/usesystem
Analyzeandcorrectshortcoming
Final
evaluation
Readyfor
final
evaluation
Aredesign
assumptions
still correct
5. Expert System Architecture and Components
Thearchitectureoftheexpertsystemconsistsofseveralcomponentsas
showningure(4)below:

Figure(4)Expertsystemarchitecture

5.1. User Interface


Theuserinteractswiththeexpertsystemthroughauserinterface
that make access more comfortable for the human and hides much of
the system complexity. The interface styles includes questions and
answers,menudriver,naturallanguages,orgraphicsinterfaces.

Explanation
processor
Inference
engine
User
Interface
Knowledge
base
Working
memory
5.2. Explanation Processor
The explanation part allows the program to explain its reasoning
to the user. These explanations include justifications for the system's
conclusion (HOW queries), explanation of why the system needs a
particularpieceofdata(WHYqueries).

5.3. Knowledge Base


The heart of the expert system contains the problem solving
knowledge (which defined as an original collection of processed
information) of the particular applications, this knowledge is
representedinseveralwayssuchasifthenrulesform.
5..4 Inference Engine
The inference engine applies the knowledge to the solution of
actual problems. It s the interpreter for the knowledge base. The
inferenceengineperformstherecognizeactcontrolcycle.
Theinferenceengineconsistsofthefollowingcomponents:
1. Ruleinterpreter.
2. Scheduler
3. HOWprocess
4. WHYprocess
5. knowledgebaseinterface.

5.5. Working Memory


It is a part of memory used for matching rules and calculation.
Whentheworkisfinishedthismemorywillberaised.
6. Systems that Explain their Actions
An interface system that can explain its behavior on demand will seem
much more believable and intelligent to its users. In general, there are
two things a user might want to know about what the system is doing.
When the system asks for a piece of evidence, the user might want to
ask,
"Whydoyouwantit?"
When the system states a conclusion, the user will frequently want to
ask,
"Howdidyouarriveatthatconclusion?"
Thissectionexploressimplemechanismsthataccommodateboth
kinds of questioning. HOW and WHY questions are different in several
rather obvious ways that affect how they can be handled in an
automatic reasoning program. There are certain natural places where
these questions are asked, and they are at opposite ends of the
inferencetree.ItisappropriatetolettheuseraskaWHYquestionwhen
the system is working with implications at the bottom of the tree; that
is:whenitwillbenecessarytoasktheusertosupplydata.

Thesystemneverneedstoaskforadditionalinformationwhenit
is working in the upper parts of the tree. These nodes represent
conclusions that the system has figured out. rather than asked for. so a
WHYquestionisnotpertinent.
To be able to make the conclusions at the top of the tree,
however,isthepurposeforwhichallthereasoningisbeingdone.The
system is trying to deduce information about these conclusions. It is
appropriatetoaskaHOWquestionwhenthesystemreportstheresults
ofitsreasoningaboutsuchnodes.
There is also a difference in timing of the questions. WHY
questions will be asked early on and then at unpredictable points all
throughout the reasoning. The system asks for information when it
discovers that it needs it. The. time for the HOW questions usually
comes at the end when all the reasoning is complete and the system is
reportingitsresults.


1- Breadth First Search Algorithm

Function Breadth First Search











Example with Breadth First Search:


A trace of breadth_first_search on the graph of Figure above follows.
Each successive number, 2,3,4, ... , represents an iteration of the "while"
loop. U is the goal state.




2- Depth First Search Algorithm

Function Depth First Search

Example with Depth First Search:
A trace of depth_first_search on the graph of Figure above appears
below. Each successive iteration of the "while" loop is indicated by a single
line (2, 3, 4, ...). The initial states of open and closed are given on line 1.
Assume U is the goal state.


3- Beast First Search Algorithm
Function Best First Search




Example with Best First Search


A trace of the execution of best first search on this graph appears above.
Suppose P is the goal state in the graph. Became P is the goal, states along
the path to P and to have low heuristic values. The heuristic is fallible: the
state O has a lower value than the goal itself and is examined first. Unlike
hill climbing, which does not maintain apriority queue for the selection of
"next" states, the algorithm recovers from this error and errors the correct
goal.


4- Implementing Heuristic Evaluation Functions
We now evaluate the performance of several different heuristics for solving
the 8-puzzle. Figure below shows a start and goal state for the 8-puzzle,
along with the first three states generated in the search.



The simplest heuristic counts the tiles out of place in each state when it is
compared with the goal.

To summarize:
1. Operations on states generate children of the state currently under
examination.
2. Each new state is checked to see whether it has occurred before (is on
either open or closed), thereby preventing loops.
3. Each state n is given an I value equal to the sum of its depth in the search
space g(n) and a heuristic estimate of its distance to a goal h(n). The h value
guides search toward heuristically promising states while the g value
prevents search from persisting indefinitely on a fruitless path.
4. States on open are sorted by their f values. By keeping all states on open
until they are examined or a goal is found, the algorithm recovers from dead
ends.
5. As an implementation point, the algorithm's efficiency can be improved
through maintenance of the open and closed lists, perhaps as heaps or leftist
trees.

You might also like