Q1

A) Translate the following statements into predicate logic

  1. Mary loves everyone

  2. Every student except George smiles.

  3. Every student who walks talks

  4. Every boy who loves Mary hates every other boy who Mary loves

  5. No one who runs walks

  6. There is a person who writes computer class

Sol

1. Mary loves everyone

xLoves(Mary,x)

2. Every student except George smiles.

x((Student(x)xGeorge)Smiles(x))¬Smiles(George)

3. Every student who walks talks

x((Student(x)Walks(x))Talks(x))

4. Every boy who loves Mary hates every other boy who Mary loves

xy((Boy(x)Loves(x,Mary)Boy(y)Loves(Mary,y)xy)Hates(x,y))

5. No one who runs walks

x(Runs(x)¬Walks(x))

(Alternatively: ¬x(Runs(x)Walks(x)))

6. There is a person who writes computer class

x(Person(x)Writes(x,ComputerClass))

B) Using the resolution algorithm (Forward and backward) prove that: John likes peanuts.

  1. John likes all kind of food.

  2. Apple and vegetable are food

  3. Anything anyone eats and not killed is food.

  4. Anil eats peanuts and still alive

  5. Harry eats everything that Anil eats.

Sol

1. Define Predicates and Translate to First-Order Logic:

Premises:

  1. John likes all kind of food: x(Food(x)Likes(John,x))

  2. Apple and vegetable are food: Food(Apple)Food(Vegetable)

  3. Anything anyone eats and not killed is food: xy((Eats(x,y)¬Killed(x))Food(y))

  4. Anil eats peanuts and still alive: Eats(Anil,Peanuts)¬Killed(Anil)

  5. Harry eats everything that Anil eats: x(Eats(Anil,x)Eats(Harry,x))

Goal: Likes(John,Peanuts)

2. Convert to Conjunctive Normal Form (CNF) Clauses:


Method 1: Forward Resolution (Fact-Driven)

In forward resolution, we start with our known facts and continuously resolve them with implications to derive new facts until we reach the goal: Likes(John,Peanuts).

  1. Resolve C3 (¬Eats(x,y)Killed(x)Food(y)) with fact C4b (¬Killed(Anil)) by substituting x=Anil:

    • Result: ¬Eats(Anil,y)Food(y)
  2. Resolve the Result (¬Eats(Anil,y)Food(y)) with fact C4a (Eats(Anil,Peanuts)) by substituting y=Peanuts:

    • Result: Food(Peanuts) (We have now proven peanuts are food)
  3. Resolve C1 (¬Food(x)Likes(John,x)) with the new fact Food(Peanuts) by substituting x=Peanuts:

    • Result: Likes(John,Peanuts)

      Goal Derived!

في اللاب مشروح ان في ال forward برضو ضيف ال negated goal to the facts and start from the facts فا الحل حرفيا هتضيف زيادة بس بعد ما توصل لستيب 3 فوق انك ناخد resolution with negated goal و توصل لل contradiction


Method 2: Backward Resolution (Goal-Driven / Refutation)

In backward resolution, we negate the goal and resolve it against the clauses to find a logical contradiction (the empty clause, ).

  1. Resolve C6 (¬Likes(John,Peanuts)) with C1 (¬Food(x)Likes(John,x)) using x=Peanuts:

    • Result: ¬Food(Peanuts)
  2. Resolve ¬Food(Peanuts) with C3 (¬Eats(x,y)Killed(x)Food(y)) using y=Peanuts:

    • Result: ¬Eats(x,Peanuts)Killed(x)
  3. Resolve the Result with C4a (Eats(Anil,Peanuts)) using x=Anil:

    • Result: Killed(Anil)
  4. Resolve Killed(Anil) with fact C4b (¬Killed(Anil)):

    • Result: (Contradiction)

      Contradiction reached! Therefore, the original un-negated goal, "John likes peanuts," must be true.


Q2

1) Establish by forward chaining that the pet is a dog.

Sol

Initial Facts in Working Memory:

Goal:

Iteration 1:

Iteration 2:

Iteration 3:

Conclusion: The goal that the pet is a dog has been successfully established using forward chaining.


B) Explain the difference between forward chaining and backward chaining.

Support your answer with an example of giving a good result using forward chaining than backward chaining.

Sol

The Differences

Feature Forward Chaining Backward Chaining
Fundamental Approach Data-Driven: It moves from the bottom up. Goal-Driven: It moves from the top down.
Starting Point Starts with the initial facts (the data currently in the working memory). Starts with a hypothesis or goal (what you want to prove).
Ending Point Stops when a goal is reached or when no more rules can be fired. Stops when all sub-goals are proven true by the initial facts.
Rule Matching Matches the current facts against the IF part (antecedent/premise) of the rules. Matches the current goal/sub-goal against the THEN part (consequent/conclusion) of the rules.
Action Taken If a rule fires, it extracts the conclusion and adds it as a new fact to the database. If a rule matches, it extracts the premises and sets them as new sub-goals to be proven.
Analogy Like an investigator piecing together clues at a crime scene to figure out what happened and who did it. Like a doctor starting with a suspected diagnosis (e.g., "flu") and checking if the patient has the specific symptoms to prove it.

When Forward Chaining is Better (The Example)

Forward chaining excels in situations where you have a small number of initial facts but a massive number of possible conclusions, such as in monitoring systems, event-driven systems, or synthesis/design tasks.

Example: A Smart Home Emergency System

Imagine a smart home system with hundreds of rules determining what to do in various situations (turn on sprinklers, call police, lock doors, adjust AC, etc.).