x represents the quantity of water in the 4gallon jug x= 0,1,2,3,4
y represents the quantity of water in 3gallon jug y=0,1,2,3
Start State: (0,0)
Goal State: (2,0)
Generate production rules for the water jug problem
We basically perform three operations to achieve the goal.
 Fill water jug.
 Empty water jug
 and Transfer water jug
Rule  State  Process 

1  (X,Y  X<4)  (4,Y) {Fill 4gallon jug} 
2  (X,Y Y<3)  (X,3) {Fill 3gallon jug} 
3  (X,Y X>0)  (0,Y) {Empty 4gallon jug} 
4  (X,Y  Y>0)  (X,0) {Empty 3gallon jug} 
5  (X,Y  X+Y>=4 ^ Y>0)  (4,Y(4X)) {Pour water from 3gallon jug into 4gallon jug until 4gallon jug is full} 
6  (X,Y  X+Y>=3 ^X>0)  (X(3Y),3) {Pour water from 4gallon jug into 3gallon jug until 3gallon jug is full} 
7  (X,Y  X+Y<=4 ^Y>0)  (X+Y,0) {Pour all water from 3gallon jug into 4gallon jug} 
8  (X,Y  X+Y <=3^ X>0)  (0,X+Y) {Pour all water from 4gallon jug into 3gallon jug} 
9  (0,2)  (2,0) {Pour 2 gallon water from 3 gallon jug into 4 gallon jug} 
Initialization:
Start State: (0,0)
Apply Rule 2:
Fill 3gallon jug
Now the state is (x,3)
Iteration 1:
Current State: (x,3)
Apply Rule 7:
Pour all water from 3gallon jug into 4gallon jug
Now the state is (3,0)
Iteration 2:
Current State : (3,0)
Apply Rule 2:
Fill 3gallon jug
Now the state is (3,3)
Iteration 3:
Current State:(3,3)
Apply Rule 5:
Pour water from 3gallon jug into 4gallon jug until 4gallon jug is full
Now the state is (4,2)
Iteration 4:
Current State : (4,2)
Apply Rule 3:
Empty 4gallon jug
Now state is (0,2)
Iteration 5:
Current State : (0,2)
Apply Rule 9:
Pour 2 gallon water from 3 gallon jug into 4 gallon jug
Now the state is (2,0) Goal Achieved.
Water Jug Solution using DFS (Depth First Search)
QConsider the following production system.
R1: IF (( X is a man and Y is a woman ) AND (X and Y are lovers))THEN (X is a friend of Y).
R2: IF ((X is a man and Y is a woman) AND ( X married Y))
THEN (X loves Y).
R3: IF ((X is a man and Y is a woman) AND (Y married X))
THEN (Y loves X).
R4: IF ((X loves Y ) AND (Y loves X))
THEN (X and Y are lovers).
If the working memory contains: Ahmed is a man, Ban is a woman, Ahmed
married Ban, Ban married Ahmed. Prove that “Ahmed is a friend of Ban”.
((Ahmed is a man and Ban is a woman) AND (Ahmed married Ban)) THEN (Ahmed loves Ban).
Also ((Ahmed is a man and Ban is a woman) AND (Ban married Ahmed)) THEN (Ban loves Ahmed).
Now ((Ahmed loves Ban) AND (Ban loves Ahmed)) THEN (Ahmed and Ban are lovers).
Also (( Ahmed is a man and Ban is a woman ) AND (Ahmed and Ban are lovers)) THEN (Ahmed is a friend of Ban).
QConsider the following rules:
R1: IF blood pressure is likely to be high THEN risk of heart failure is highR2: IF blood pressure is likely to be low THEN risk of heart failure is low
R3: IF alcohol consumption is high AND patient salt intake is high
THEN blood pressure is likely to be high
R4: IF alcohol consumption is low AND patient salt intake is low
THEN blood pressure is likely to be low
R5: IF units of alcohol per week are > 30 THEN alcohol consumption is high
R6: IF units of alcohol per week are < 20 THEN alcohol consumption is low
R7: IF units of alcohol per week are >= 20 AND <= 30
THEN alcohol consumption is average
And the following facts: units of alcohol >30, salt intake is high.
Using forward chaining, determine a patient's risk of heart failure.
If A is true then B has to be true, it can't be false.
Given facts (which are always true):
GF1: unit of alcohol>30
GF2: Salt intake is high
Using rule R5:
D1: We get, alcohol consumption is high.
In rule R3:
Using GF2 and D1 , we get,
D2: Blood pressure is high
Using R1 :
D3: Risk of heart failure is high.
Q A monkey is in a room containing a box and a bunch of bananas. The bananas are hanging from the ceiling out of reach of the monkey. How can the monkey obtain the bananas? (The monkey is supposed to go to the box, push it under the bananas, climb on top of it and grasp the bananas.) Specify the rules for a production system to solve the monkeyandbananas problem.
sol//
QConsider the following production rules:
R1: IF has(Animal,hair) or give(Animal.milk) THEN isa(Animal,mammal)
R2: IF has((flies(Animal) and lays(Animal,eggs)) THEN isa(Animal,bird)
R3: IF isa(Animal,mammal) and (eats(Animal,meat) or (has(Animal,pointed_teeth) and has(Animal,claws) and has(Animal,forward_pointing_eyes))) THEN isa(Animal,carnivore)
R4: IF isa(Animal,carnivore) and has(Animal,tawny_colour) and has(Animal,dark_spots) THEN isa(Animal,cheetah)
R5: IF isa(Animal,carnivore) and has(Animal,tawny_colour) and has(Animal,black_stripes) THEN isa(Animal,tiger)
R6: IF isa(Animal,bird) and not flies(Animal) and swims(Animal) THEN isa(Animal,penguin)
R7: IF isa(Animal,bird) and has(Animal,large_wingspan) THEN isa(Animal,albatros)
Assume there are the following facts in the working memory: has(jimmy,hair), has(jimmy,pointed_teeth), has(jimmy,claws), has(jimmy,forward_pointed_eyes), has(jimmy,black_stripes), has(jimmy,tawny_colour). Prove isa(jimmy,tiger) using backward chaining.
sol//
hobbes is a tiger animal is a tiger

 R4

hobbes has black stripes animal has black stripes

 succeeds due to A1

hobbes is a carnivore animal is a carnivore

 R3

hobbes eats meat animal eats meat

 succeeds due to A2

hobbes is a mammal animal is a mammal

 R1

hobbes gives milk animal gives milk
Q
sol//