💻 Practice Exercises — Predicate Logic
Work through these exercises to solidify every aspect of FOL. Solutions are provided — try each problem yourself first.
1. English → FOL Translation
English: Every student who studies hard passes the exam.
Predicates: Student(x), StudiesHard(x), Passes(x, exam)
Show Solution
English: There is a barber who shaves everyone who does not shave themselves.
Predicates: Barber(x), Shaves(x, y)
Show Solution
Note: If we also assert ∀y (Shaves(x,y) → ¬Shaves(y,y)), we get Russell’s Barber Paradox.
English: No dog likes every cat.
Show Solution
Equivalently: ∀x (Dog(x) → ∃y (Cat(y) ∧ ¬Likes(x,y)))
English: Everyone who loves all animals is loved by someone.
Show Solution
English: Exactly one person solved the problem.
Show Solution
English: If every bird can fly, then Tweety can fly (given Tweety is a bird).
Show Solution
This is actually a tautology by UI — instantiating x = Tweety.
2. Unification Drills
Find the most general unifier (MGU) or state that unification fails.
Unify: P(x, f(y)) and P(a, f(g(z)))
Show Solution
θ = {x/a, y/g(z)}
Result: P(a, f(g(z)))
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)}
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.
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))
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
Given KB:
- ∀x (Dog(x) → Animal(x))
- ∀x (Animal(x) → Mortal(x))
- Dog(Fido)
Prove: Mortal(Fido)
Show Solution
Clausal form:
- ¬Dog(x) ∨ Animal(x)
- ¬Animal(y) ∨ Mortal(y)
- Dog(Fido)
- ¬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.
Given KB:
- ∀x ∀y (Parent(x,y) ∧ Female(x) → Mother(x,y))
- Parent(Mary, John)
- Female(Mary)
Prove: Mother(Mary, John)
Show Solution
Clausal form:
- ¬Parent(x,y) ∨ ¬Female(x) ∨ Mother(x,y)
- Parent(Mary, John)
- Female(Mary)
- ¬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): □
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
Given:
- ∀x (Programmer(x) → UsesFOL(x))
- Programmer(Alice)
Derive: UsesFOL(Alice)
Show Solution
- ∀x (Programmer(x) → UsesFOL(x)) [premise]
- Programmer(Alice) [premise]
- Programmer(Alice) → UsesFOL(Alice) [UI on 1, x/Alice]
- UsesFOL(Alice) [MP on 3, 2] ✅
Given: ∃x (Student(x) ∧ Passed(x))
Derive: ∃x Student(x)
Show Solution
- ∃x (Student(x) ∧ Passed(x)) [premise]
- Student(c) ∧ Passed(c) [EI, c is fresh constant]
- Student(c) [Simplification on 2]
- ∃x Student(x) [EG on 3]
Given:
- ∀x (CS_Student(x) → Knows(x, Logic))
- ∀x (Knows(x, Logic) → CanProve(x, Theorems))
- CS_Student(Bob)
Derive: CanProve(Bob, Theorems)
Show Solution
- CS_Student(Bob) → Knows(Bob, Logic) [UI on 1]
- Knows(Bob, Logic) [MP on above + premise 3]
- Knows(Bob, Logic) → CanProve(Bob, Theorems) [UI on 2]
- CanProve(Bob, Theorems) [MP on above + step 2] ✅
5. Interpretation & Model Exercises
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
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.