Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

AI ASSIGNMENT 2

1. Solve the wumpus world problem with the help of predicate logic and rules of inference.
Ans -
● The agent explores a cave consisting of rooms connected by passageways.
● Lurking somewhere in the cave is the Wumpus, a beast that eats any agent that enters
its room.
● Some rooms contain bottomless pits that trap any agent that wanders into the room.
● The Wumpus can fall into a pit too, so avoid them.
● Occasionally, there is a heap of gold in a room.
● The goal is to collect the gold and exit the world without being eaten.
● The agent always starts with [1,1] facing to the right.
● The agent has only one move.
● The agent will perceive the stench if he is in the room adjacent to the Wumpus.

● The agent will perceive a breeze if he is in the room directly adjacent to the Pit.

● The agent will perceive the glitter in the room where the gold is present.

● Initially, the agent is in the first room or on the square [1,1], and we already know that
this room is safe for the agent.
Since the agent is alive and perceives neither a breeze nor a stench at [1,1], it knows that
[1,1] and its neighbours are OK.
In Room [1,1] the agent does not feel any breeze or any Stench which means the adjacent
squares are also OK.

R1 : ¬S11 → ¬W11 ⋀ ¬W12 ⋀ ¬W21

Now agent will either move to [1, 2] or [2,1]. Suppose the agent moves to the room [2, 1], at
this room agent perceives some breeze which means Pit is around this room. The pit can be in
[3, 1] or [2,2] so we will add the symbol ‘P?’ to say that, is this Pit room. Now the agent will
go back to the [1, 1] room. 

R2 : ¬S21 → ¬W11 ⋀ ¬W22 ⋀ ¬W21⋀ ¬W31


Now the agent will move to the room [1,2] which is OK. In the room [1,2] agent perceives a
stench which means there must be a Wumpus nearby. But Wumpus cannot be in the room
[1,1] and in [2,2]. Therefore the agent infers that Wumpus is in the room [1,3], and in the
current state, there is no breeze which means in [2,2] there is no Pit and no Wumpus. So it
is safe, and we will mark it OK, and the agent moves further in [2,2].

R3 : ¬S12 → ¬W11 ⋀ ¬W12 ⋀ ¬W22⋀ ¬W13

In-room [2,2], there is no stench and no breezes present so let's suppose the agent decides to
move to [2,3]. In-room [2,3] agent perceives glitter, so it should grab the gold and climb out
of the cave.

R4 : S12 → W11 ⋀ W12 ⋀ W22 ⋀ W13

>> Apply Modus Ponens with ¬S11 and R1 :


(R1) ¬S11→ ¬W11 ⋀ ¬W12 ⋀ ¬W21 and ¬S11
⇒ ¬W11 ⋀ ¬W12 ⋀ ¬W21

>> Applying AND elimination.


⇒ W11, ¬W12, ¬W21

>> Apply Modus Ponens with ¬S21 and R2 :


(R2) ¬S21 → ¬W11 ⋀ ¬W22 ⋀ ¬W21⋀ ¬W31 and ¬S21
⇒ ¬W11 ⋀ ¬W22 ⋀ ¬W21 ⋀ ¬W31

>> Applying AND elimination.


⇒ ¬W22, ¬W21, ¬W31
>> Apply Modus Ponens with S21 and R4 :
(R4) S12 → W11 ⋀ W12 ⋀ W22 ⋀ W13 and S21
⇒ W11 ⋀ W12 ⋀ W22 ⋀ W13

>> Apply unit resolution on W11 ⋀ W12 ⋀ W22 ⋀ W13 and ¬W11
⇒ W12 ⋀ W22 ⋀ W13

>> Apply unit resolution on W12 ⋀ W22 ⋀ W13 and ¬W22


⇒ W12 ⋀ W13

>> Apply unit resolution on W12 ⋀ W13 and ¬W12


⇒ W13
Hence proved that the wumpus is there in the room [1,3].

2. Solve using resolution, Consider the following axioms:All hounds howl at night.
Anyone who has any cats will not have any mice.
Light sleepers do not have anything which howls at night.
John has either a cat or a hound.
(Conclusion) If John is a light sleeper, then John does not have any mice
Ans -
Hound(x): x is a hound.
Howl(x): x howls at night.
Have(x, y): x have y.
LS(x): x is a light sleeper.
Cat(y): y is a cat.
Mouse(z): z is a mouse.

Step 1: Convert all axioms to predicate logic

1. ∀x(Hound(x) → Howl(x))
2. ∀x(Have(x, y) ∧ Cat(y) → ¬(Have(x, a) ∧ Mouse(a)))
3. ∀x LS(x) ∧ Have(x, y) → Howl(y)
4. Have(John, y) ∧ (Cat(y) ∨ Hound(y)))
5. LS(John) → ¬ (Have(John, y) ∧ Mouse(y))

Step 2: Convert all predicates to CNF

1. ¬Hound(x) ∨ Howl(x)
2. ¬(Have(x, y) ∧ Cat(y)) ∨ ¬(Have(x, a) ∧ Mouse(a))
3. ¬( LS(x) ∧ Have(x, y)) ∨ ¬Howl(y)
4. Have(John, y) ∧ (Cat(y) ∨ Hound(y))
5. LS(John) ∨ Have(John, y) ∧ Mouse(y)

Step 3: Negate the conclusion

¬ (LS(John) ∧ Have(John, b) ∧ Mouse(b))

Step 4: Construct resolution tree

3. Unify (if possible) the following pairs of predicates and give the resulting
substitutions. b is a constant.

a. P(x, f(x), z) and P(g(y),f(g(b)),y)


b. P(x, f(x)) and P(f(y), y)
c. P(x, f(z)) and P(f(y), y)
Ans -
a. P(x, f(x), z) and P(g(y), f(g(b)), y)
To unify these predicates, we can make the following substitutions:
x = g(y)
z=y
This results in the unified predicate: P(g(y), f(g(y)), y)

b. P(x, f(x)) and P(f(y), y)


To unify these predicates, we can make the following substitutions:
x = f(y)
This results in the unified predicate: P(f(y), f(f(y)))

c. P(x, f(z)) and P(f(y), y)


To unify these predicates, we can make the following substitutions:
x = f(y)
z=y
This results in the unified predicate: P(f(y), f(y))

4.Consider the following axioms:


1. Anyone whom Mary loves is a football star.
2. Any student who does not pass does not play.
3. John is a student.
4. Any student who does not study does not pass.
5. Anyone who does not play is not a football star.
6. (Conclusion) If John does not study, then Mary does not love John.
Solve using resolution.
Ans -
Step 1: Convert all axioms to predicate logic

1. ∀ x (Loves(Mary,x) → Star(x))
2. ∀ x (Student(x) ∧ ¬ Pass(x) → ¬ Play (x))
3. Student (John)
4. ∀ x (Student (x) ∧ ¬ Study (x) → ¬ Pass (x))
5. ∀ x (¬ Play (x) → ¬ Star (x))
6. ¬ Study (John) → ¬ Loves (Mary,John) [Conclusion]

Step 2: Convert all predicates to CNF

1. ¬ Loves(Mary,x) ∨ Star(x)
2. ¬ (Student(x) ∧ ¬ Pass(x)) ∨ ¬ Play (x)
3. Student (John)
4. ¬ (Student (x) ∧ ¬ Study (x)) ∨ ¬ Pass (x)
5. Play (x) ∨ ¬ Star (x)
6. Study (John) ∨ ¬ Loves (Mary,John) [Conclusion]

Step 3: Negate the conclusion


¬ (Study (John) ∨ ¬ Loves (Mary,John))

Step 4: Construct resolution tree

You might also like