You are on page 1of 14

Predicate Logic

Predicate logic finds logic from a language, which suggests powerful way of deriving new knowledge from old i.e.
deriving new knowledge from old which is known.

Standard logic symbols: Material implication, Not, Or, And, for all, there exist

Real world facts can be represented in propositional logic written as wff (well formed formulas). Representing
simple facts

It is raining : RAINING It is sunny : SUNNY It is windy : WINDY


If it is raining, then it is not sunny RAINING SUNNY

It has several limitations like


Socrates is a man SOCRATMAN Plato is a man PLATOMAN

No conclusion, rather we can say MAN(SOCRATES), MAN(PLATO)


Uses predicate logic that reflects structure of the knowledge.

1) Marcus was a man.


2) Marcus was a Pompeian.
3) All Pompeians were Romans.
4) Caesar was a ruler.
5) All Romans were either loyal to Caesar or hated him.
6) Every one is loyal to someone.
7) People only try to assassinate rulers they are not loyal to.
8) Marcus tried to assassinate Caesar.

1) Marcus was a man. man(Marcus)


2) Marcus was a Pompeian. Pompeian(Marcus)
3) All Pompeians were Romans.x: Pompeian(x) Roman(x)
4) Caesar was a ruler. ruler(Caesar)
5) All Romans were either loyal to Caesar or hated him.
inclusive-or x: Roman(x) loyalto(x, Caesar) hate(x, Caesar)
exclusive-or x: Roman(x) (loyalto(x, Caesar) hate(x, Caesar))
(loyalto(x, Caesar) hate(x, Caesar))
6) Every one is loyal to someone. x: y: loyalto(x, y)
7) People only try to assassinate rulers they are not loyal to.
x: y: person(x) ruler(y) tryassassinate(x, y) loyalto(x, y)
8) Marcus tried to assassinate Caesar. tryassassinate(Marcus, Caesar)

Was Marcus loyal to Caesar?


Though we know Marcus was a man, but we cannot conclude that Marcus was a person. To make it decisive we
need to add another statement and conclude that Marcus was not loyal to Caesar.
All men are people x: man(x) person(x)

Instance & isa relationships: useful form of reasoning and property inheritance. The instance predicate has two
arguments first one is an object and second one is an class to which object belongs. Statement 3 says if a object is a
subclass of Pompeian, it will be also an instance of superclass Roman.

1) instance(Marcus, man)
2) instance(Marcus, Pompeian)
3) x: instance(x, Pompeian) instance(x, Roman)
4) instance(Caesar, ruler)
5) x: instance(x, Roman) loyalto(x, Caesar) hate(x, Caesar)
1
isa predicate used below to show the inheritance.

1) instance(Marcus, man)
2) instance(Marcus, Pompeian)
3) isa(Pompeian, Roman)
4) instance(Caesar, ruler)
5) x: instance(x, Roman) loyalto(x, Caesar) hate(x, Caesar)

Another Example:
1. Marcus was a man. man(Marcus)
2. Marcus was a Pompeian. Pompeian(Marcus)
3. Marcus was born in 40AD. born(Marcus, 40)
4. All men are mortal. x: man(x) mortal(x)
5. All Pompeians died in 79AD x: [Pompeian(x) died(x, 79)
6. Volcano erupted in 79AD erupted(volcano, 79)
7. No mortal lives longer than 150 years x: t1: t2: mortal (x) born(t1) gt(t2-t1, 150) dead(x, t2)
8. It is now 2012
9. Alive means not dead x: t: [alive(x, t) dead(x, t)] [ dead (x, t) alive(x, t)]
10. If someone dies then it is dead at all later time x: t1: t2: died(x, t1) gt(t2, t1) dead(x, t2)

Query: Is Marcus alive?

alive(Marcus, now) x=Marcus, t=now


use 9
dead(Marcus, now)
use 10
died(Marcus, t1) gt(now, t1)
use 5
Pompenian(Marcus) gt(now, 79)

gt(now, 79)
use 8
gt(2012, 79)
compute gt
nil
If the final result is nil then query succeeds, so Marcus is not alive.

Conversion to Clause form

Problem: All Romans who know Marcus either hate Caesar or think that anyone who hates anyone is crazy
wff: x: [Roman(x) know(x, Marcus)] hate(x, Caesar) (y: z: hate(y, z) thinkcrazy(x, y))]

Rules : 1 Eliminate . If ab we can replace it by a b


x: [Roman(x) know(x, Marcus)] [hate(x, Caesar) (y: (z: hate(y, z) thinkcrazy(x, y))]

Rule: 2 (p) = p, (a b) = a b, (a b) = a b, x: P(x) = x: P(x), x: P(x) = x: P(x)


x: [Roman(x) know(x, Marcus)] [hate(x, Caesar) (y: z: hate(y, z) thinkcrazy(x, y))]

Rule:3 Move all quantifier at the left side without changing their relative order (called prenex normal form)
x: y: z: [Roman(x) know(x, Marcus)] [hate(x, Caesar) (hate(y, z) thinkcrazy(x, y))]

Rule: 4 Eliminate existential quantifiers.


x: y: father-of(y, x) can be replaced as x: father-of(S2(x), x)
here S2 is a function that generates y for each x.
2
Tic-tac-toe Problem
Program-1
9 board vector representing 1 2 3 Requires a table of 39 elements of each 9
All element contains 0 if square is blank 4 5 6 vectors. Content of these elements to be
1 if filled with X, 2 if filled with O 7 8 9 set by programmer to make it work.

Algorithm: 1. Convert vector board as a ternary number


2. Use n umber computed as an index and access the corresponding vector
3. vector shows the next move

Searching is efficient, much faster process and more accurate, though having several disadvantage
Takes lots of space to store the table that specifies the correct move
One has to do lot of work to enter the table
Very hard to enter all such manual entry w/o any error
To extend the game in 3D we need to start from scratch and to enter 327 entries.
Program-2
Same vector used as before. Value stored 2 indicating blank, 3 indicating X, indicating O.
Moves starts from 1 and end at 9.

Algorithm:
Make2: Returns 5 if centre sq. is blank (board[5] = 2), else returns any blank non-corner square.

Posswin(p): Return 0 if player p cannot win on the next move, else returns number of the sq. that crates the winning
move. Check each row, column and diagonal at a time. If product is 18 (3x3x2), then X can win, else if product is
50(5x5x2) then O can win.

Go(n): Move at n. If turn is odd (X) then board[n] = 3. If turn is even (O) then board[n] = 5. Increment turn by 1.

Turn = 1 Go(1) upper left corner


Turn = 2 If board[5] is blank, Go(5) else Go(1)
Turn = 3 If board[9] is blank Go(9) else Go(3)
Turn = 4 If Posswin(X) is not 0, then Go(Posswin(X)) [block opponents win] else Go(Make2)
Turn = 5 If Posswin(X) is not 0, then Go(Posswin(X)) [win] else if Posswin(O) is not 0, then
Go(Posswin(O) [block win], else if board[7] is blank then Go(7) else Go(3)
Turn = 6 If Posswin(O) is not 0, then Go(Posswin(O)) [win] else if Posswin(X) is not 0, then
Go(Posswin(X) [block win], else Go(Make2)
Turn = 7 If Posswin(X) is not 0, then Go(Posswin(X)) [win] else if Posswin(O) is not 0, then
Go(Posswin(O) [block win], else Go(any blank)
Turn = 8 If Posswin(O) is not 0, then Go(Posswin(O)) [win] else if Posswin(X) is not 0, then
Go(Posswin(X) [block win], else Go(any blank)
Turn = 9 Same as turn 7.

Comments: Program not efficient in terms of time, but really efficient in terms of space. Not pain to enter the table.

Program-3
Representation of the board 8 3 4 Create a magic square with addition is 15.
1 5 9
6 7 2
Algorithm:
Keep a list of each square a player holds.
If ( 15 sum of two squares <=0 or > 9, then two squares are not-collinear can be ignored
Else if the two squares represents a blank, that produce a win.
Since a player can hold max 4 squares, fewer squares to be examined rather than Program-2 in Posswin(p), so it
will be more faster than the previous.

3
Problems, Problem spaces and search
Describes kind of problem with which AI typically concerned. To build a solution we need 4 steps:
Define the problem. Detailed specification of each state.
Analyze the problem. To find out possible technique.
Represent task knowledge necessary to solve the problem efficiently
Choose best problem solving technique

Chess Board Problem: Chess Playing is not a problem statement only. We need to define initial board position,
all legal moves and board position for a win. Also not only playing legal move rather than play a move for a
possible win.
All possible move can be stored in a table, but requires huge space and not possible to enter all such alternatives.
Though processing is faster but not a real life solution. Better way to do this to write rules for several elements like
White Pawn at Square(row r, column c)
If (Square(r+1, c) = empty and Square(r+2, c) = empty)
Move White Pawn at Square(r+2, c)
This allows general rules defined for each element.
Allows formal definition of a problem to move from one state to another.

Water Jug Problem: Given 2 jugs one of 4lt and another 3lt, without any measuring marker in it. Water
supply is plenty. How we can get 2lt water in 4lt jug.
Problem defined as a pair (x,y), where x water in bigger jug, y water in smaller jug. Possible value
of x = 0, 1, 2, 3, 4 and y = 0, 1, 2, 3. Initial state (0, 0) and goal state is (2, n) for any value of n.
4lt Jug 3 lt jug
To provide formal description of the problem 0 0
Define state space 0 3
Specify one or more state as initial state from all available 3 0
Define one or more goal state 3 3
Specify set of rules 4 2
Production system: A set of rules consisting a pattern at the left side. And an 0 2
Operation to be performed in the rule at the right side. 2 0
One or more knowledge that contains information appropriate for a task
A control strategy that specifies order of the rules to compare
Control Strategy: To find out which rule to apply next
That causes motion towards goal state
To be systematic so that to eliminate arrival of a state several time unnecessarily

Construct a tree with initial state as root. Generate all offspring root. Now for each leaf node generate all
its successor by applying the rules that are appropriate. Use BFS or DFS to find out the tree.
(0,0)

(4,0) (0,3)

(4,3) (0,0) (1,3) (4,3) (0,0) (3,0)


BFS Algorithm
1. Create a variable called NLIST and set as initial state
2. Until goal state is found or list is empty
Remove first element from NLIST call it X. if NLIST empty then quit
For each rule that match node X do
Apply the rule to generate a new state
If new state is goal state, quit and return the state
Else add new state to the end of NLIST.
4
DFS Algorithm:
1. If initial state is goal state, quit and return success
2. Else do the following until success or failure
Generate a successor E of the initial state.
If no more successor return as failure
Call DFS with E as initial state
If success then signal success else continue the loop
Advantage of DFS:
Requires less memory since only nodes of current path is stored.
May find solution without searching total search space at all.
Advantage of BFS:
Not trapped in a blind alley. DFS may trap in a unfruitful alley for long time.
Minimal solution can be achieved.

Heuristic Search
A search technique that constructs a control structure with the requirement of mobility and systematicity to solve a
hard problem. It no longer guaranteed to find best solution but always gives good solution. Improves efficiency of
search process by sacrificing claims for best solution.
Example is a TSP problem where search time reduced to N2 much less in comparison to n!. TSP can be solved with
nearest neighbor heuristic, where we find local superior each time. Possible example of TSP algorithm
Arbitrarily select a city Select next city by looking at all no visited city and the one closet to the previous city
Repeat until all cities are visited.
Heuristic function is a function that maps from problem state description to a number (weight). Based on the state,
heuristic function gives the weight to find any solution towards the solution. Purpose of heuristic function is to
guide the search process in most profitable direction. More accurate the function at any point, more directly towards
the solution.

Problem Characteristics
Is the problem decomposable into smaller sub problem?
An example to find integral calculus (x2 + x + sin2x)dx
At each steps is checks whether
it is solvable. If not it tries x2 dx x dx sin2x dx
to decompose in smaller
parts by recursive call to x3/3 x2/2 (1-cos2x)/2 dx
itself.
1/2 dx -1/2 cos2x dx

x/2 -1/4 sinx2x


Can solution steps be ignored or undone if they are unwise?
Ignorable: In a mathematical proof, any successful try can be ignored and a new alternative effort can be restarted.
Control structure can easily be implemented because it does not require to store previous path.
Recoverable: 8 puzzle games, where any wrong move can be undone, so with few more steps solution can be
achieved. More complex control structure required where production systems needs to backtrack with a path. So
need to store the tree always.
Irrecoverable: Chess game, any wrong move cannot be undone. Most complex structure where move is final, not
possible to recover.

Is the problem universe predictable?


Certain outcome: 8 puzzle game, where possible to plan entire sequences and also possible to back track any move.
Uncertain outcome: like bridge game, where planning cannot be perfect because it depends move of each player.
Also not possible to know exact card position. Only possible to investigate several rules and probability of various
outcome to choose a plan.
5
Is a good solution absolute or relative?
Take example of Marcus or TSP problem. There might be more than one path to get good solution. If a good
solution can be achieved in a path, it is not required to find any other path. Though any-path solution is easy to find
computationally than the best path solution.

Is the solution is a state or a path?


Example of Water jug problem, where to find final goal state is not important, but important is the full path to
achieve the solution. In case of Marcus problem ultimate goal is to find state i.e. whether the query is true or false.

What is the role of the knowledge?


In case of highly powerful computer can be used to play chess, where the software can be built with little
knowledge. But even powerful computer also cannot compute some problem where knowledge is required and that
needs to be fed in the system.

Does the task require interaction with person?


Sometimes human interaction required to solve a hard problem. So the systems asks user to give input interactively
and take decision on top the input.
Heuristic Search Techniques
Generate and Test
Example: Take 4 six sided cube. Each side of each cube painted with one of four color. To arrange the cubes in a
row so that each side gives a one color. As systematic but slow approach is to take each block and considering all
possibilities. Whereas heuristic approach can be used for a faster solution. First see each side of a block and if
found a specific color (say red) covers more sides then align in such a way only one side with red color shows
outside faces. This eliminates several possibilities to make unnecessary test.

1. Generate a possible solution. For some problems, this means generating a particular point in the problem space.
For others it means generating a path from a start state
2. Test to see if this is actually a solution by comparing the chosen point or the endpoint of the chosen path to the
set of acceptable goal states.
3. If a solution has been found, quit, Otherwise return to step 1.

It is a depth first search procedure with backtracking.


In its most systematic form, it is simply an exhaustive search of the problem space.
Operate by generating solutions randomly, no guarantee that solution will be found.
Also called as British Museum algorithm

Hill climbing
Example: To reach to the downtown of a city. Proceed towards the tallest building.
Is a variant of generate-and test in which feedback from the test procedure is used to help the generator decide
which direction to move in search space.
The test function is augmented with a heuristic function that provides an estimate of how close a given state is
to the goal state.
Computation of heuristic function can be done with negligible amount of computation.
Hill climbing is often used when a good heuristic function is available for evaluating states but when no other
useful knowledge is available

Simple Hill Climbing


1. Evaluate the initial state. If it is also goal state, then return it and quit. Otherwise continue with the initial state
as the current state.
2. Loop until a solution is found or until there are no new operators left to be applied in the current state:
a. Select an operator that has not yet been applied to the current state and apply it to produce a new state
b. Evaluate the new state
i. If it is the goal state, then return it and quit.
ii. If it is not a goal state but it is better than the current state, then make it the current state.
iii. If it is not better than the current state, then continue in the loop.
6
The key difference between Simple Hill climbing and Generate-and-test is the use of heuristic function as a
way to inject task specific knowledge into the control process.
Is one state better than another? For this algorithm to work, precise definition of better must be provided.
Example: Take 4 six cube problem. Take one block, rotate 90 degree and see whether resulting state is better. If
better then keep it and take another block. If not go back to the previous state and try rotating in another way.

Steepest-Ascent Hill Climbing


This is a variation of simple hill climbing which considers all the moves from the current state and selects the best
one as the next state. Whereas simple hill climbing selects better one as next state. Also known as Gradient search
1. Evaluate the initial state. If it is also a goal state, then return it and quit. Otherwise, continue with the initial
state as the current state.
2. Loop until a solution is found or until a complete iteration produces no change to current state:
a. Let SUCC be a state such that any possible successor of the current state will be better than SUCC
b. For each operator that applies to the current state do:
i. Apply the operator and generate a new state
ii. Evaluate the new state. If is is a goal state, then return it and quit. If not, compare it to SUCC.
If it is better, then set SUCC to this state. If it is not better, leave SUCC alone.
c. If the SUCC is better than the current state, then set current state to SYCC,
This simple policy has three well-known drawbacks, i.e. not able to find the goal state.
1. Local Maxima: a local maximum is a state which better than its neighbor
but not better than a state farther away. At local maxima all moves appear
to make thing worse.
2. Plateaus: An area of the search space where evaluation function is flat.
Not possible to determine best direction, thus requiring random walk.
3. Ridge: Where there are steep slopes and the search
direction is not towards the top but towards the side.
Some ways of dealing above problems as below, though not guaranteed.
1. Backtrack to some earlier node and follow different direction. A good way
to deal local maxima.
2. Make a big jump in other direction to get a new search space. Good to deal
the issue of plateau.
3. Apply two or more rules before doing the test. Good for ridge handling.
Example: Use local heuristic function: Add one point for every block resting on the thing it is
A H supposed to be. Subtract one point for every block that is sitting on the wrong side.
G Goal State score 8. Initial State score: -1-1+1+1+1+1+1+1 = 4 (A & B has negative mark)
H
H Fig a. : score +1-1+1+1+1+1+1+1 = 6. (B negative)
G F
G
Better score than initial state, can be moved to this state.
E G G
F Fig b: score +1-1+1+1+1+1+1-1 (4)
D F F F Fig c: score +1-1+1+1+1+1+1-1 (4)
E
C E E E Hill climbing halts because both score is less than 6.
D
B D D D Process reached to local maxima. To be modify the
C
A C C H C heuristic function to overcome this problem.
B
B A B A B A H
Initial state Goal State
a. b. c.
Use global heuristic function: For each block with correct support structure, add one point for every block in the
supporting structure. For incorrect supporting structure, subtract one point for every block in the existing structure
Initial state: -7+0-1-2-3-4-5-6 = -28 Goal state: 0+1+2+3+4+5+6+7 = 28
Fig a: 0+0-1-2-3-4-5-6 = -21
Better score than initial, move to this state
Fig b: 0+0-1-2-3-4-5-1 = -16 Fig c: 0+0+-1-2-3-4-5+0 = -15. So next move goes to fig c.

7
Simulated Annealing
An alternative to a random-restart hill-climbing when stuck on a local maximum is to do a reverse walk to
escape the local maximum.
In the beginning of the process some downhill moves considered to explore whole space early, so that starting
state could be better.
Attempt to reach minimum rather than maximm. Actually it is a process of descending a valley.
The term simulated annealing derives from the roughly analogous physical process of heating and then slowly
cooling a substance to obtain a strong crystalline structure. Rate at which system cooled down is called
annealing schedule.
The simulated annealing process lowers the temperature by slow stages until the system ``freezes" and no
further changes occur.
Probability of transition to higher energy state is given by function:
P = e E/kt
Where E is the positive change in the energy level, T is the temperature, K is Boltzmann constant.

The algorithm for simulated annealing is slightly different from the simple-hill climbing procedure. The three
differences are:
The annealing schedule must be maintained
Moves to worse states may be accepted
It is good idea to maintain, in addition to the current state, the best state found so far.

1. Evaluate the initial state. If it is also a goal state, then return it and quit. Otherwise, continue with the initial
state as the current state.
2. Initialize BEST-SO-FAR to the current state.
3. Initialize T according to the annealing schedule
4. Loop until a solution is found or until there are no new operators left to be applied in the current state.
a. Select an operator that has not yet been applied to the current state and apply it to produce a new state.
b. Evaluate the new state. Compute:
E = ( value of current ) ( value of new state)
If the new state is a goal state, then return it and quit.
If it is a goal state but is better than the current state, then make it the current state. Also set
BEST-SO-FAR to this new state.
If it is not better than the current state, then make it the current state with probability p as
defined above. This step is usually implemented by invoking a random number generator to
produce a number in the range [0, 1]. If the number is less than p, then the move is accepted.
Otherwise, do nothing.
c. Revise T as necessary according to the annealing schedule
5. Return BEST-SO-FAR as the answer

Best First Search


Combines the advantages of DFS and BFS into a single method.
DFS is good because it allows a solution to be found without all competing branches having to be expanded.
BFS is good because it does not get branches on dead end paths.
One way of combining the tow is to follow a single path at a time, but switch paths whenever some
competing path looks more promising than the current one does.
At each step of the BFS search process, we select the most promising of the nodes we have generated so far.
This is done by applying an appropriate heuristic function to each of them.
We then expand the chosen node by using the rules to generate its successors
Similar to Steepest ascent hill climbing with two exceptions:
In hill climbing, one move is selected and all the others are rejected, never to be reconsidered. This
produces the straightline behaviour that is characteristic of hill climbing.
In BFS, one move is selected, but the others are kept around so that they can be revisited later if the
selected path becomes less promising. Further, the best available state is selected in the BFS, even
if that state has a value that is lower than the value of the state that was just explored. This contrasts
8
with hill climbing, which will stop if there are no successor states with better values than the
current state. A
A A A A
B C(5) D
Step-1 B(3) C(5) D(1) B(3) C(5) D B C(5) D
G(6) H(5) E F(6)
Step-2
E(4) F(6) G(6) H(5) E(4) F(6)
I(2) J(1)
Step-3 Step-4 Step-5
Hill climbing stops if no successor has better values than current state, whereas Best First Search considers the node
having less value than current state.

OR Graph
It is sometimes important to search graphs so that duplicate paths will not be pursued.
An algorithm to do this will operate by searching a directed graph in which each node represents a point in
problem space.
Each node will contain:
Description of problem state it represents
Indication of how promising it is
Parent link that points back to the best node from which it came
List of nodes that were generated from it
Parent link will make it possible to recover the path to the goal once the goal is found.
The list of successors will make it possible, if a better path is found to an already existing node, to
propagate the improvement down to its successors.
This is called OR-graph, since each of its branches represents an alternative problem solving path
two lists of nodes required
OPEN nodes that have been generated and have had the heuristic function applied to them but
which have not yet been examined. OPEN is actually a priority queue in which the elements with
the highest priority are those with the most promising value of the heuristic function.
CLOSED- nodes that have already been examined. We need to keep these nodes in memory if we
want to search a graph rather than a tree, since whenever a new node is generated, we need to
check whether it has been generated before.

Algorithm
1. Start with OPEN containing just the initial state
2. Until a goal is found or there are no nodes left on OPEN do:
a. Pick the best node on OPEN
b. Generate its successors
c. For each successor do:
i. If it has not been generated before, evaluate it, add it to OPEN, and record its parent.
ii. If it has been generated before, change the parent if this new path is better than the
previous one. In that case, update the cost of getting to this node and to any successors that
this node may already have.
Explanation
It proceeds in steps, expanding one node at each step, until it generates a node that corresponds to a goal
state.
At each step, it picks the most promising of 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 checking to see if any of them have been generated before.
By doing this check, we can guarantee that each node only appears once in the graph, although many nodes
may point to it as a successor.

9
Representing Knowledge using rule
Declarative Representation: Knowledge specified, but how to use the knowledge is not given. Must be augmented
as a program that specifies what is to be done and how. Program consists of several control structure
Procedural Representation: Control information embedded with the knowledge itself. An interpreter can interpret
this knowledge.

Logic Programming: Where logical assertion viewed as program.

Implication of the form p implies q written as p q. In prolog it is written as q :- p. It is natural because


interpreter always works from the goal to backwards.
x: y: Q(x, y) P(x) can be written as P(X) :- Q(X, Y).

x: pet(x) small(x) apartmentpet(x) apartmentpet(x) :- pet(x), small(x).


x: cat(x) dog(x) pet(x) pet(x) :- cat(x). pet(x) :- dog(x).
x: poodle(x) dog(x) small(x) dog(x) :- poodle(x). small(x) :- poodle(x).
poodle(tom) poodle(tom).

Logical Representation PROLOG Representation

Logical negation cannot be presented, i.e. not possible to encode the following logical expression to program
x: dog(x) cat(x)
Instead negation represented implicitly by lack of assertion and returning the rule as failure. If the program asks
following query result will be false because there is no assertion on tom as cat. ?- cat(tom).

Advantage of logic programming: programmer needs to write only the rules and facts, since search engine is built
into the language. Disadvantage is that search control is fixed.

Forward vs Backward reasoning: Search procedure is to discover through problem space from initial state to goal
state. Procedure have two ways:
Forward search : initial to goal state. Initial state is the root of a tree. Generate next level with all rules whose left
side match the root and right side is the new state. Continue until goal state is reached.

Backward search : goal to initial state. Goal state is root of the tree. Generate next level with all rules whose right
side matches the root node. Left side of the rule generate the next level of the tree. Continue until initial state
reached.

Following factors depends whether to select forward or backward reasoning


Move from smaller set of states to higher set of states. Find possible start state and goal state and select.
Proceed in the direction with lower branching factor (average no of nodes can be reached from a single node).
Will the program is asked to justify the reasoning process to a user? Proceed in the direction that corresponds to
a better user thinking.
What kind of event going to trigger? If it is an arrival of a new fact then forward reasoning make sense. If it is a
query to which response is desired backward reasoning is better choice.

The steps from an Integration to the result, it is easy to move in forward direction from start state, where as moving
from a unfamiliar point to home, backward direction is easier. Depending on the problem forward or backward
direction needs to be decided.
Bidirectional search: Start both from forward and backward direction, until two paths meet somewhere in between.
It also may be ineffective if both paths does not meet at all.

Prolog supports backward reasoning, where a query system searches from goal state.

10
Natural Language Processing
Language means communicating with the world in terms of speaking and writing. Processing written language is
easier than processing speech. To process spoken language, we need all facilities of written language with
additional knowledge to handle noise and ambiguities of audio signal.
Entire language processing task is divided in two parts:
Processing written language using lexical, syntactic, semantic knowledge of language
Processing spoken language using all information needed above along with phonology and information to
handle ambiguities.
Problem: English sentence are incomplete descriptions of the information that they are intend to convey
Some dogs are outside Some dogs are on the lawn. Three dogs are on the lawn.
Good side: Language allows speakers to be as vague or precise. Also allows speaker to leave out things they
believe the hearer already know.
Problem: No natural language program can be complete because new words can be generated.
I will google it.
Take an example of this sentence: I want to print Bills .init file.
Morphological Analysis: Individual words are analyzed into their components and non-word tokens such as
punctuation. Objective is to
Pull apart Bill into proper noun Bill and possessive suffix s
Recognize the sequence .init file as an extension that is functioning as an adjective.
Also assign syntactic categories to all words to interpret suffix and prefix. Like prints is the singular form of print.
Syntactic Analysis: Sentences transformed to a structure that shows how words S
relate to each other. This is called parsing and to convert a sentence to a structure.
Here syntax of the language grammar is verified but not the meaning of the NP VP
sentence. Like
Moon move round the earth or The earth moves round the moon. PN V NP
Both are syntactically correct but not semantically.
Based on the rule of grammar a parsed tree is generated. Here parse tree generated Bill printed the NP1
For Bill printed the file.
ADJ N
Top down parsing: Begin with start symbol, apply grammar rule until symbols at the terminal
Of the tree correspond to the components of the sentence
file
Bottom up parsing: Begin with sentence to be parsed, apply rule backward until a single tree
Appears with terminals are the word of the sentence nad top node is the start symbol.
Understanding a sentence having different meaning Have the students who missed the exam
Have used as main verb in an imperative sentence Have the students who missed the exam take it today
Have used as auxiliary verb in interrogative sentence Have the students who missed the exam taken it today?
Four ways to choose actual meaning from multiple interpretation
All Paths: Follow all possible paths to build all possible combination. Ultimately ignored some of the components
on lack of proper words. Like above sentence becomes interrogative when taken appears. But used as imperative
sentence if take appears. Not efficient because some spurious constituents are built and ignored later.
Best path with backtracking: Follow one path at a time and record each point which is required when that path
does not find the goal and needs to be backtracked from some earlier point. Disadvantage is that same constituents
may need to analyze several times. For wrong interpretation of have and backtracked then the students who
missed the exam needs to be analyzed again. Also needs time and space to maintain each state.
Best path and patchup: Follow one path at a time and for any error detected shuffle around the components
already detected. If have taken as auxiliary verb then the students who missed the exam is considered as subject.
If taken appears next path simply continued. If take appears next then have become main verb. Above
sentence becomes subject of the embedded sentence. Subject of the main sentence is filled with you.
Disadvantage is that interaction among the rules of the grammar required.
11
Planning
Components: Choose the best rule to apply, based on the best available heuristic information
Apply the chosen rule to compute new problem state
Detect when solution found
Detect dead end so that they can be abandoned and directed to fruitful direction
Detect when almost correct solution found, employ special technique to get totally correct state
Goal stack Planning
Problem solver uses a single stack containing both goals and operators that is proposed to attain the goal. Also
maintains database of current situation and provision to add, delete operators.

A flat surface with several blocks of same size. They can be stacked upon on another. A robot arm can manipulate
the block one at a time from the top. Few actions are
UNSTACK(A, B) Pickup block A from the top of B. Arm must be empty and no block on top of A
STACK(A, B) Place block A on top of B. Arm must be holding A and top of B is clear
PICKUP(A) Pickup a A from the table and hold it. Arm must be empty and nothing on top of A
PUTDOWN(A) Put A down on the table. The arm must be holding A.

Fe predicate rules required to execute this:


ON(A, B) Block A is on top of B ONTABLE(A) A is on the table
CLEAR(A) Nothing on top of A HOLDING(A) arm holding A
ARMEMPTY arm holding nothing

x: HOLDING(x) ARMEMPTY
x: ONTABLE(x) y: ON(x, y)
x: y: ON(y, x) CLEAR(x)

B C B
A C D A D
Start state : ON(B,A) ONTABLE(A) Goal State : ON(C,A) ON(B,D)
ONTABLE(C) ONTABLE(D) ARMEMPTY ONTABLE(A) ONTABLE(D)

ONTABLE(A) and ONTABLE(D) are already true in initial state and in short mentioned as OTAD.
In backward reasoning process, goal stack contains ON(C,A) ON(B,D) OTAD
STACK(C, A) fig-1
In current state ON(C,A) is not true, we check for operator for which it is true. ON(B, D)
We need to stack C on A. So ON(C, A) replaced by STACK(C, A), that yields ON(C,A) ON(B,D) OTAD
CLEAR(A) fig-2
To satisfy STACK(C, A), previous condition needs to be satisfied, which is HOLDING(C)
CLEAR(A) HOLDING(C). So the goal stack is changed to fig 2 CLEAR(A) HOLDING(C)
STACK(C, A)
ON(B, D)
Next check whether CLEAR(A) is true and it is not. Only operator that makes ON(C,A) ON(B,D) OTAD
It true is UNSTACK(B,A), So the goal stack changed as shown fig 3. ON(B, A) fig-3
CLEAR(B)
Now ON(B,A), CLEAR(B) and ARMEMPTY all are satisfied, so they ARMEMPTY
poped from the stack (fig-4). Because of all precondition satisfied so the next ON(B,A) CLEAR(B) ARMEMPTY
element UNSTACK(B,A) is poped up. At this point the database contains UNSTACK(B,A)
HOLDING(C)
CLEAR(A) HOLDING(C)
ONTABLE(A) ONTABLE(C) ONTABLE(D) HOLDING(B) STACK(C, A)
CLEAR(A) ON(B, D)
And the goal stack contains as shown. How we need to satisfy HOLDING(C) ON(C,A) ON(B,D) OTAD
Which will be true when PICKUP(C) or UNSTACK(C,x) is true.fig(5a,5b) HOLDING(C) fig-4
CLEAR(A) HOLDING(C)
STACK(C, A)
ON(B, D)
ON(C,A) ON(B,D) OTAD 12
ONTABLE(C) fig-5a ON(C,x) fig-5b CLEAR(x) fig-6
CLEAR(C) CLEAR(C) HOLDING(C)
ARMEMPTY ARMEMPTY CLEAR(x) HOLDING(C)
ONTABLE(C) CLEAR(C) ARMEMPTY ON(C,x) CLEAR(C) ARMEMPTY STACK(C,x)
PICKUP(C) UNSTACK(C,x) CLEAR(C)
CLEAR(A) HOLDING(C) CLEAR(A) HOLDING(C) ARMEMPTY
STACK(C, A) STACK(C, A) ON(C,x) CLEAR(C) ARMEMPTY
ON(B, D) ON(B, D) UNSTACK(C,x)
ON(C,A) ON(B,D) OTAD ON(C,A) ON(B,D) OTAD CLEAR(A) HOLDING(C)
STACK(C, A)
ON(B, D)
If we consider the second condition is satisfied and to satisfy ON(C,x) we ON(C,A) ON(B,D) OTAD
need to use STACK to put C on x. fig-6.
CLEAR(D) fig-7
HOLDING(B)
If we consider first condition 5a is satisfied, then we get ONTABLE(C)
CLEAR(D) HOLDING(B)
And CLEAR(C) is true, but ARM is not empty because it is now holding STACK(B,D)
B. So we get fig 7. Here CLEAR(D) and HOLDING(B) are true, so ONTABLE(C) CLEAR(C) ARMEMPTY
STACK(B,D) moved B to D. Now the database is PICKUP(C)
CLEAR(A) HOLDING(C)
STACK(C, A)
ONTABLE(A) ONTABLE(C) ONTABLE(D) ON(B,D) ON(B, D)
ARMEMPTY ON(C,A) ON(B,D) OTAD
Now all precondition are satisfied to execute PICKUP(C) and then
STACK(C,A) is also executed and ON(B,D) is already true.

Simple steps are 1. UNSTACK(B,A) 2. STACK(B,D) 3. PICKUP(C) 4. STACK(C,A)

Game Playing
MINIMAX Search Technique
Depth first and depth limited search procedure. Idea is
to start at the current position
use a move generator to generate set of possible successor position
use static evaluation function to find the best one (static function returns large value for a possible win of us
and small value for a possible win of opponent. As an example if heuristic function return value from 10 to
-10, then 10 is a possible win for us and -10 for possible win for opponents.
A
Because of B has maximum value as the successor from A. Next position to move is B.
This is called one ply search where only one successor is considered, that may not give B(8) C(3) D(-2)
accurate solution. So more than one ply is used for several games like chess. Here we
look ahead to see what will happen, after opponents move. A two ply look ahead tree is shown here. Here
opponent move is also considered. It is clear opponent choose one of moves among E, F, G for a move of B.
Heuristic function chooses minimum value for opponents move, so for this case F (-6) will be chosen by the
opponent. Clearly B is not a good choice for my move in two ply search,
because it gives opponents move to -6. Whereas C gives A
Maximizing ply
opponents move -2, which greater than B. The two
ply system is shown here. So my choice will be C, which
gives least value of the opponent. B(-6) C(-2) D(-4)
Minimizing ply
Alpha-Beta cutoff E(9) F(-6) G(0) H(8) I(-2) J(-4) K(-3)
Use Branch and Bound technique to improve the solution, where if a
clearly worse solution can be found that is abandoned. It includes two bounds one for each player, called alpha-beta
pruning. It requires two threshold values, one representing lower value (alpha) and another upper value (beta).
A(>3)
After examining F, opponent is guaranteed to score -5 Maximizing ply
or less at C. But we also know A must be >3, which is
already achieved at B. So the score -5 is less than 3, that
B(3) C(<-5)
way when F is examined, then G can be abandoned.
Minimizing ply
D(3) E(5) F(-5) 13G
Use of two threshold alpha and beta. When sub tree of B
Is searched, it is clear that A can have at least 3. This is the A
Maximizing ply
Alpha value and it is passed while examining C sub tree.
After K is examined, we see I is guaranteed a maximum
Score of 0, which is less than alpha value (3). Also F can B C
have value 0, so other sub tree of I i.e. L need not to be Minimizing ply
examined. D(3) E(5) F G H(4)
Maximizing ply
Now consider how beta can be used. After cutting further
I J(5) M(7) N(8)
Examination of I, J is examined and yielding value 5. So Minimizing ply
F is assigned 5 (max of 0 and 5). Whereas C will get 5 or
less. Now if we expand G and gets value of M is 7, which K(0) L(7)
is greater than beta cutoff 5. Because of C wants minimum
value so G is not chosen, because an alternate move at F gives value 5. So any other branches of G needs not to be
examined.

So at maximizing level, we can rule out a move early if its value is less than cutoff threshold alpha. Also at
minimizing level, we can rule out a move early if its value is more than cutoff threshold beta.

14

You might also like