💻 Practice Exercises — Predicate Logic

GATE Relevance: High

Work through these exercises to solidify every aspect of FOL. Solutions are provided — try each problem yourself first.

1. English → FOL Translation

Exercise 1.1

English: Every student who studies hard passes the exam.

Predicates: Student(x), StudiesHard(x), Passes(x, exam)

Show Solution
∀x (Student(x) ∧ StudiesHard(x) → Passes(x, Exam))
Exercise 1.2

English: There is a barber who shaves everyone who does not shave themselves.

Predicates: Barber(x), Shaves(x, y)

Show Solution
∃x (Barber(x) ∧ ∀y (¬Shaves(y,y) → Shaves(x,y)))

Note: If we also assert ∀y (Shaves(x,y) → ¬Shaves(y,y)), we get Russell’s Barber Paradox.

Exercise 1.3

English: No dog likes every cat.

Show Solution
¬∃x (Dog(x) ∧ ∀y (Cat(y) → Likes(x,y)))

Equivalently: ∀x (Dog(x) → ∃y (Cat(y) ∧ ¬Likes(x,y)))

Exercise 1.4

English: Everyone who loves all animals is loved by someone.

Show Solution
∀x [(∀y (Animal(y) → Loves(x,y))) → ∃z Loves(z,x)]
Exercise 1.5

English: Exactly one person solved the problem.

Show Solution
∃x (Person(x) ∧ Solved(x, Problem) ∧ ∀y (Person(y) ∧ Solved(y, Problem) → y = x))
Exercise 1.6

English: If every bird can fly, then Tweety can fly (given Tweety is a bird).

Show Solution
(∀x (Bird(x) → CanFly(x))) → (Bird(Tweety) → CanFly(Tweety))

This is actually a tautology by UI — instantiating x = Tweety.

2. Unification Drills

Find the most general unifier (MGU) or state that unification fails.

Exercise 2.1

Unify: P(x, f(y)) and P(a, f(g(z)))

Show Solution

θ = {x/a, y/g(z)}

Result: P(a, f(g(z)))

Exercise 2.2

Unify: Q(x, x) and Q(f(y), f(f(a)))

Show Solution

x → f(y) and x → f(f(a)), so f(y) = f(f(a)), giving y = f(a).

θ = {x/f(f(a)), y/f(a)}

Exercise 2.3

Unify: R(x, f(x)) and R(f(y), y)

Show Solution

x = f(y) and f(x) = y ⇒ y = f(f(y)) — occur check fails!

Unification fails.

Exercise 2.4

Unify: Knows(John, x) and Knows(y, Mother(y))

Show Solution

y = John, x = Mother(y) = Mother(John)

θ = {y/John, x/Mother(John)}

Result: Knows(John, Mother(John))

Exercise 2.5

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

Show Solution

x = f(b,b), y = g(z)

θ = {x/f(b,b), y/g(z)}

3. Resolution Proofs

Exercise 3.1

Given KB:

  1. ∀x (Dog(x) → Animal(x))
  2. ∀x (Animal(x) → Mortal(x))
  3. Dog(Fido)

Prove: Mortal(Fido)

Show Solution

Clausal form:

  1. ¬Dog(x) ∨ Animal(x)
  2. ¬Animal(y) ∨ Mortal(y)
  3. Dog(Fido)
  4. ¬Mortal(Fido)   [negated goal]

Resolution steps:

  • Resolve (2) & (4): {y/Fido} → ¬Animal(Fido)   [clause 5]
  • Resolve (1) & (5): {x/Fido} → ¬Dog(Fido)   [clause 6]
  • Resolve (3) & (6): □ (empty clause)

✅ Proof complete. Mortal(Fido) is entailed.

Exercise 3.2

Given KB:

  1. ∀x ∀y (Parent(x,y) ∧ Female(x) → Mother(x,y))
  2. Parent(Mary, John)
  3. Female(Mary)

Prove: Mother(Mary, John)

Show Solution

Clausal form:

  1. ¬Parent(x,y) ∨ ¬Female(x) ∨ Mother(x,y)
  2. Parent(Mary, John)
  3. Female(Mary)
  4. ¬Mother(Mary, John)   [negated goal]

Resolve (1) & (4): {x/Mary, y/John} → ¬Parent(Mary, John) ∨ ¬Female(Mary) [5]

Resolve (5) & (2): ¬Female(Mary) [6]

Resolve (6) & (3): □

Exercise 3.3 — Skolemization Practice

Convert to clausal form: ∀x ∃y ∀z (P(x,y) ∨ (Q(y,z) → R(x,z)))

Show Solution

Step 1 — Eliminate →: ∀x ∃y ∀z (P(x,y) ∨ ¬Q(y,z) ∨ R(x,z))

Step 2 — Skolemize: y depends on x, so y → f(x):

∀x ∀z (P(x, f(x)) ∨ ¬Q(f(x), z) ∨ R(x, z))

Step 3 — Drop universal quantifiers:

Single clause: {P(x, f(x)), ¬Q(f(x), z), R(x, z)}

4. Natural Deduction Exercises

Exercise 4.1 — Apply UI and Modus Ponens

Given:

  1. ∀x (Programmer(x) → UsesFOL(x))
  2. Programmer(Alice)

Derive: UsesFOL(Alice)

Show Solution
  1. ∀x (Programmer(x) → UsesFOL(x))   [premise]
  2. Programmer(Alice)   [premise]
  3. Programmer(Alice) → UsesFOL(Alice)   [UI on 1, x/Alice]
  4. UsesFOL(Alice)   [MP on 3, 2] ✅
Exercise 4.2 — Apply EI

Given: ∃x (Student(x) ∧ Passed(x))

Derive: ∃x Student(x)

Show Solution
  1. ∃x (Student(x) ∧ Passed(x))   [premise]
  2. Student(c) ∧ Passed(c)   [EI, c is fresh constant]
  3. Student(c)   [Simplification on 2]
  4. ∃x Student(x)   [EG on 3]
Exercise 4.3 — Multi-step Proof

Given:

  1. ∀x (CS_Student(x) → Knows(x, Logic))
  2. ∀x (Knows(x, Logic) → CanProve(x, Theorems))
  3. CS_Student(Bob)

Derive: CanProve(Bob, Theorems)

Show Solution
  1. CS_Student(Bob) → Knows(Bob, Logic)   [UI on 1]
  2. Knows(Bob, Logic)   [MP on above + premise 3]
  3. Knows(Bob, Logic) → CanProve(Bob, Theorems)   [UI on 2]
  4. CanProve(Bob, Theorems)   [MP on above + step 2] ✅

5. Interpretation & Model Exercises

Exercise 5.1

Let D = {1, 2, 3}. Under interpretation I where P(x) means “x is even”, determine:

  • ∀x P(x)   = ?
  • ∃x P(x)   = ?
  • ∃x ¬P(x)   = ?
Show Solution
  • ∀x P(x) = P(1) ∧ P(2) ∧ P(3) = F ∧ T ∧ F = False
  • ∃x P(x) = P(1) ∨ P(2) ∨ P(3) = F ∨ T ∨ F = True
  • ∃x ¬P(x) = ¬P(1) ∨ ¬P(2) ∨ ¬P(3) = T ∨ F ∨ T = True
Exercise 5.2

Is ∀x (P(x) → Q(x)) logically equivalent to ∀x P(x) → ∀x Q(x)?

Show Solution

No! The first entails the second, but not vice versa.

Counterexample: D = {a, b}, P(a) = T, P(b) = F, Q(a) = T, Q(b) = F.

  • ∀x P(x) = F, so ∀x P(x) → ∀x Q(x) = T (antecedent false).
  • ∀x (P(x) → Q(x)): P(b) → Q(b) = F → F = T; P(a) → Q(a) = T → T = T. Also T. Same here, but try:

D = {a, b}, P(a) = T, P(b) = F, Q(a) = F, Q(b) = T.

  • ∀x P(x) = F, so ∀x P(x) → ∀x Q(x) = T.
  • ∀x (P(x) → Q(x)): P(a) → Q(a) = T → F = F. So overall F.

Here second is T but first is F. So NOT equivalent.