Workbook Sol
Workbook Sol
Alice Gao
December 9, 2019
Contents
1 Propositional Logic 3
1.1 Translations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Structural Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.1 A template for structural induction on well-formed propositional for-
mulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 The Semantics of an Implication . . . . . . . . . . . . . . . . . . . . . . . . 15
1.4 Tautology, Contradiction, and Satisfiable but Not a Tautology . . . . . . . . 16
1.5 Logical Equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.6 Analyzing Conditional Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.7 Circuit Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.8 Tautological Consequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.9 Formal Deduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.9.1 Rules of Formal Deduction . . . . . . . . . . . . . . . . . . . . . . . . 29
1.9.2 Format of a Formal Deduction Proof . . . . . . . . . . . . . . . . . . 31
1.9.3 Strategies for writing a formal deduction proof . . . . . . . . . . . . 31
1.9.4 And elimination and introduction . . . . . . . . . . . . . . . . . . . . 33
1.9.5 Implication introduction and elimination . . . . . . . . . . . . . . . . 34
1.9.6 Or introduction and elimination . . . . . . . . . . . . . . . . . . . . . 36
1.9.7 Negation introduction and elimination . . . . . . . . . . . . . . . . . 38
1.9.8 Putting them together! . . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.9.9 Putting them together: Additional exercises . . . . . . . . . . . . . . 45
1.9.10 Other problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
1.10 Soundness and Completeness of Formal Deduction . . . . . . . . . . . . . . . 47
1.10.1 The soundness of inference rules . . . . . . . . . . . . . . . . . . . . . 47
1.10.2 Soundness and Completeness of Formal Deduction . . . . . . . . . . 49
1.11 Proving the Completeness Theorem . . . . . . . . . . . . . . . . . . . . . . . 52
1
2 Predicate Logic 55
2.1 Translations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.2 Semantics of Predicate Formulas . . . . . . . . . . . . . . . . . . . . . . . . 61
2.2.1 Evaluating Formulas with No Variables . . . . . . . . . . . . . . . . . 61
2.2.2 Evaluating Formulas without Bound Variables . . . . . . . . . . . . . 63
2.2.3 Evaluating Formulas with Free and Bound Variables . . . . . . . . . 64
2.2.4 Evaluating Formulas with Bound Variables Only . . . . . . . . . . . 66
2.3 Tautological Consequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.3.1 Semantic Entailment - Additional Exercises . . . . . . . . . . . . . . 78
2.4 Formal Deduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
2.4.1 Forall-elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
2.4.2 Exists-introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
2.4.3 Forall-introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
2.4.4 Forall-introduction - Additional Exercises . . . . . . . . . . . . . . . 82
2.4.5 Exists-elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
2.4.6 Exists-Elimination - Additional Exercises . . . . . . . . . . . . . . . . 85
2.4.7 Putting them together . . . . . . . . . . . . . . . . . . . . . . . . . . 86
2.4.8 Putting them together - Additional Exercises . . . . . . . . . . . . . 90
2.5 Soundness and Completeness of Natural Deduction . . . . . . . . . . . . . . 91
2.5.1 Proving that an inference rule is sound or not sound . . . . . . . . . 91
2.5.2 Additional Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
2.5.3 Proofs using the soundness and completeness theorems . . . . . . . . 97
3 Program Verification 98
3.1 Partial and Total Correctness . . . . . . . . . . . . . . . . . . . . . . . . . . 98
3.2 Assignment Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
3.3 Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
3.4 Conditional Statements: Additional Exercises . . . . . . . . . . . . . . . . . 109
3.5 While Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
3.6 While Loops: Additional Exercises . . . . . . . . . . . . . . . . . . . . . . . 114
3.7 Array Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
3.8 Putting them together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
4 Undecidability 123
4.1 Prove that a problem is decidable . . . . . . . . . . . . . . . . . . . . . . . . 123
4.2 The Halting Problem is Undecidable . . . . . . . . . . . . . . . . . . . . . . 124
4.3 Prove that a problem is undecidable . . . . . . . . . . . . . . . . . . . . . . 125
2
1 Propositional Logic
1.1 Translations
Exercise 1. Translate the following three sentences into propositional logic.
3
Exercise 2. Translate the following sentence into multiple propositional formulas. Show
that they are logically equivalent using a truth table.
Soo-Jin will eat an apple or an orange but not both.
• (¬(𝑎 ↔ 𝑜))
It is not the case that a and o have the same truth value.
• ((¬𝑎) ↔ 𝑜) ⊨⊨ (𝑎 ↔ (¬𝑜))
negated a and o have the same truth value.
4
Exercise 3. Translate the following sentence into at least three syntactically different propo-
sitional formulas. Show that they are logically equivalent using a truth table.
If it is sunny tomorrow, then I will play golf, provided that I am relaxed.
Solution:
• 𝑠: It is sunny tomorrow.
• 𝑟: I am relaxed.
I can think of three ways of translating this sentence into a propositional formula.
5
Exercise 4. Translate the following sentence into a propositional formula.
If I ace CS 245, I will get a job at Google; otherwise I will apply for the Geek
Squad.
• 𝑎: I ace CS 245.
First, let’s break down this sentence into two parts by the semicolon.
The first part translates into an implication because of the key word “if”. It becomes (𝑎 → 𝑔).
In the second part, “otherwise” means that “if I don’t ace CS 245”. After rephrasing, the
second part becomes “If I don’t ace CS 245, then I will apply for the Geek Squad.” This is
another implication ((¬𝑎) → 𝑠).
Now the tricky part is: what connective should we use to connect the two parts together?
Two natural options are ∧ and ∨. The ∨ option seems possible because the sentence could
be rephrase as “If I ace CS 245, ...; or otherwise ....”
The correct connective to use is ∧ for the following reasons.
Let’s consider the scenario in which I ace CS 245, I don’t get a job at Google and I apply for
the Geek Squad. In this case, is the sentence true or false? Intuitively, the sentence should
be false, because the first implication is violated when I ace CS 245 but do not get a job at
Google. Now let’s look at the truth values of the two possible propositional formulas:
• If we use ∧ as the connective, the resulting formula ((𝑎 → 𝑔) ∧ ((¬𝑎) → 𝑠)) is false
in this scenario. The truth value of the formula is the same as the truth value of the
sentence in this scenario.
• If we use ∨ as the connective, the resulting formula ((𝑎 → 𝑔) ∧ ((¬𝑎) → 𝑠)) is true in
this scenario. This truth value of the formula is different from the truth value of the
sentence in this scenario. Therefore, ∨ is not the correct connective to use because the
resulting formula has a different meaning from the formula.
6
Exercise 5. Translate the following sentence into two propositional formulas and explain
why the two formulas are not logically equivalent.
Sidney will carry an umbrella unless it is sunny.
• Interpretation 1:
Intuitively, many people understand “unless” as an “exclusive OR”, which means that
exactly one of the two parts of the sentence is true at a time.
With this interpretation, “unless” is equivalent to an “if and only if not”. The sentence
is true under the following two scenarios:
Note that this interpretation does not allow Sidney to carry an umbrella when it is
sunny. So the sentence is false when 𝑢 and 𝑠 are both true.
In propositional logic, this is equivalent to
((¬𝑢) ↔ 𝑠) (1)
⊨⊨ ((¬𝑢) ∧ 𝑠) ∨ (𝑢 ∧ (¬𝑠))) (2)
⊨⊨ ((𝑢 ∨ 𝑠) ∧ (¬(𝑢 ∧ 𝑠))) (3)
⊨⊨ ((𝑢 ∨ 𝑠) ∧ ((¬𝑢) ∨ (¬𝑠))). (4)
All the formulas above are equivalent. They look different but their meanings are the
same.
• Interpretation 2:
Alternatively, you may think of “unless” as meaning “if not”. Then the sentence
becomes: if it is not sunny, then Sidney will carry an umbrella. In propositional logic,
this becomes:
((¬𝑠) → 𝑢) (5)
⊨⊨ ((¬(¬𝑠)) ∨ 𝑢) (6)
⊨⊨ (𝑠 ∨ 𝑢). (7)
7
– It is sunny and Sidney does not carry an umbrella.
– It is sunny and Sidney carries an umbrella.
Notice that this interpretation allows Sidney to carry an umbrella when it is sunny. So
the sentence is true when 𝑢 and 𝑠 are both true.
8
1.2 Structural Induction
1.2.1 A template for structural induction on well-formed propositional formulas
Theorem: Every well-formed propositional formula 𝐴 has the property 𝑃 .
Induction step:
By the principle of structural induction, 𝑃 (𝐴) holds for every well-formed propositional
formula 𝐴.
QED
9
Theorem 1. Every well-formed propositional formula has an equal number of opening and
closing brackets.
Solution: Each check mark indicates one point awarded to an important step of your proof.
Proof by Structural Induction. Let 𝑃 (𝜑) denote that the well-formed formula 𝜑 has an equal
number of opening and closing brackets. ✓
Let 𝑜𝑝(𝜑) and 𝑐𝑙(𝜑) denote the number of opening and closing brackets of 𝜑 respectively.
Base case: 𝜑 is a propositional symbol 𝑞. Prove that 𝑃 (𝑞) holds.
𝑞 has zero opening and zero closing bracket. Thus, 𝑃 (𝜑) holds. ✓
Induction step:
𝑜𝑝((¬𝑎)) (8)
= 1 + 𝑜𝑝(𝑎) By inspection of (¬𝑎) (9)
= 1 + 𝑐𝑙(𝑎) By induction hypothesis✓ (10)
= 𝑐𝑙((¬𝑎)) By inspection of (¬𝑎) (11)
Case 2: 𝜑 is (𝑎 ∗ 𝑏) where 𝑎 and 𝑏 are well-formed and ∗ is one of the four binary
connectives ∧, ∨, →, ↔.
Induction hypothesis: Assume that 𝑃 (𝑎) ✓ and 𝑃 (𝑏) ✓ hold (i.e. 𝑜𝑝(𝑎) = 𝑐𝑙(𝑎)
and 𝑜𝑝(𝑏) = 𝑐𝑙(𝑏)).
We need to prove that 𝑃 ((𝑎 ∗ 𝑏)) holds.
By the principle of structural induction, 𝑃 (𝜑) holds for every well-formed formula 𝜑.
✓ QED
10
Theorem 2. Every proper prefix of a well-formed formula has more opening than closing
brackets.
Solution:
Proof by Structural Induction. Let 𝑃 (𝜑) denote that every proper prefix of the well-formed
formula 𝜑 has more opening than closing brackets.
Let 𝑜𝑝(𝜑) and 𝑐𝑙(𝜑) denote the number of opening and closing brackets of 𝜑 respectively.
Base case: 𝜑 is a propositional variable 𝑞. Prove that 𝑃 (𝑞) holds.
Induction step:
𝑜𝑝(() = 1 (15)
𝑐𝑙(() = 0 (16)
𝑜𝑝(() > 𝑐𝑙(() (17)
𝑜𝑝((¬) = 1 (18)
𝑐𝑙((¬) = 0 (19)
𝑜𝑝((¬) > 𝑐𝑙(() (20)
𝑜𝑝((¬𝑚) (21)
= 1 + 𝑜𝑝(𝑚) (22)
> 1 + 𝑐𝑙(𝑚) By the induction hypothesis on 𝑚 (23)
> 𝑐𝑙(𝑚) (24)
= 𝑐𝑙((¬𝑚) (25)
𝑜𝑝((¬𝑎) (26)
= 1 + 𝑜𝑝(𝑎) (27)
= 1 + 𝑐𝑙(𝑎) By Theorem 1 and 𝑎 is a well-formed formula (28)
> 𝑐𝑙(𝑎) (29)
= 𝑐𝑙((¬𝑎) (30)
11
Case 2: 𝜑 is (𝑎 ∗ 𝑏) where 𝑎 and 𝑏 are well-formed and ∗ is a binary connective.
Let 𝑚 and 𝑛 denote any proper prefix of 𝑎 and 𝑏 respectively.
Induction hypothesis: Assume that 𝑃 (𝑎) and 𝑃 (𝑏) hold. In other words, 𝑃 (𝑚)
and 𝑃 (𝑛) are true.
We need to prove that 𝑃 ((𝑎 ∗ 𝑏)) holds.
There are six possible proper prefixes of (𝑎 ∗ 𝑏): (, (𝑚, (𝑎, (𝑎∗, (𝑎 ∗ 𝑛, and (𝑎 ∗ 𝑏.
𝑜𝑝(() = 1 (31)
𝑐𝑙(() = 0 (32)
𝑜𝑝(() > 𝑐𝑙(() (33)
𝑜𝑝((𝑚) (34)
= 1 + 𝑜𝑝(𝑚) (35)
> 1 + 𝑐𝑙(𝑚) By the induction hypothesis on 𝑚 (36)
> 𝑐𝑙(𝑚) (37)
= 𝑐𝑙((𝑚) (38)
𝑜𝑝((𝑎) (39)
= 1 + 𝑜𝑝(𝑎) (40)
= 1 + 𝑐𝑙(𝑎) By Theorem 1 and 𝑎 is a well-formed formula (41)
> 𝑐𝑙(𝑎) (42)
= 𝑐𝑙((𝑎) (43)
𝑜𝑝((𝑎∗) (44)
= 1 + 𝑜𝑝(𝑎) (45)
= 1 + 𝑐𝑙(𝑎) By Theorem 1 and 𝑎 is a well-formed formula (46)
> 𝑐𝑙(𝑎) (47)
= 𝑐𝑙((𝑎∗) (48)
12
𝑜𝑝((𝑎 ∗ 𝑛) (49)
= 1 + 𝑜𝑝(𝑎) + 𝑜𝑝(𝑛) (50)
= 1 + 𝑐𝑙(𝑎) + 𝑜𝑝(𝑛) By Theorem 1 and 𝑎 is a well-formed formula (51)
> 1 + 𝑐𝑙(𝑎) + 𝑐𝑙(𝑛) By the induction hypothesis on 𝑛 (52)
> 𝑐𝑙(𝑎) + 𝑐𝑙(𝑛) (53)
= 𝑐𝑙((𝑎 ∗ 𝑛) (54)
𝑜𝑝((𝑎 ∗ 𝑏) (55)
= 1 + 𝑜𝑝(𝑎) + 𝑜𝑝(𝑏) (56)
= 1 + 𝑐𝑙(𝑎) + 𝑐𝑙(𝑏) By Theorem 1 and 𝑎 is a well-formed formula (57)
> 𝑐𝑙(𝑎) + 𝑐𝑙(𝑏) (58)
= 𝑐𝑙((𝑎 ∗ 𝑏) (59)
By the principle of structural induction, 𝑃 (𝜑) holds for every well-formed formula 𝜑.
QED
13
Theorem 3. Consider the set 𝐼(𝑋, 𝐶, 𝑃 ) inductively defined by the domain set 𝑋 = ℝ, the
core set 𝐶 = {0, 2}, and the set of operations 𝑃 = {𝑓1(𝑥, 𝑦) = 𝑥 + 𝑦, 𝑓2(𝑥, 𝑦) = 𝑥 − 𝑦}.
Every element in 𝐼(𝑋, 𝐶, 𝑃 ) is an even integer.
Solution:
Proof by Structural Induction. Base case: We need to prove that every element of the core
set 𝐶 is an even integer. 0 is even because 0 = 2 ∗ 0. 2 is even because 2 = 2 ∗ 1.
Induction step:
Case 1: Let 𝑥, 𝑦 ∈ 𝐼(𝑋, 𝐶, 𝑃 ).
Induction hypotheses: Assume that 𝑥 and 𝑦 are even integers.
We will prove that 𝑓1(𝑥, 𝑦) is an even integer.
𝑥 and 𝑦 are even integers. Thus, by the induction hypotheses, 𝑥 = 2𝑚 and 𝑦 = 2𝑛 where
𝑚 and 𝑛 are integers. Then, 𝑓1(𝑥, 𝑦) = 𝑥 + 𝑦 = 2𝑚 + 2𝑛 = 2(𝑚 + 𝑛). Since (𝑚 + 𝑛) is an
integer, 𝑓1(𝑥, 𝑦) is an even integer.
Case 2: Let 𝑥, 𝑦 ∈ 𝐼(𝑋, 𝐶, 𝑃 ).
Induction hypotheses: Assume that 𝑥 and 𝑦 are even integers.
We will prove that 𝑓2(𝑥, 𝑦) is an even integer.
𝑥 and 𝑦 are even integers. Thus, by the induction hypotheses, 𝑥 = 2𝑚 and 𝑦 = 2𝑛 where
𝑚 and 𝑛 are integers. Then, 𝑓2(𝑥, 𝑦) = 𝑥 − 𝑦 = 2𝑚 − 2𝑛 = 2(𝑚 − 𝑛). Since (𝑚 − 𝑛) is an
integer, 𝑓2(𝑥, 𝑦) is an even integer.
14
1.3 The Semantics of an Implication
Exercise 6. Do you really understand an implication? We will find out.
• Think of an implication as a promise that someone made to you. In what case can you
prove that the promise has been broken (i.e. the implication is false)?
• When the premise is true, what is the relationship between the truth value of the
conclusion and the truth value of the implication?
• When the premise is false, the implication is vacuously true. Could you come up with
an intuitive explanation for this?
15
1.4 Tautology, Contradiction, and Satisfiable but Not a Tautology
Exercise 7. Determine whether each of the following formulas is a tautology, satisfiable but
not a tautology, or a contradiction.
• 𝑝
Solution: Answer: Satisfiable but not a tautology.
Reason: True when 𝑝 is true and false when 𝑝 is false.
• ((𝑟 ∧ 𝑠) → 𝑟)
Solution: Answer: Tautology.
Reason: When 𝑟 is true, the conclusion of the implication is true, so the implication
is true. When 𝑟 is false, the premise of the implication is false, so the implication is
vacuously true.
16
1.5 Logical Equivalence
Exercise 8. ”If it is sunny, I will play golf, provided that I am relaxed.”
𝑠: it is sunny. 𝑔: I will play golf. 𝑟: I am relaxed.
There are three possible translations:
1. (𝑟 → (𝑠 → 𝑔))
2. ((𝑠 ∧ 𝑟) → 𝑔)
3. (𝑠 → (𝑟 → 𝑔))
(𝑟 → (𝑠 → 𝑔)) (60)
⊨⊨ (𝑟 → ((¬𝑠) ∨ 𝑔)) Implication (61)
⊨⊨ ((¬𝑟) ∨ ((¬𝑠) ∨ 𝑔)) Implication (62)
⊨⊨ (((¬𝑟) ∨ (¬𝑠)) ∨ 𝑔) Associativity (63)
⊨⊨ (((¬(𝑟 ∧ 𝑠)) ∨ 𝑔) De Morgan (64)
⊨⊨ ((𝑟 ∧ 𝑠) → 𝑔) Implication (65)
⊨⊨ ((𝑠 ∧ 𝑟) → 𝑔) Commutativity (66)
(𝑟 → (𝑠 → 𝑔)) (67)
⊨⊨ (𝑟 → ((¬𝑠) ∨ 𝑔)) Implication (68)
⊨⊨ ((¬𝑟) ∨ ((¬𝑠) ∨ 𝑔)) Implication (69)
⊨⊨ (((¬𝑟) ∨ (¬𝑠)) ∨ 𝑔) Associativity (70)
⊨⊨ (((¬𝑠) ∨ (¬𝑟)) ∨ 𝑔) Commutativity (71)
⊨⊨ ((¬𝑠) ∨ ((¬𝑟) ∨ 𝑔)) Associativity (72)
⊨⊨ ((¬𝑠) ∨ (𝑟 → 𝑔)) Implication (73)
⊨⊨ (𝑠 → (𝑟 → 𝑔)) Implication (74)
17
Exercise 9. ”If it snows then I will not go to class but I will do my assignment.”
𝑠: it snows. 𝑐: I will go to class. 𝑎: I will do my assignment.
There are two possible translations:
1. ((𝑠 → (¬𝑐)) ∧ 𝑎)
2. (𝑠 → ((¬𝑐) ∧ 𝑎))
Solution:
Proof. We need to find a valuation 𝑡 under which the two formulas have different values.
Consider the truth valuation 𝑡 where 𝑡(𝑠) = 0, 𝑡(𝑐) = 1, and 𝑡(𝑎) = 0.
The two formulas have different values under 𝑡, as shown below.
• (𝑠 → ((¬𝑐) ∧ 𝑎))𝑡 = 1
18
1.6 Analyzing Conditional Code
Consider the following code fragment:
• 𝑖: input > 0
• 𝑢: output
The code fragment becomes the following. We’ll call this code fragment #1.
if ( i || !u ) {
if ( !( u && q) ) {
P1
} else if ( u && !q ) {
P2
} else { P3 }
} else { P4 }
Code fragment #2:
if (( i && u) && q) {
P3
} else if (!i && u) {
P4
} else {
P1
}
Prove that these two pieces of code fragments are equivalent:
Solution:
19
Prove that the condition leading to 𝑃2 is logically equivalent to 0.
The condition leading to 𝑃2 :
Prove that the condition leading to 𝑃3 is true if and only if all three variables are true.
The condition leading to 𝑃3 :
Prove that the condition leading to 𝑃4 is true if and only if 𝑖 is false and 𝑢 is true.
The condition leading to 𝑃4 :
20
1.7 Circuit Design
Basic gates:
Problem: Your instructors, Alice, Carmen, and Collin, are choosing questions to be put on
the midterm. For each problem, each instructor votes either yes or not. A question is chosen
if it receives two or more yes votes. Design a circuit, which outputs yes whenever a question
is chosen.
x y z output
1 1 1 1
1 1 0 1
1 0 1 1
1 0 0 0
0 1 1 1
0 1 0 0
0 0 1 0
0 0 0 0
Solution:
21
Solution 1:
• ((𝑥 ∧ 𝑦) ∧ 𝑧)
• ((𝑥 ∧ 𝑦) ∧ (¬𝑧))
• ((𝑥 ∧ (¬𝑦)) ∧ 𝑧)
• (((¬𝑥) ∧ 𝑦) ∧ 𝑧)
Making a circuit clear and readable can be challenging. Here are some advice on
drawing circuits:
22
Solution 2:
23
Solution 3:
24
Solution 4 (contributed by Triman Kandola)
25
1.8 Tautological Consequence
Exercise 10. Let Σ = {(𝑝 → 𝑞), (𝑞 → 𝑟)}. Is Σ satisfiable? Why or why not?
Solution: Σ is satisfied by the truth valuation 𝑡 where 𝑡(𝑝) = 1, 𝑡(𝑞) = 1 and 𝑡(𝑟) = 1.
Note that (𝑝 → 𝑞)𝑡 = 1 and (𝑞 → 𝑟)𝑡 = 1. Thus, Σ is satisfiable.
Solution: Σ is not satisfiable. To show this, we need to show that, under every truth
valuation, at least one formula in Σ is false.
Consider an arbitrary truth valuation 𝑡. Under 𝑡, 𝑝 is either true or false.
In both cases, 𝑡 does not satisfy Σ. Therefore, no truth valuation can satisfy Σ. Σ is not
satisfiable.
26
Exercise 13. Prove that {(¬(𝑝 ∧ 𝑞)), (𝑝 → 𝑞)} ⊨ (¬𝑝).
Solution:
Proof. Consider a truth valuation 𝑡 such that (¬(𝑝 ∧ 𝑞))𝑡 = 1 and (𝑝 → 𝑞)𝑡 = 1.
Since (𝑝 → 𝑞)𝑡 = 1, it is not the case that 𝑝𝑡 = 1 and 𝑞 𝑡 = 0.
Since (¬(𝑝 ∧ 𝑞))𝑡 = 1, it is not the case that 𝑝𝑡 = 1 and 𝑞 𝑡 = 1.
Thus, the two premises are true under two scenarios:
In both scenarios, the conclusion is true. Thus, the tautological consequence holds.
Solution:
Proof. Consider the truth valuation 𝑡 where 𝑝𝑡 = 0 and 𝑞 𝑡 = 1.
By definitions of the connectives, (¬(𝑝 ∧ 𝑞))𝑡 = 1, (𝑝 → 𝑞)𝑡 = 1 and (𝑝 ↔ 𝑞)𝑡 = 0. Thus,
the tautological consequence does not hold.
Solution:
Proof. Since there is no premise, we need to prove that the conclusion ((𝑝 ∧ 𝑞) → 𝑝)) is a
tautology.
Consider any truth valuation 𝑡. Under 𝑡, p must be either true or false.
• 𝑝𝑡 = 0: The premise of the implication ((𝑝∧𝑞) → 𝑝)) is true. Therefore, the implication
is true.
Thus, the conclusion is true under any truth valuation and is a tautology. The tautological
consequence holds.
27
Exercise 16. Prove that {𝑟, (𝑝 → (𝑟 → 𝑞))} ⊨ (𝑝 → (𝑞 ∧ 𝑟)).
Solution:
Proof. Consider a truth valuation 𝑡 where 𝑟𝑡 = 1 and (𝑝 → (𝑟 → 𝑞))𝑡 = 1. We need to show
that (𝑝 → (𝑞 ∧ 𝑟))𝑡 = 1.
Consider two cases: 𝑝𝑡 = 0 and 𝑝𝑡 = 1.
If 𝑝𝑡 = 0, then (𝑝 → (𝑞 ∧ 𝑟))𝑡 = 1.
Otherwise, suppose that 𝑝𝑡 = 1. We need to show that (𝑞 ∧ 𝑟)𝑡 = 1.
By the definition of implication, (𝑟 → 𝑞)𝑡 = 1 since (𝑝 → (𝑟 → 𝑞))𝑡 = 1. Since 𝑟𝑡 = 1 and
(𝑟 → 𝑞)𝑡 = 1, then 𝑞 𝑡 = 1 by the definition of implication. By the definition of ∧, (𝑞 ∧𝑟)𝑡 = 1
since 𝑞 and 𝑟 are both true under 𝑡. Therefore, (𝑝 → (𝑞 ∧ 𝑟))𝑡 = 1.
In both cases, the conclusion is true under 𝑡. The tautological consequence holds.
Solution:
Remark 1. We need to come up with a truth valuation under which both premises are true
and the conclusion is false.
(¬𝑝) has to be true. So 𝑝 has to be false under this truth valuation.
(𝑞 → 𝑝) has to be true and 𝑝 is false. Thus, 𝑞 must be false under this truth valuation.
Therefore, this truth valuation must make 𝑝 false and 𝑞 false.
Solution:
Proof. Consider any truth valuation 𝑡 under which both premises are true. If such a truth
valuation exists, we have to show that 𝑟 must be true under this truth valuation.
However, such a truth valuation does not exist. There are two possible cases. 𝑝 is true or 𝑝
is false. If 𝑝 is false, then this truth valuation does not satisfy the first premise. If 𝑝 is true
under this truth valuation, then (¬𝑝) must be false. This truth valuation does not satisfy
the second premise.
Since no truth valuation satisfies both premises, the tautological consequence holds.
28
1.9 Formal Deduction
1.9.1 Rules of Formal Deduction
membership (∈)
Addition of premises (+)
if 𝐴 ∈ Σ,
if Σ ⊢ 𝐴,
then Σ ⊢ 𝐴.
then Σ, Σ′ ⊢ 𝐴.
Special case: Reflexivity (Ref)
𝐴 ⊢ 𝐴.
if Σ ⊢ 𝐴, if Σ ⊢ 𝐴 ∧ 𝐵,
Σ ⊢ 𝐵, then Σ ⊢ 𝐴.
then Σ ⊢ 𝐴 ∧ 𝐵. if Σ ⊢ 𝐴 ∧ 𝐵,
then Σ ⊢ 𝐵.
if Σ ⊢ 𝐴, if Σ, 𝐴 ⊢ 𝐶,
then Σ ⊢ 𝐴 ∨ 𝐵. Σ, 𝐵 ⊢ 𝐶,
if Σ ⊢ 𝐵, then Σ, 𝐴 ∨ 𝐵 ⊢ 𝐶.
then Σ ⊢ 𝐴 ∨ 𝐵.
if Σ, 𝐴 ⊢ 𝐵, if Σ, ¬𝐴 ⊢ 𝐵,
Σ, 𝐴 ⊢ ¬𝐵, Σ, ¬𝐴 ⊢ ¬𝐵,
then Σ ⊢ ¬𝐴. then Σ ⊢ 𝐴.
if Σ, 𝐴 ⊢ 𝐵, if Σ ⊢ 𝐴,
then Σ ⊢ 𝐴 → 𝐵. Σ ⊢ 𝐴 → 𝐵,
then Σ ⊢ 𝐵.
29
Equivalence introduction (↔ +) Equivalence elimination (↔ −)
if Σ, 𝐴 ⊢ 𝐵, if Σ ⊢ 𝐴,
Σ, 𝐵 ⊢ 𝐴, Σ ⊢ 𝐴 ↔ 𝐵,
then Σ ⊢ 𝐴 ↔ 𝐵. then Σ ⊢ 𝐵.
if Σ ⊢ 𝐵,
Σ ⊢ 𝐴 ↔ 𝐵,
then Σ ⊢ 𝐴.
Comments:
• For each connective, the rules come in pairs. The introduction rule produces a conclu-
sion with the connective in it. The elimination rule produces a conclusion without the
connective.
• 𝐴 and 𝐵 can be any propositional formula. In particular, 𝐴 and 𝐵 can be the same.
30
1.9.2 Format of a Formal Deduction Proof
• Every line contains: a line number, a set of premises, the ⊢ symbol, a conclusion, and
a justification containing a formal deduction rule and possibly line numbers.
• The last line of a proof is the same as the original statement to be proved.
• Every line of the proof can be justified in two ways: (1) using the premises on the left
of ⊢ using the membership ∈ rule. (2) using one or more conclusions on previous lines
by using any other formal deduction rule.
• You have to bring a premise to the right of ⊢ before you can use it in a subsequent
line.
31
• We are only able to add a premise on the left of ⊢ if a formal deduction rule allows us
to do so.
• Eventually, we will need to remove the additional premises from the left of ⊢ in order
to produce the conclusion required in the original statement to be proved.
32
1.9.4 And elimination and introduction
Exercise 19. Show that (𝑝 ∧ 𝑞), (𝑟 ∧ 𝑠) ⊢ (𝑞 ∧ 𝑠).
Solution:
(1) 𝑝 ∧ 𝑞, 𝑟 ∧ 𝑠 ⊢ 𝑝 ∧ 𝑞 by (∈)
(2) 𝑝 ∧ 𝑞, 𝑟 ∧ 𝑠 ⊢ 𝑞 by ∧ −, 1
(3) 𝑝 ∧ 𝑞, 𝑟 ∧ 𝑠 ⊢ 𝑟 ∧ 𝑠 by (∈)
(4) 𝑝 ∧ 𝑞, 𝑟 ∧ 𝑠 ⊢ 𝑠 by ∧ −, 3
(5) 𝑝 ∧ 𝑞, 𝑟 ∧ 𝑠 ⊢ 𝑞 ∧ 𝑠 by ∧ +, 2, 4
Solution:
(1) (𝑝 ∧ 𝑞) ∧ 𝑟 ⊢ (𝑝 ∧ 𝑞) ∧ 𝑟 by (∈)
(2) (𝑝 ∧ 𝑞) ∧ 𝑟 ⊢ (𝑝 ∧ 𝑞) by ∧ −, 1
(3) (𝑝 ∧ 𝑞) ∧ 𝑟 ⊢ 𝑟 by ∧ −, 1
(4) (𝑝 ∧ 𝑞) ∧ 𝑟 ⊢ 𝑝 by ∧ −, 2
(5) (𝑝 ∧ 𝑞) ∧ 𝑟 ⊢ 𝑞 by ∧ −, 2
(6) (𝑝 ∧ 𝑞) ∧ 𝑟 ⊢ 𝑞 ∧ 𝑟 by ∧ +, 3, 5
(7) (𝑝 ∧ 𝑞) ∧ 𝑟 ⊢ 𝑝 ∧ (𝑞 ∧ 𝑟) by ∧ +, 4, 6
33
1.9.5 Implication introduction and elimination
Exercise 21. Show that (𝑝 → 𝑞), (𝑞 → 𝑟) ⊢ (𝑝 → 𝑟).
Solution:
(1) 𝑝 → 𝑞, 𝑞 → 𝑟, 𝑝 ⊢ 𝑝 → 𝑞 by (∈)
(2) 𝑝 → 𝑞, 𝑞 → 𝑟, 𝑝 ⊢ 𝑝 by (∈)
(3) 𝑝 → 𝑞, 𝑞 → 𝑟, 𝑝 ⊢ 𝑞 by (→ −, 1, 2)
(4) 𝑝 → 𝑞, 𝑞 → 𝑟, 𝑝 ⊢ 𝑞 → 𝑟 by (∈)
(5) 𝑝 → 𝑞, 𝑞 → 𝑟, 𝑝 ⊢ 𝑟 by (→ −, 3, 4)
(6) 𝑝 → 𝑞, 𝑞 → 𝑟 ⊢ 𝑝 → 𝑟 by (→ +, 5)
Solution:
34
Exercise 23. Show that (𝑝 → (𝑞 → 𝑟)) ⊢ ((𝑝 ∧ 𝑞) → 𝑟).
Solution:
Solution:
(1) (𝑝 ∧ 𝑞) → 𝑟, 𝑝, 𝑞 ⊢ (𝑝 ∧ 𝑞) → 𝑟 by (∈)
(2) (𝑝 ∧ 𝑞) → 𝑟, 𝑝, 𝑞 ⊢ 𝑝 by (∈)
(3) (𝑝 ∧ 𝑞) → 𝑟, 𝑝, 𝑞 ⊢ 𝑞 by (∈)
(4) (𝑝 ∧ 𝑞) → 𝑟, 𝑝, 𝑞 ⊢ 𝑝 ∧ 𝑞 by (∧+, 2, 3)
(5) (𝑝 ∧ 𝑞) → 𝑟, 𝑝, 𝑞 ⊢ 𝑟 by (→ −, 1, 4)
(6) (𝑝 ∧ 𝑞) → 𝑟, 𝑝 ⊢ 𝑞 → 𝑟 by (→ +, 5)
(7) (𝑝 ∧ 𝑞) → 𝑟 ⊢ 𝑝 → (𝑞 → 𝑟) by (→ +, 6)
35
1.9.6 Or introduction and elimination
Exercise 25. Show that (𝑝 ∨ 𝑞) ⊢ ((𝑝 → 𝑞) ∨ (𝑞 → 𝑝)).
Solution:
(1) 𝑝, 𝑞 ⊢ 𝑝 by (∈)
(2) 𝑝⊢𝑞→𝑝 by (→ +, 1)
(3) 𝑞, 𝑝 ⊢ 𝑞 by (∈)
(4) 𝑞⊢𝑝→𝑞 by (→ +, 1)
(5) 𝑝 ⊢ (𝑝 → 𝑞) ∨ (𝑞 → 𝑝) by (∨+, 2)
(6) 𝑞 ⊢ (𝑝 → 𝑞) ∨ (𝑞 → 𝑝) by (∨+, 4)
(7) (𝑝 ∨ 𝑞) ⊢ (𝑝 → 𝑞) ∨ (𝑞 → 𝑝) by (∨−, 5, 6)
Solution:
(1) 𝑝 → 𝑞, 𝑝 ⊢ 𝑝 by (∈)
(2) 𝑝 → 𝑞, 𝑝 ⊢ 𝑝 → 𝑞 by (∈)
(3) 𝑝 → 𝑞, 𝑝 ⊢ 𝑞 by (→ −, 1, 2)
(4) 𝑝 → 𝑞, 𝑟 ⊢ 𝑟 by (∈)
(5) 𝑝 → 𝑞, 𝑟 ⊢ (𝑟 ∨ 𝑞) by (∨+, 4)
(6) 𝑝 → 𝑞, 𝑝 ⊢ (𝑟 ∨ 𝑞) by (∨+, 3)
(7) 𝑝 → 𝑞, 𝑟 ∨ 𝑝 ⊢ (𝑟 ∨ 𝑞) by (∨−, 5, 6)
(8) 𝑝 → 𝑞 ⊢ (𝑟 ∨ 𝑝) → (𝑟 ∨ 𝑞) by (→ +, 7)
36
Exercise 27. Show that ((𝑝 ∧ 𝑞) ∨ (𝑝 ∧ 𝑟)) ⊢ (𝑝 ∧ (𝑞 ∨ 𝑟)).
Solution:
Solution:
37
1.9.7 Negation introduction and elimination
Exercise 29. Show that 𝑝 → (¬𝑝) ⊢ (¬𝑝).
Solution:
Solution:
38
Exercise 31. Show that (𝑝 → 𝑞), (¬𝑞) ⊢ (¬𝑝).
Solution:
Solution:
Solution:
39
Exercise 34. Show that (𝑝 ∨ 𝑞), (¬𝑝) ⊢ 𝑞.
Solution:
Solution:
40
1.9.8 Putting them together!
Exercise 36. (De Morgan’s Law) Show that (¬(𝑎 ∨ 𝑏)) ⊢ ((¬𝑎) ∧ (¬𝑏)).
Solution:
(1) ¬(𝑎 ∨ 𝑏), 𝑎 ⊢ ¬(𝑎 ∨ 𝑏) by (∈)
(2) ¬(𝑎 ∨ 𝑏), 𝑎 ⊢ 𝑎 by (∈)
(3) ¬(𝑎 ∨ 𝑏), 𝑎 ⊢ (𝑎 ∨ 𝑏) by (∨+, 2)
(4) ¬(𝑎 ∨ 𝑏), 𝑏 ⊢ ¬(𝑎 ∨ 𝑏) by (∈)
(5) ¬(𝑎 ∨ 𝑏), 𝑏 ⊢ 𝑏 by (∈)
(6) ¬(𝑎 ∨ 𝑏), 𝑏 ⊢ (𝑎 ∨ 𝑏) by (∨+, 5)
(7) ¬(𝑎 ∨ 𝑏) ⊢ ¬𝑎 by (∧+, 1, 3)
(8) ¬(𝑎 ∨ 𝑏) ⊢ ¬𝑏 by (∧+, 4, 6)
(9) ¬(𝑎 ∨ 𝑏) ⊢ ¬𝑎 ∧ ¬𝑏 by (∧+, 7, 8)
Exercise 37. (De Morgan’s Law) Show that ((¬𝑎) ∧ (¬𝑏)) ⊢ (¬(𝑎 ∨ 𝑏)).
Solution:
(1) ¬𝑎 ∧ ¬𝑏, 𝑎, ¬𝑞 ⊢ ¬𝑎 ∧ ¬𝑏 by (∈)
(2) ¬𝑎 ∧ ¬𝑏, 𝑎, ¬𝑞 ⊢ ¬𝑎 by (∧−, 1)
(3) ¬𝑎 ∧ ¬𝑏, 𝑎, ¬𝑞 ⊢ 𝑎 by (∈)
(4) ¬𝑎 ∧ ¬𝑏, 𝑎 ⊢ 𝑞 by (¬−, 2, 3)
(5) ¬𝑎 ∧ ¬𝑏, 𝑏, ¬𝑞 ⊢ ¬𝑎 ∧ ¬𝑏 by (∈)
(6) ¬𝑎 ∧ ¬𝑏, 𝑏, ¬𝑞 ⊢ ¬𝑏 by (∧−, 5)
(7) ¬𝑎 ∧ ¬𝑏, 𝑏, ¬𝑞 ⊢ 𝑏 by (∈)
(8) ¬𝑎 ∧ ¬𝑏, 𝑏 ⊢ 𝑞 by (¬−, 6, 7)
(9) ¬𝑎 ∧ ¬𝑏, 𝑎 ∨ 𝑏 ⊢ 𝑞 by (∨−, 4, 8)
(10) ¬𝑎 ∧ ¬𝑏, 𝑎, 𝑞 ⊢ ¬𝑎 ∧ ¬𝑏 by (∈)
(11) ¬𝑎 ∧ ¬𝑏, 𝑎, 𝑞 ⊢ ¬𝑎 by (∧−, 10)
(12) ¬𝑎 ∧ ¬𝑏, 𝑎, 𝑞 ⊢ 𝑎 by (∈)
(13) ¬𝑎 ∧ ¬𝑏, 𝑎 ⊢ ¬𝑞 by (¬+, 11, 12)
(14) ¬𝑎 ∧ ¬𝑏, 𝑏, 𝑞 ⊢ ¬𝑎 ∧ ¬𝑏 by (∈)
(15) ¬𝑎 ∧ ¬𝑏, 𝑏, 𝑞 ⊢ ¬𝑏 by (∧−, 14)
(16) ¬𝑎 ∧ ¬𝑏, 𝑏, 𝑞 ⊢ 𝑏 by (∈)
(17) ¬𝑎 ∧ ¬𝑏, 𝑏 ⊢ ¬𝑞 by (¬+, 15, 16)
(18) ¬𝑎 ∧ ¬𝑏, 𝑎 ∨ 𝑏 ⊢ ¬𝑞 by (∨−, 13, 18)
(19) ¬𝑎 ∧ ¬𝑏 ⊢ ¬(𝑎 ∨ 𝑏) by (∧+, 8, 18)
41
Exercise 38. (De Morgan’s Law) Show that ((¬𝑎) ∨ (¬𝑏)) ⊢ (¬(𝑎 ∧ 𝑏)).
Solution:
Solution:
42
Exercise 40. (De Morgan’s Law) Show that (¬(𝑎 ∧ 𝑏)) ⊢ ((¬𝑎) ∨ (¬𝑏)).
Solution:
Solution:
43
Exercise 42. (Law of excluded middle) ∅ ⊢ (𝑎 ∨ (¬𝑎)).
Solution: Solution 1:
Solution 2:
44
1.9.9 Putting them together: Additional exercises
Exercise 43. (¬(𝑝 → 𝑞)) ⊢ 𝑝.
45
1.9.10 Other problems
Exercise 48. E4 Exercise 4: Prove that for any set of propositional formulas Σ and any
propositional variables 𝑝 and 𝑞, if Σ ⊢ 𝑝, then Σ ⊢ ((¬𝑝) → 𝑞).
Solution:
Proof. Let Σ be a set of propositional formulas and let 𝑝 and 𝑞 be propositional variables.
Assume that Σ ⊢ 𝑝. This means that the following proof exists.
Using the above proof, we will construct a formal deduction proof for Σ ⊢ ((¬𝑝) → 𝑞).
46
1.10 Soundness and Completeness of Formal Deduction
1.10.1 The soundness of inference rules
Exercise 49. The following inference rule is called Disjunctive syllogism.
if Σ ⊢ ¬𝐴,
Σ ⊢ 𝐴 ∨ 𝐵,
then Σ ⊢ 𝐵.
Solution:
Proof. Consider a truth valuation 𝑡 under which Σ𝑡 = 1. Since Σ ⊨ (¬𝐴) and Σ ⊨ 𝐴 ∨ 𝐵,
we have that (¬𝐴)𝑡 = 1 and (𝐴 ∨ 𝐵)𝑡 = 1. We need to show that 𝐵𝑡 = 1.
By the truth table of ¬, since (¬𝐴)𝑡 = 1, 𝐴𝑡 = 0.
By the truth table of ∨, since (𝐴 ∨ 𝐵)𝑡 = 1, at least one of 𝐴 and 𝐵 is true under 𝑡. Since
𝐴𝑡 = 0, then 𝐵𝑡 = 1.
Therefore, Σ ⊨ 𝐵 holds.
Remark 2. To prove that a tautological consequence holds, we need to consider all truth
valuations under which all of the premises are true. For each such truth valuation, we need
to show that the conclusion is true.
The proof typically looks like the following.
• Consider a truth valuation 𝑡 under which all of the premises are true.
• If premise 1 is true under 𝑡, then 𝐴 must be ... under 𝑡 and 𝐵 must be ... under 𝑡. If
premise 2 is true under 𝑡, then ...
• Case 1: this case is impossible because .../... the conclusion is true under 𝑡.
• Case 2: ...
• The conclusion is true in every case. Therefore, the tautological consequence holds.
47
Exercise 50. Consider the following inference rule:
(𝐴 → 𝐵)
Flip the implication
(𝐵 → 𝐴)
{(𝐴 → 𝐵)} ⊭ (𝐵 → 𝐴)
You must use the definition of tautological consequence to write your proof. Do not use
any other technique such as truth table, valuation tree, logical identities, formal deduction,
soundness, or completeness.
Solution:
Remark 3. To prove that a tautological consequence does not hold, we need to find a concrete
counterexample, which shows that, there is a truth valuation 𝑡 under which all of the premises
are true and the conclusion is false.
A concrete counterexample consist of the following:
• Choose concrete formulas for 𝐴 and 𝐵. In the following proof, we let 𝐴 be 𝑝 and 𝐵 be
𝑞 where 𝑝 and 𝑞 are propositional variables.
• Choose a truth valuation 𝑡 such that all the premises are true and the conclusion is
false.
Choosing a concrete formula for each symbol is important. In the proof below, if we do not
assign concrete formulas to 𝐴 and 𝐵, then we cannot make claims about their truth values
under 𝑡. We want to find a truth valuation under which 𝐵 is true and 𝐴 is false. This is
not possible if 𝐵 is (𝑟 ∧ (¬𝑟)) and 𝐴 is (𝑟 ∨ (¬𝑟)).
The difficult part is coming up with a counterexample that works. After that, writing up the
proof is straightforward.
Proof. To prove that the tautological consequence does not hold, we need to find one coun-
terexample.
Let 𝑝 and 𝑞 be two propositional variables. Let 𝐴 be 𝑝 and let 𝐵 be 𝑞. Consider a truth
valuation 𝑡 under which 𝑝𝑡 = 0 and 𝑞 𝑡 = 1.
Under 𝑡, the premise is true. (𝐴 → 𝐵)𝑡 = (𝑝 → 𝑞)𝑡 = 1.
Under 𝑡, the conclusion is false. (𝐵 → 𝐴)𝑡 = (𝑞 → 𝑝)𝑡 = 0.
We found a truth valuation under which the premise is true and the conclusion is false.
Thus, the tautological consequence does not hold.
48
1.10.2 Soundness and Completeness of Formal Deduction
Exercise 51. Prove or disprove this statement: If {𝑎, 𝑏} ⊢ 𝑐, then ∅ ⊨ ((𝑎 ∧ 𝑏) → 𝑐). 𝑎, 𝑏,
and 𝑐 are well-formed propositional formulas.
Solution:
Remark 4. The statement is an implication, and the premise and the conclusion of the
implication differ in two ways. The premise is about the existence of a formal deduction
proof, whereas the conclusion is about a tautological consequence. Moreover, the premise has
𝑎 and 𝑏 on the left hand side, whereas the conclusion has everything on the right hand side.
Thus, there are two ways for us to transform the premise into the conclusion.
Approach 1:
A visual representation of approach 1:
Approach 2:
A visual representation of approach 2:
First, we move 𝑎 and 𝑏 from the left hand side to the right hand side by proving that {𝑎, 𝑏} ⊢ 𝑐
and ∅ ⊢ ((𝑎 ∧ 𝑏) → 𝑐) are equivalent.
Then, we transform ∅ ⊢ ((𝑎 ∧ 𝑏) → 𝑐) (the existence of a proof) to ∅ ⊨ ((𝑎 ∧ 𝑏) → 𝑐) (a
tautological consequence) by the soundness of formal deduction.
49
Proof 1. We will prove the statement.
Assume {𝑎, 𝑏} ⊢ 𝑐 holds.
By the soundness of formal deduction, the tautological consequence {𝑎, 𝑏} ⊨ 𝑐 holds.
Consider a truth valuation 𝑡 under which 𝑎𝑡 = 1 and 𝑏𝑡 = 1. We know that 𝑐𝑡 = 1 by
{𝑎, 𝑏} ⊨ 𝑐. Therefore, by the definition of an implication, we know that ((𝑎 ∧ 𝑏) → 𝑐) is a
tautology.
Consider a truth valuation 𝑡. There is no formula in ∅. Thus, 𝑡 satisfies ∅. 𝑡 also satisfies
((𝑎 ∧ 𝑏) → 𝑐) since ((𝑎 ∧ 𝑏) → 𝑐) is a tautology. Therefore, the tautological consequence
∅ ⊨ ((𝑎 ∧ 𝑏) → 𝑐) holds.
50
Exercise 52. Prove or disprove this statement: If {𝐴} ⊨ 𝐵, then ∅ ⊢ (𝐵 → 𝐴). 𝐴 and 𝐵
are well-formed propositional formulas.
Solution:
Remark 5. To show that the implication is false, we need to choose concrete formulas for
𝐴 and 𝐵 such that the premise is true and the conclusion is false.
By inspecting the premise and the conclusion, we see that the concrete formulas need to make
sure that 𝐴 entails 𝐵, but 𝐵 does not entail 𝐴.
Choosing 𝐴 to be 𝑝 and 𝐵 to be (𝑝 ∨ 𝑞) satisfy both requirements.
51
1.11 Proving the Completeness Theorem
Exercise 53. Prove that the following two definitions of a consistent set are equivalent.
52
Exercise 54. Let Σ1 and Σ2 be sets of propositional formulas. Let Σ1 ⊆ Σ2 .
Prove or disprove the statement below: If Σ1 is consistent, then Σ2 is consistent.
53
Prove that the following two definitions of a maximally consistent set are equivalent. Assume
that Σ is consistent.
Part (a) Prove that if a set Σ satisfies definition 1, then it also satisfies definition 2.
Proof Sketch:
To show that Σ satisfies definition 2, we need to show that for every propositional formula
𝐴, Σ ⊢ 𝐴 or Σ ⊢ (¬𝐴). If at least one of Σ ⊢ 𝐴 and Σ ⊢ (¬𝐴) is true, then we are done.
However, it is unlikely that we can prove that one of them is always true. Therefore, it must
be the case that one is true in some scenarios and the other one is true in other scenarios.
A common approach for proving a disjunction is to divide into several cases. It must be true
that either Σ ⊢ 𝐴 or Σ ⊬ 𝐴. In fact, these two cases are mutually exclusive and exhaustive.
Therefore, we will consider two cases. In each case, we will need to prove that Σ ⊢ 𝐴 and
Σ ⊢ (¬𝐴).
Part (b) Prove that if a set Σ satisfies definition 2, then it also satisfies definition 1.
Proof sketch:
54
2 Predicate Logic
2.1 Translations
Exercise 56. Let the domain be the set of animals. Let 𝐵(𝑥) mean that 𝑥 is a bear. Let
𝐻(𝑥) mean that 𝑥 likes honey.
Translate “every bear likes honey” into predicate logic.
Solution: People often come up with the following two translations. See the formulas and
the corresponding explanations below.
To differentiate between two predicate formulas, it is often a useful exercise to come up with
a domain for which one formula is true and the other formula is false.
Consider a domain, which contains a bear A who likes honey and a rabbit B.
• For this domain, the first formula is false. When 𝑥 is rabbit 𝐵, 𝑥 is not a bear.
• For this domain, the second formula is true. When 𝑥 is bear 𝐴, it likes honey, so the
implication is true. When 𝑥 is rabbit B, it is not a bear, so the implication is vacuously
true. Since the implication is true for every element of the domain, the formula is true.
55
Exercise 57. Let the domain be the set of animals. Let 𝐵(𝑥) mean that 𝑥 is a bear. Let
𝐻(𝑥) mean that 𝑥 likes honey.
Translate “some bear likes honey” into predicate logic.
Solution: People often come up with the following two translations. See the formulas and
the corresponding explanations below.
To differentiate these two formulas, let’s consider a domain, which contains a rabbit B. For
this domain, the original sentence should be false because there is no bear.
• For this domain, the first formula is false. We cannot find a bear in the domain, which
is required by the formula.
• For this domain, the second formula is true. When 𝑥 is rabbit 𝐵, 𝐵 is not a bear, so
the premise of the implication is false. Thus, the implication is vacuously true. Since
we have found an animal which makes the implication true, the formula is true.
56
Based on the two exercises above, could you summarize the general patterns of translations?
Which binary connectives usually go with the universal and the existential quantifiers?
As a general rule of thumb, the universal quantifier is often used in conjunction with the im-
plication (→), and the existential quantifier is often used in conjunction with the conjunction
(∧). We’ve seen examples of both above.
The universal quantifier
• ∀ and →: This universal quantifier pairs well with the implication. This combination
is used to make a statement about a subset of the domain. Therefore, we use the
premise of the implication to restrict our attention to this subset. We don’t have to
worry about any element that is not in this subset because the implication is vacuously
true for any such element.
• ∃ and ∧: The existential quantifier pairs well with the conjunction. This combination
can be used to express the fact that there exists an element of domain which has the
two properties connected by the conjunction.
• ∃ and →: This combination does not make sense logically. The main reason is that it
is too easy to make such a formula true. As soon as we find an element of the domain,
which makes the premise of the implication false, the implication is vacuously true and
the formula is true as well.
57
Exercise 58. Translate the following sentences into predicate formulas.
Let the domain contain the set of all students and courses. Define the following predicates:
𝐶(𝑥): 𝑥 is a course.
𝑆(𝑥): 𝑥 is a student.
𝑇 (𝑥, 𝑦): student 𝑥 has taken course 𝑦.
58
Exercise 59. Translating “at least”, “at most”, and “exactly”.
Translate the following sentences into predicate formulas.
The formula says: there are two bears 𝑥 and 𝑦, and 𝑥 and 𝑦 must be different. Note
that, if we don’t have (𝑥 ≠ 𝑦), the formula only guarantees that there exists one bear
because 𝑥 and 𝑦 could refer to the same animal in the domain.
The negation of “at most one” is “at least two”. Therefore, the sentence is equivalent
to “It is not the case that there exist two different bears”.
Using the generalized De Morgan’s laws, we can show that the above formula is logically
equivalent to the formula below.
This formula says that: If we can find two bears 𝑥 and 𝑦, then 𝑥 and 𝑦 must refer to
the same bear. To understand this formula, imagine that I made the claim that there
is at most one bear. Then your goal is to disprove my claim. You find two bears in
the domain and show them to me. For my claim to be true, I have to be able to prove
that the two bears you found are actually the same bear. I have to be able to do this
no matter which two bears you show to me.
Yet another translation is that: ((there is no bear) or (there is exactly one bear)). We
can use any translation of ”there is exactly one bear” on the next page.
59
• There is exactly one bear.
Solution: One translation is: there is at least one bear and there is at most one bear.
Another translation: there is at least one bear and if there is another bear, then the
two bears must be the same.
60
2.2 Semantics of Predicate Formulas
Consider this language of predicate logic:
• Individual constant symbols: 𝑎, 𝑏, 𝑐
• Free Variable Symbols: 𝑢, 𝑣, 𝑤
• Bound Variable symbols: 𝑥, 𝑦, 𝑧
• Function symbols: 𝑓 is a unary function, 𝑔 is a binary function.
• Predicate/Relation symbols: 𝑃 is a unary predicate, 𝑄 is a binary predicate.
I like to deal with the predicates last. So let’s assign meanings to the individual constant
symbols. Let 𝑐𝑣 = 1 and 𝑎𝑣 = 2. Then, we have that 𝑄(𝑐, 𝑎)𝑣 is true if and only if ⟨1, 2⟩ ∈ 𝑄𝑣 .
Finally, let’s define 𝑄𝑣 . Above the above analysis, at a minimum, we need ⟨1, 2⟩ ∈ 𝑄𝑣 .
We could include other tuples in 𝑄𝑣 if we like, but they don’t affect the truth value of this
formula. Thus, let 𝑄𝑣 = {⟨1, 2⟩}.
Solution Text: The valuation 𝑣 is given below.
• 𝐷 = {1, 2, 3}.
• 𝑎𝑣 = 2, 𝑐𝑣 = 1.
• 𝑓 𝑣 (𝑥) = 𝑥, ∀𝑥 ∈ 𝐷.
• 𝑄𝑣 = {⟨1, 2⟩}.
Therefore, 𝑄(𝑓(𝑐), 𝑎)𝑣 = 1 since all of the following hold:
𝑓(𝑐)𝑣 = 𝑓 𝑣 (1) = 1 (100)
𝑎𝑣 = 2 (101)
⟨1, 2⟩ ∈ 𝑄𝑣 . (102)
61
Exercise 61. Give a valuation 𝑣 such that 𝑄(𝑓(𝑐), 𝑎)𝑣 = 0.
Solution:
Remark 7. All we need to do is make one small adjustment to the interpretation in exer-
cise 60.
To make the formula false, we need to make sure the tuple ⟨1, 2⟩ ∉ 𝑄𝑣 . Let 𝑄𝑣 be the empty
set.
• 𝐷 = {1, 2, 3}.
• 𝑎𝑣 = 2, 𝑐𝑣 = 1.
• 𝑓 𝑣 (𝑥) = 𝑥, ∀𝑥 ∈ 𝐷.
• 𝑄𝑣 = ∅.
62
2.2.2 Evaluating Formulas without Bound Variables
Exercise 62. Give a valuation 𝑣 such that 𝑄(𝑓(𝑢), 𝑎)𝑣 = 1.
Solution:
Remark 8. Let’s start with the valuation in the solution to exercise 60. We simplify the
formula below.
𝑓(𝑢)𝑣 = 𝑓 𝑣 (𝑢𝑣 ) = 𝑢𝑣 , 𝑎𝑣 = 2.
Thus, the formula is true if and only if ⟨𝑢𝑣 , 2⟩ ∈ 𝑄𝑣 .
The only tuple in 𝑄𝑣 is ⟨1, 2⟩. Thus, it is sufficient to let 𝑢𝑣 = 1.
Solution:
Remark 9. Let’s start with the valuation in the solution to exercise 62, and modify 𝑄𝑣 to
be the empty set. Under 𝑣, the formula is false, using similar reasoning as exercise 61.
63
2.2.3 Evaluating Formulas with Free and Bound Variables
Exercise 64. Give a valuation 𝑣 such that (∃𝑥 𝑄(𝑥, 𝑢))𝑣 = 1. Assume that the domain is
𝐷 = {1, 2, 3}.
Solution:
Remark 10. Here is more explanation to help you understand how I came up with the
valuation 𝑣 above.
𝑢 is a free variable in the formula. Let’s arbitrarily define 𝑢𝑣 = 2.
To make the formula true, there must be at least one tuple in 𝑄𝑣 and the second value in the
tuple (the value of 𝑢 in the tuple) must be 2 because 𝑢𝑣 = 2. Let 𝑄𝑣 = {⟨1, 2⟩}.
Given the 𝑣 above, we know that 𝑄(𝑢, 𝑤)𝑣(𝑢/1) = 1 because all of the following hold:
64
Exercise 65. Give a valuation 𝑣 such that (∀𝑥 𝑄(𝑥, 𝑢))𝑣 = 1. Assume that the domain is
𝐷 = {1, 2, 3}.
Solution:
• 𝐷 = {1, 2, 3}.
• 𝑎𝑣 = 2, 𝑏𝑣 = 1, 𝑐𝑣 = 1.
• 𝑓 𝑣 (𝑥) = 𝑥, ∀𝑥 ∈ 𝐷, 𝑔𝑣 (𝑥) = 1, ∀𝑥 ∈ 𝐷.
𝐸[𝑥 ↦ 1](𝑥) = 1
𝐸[𝑥 ↦ 1](𝑦) = 2
⟨1, 2⟩ ∈ 𝑄𝑣 .
𝐸[𝑥 ↦ 2](𝑥) = 2
𝐸[𝑥 ↦ 2](𝑦) = 2
⟨2, 2⟩ ∈ 𝑄𝑣 .
𝐸[𝑥 ↦ 3](𝑥) = 3
𝐸[𝑥 ↦ 3](𝑦) = 2
⟨3, 2⟩ ∈ 𝑄𝑣 .
65
2.2.4 Evaluating Formulas with Bound Variables Only
Exercise 66. Give an interpretation 𝐼 and an environment 𝐸 such that (∃𝑥(∀𝑦 𝑄(𝑥, 𝑦)))𝑣 =
1. Start with the domain 𝐷 = {1, 2, 3}.
Solution:
Remark 12. To make the formula true, there must be at least 3 tuples in 𝑄𝑣 because 𝑦 (the
second value of each tuple) could take any of the 3 possible values in the domain.
The first element of all three tuples must be the same because there must be one value for 𝑥
that makes 𝑄(𝑥, 𝑦) true.
Note that, when choosing the value of 𝑥, we do not know the value of 𝑦 yet. Our choice of
value for 𝑥 cannot depend on the value of 𝑦.
One definition of 𝑄𝑣 that satisfies all these requirements is 𝑄𝑣 = {⟨1, 1⟩, ⟨1, 2⟩, ⟨1, 3⟩}.
• 𝐷 = {1, 2, 3}.
• 𝑎𝑣 = 2, 𝑏𝑣 = 1, 𝑐𝑣 = 1.
• 𝑓 𝑣 (𝑥) = 𝑥, ∀𝑥 ∈ 𝐷, 𝑔𝑣 (𝑥) = 1, ∀𝑥 ∈ 𝐷.
66
• [𝑦 ↦ 3]: 𝑄(𝑥, 𝑦)(𝐼,𝐸[𝑥↦1][𝑦↦3]) = 1 because all of the following hold.
67
Exercise 67. Give an interpretation 𝐼 and an environment 𝐸 such that (∃𝑥(∀𝑦 𝑄(𝑥, 𝑦)))𝑣 =
0. Start with the domain 𝐷 = {1, 2, 3}.
Solution:
Remark 13. The formula has no free variables. The bound variables get their meanings
through the quantifiers. Thus, there is no need to define an environment. We only need to
define an interpretation to evaluate the formula.
There are many ways to make the formula false. An easy solution is to let 𝑄𝑣 be the empty
set. Then, 𝑄𝑣 (𝑥, 𝑦) is always false and the formula must be false as well.
If there are tuples in 𝑄𝑣 , we need to make sure that 𝑄𝑣 does not have three tuples such that
the first value of all three tuples are the same and the second value in all three tuples are all
different.
Solution Text:
The interpretation 𝐼 is shown below.
• 𝐷 = {1, 2, 3}.
• 𝑎𝑣 = 2, 𝑏𝑣 = 1, 𝑐𝑣 = 1.
• 𝑓 𝑣 (𝑥) = 𝑥, ∀𝑥 ∈ 𝐷, 𝑔𝑣 (𝑥) = 1, ∀𝑥 ∈ 𝐷.
• [𝑥 ↦ 1]:
By the rules of satisfaction for ∀, to prove that (∀𝑦 𝑄(𝑥, 𝑦))(𝐼,𝐸[𝑥↦1]) = 0, we need to
prove that 𝑄(𝑥, 𝑦)(𝐼,𝐸[𝑥↦1][𝑦↦𝑑𝑦 ]) = 0 for some 𝑑𝑦 ∈ 𝐷.
𝑄(𝑥, 𝑦)(𝐼,𝐸[𝑥↦1][𝑦↦2]) = 0 holds since all of the following statements hold.
Therefore, 𝑄(𝑥, 𝑦)(𝐼,𝐸[𝑥↦1][𝑦↦2]) = 0 holds, which means that (∀𝑦 𝑄(𝑥, 𝑦))(𝐼,𝐸[𝑥↦1]) = 0
holds.
68
• [𝑥 ↦ 2]:
𝑄(𝑥, 𝑦)(𝐼,𝐸[𝑥↦2][𝑦↦1]) = 0 holds because all of the following statements hold.
• [𝑥 ↦ 3]:
𝑄(𝑥, 𝑦)(𝐼,𝐸[𝑥↦3][𝑦↦1]) = 0 holds because all of the following statements hold.
69
2.3 Tautological Consequence
Collected Wisdom:
70
Exercise 68. Show that {(∀𝑥 𝑃 (𝑥))} ⊨ (∃𝑥 𝑃 (𝑥)).
Solution:
Proof. Consider an interpretation 𝐼 such that (∀𝑥 𝑃 (𝑥))𝑣 = 1. We will prove that (∃𝑥 𝑃 (𝑥))𝑣 =
1.
Consider an arbitrary environment 𝐸. Let 𝑑1 ∈ 𝐷 be a domain element.
By the satisfaction rules for ∀, 𝑃 (𝑥)(𝐼,𝐸[𝑥↦𝑑1 ]) = 1. Therefore, 𝐸[𝑥 ↦ 𝑑1 ](𝑥) = 𝑑1 ∈ 𝑃 𝑣 .
By the satisfaction rules for ∃, (∃𝑥 𝑃 (𝑥))𝑣 = 1.
Solution:
Proof. To prove that the tautological consequence does hold, we need to find an interpreta-
tion 𝐼 such that (∃𝑥 𝑃 (𝑥))𝑣 = 1 and (∀𝑥 𝑃 (𝑥))𝑣 = 0.
Consider the interpretation 𝐼 below.
• 𝐷 = {1, 2}.
• 𝑃 𝑣 = {1}.
71
Exercise 70. Show that {(∀𝑥 (𝐴 → 𝐵))} ⊨ ((∀𝑥 𝐴) → (∀𝑥 𝐵)), where 𝑥 is a variable
symbol and 𝐴 and 𝐵 are well-formed predicate formulas.
Solution:
Proof. Consider an interpretation 𝐼 and an environment 𝐸 such that (∀𝑥 (𝐴 → 𝐵))𝑣 = 1.
We will prove that ((∀𝑥 𝐴) → (∀𝑥 𝐵))𝑣 = 1.
To show that ((∀𝑥 𝐴) → (∀𝑥 𝐵))𝑣 = 1, we assume that (∀𝑥 𝐴)𝑣 = 1.
By the satisfaction rule for ∀, we have that
By our assumption, (∀𝑥 (𝐴 → 𝐵))𝑣 = 1. By the satisfaction rule for ∀, we have that
(∀𝑥 𝐵)𝑣 = 1.
Thus, the tautological consequence holds.
72
Exercise 71. Show that {((∀𝑥 𝐴) → (∀𝑥 𝐵))} ⊭ (∀𝑥 (𝐴 → 𝐵)), where 𝑥 is a variable
symbol and 𝐴 and 𝐵 are well-formed predicate formulas.
Solution:
Remark 14. The most important step for the proof below is to come up with the concrete
example such that the premises are all true and the conclusion is false.
I first chose concrete formulas for 𝐴 and 𝐵. This step is important. Without doing so, I
may not be able to make claims about whether 𝐴 and 𝐵 are true or false under a particular
interpretation.
Next, I construct an interpretation to satisfy the two requirements. I start by picking a
domain containing two elements. It is small enough to be manageable and large enough to
give me a few possibilities to experiment with.
Then, I try to find definitions for 𝑃 𝑣 and 𝑄𝑣 to satisfy the two requirements.
First, I want to make the conclusion (∀𝑥 (𝑃 (𝑥) → 𝑄(𝑥))) false. To do this, it is sufficient to
make 𝑃 to be true and 𝑄 to be false for one value of 𝑥 (so that the implication (𝑃 (𝑥) → 𝑄(𝑥))
is false). I used 𝑥 = 2 for this case and made sure that 2 ∈ 𝑃 𝑣 and 2 ∉ 𝑄𝑣 .
Next, I want to make the premise true. Since 2 ∉ 𝑄𝑣 , then (∀𝑥 𝑄(𝑥)) is false. So the
conclusion of the premise is false. To make the premise true, I have to make the premise of
the premise false. This means that, I need to make sure at least one domain element is not
in 𝑃 𝑣 . Therefore, I defined 𝑃 𝑣 such that 1 ∉ 𝑃 𝑣 .
Proof. Let 𝐴 be 𝑃 (𝑥) and let 𝐵 be 𝑄(𝑥), where 𝑃 and 𝑄 are unary predicates. Consider
the following interpretation:
• 𝐷 = {1, 2}
• 𝑃 𝑣 = {2} and 𝑄𝑣 = {1}
We need to show that ((∀𝑥 𝑃 (𝑥)) → (∀𝑥 𝑄(𝑥)))𝑣 = 1 and (∀𝑥 (𝑃 (𝑥) → 𝑄(𝑥)))𝑣 = 0. Let
𝐸 be an arbitrary environment.
First, we will show that ((∀𝑥 𝑃 (𝑥)) → (∀𝑥 𝑄(𝑥)))𝑣 = 1.
𝑃 (𝑥)(𝐼,𝐸[𝑥↦1]) = 0 because 𝐸[𝑥 ↦ 1](𝑥) = 1 ∉ 𝑃 𝑣 . By the satisfaction rule for ∀,
(∀𝑥 𝑃 (𝑥))𝑣 = 0.
By the satisfaction rule for an implication, ((∀𝑥 𝑃 (𝑥)) → (∀𝑥 𝑄(𝑥)))𝑣 = 1 because
(∀𝑥 𝑃 (𝑥))𝑣 = 0.
Next, we will show that (∀𝑥 (𝑃 (𝑥) → 𝑄(𝑥)))𝑣 = 0.
(𝑃 (𝑥) → 𝑄(𝑥))(𝐼,𝐸[𝑥↦2]) = 0 because 𝐸[𝑥 ↦ 2](𝑥) = 2 ∈ 𝑃 𝑣 and 𝐸[𝑥 ↦ 2](𝑥) = 2 ∉ 𝑄𝑣 .
By the satisfaction rule for ∀, (∀𝑥 (𝑃 (𝑥) → 𝑄(𝑥)))𝑣 = 0.
In summary, the tautological consequence does not hold.
73
Exercise 72. Show that {(∃𝑦 (∀𝑥 𝑄(𝑥, 𝑦)))} ⊨ (∀𝑥 (∃𝑦 𝑄(𝑥, 𝑦))).
Solution:
Proof. Consider an interpretation 𝐼 such that (∃𝑦 (∀𝑥 𝑄(𝑥, 𝑦)))𝑣 = 1. We will prove that
(∀𝑥 (∃𝑦 𝑄(𝑥, 𝑦)))𝑣 = 1. Let 𝐸 be an arbitrary environment.
By the satisfaction rules for ∃, we have
Note that in the environment 𝐸[𝑦 ↦ 𝑑𝑦 ][𝑥 ↦ 𝑑], the value of 𝑑𝑦 was chosen first
and does not depend on the value of 𝑑. Thus, the environment 𝐸[𝑦 ↦ 𝑑𝑦 ][𝑥 ↦ 𝑑]
is equivalent to the environment 𝐸[𝑥 ↦ 𝑑][𝑦 ↦ 𝑑𝑦 ]. It does not matter whether
we chose the value for 𝑥 or the value for 𝑦 first. Therefore, we rewrite the formula
above as follows.
74
Exercise 73. Show that {(∀𝑥 (∃𝑦 𝑄(𝑥, 𝑦)))} ⊭ (∃𝑦 (∀𝑥 𝑄(𝑥, 𝑦))).
Solution:
Remark 15. If I attempt to prove the tautological consequence, what would happen?
By the satisfaction rules for ∀, we have
for every 𝑑 ∈ 𝐷 and for some 𝑑𝑦 ∈ 𝐷 where the value of 𝑑𝑦 may depend on the value of 𝑑𝑥 .
Note that the value of 𝑑𝑦 may depend on the value of 𝑑𝑥 . In other words, for every value of
𝑑𝑥 , we may choose a different value of 𝑑𝑦 to satisfy the formula. Therefore, we CANNOT
switch the two overrides in the environment. The following formula is FALSE.
Proof. To prove that the tautological consequence does not hold, we need to find an inter-
pretation 𝐼 such that (∀𝑥 (∃𝑦 𝑄(𝑥, 𝑦)))𝑣 = 1 and (∃𝑦 (∀𝑥 𝑄(𝑥, 𝑦)))𝑣 = 0.
Consider the interpretation 𝐼 below.
• 𝐷 = {1, 2}.
First, we will show that (∀𝑥 (∃𝑦 𝑄(𝑥, 𝑦)))𝑣 = 1. Let 𝐸 be an arbitrary environment.
Consider all possible values of 𝑥.
75
Thus, by the satisfaction rule for ∀, (∀𝑥 (∃𝑦 𝑄(𝑥, 𝑦)))𝑣 = 1.
Next, we will show that (∃𝑦 (∀𝑥 𝑄(𝑥, 𝑦)))𝑣 = 0. Let 𝐸 be an arbitrary environment.
Consider all possible values of 𝑦.
76
Exercise 74. Show that {(∀𝑥 (∃𝑦 (𝑃 (𝑥) ∨ 𝑄(𝑦))))} ⊨ (∃𝑦 (∀𝑥 (𝑃 (𝑥) ∨ 𝑄(𝑦)))).
Remark 16. Wait a second! In exercise 73, didn’t we just show that this tautological
consequence does NOT hold? Not quite. In exercise 73, we dealt with a generic predicate
formula 𝑄(𝑥, 𝑦) without knowing any additional information about the predicate. In this
question, we are working with a much more concrete predicate formula (𝑃 (𝑥) ∨ 𝑄(𝑦)). It
turns out that, having this concrete predicate formula allows us to prove the tautological
consequence.
77
2.3.1 Semantic Entailment - Additional Exercises
Exercise 75. {((∀𝑥 𝑃 (𝑥)) ∨ (∀𝑥 𝑄(𝑥)))} ⊨ (∀𝑥 (𝑃 (𝑥) ∨ 𝑄(𝑥))).
78
2.4 Formal Deduction
Comments:
• ∀− is analogous to ∧−.
• ∀+ is analogous to ∧+.
Intuitively, this rule means that: from “any member 𝑢 of the set has a certain property”
we can deduce that “every member of the set has this property”. The arbitrariness
of 𝑢 means that the choice of 𝑢 is independent of the premises in Σ. This point is
expressed by “𝑢 not occurring in Σ”.
We know nothing about 𝑢 except that 𝑢 is a domain element. If 𝑢 is special, our
conclusion may not be valid.
∃-introduction (∃+)
Comments:
• ∃− is analogous to ∨−.
– Proof by cases.
– The conclusion may have nothing to do with the starting formula.
• ∃+ is analogous to ∨+.
79
2.4.1 Forall-elimination
Exercise 78. Show that {𝑃 (𝑢), ∀𝑥 (𝑃 (𝑥) → (¬𝑄(𝑥)))} ⊢ (¬𝑄(𝑢)).
Solution:
2.4.2 Exists-introduction
Exercise 79. Show that {(¬𝑃 (𝑣))} ⊢ (∃𝑥 (𝑃 (𝑥) → 𝑄(𝑣))).
Solution:
Solution:
80
2.4.3 Forall-introduction
Exercise 81. Show that {(∀𝑥 𝑃 (𝑥))} ⊢ (∀𝑦 𝑃 (𝑦)).
Solution:
Exercise 82. Show that (∀𝑥 (𝑃 (𝑥) → 𝑄(𝑥))) ⊢ ((∀𝑥 𝑃 (𝑥)) → (∀𝑦 𝑄(𝑦))).
Solution:
81
2.4.4 Forall-introduction - Additional Exercises
Exercise 83. {(∀𝑥 (∀𝑦 𝑃 (𝑥, 𝑦)))} ⊢ (∀𝑦 (∀𝑥 𝑃 (𝑥, 𝑦))).
Exercise 88. {(∀𝑥 (𝑃 (𝑥) → 𝑄(𝑥)))} ⊢ ((∀𝑥 (¬𝑄(𝑥))) → (∀𝑥 (¬𝑃 (𝑥)))).
Exercise 89. {(∀𝑥 (∀𝑦 (𝑅(𝑥, 𝑦) → 𝑅(𝑦, 𝑥))))} ⊢ (∀𝑥 (∀𝑦 (𝑅(𝑦, 𝑥) → 𝑅(𝑥, 𝑦)))).
Exercise 90. {(∀𝑥 (∀𝑦 (∀𝑧 ((𝑅(𝑥, 𝑦) ∧ 𝑅(𝑦, 𝑧)) → 𝑅(𝑥, 𝑧))))), (∀𝑥 (¬𝑅(𝑥, 𝑥)))}
⊢ (∀𝑥 (∀𝑦 (∀𝑧 (¬((𝑅(𝑥, 𝑦) ∧ 𝑅(𝑦, 𝑧)) ∧ 𝑅(𝑧, 𝑥)))))).
Exercise 91. {(∀𝑥 (∀𝑦 (∀𝑧 ((𝑅(𝑥, 𝑦) ∧ 𝑅(𝑥, 𝑧)) → 𝑅(𝑦, 𝑧))))), (∀𝑥 𝑅(𝑥, 𝑥))}
⊢ (∀𝑥 (∀𝑦 (∀𝑧 ((𝑅(𝑥, 𝑦) ∧ 𝑅(𝑦, 𝑧)) → 𝑅(𝑥, 𝑧))))).
82
2.4.5 Exists-elimination
Exercise 92. (∃𝑥 𝑃 (𝑥)) ⊢ (∃𝑦 𝑃 (𝑦)).
Solution:
Solution:
83
Exercise 95. Show that (∀𝑥 (𝑃 (𝑥) → 𝑄(𝑥))), (∃𝑥 𝑃 (𝑥)) ⊢ (∃𝑥 𝑄(𝑥)).
Solution:
Exercise 96. Show that (∀𝑥 (𝑄(𝑥) → 𝑅(𝑥))), (∃𝑥 (𝑃 (𝑥) ∧ 𝑄(𝑥))) ⊢ (∃𝑥 (𝑃 (𝑥) ∧ 𝑅(𝑥))).
Solution:
1. (∀𝑥 (𝑄(𝑥) → 𝑅(𝑥))) premise
2. (∃𝑥 (𝑃 (𝑥) ∧ 𝑄(𝑥))) premise
3. (𝑃 (𝑢) ∧ 𝑄(𝑢)), 𝑢 fresh assumption
4. 𝑃 (𝑢) ∧e: 3
5. 𝑄(𝑢) ∧e: 3
6. (𝑄(𝑢) → 𝑅(𝑢)) ∀e: 1
7. 𝑅(𝑢) →e: 5, 6
8. (𝑃 (𝑢) ∧ 𝑅(𝑢)) ∧i: 4, 7
9. (∃𝑥 (𝑃 (𝑥) ∧ 𝑅(𝑥))) ∃i: 8
10. (∃𝑥 (𝑃 (𝑥) ∧ 𝑅(𝑥))) ∃e: 2, 3-9
84
2.4.6 Exists-Elimination - Additional Exercises
Exercise 97. {(∃𝑥 (𝑃 (𝑥) → 𝑄(𝑥))), (∀𝑦 𝑃 (𝑦))} ⊢ (∃𝑥 𝑄(𝑥))
Exercise 98. {(∃𝑥 (∃𝑦 𝑃 (𝑥, 𝑦)))} ⊢ (∃𝑦 (∃𝑥 𝑃 (𝑥, 𝑦))).
Exercise 99. {(∃𝑥 ((¬𝑃 (𝑥)) ∧ (¬𝑄(𝑥))))} ⊢ (∃𝑥 (¬(𝑃 (𝑥) ∧ 𝑄(𝑥)))).
Exercise 100. {(∃𝑥 ((¬𝑃 (𝑥)) ∨ 𝑄(𝑥)))} ⊢ (∃𝑥 (¬(𝑃 (𝑥) ∧ (¬𝑄(𝑥))))).
85
2.4.7 Putting them together
Exercise 101. Show that (∃𝑦 (∀𝑥 𝑃 (𝑥, 𝑦))) ⊢ (∀𝑥 (∃𝑦 𝑃 (𝑥, 𝑦))).
Solution: There are two different solutions, depending whether we apply ∀+ last or apply
∃− last.
Applying ∃− last:
Applying ∀+ last:
86
Exercise 102. Show that {(∃𝑥 𝑃 (𝑥)), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦))))} ⊢ (∀𝑦 𝑄(𝑦)).
Solution: There are two different solutions, depending whether we apply ∀+ last or apply
∃− last.
(1) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) by (∈)
(2) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ (∀𝑦 (𝑃 (𝑢) → 𝑄(𝑦))) by (∀−, 1)
(3) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ (𝑃 (𝑢) → 𝑄(𝑣)) by (∀−, 2)
(4) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ 𝑃 (𝑢) by (∈)
(5) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ 𝑄(𝑣) by (→ −, 3, 4)
(6) (∃𝑥 𝑃 (𝑥)), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ 𝑄(𝑣) by (∃−, 5)
(7) (∃𝑥 𝑃 (𝑥)), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ (∀𝑦 𝑄(𝑦)) by (∀+, 6)
(1) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) by (∈)
(2) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ (∀𝑦 (𝑃 (𝑢) → 𝑄(𝑦))) by (∀−, 1)
(3) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ (𝑃 (𝑢) → 𝑄(𝑣)) by (∀−, 2)
(4) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ 𝑃 (𝑢) by (∈)
(5) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ 𝑄(𝑣) by (→ −, 3, 4)
(6) 𝑃 (𝑢), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ (∀𝑦 𝑄(𝑦)) by (∀+, 5)
(7) (∃𝑥 𝑃 (𝑥)), (∀𝑥 (∀𝑦 (𝑃 (𝑥) → 𝑄(𝑦)))) ⊢ (∀𝑦 𝑄(𝑦)) by (∃−, 6)
87
Exercise 103. Show that {(¬(∃𝑥 𝑃 (𝑥)))} ⊢ (∀𝑥 (¬𝑃 (𝑥))). (De Morgan)
Solution:
Exercise 104. Show that {(∀𝑥 (¬𝑃 (𝑥)))} ⊢ (¬(∃𝑥 𝑃 (𝑥))). (De Morgan)
Solution:
(1) (∀𝑥 (¬𝑃 (𝑥))), 𝑃 (𝑢), ¬𝑄(𝑣) ⊢ (∀𝑥 (¬𝑃 (𝑥))) by (∈)
(2) (∀𝑥 (¬𝑃 (𝑥))), 𝑃 (𝑢), ¬𝑄(𝑣) ⊢ ¬𝑃 (𝑢) by (∀−, 1)
(3) (∀𝑥 (¬𝑃 (𝑥))), 𝑃 (𝑢), ¬𝑄(𝑣) ⊢ 𝑃 (𝑢) by (∈)
(4) (∀𝑥 (¬𝑃 (𝑥))), 𝑃 (𝑢) ⊢ 𝑄(𝑣) by (¬−, 2, 3)
(5) (∀𝑥 (¬𝑃 (𝑥))), (∃𝑥 𝑃 (𝑥)) ⊢ 𝑄(𝑣) by (∃−, 4)
(6) (∀𝑥 (¬𝑃 (𝑥))), 𝑃 (𝑢), 𝑄(𝑣) ⊢ (∀𝑥 (¬𝑃 (𝑥))) by (∈)
(7) (∀𝑥 (¬𝑃 (𝑥))), 𝑃 (𝑢), 𝑄(𝑣) ⊢ ¬𝑃 (𝑢) by (∀−, 6)
(8) (∀𝑥 (¬𝑃 (𝑥))), 𝑃 (𝑢), 𝑄(𝑣) ⊢ 𝑃 (𝑢) by (∈)
(9) (∀𝑥 (¬𝑃 (𝑥))), 𝑃 (𝑢) ⊢ ¬𝑄(𝑣) by (¬+, 7, 8)
(10) (∀𝑥 (¬𝑃 (𝑥))), (∃𝑥 𝑃 (𝑥)) ⊢ ¬𝑄(𝑣) by (∃−, 9)
(11) (∀𝑥 (¬𝑃 (𝑥))) ⊢ (¬(∃𝑥 𝑃 (𝑥))) by (¬+, 5, 10)
88
Exercise 105. Show that {(∃𝑥 (¬𝑃 (𝑥)))} ⊢ (¬(∀𝑥 𝑃 (𝑥))). (De Morgan)
Solution:
1. (∃𝑥 (¬𝑃 (𝑥))) premise
2. (∀𝑥 𝑃 (𝑥)) assumption
3. (¬𝑃 (𝑢)), 𝑢 fresh assumption
4. 𝑃 (𝑢) ∀e: 2
5. ⊥ ⊥i: 3, 4
6. ⊥ ∃e: 1, 3-5
7. (¬(∀𝑥 𝑃 (𝑥))) ¬i: 2-6
Exercise 106. Show that {(¬(∀𝑥 𝑃 (𝑥)))} ⊢ (∃𝑥 (¬𝑃 (𝑥))). (De Morgan)
Solution:
1. (¬(∀𝑥 𝑃 (𝑥))) premise
2. (¬(∃𝑥 (¬𝑃 (𝑥)))) assumption
3. 𝑢 fresh assumption
4. (¬𝑃 (𝑢)) assumption
5. (∃𝑥 (¬𝑃 (𝑥))) ∃i: 4
6. ⊥ 2, 5
7. 𝑃 (𝑢) PBC: 4-6
8. (∀𝑥 𝑃 (𝑥)) ∀i: 3-7
9. ⊥ ⊥i: 1, 8
10. (∃𝑥 (¬𝑃 (𝑥))) PBC: 2-9
89
2.4.8 Putting them together - Additional Exercises
Exercise 107. {(∀𝑥 (𝑃 (𝑥) → (¬𝑄(𝑥))))} ⊢ (¬(∃𝑥 (𝑃 (𝑥) ∧ 𝑄(𝑥)))).
Exercise 109. {(∀𝑥 (𝑃 (𝑥) → (𝑄(𝑥) ∨ 𝑅(𝑥)))), (¬(∃𝑥 (𝑃 (𝑥) ∧ 𝑅(𝑥))))} ⊢ (∀𝑥 (𝑃 (𝑥) → 𝑄(𝑥))).
Exercise 110. {(∃𝑥 (𝑃 (𝑥) ∧ 𝑄(𝑥))), (∀𝑥 (𝑃 (𝑥) → 𝑅(𝑥)))} ⊢ (∃𝑥 (𝑅(𝑥) ∧ 𝑄(𝑥))).
Exercise 111. {(∃𝑥 (∃𝑦 (𝑆(𝑥, 𝑦) ∨ 𝑆(𝑦, 𝑥))))} ⊢ (∃𝑥 (∃𝑦 𝑆(𝑥, 𝑦))).
Exercise 113. {(∀𝑥 (∃𝑦 𝑅(𝑥, 𝑦)))} ⊢ (∀𝑥 (∃𝑦 (∃𝑧 (𝑅(𝑥, 𝑦) ∧ 𝑅(𝑥, 𝑧))))).
Exercise 114. {(∀𝑥 (𝑃 (𝑥) ∨ 𝑄(𝑥))), (∃𝑥 (¬𝑄(𝑥))), (∀𝑥 (𝑅(𝑥) → (¬𝑃 (𝑥))))} ⊢ (∃𝑥 (¬𝑅(𝑥))).
Exercise 116. {(∀𝑥 (∃𝑦 (𝑃 (𝑥) ∨ 𝑄(𝑦))))} ⊢ (∃𝑦 (∀𝑥 (𝑃 (𝑥) ∨ 𝑄(𝑦)))).
Exercise 117. {(∀𝑥 ((∃𝑦 𝑃 (𝑦)) → 𝑄(𝑥)))} ⊢ (∀𝑥 (∃𝑦 (𝑃 (𝑦) → 𝑄(𝑥)))).
Exercise 118. {(∀𝑥 (𝑃 (𝑥, 𝑥) ∨ (∀𝑦 𝑄(𝑥, 𝑦))))} ⊢ (∀𝑥 ((∃𝑦 𝑃 (𝑥, 𝑦)) ∨ 𝑄(𝑥, 𝑥))).
90
2.5 Soundness and Completeness of Natural Deduction
2.5.1 Proving that an inference rule is sound or not sound
Lemma 1. Let 𝑡 be a predicate term. Let 𝐼 be an interpretation with domain 𝐷. Let 𝐸 be
an environment. Then we have that
𝑡𝑣 ∈ 𝐷.
Lemma 2. Let 𝐴 be a well-formed predicate formula. Let 𝑡 be a predicate term. Let 𝐼 and
𝐸 be an interpretation and environment. Let 𝑥 be a variable. Then we have that
𝑣
𝐴[𝑡/𝑥]𝑣 = 𝐴(𝐼,𝐸[𝑥↦𝑡 ]) .
Exercise 120. Prove that the ∀e inference rule is sound. That is, prove that the tautological
consequence holds:
The proof sketch below is like an outline or a master plan. I will lay down the plan first.
Then I will fill in the missing details.
Proof Sketch. Consider an interpretation and environment (𝐼, 𝐸) such that (∀𝑥 𝐴)𝑣 = 1.
We need to show that 𝐴[𝑡/𝑥]𝑣 = 1.
(∀𝑥 𝐴)𝑣 = 1 holds because ...
𝑣
𝐴(𝐼,𝐸[𝑥↦𝑡 ])
= 1 holds because ...
𝐴[𝑡/𝑥]𝑣 = 1 holds because ...
Thus, the tautological consequence holds and the inference rule is sound.
Solution: Let (𝐼, 𝐸) be an interpretation and environment such that (∀𝑥 𝐴)𝑣 = 1.
By the satisfaction rule for ∀, we have that 𝐴(𝐼,𝐸[𝑥↦𝑑]) = 1, for every 𝑑 ∈ 𝐷.
𝑣
By Lemma 1, 𝑡𝑣 is some domain element. Thus, we have that 𝐴(𝐼,𝐸[𝑥↦𝑡 ])
= 1.
𝑣
By Lemma 2, we have that 𝐴[𝑡/𝑥]𝑣 = 𝐴(𝐼,𝐸[𝑥↦𝑡 ]) . Thus, we have that 𝐴[𝑡/𝑥]𝑣 = 1.
91
Exercise 121. Prove that the ∃i inference rule is sound. That is, prove that the tautological
consequence holds:
Proof Sketch. Consider an interpretation and environment (𝐼, 𝐸) such that 𝐴[𝑡/𝑥]𝑣 = 1. We
need to show that (∃𝑥 𝐴)𝑣 = 1.
𝐴[𝑡/𝑥]𝑣 = 1 holds because ...
𝑣
𝐴(𝐼,𝐸[𝑥↦𝑡 ])
= 1 holds because ...
(∃𝑥 𝐴)𝑣 = 1 holds because ...
Thus, the tautological consequence holds and the inference rule is sound.
Solution: Let (𝐼, 𝐸) be an interpretation and environment such that 𝐴[𝑡/𝑥]𝑣 = 1.
𝑣 𝑣
By Lemma 2, we have that 𝐴[𝑡/𝑥]𝑣 = 𝐴(𝐼,𝐸[𝑥↦𝑡 ]) . Thus, we have that 𝐴(𝐼,𝐸[𝑥↦𝑡 ])
= 1.
By Lemma 1, 𝑡𝑣 is some domain element. Thus, by the satisfaction rule for ∃, we have that
(∃𝑥 𝐴)𝑣 = 1.
92
Exercise 122. Prove that the following inference rule is NOT sound.
𝐴[𝑡/𝑥]
∀𝑖∗
(∀𝑥 𝐴) (127)
where 𝐴 is a predicate formula, 𝑡 is a predicate term, and 𝑥 is a variable.
Proof Sketch. Define the symbols in the language of Predicate logic that we consider.
Choose 𝐴 to be a concrete Predicate formula. Choose 𝑡 to be a concrete Predicate term.
Define an interpretation and an environment (𝐼, 𝐸).
Show that 𝐴[𝑡/𝑥]𝑣 = 1.
Show that (∀𝑥 𝐴)𝑣 = 0.
Solution:
Remark 18. How did I come up with the interpretation and the environment below?
Given the definition of 𝐷, 𝐸, and 𝐴 and 𝑡, we can simplify the premise and the conclusion.
The premise becomes 𝐴[𝑡/𝑥] = 𝑃 (𝑥)[𝑦/𝑥] = 𝑃 (𝑦).
The conclusion becomes (∀𝑥 𝑃 (𝑥)).
To make the premise true, we need to define 𝐸(𝑦) and 𝑃 𝑣 such that 𝑃 (𝑦) is true. If we
choose 𝐸(𝑦) = 1, then we need 1 ∈ 𝑃 𝑣 . If we choose 𝐸(𝑦) = 2, then we need 2 ∈ 𝑃 𝑣 . In the
solution below, I chose 𝐸(𝑦) = 1 and 1 ∈ 𝑃 𝑣 .
To make the conclusion false, we need to make sure that 𝑃 (𝑥) is false for one element of the
domain. By the above definition, we already know that 𝑃 (𝑥) is true when 𝑥 is 1. The only
other element of the domain is 2. So we need to make sure that 𝑃 (𝑥) is false when 𝑥 is 2,
which means that 2 ∉ 𝑃 𝑣 .
Solution Text:
We need to provide an interpretation 𝐼 and an environment 𝐸 such that 𝐴[𝑡/𝑥]𝑣 = 1 and
(∀𝑥 𝐴)𝑣 = 0.
Consider the language of predicate logic where 𝑃 (1) is a unary predicate and 𝑥 and 𝑦 are
variables.
Let 𝐴 be 𝑃 (𝑥) and let 𝑡 be 𝑦. Let the interpretation 𝐼 be defined below.
• 𝐷 = {1, 2}
• 𝑃 𝑣 = {1}
Let the environment 𝐸 be defined by 𝐸(𝑥) = 1 and 𝐸(𝑦) = 1.
𝑣
First, we show that 𝐴[𝑡/𝑥]𝑣 = 1. By Lemma 2, 𝐴[𝑡/𝑥]𝑣 = 𝐴(𝐼,𝐸[𝑥↦𝑡 ]) . By the definition of
the term 𝑡, 𝑡𝑣 = 𝑦𝑣 = 𝐸(𝑦) = 1. Thus, 𝐴[𝑡/𝑥]𝑣 = 𝐴(𝐼,𝐸[𝑥↦1]) = 𝑃 (𝑥)(𝐼,𝐸[𝑥↦1]) = 1 because
𝐸[𝑥 ↦ 1](𝑥) = 1 ∈ 𝑃 𝑣 .
Next, we show that (∀𝑥 𝐴)𝑣 = 0. By the satisfaction rule for ∀, we need to show that
𝐴(𝐼,𝐸[𝑥↦𝑑]) = 0 for at least one 𝑑 ∈ 𝐷. We have that 𝐴(𝐼,𝐸[𝑥↦2]) = 𝑃 (𝑥)(𝐼,𝐸[𝑥↦2]) = 0
because 𝐸[𝑥 ↦ 2](𝑥) = 2 ∉ 𝑃 𝑣 .
93
Exercise 123. Prove that the following inference rule is NOT sound.
(∃𝑥 𝐴)
∃𝑒∗
𝐴[𝑡/𝑥] (128)
Proof Sketch. Define the symbols in the language of Predicate logic that we consider.
Choose 𝐴 to be a concrete Predicate formula. Choose 𝑡 to be a concrete Predicate term.
Define an interpretation and an environment (𝐼, 𝐸).
Show that (∃𝑥 𝐴)𝑣 = 1.
Show that 𝐴[𝑡/𝑥]𝑣 = 0.
Solution: We need to provide an interpretation 𝐼 and an environment 𝐸 such that (∃𝑥 𝐴)𝑣 =
1 and 𝐴[𝑡/𝑥]𝑣 = 0.
Consider the language of predicate logic where 𝑃 (1) is a unary predicate and 𝑥 and 𝑦 are
variables.
Let 𝐴 be 𝑃 (𝑥) and let 𝑡 be 𝑦. Let the interpretation 𝐼 be defined below.
• 𝐷 = {1, 2}
• 𝑃 𝑣 = {1}
𝐴(𝐼,𝐸[𝑥↦1]) = 1
(∃𝑥 𝐴)𝑣 = 1.
𝑡𝑣 = 𝑦𝑣 = 𝐸(𝑦) = 2.
94
By the definition of 𝑃 𝑣 , we have that
𝑣
𝐴(𝐼,𝐸[𝑥↦𝑡 ])
= 𝐴(𝐼,𝐸[𝑥↦2]) = 0
95
2.5.2 Additional Exercises
Exercise 124. Prove that the following inference rule is sound.
Exercise 126. Prove that the following inference rule is NOT sound.
Exercise 127. Prove that the following inference rule is NOT sound.
96
2.5.3 Proofs using the soundness and completeness theorems
Exercise 128. Let Σ be a set of Predicate formulas and let 𝐴 be a Predicate formula.
If Σ ∪ {(¬𝐴)} is unsatisfiable, then Σ ⊢ 𝐴.
Proof Sketch. Assume that Σ ∪ {(¬𝐴)} is unsatisfiable. This means that, for any interpre-
tation and environment (𝐼, 𝐸), at least one formula in Σ ∪ {(¬𝐴)} is false.
Prove that Σ ⊨ 𝐴. Consider an interpretation and environment (𝐼, 𝐸). Assume that every
formula in Σ is true under (𝐼, 𝐸). Prove that 𝐴 is true under (𝐼, 𝐸).
We have Σ ⊢ 𝐴 by the completeness of Natural Deduction.
Solution:
Remark 19. What does it mean for a set of formula Σ to be unsatisfiable?
• It means that “for every (𝐼, 𝐸), at least one formula in Σ is false.”
Example 1: The set {𝑃 (𝑥), (¬𝑃 (𝑥))} is unsatisfiable. Under any (𝐼, 𝐸), if 𝑃 (𝑥) is
true, then (¬𝑃 (𝑥)) must be false. If (¬𝑃 (𝑥)) is true, then 𝑃 (𝑥) must be false.
• It DOES NOT mean that “ for every (𝐼, 𝐸), at least one formula in Σ is a contradic-
tion.”
Example 2: The set {(𝑃 (𝑥) ∧ (¬𝑃 (𝑥)))} is unsatisfiable. Under any (𝐼, 𝐸), (𝑃 (𝑥) ∧
(¬𝑃 (𝑥))) is always false. Note that this is only one type of unsatisfiable set.
• It DOES NOT mean that “for one pair (𝐼, 𝐸), at least one formula in Σ is false.”
When proving the tautological consequence Σ ⊨ 𝐴, why do we only consider the cases when
every formula in Σ is true?
By the definition of tautological consequence, we only need to verify that 𝐴 is true in the case
when every formula in Σ is true under an (𝐼, 𝐸). Thus, we do not need to consider the case
when a formula in Σ is false under an (𝐼, 𝐸).
Solution Text: Assume that Σ ∪ {(¬𝐴)} is unsatisfiable. This means that, for any
interpretation and environment (𝐼, 𝐸), at least one formula in Σ ∪ {(¬𝐴)} is false.
We need to prove that Σ ⊨ 𝐴. Consider an interpretation and environment (𝐼, 𝐸). Assume
that every formula in Σ is true under (𝐼, 𝐸). We need to prove that 𝐴 is true under (𝐼, 𝐸).
Under the (𝐼, 𝐸) we are considering, every formula in Σ is true and at least one formula in
Σ ∪ {(¬𝐴)} is false. Therefore, it must be that (¬𝐴)𝑣 = 0. By the definition of ¬, 𝐴𝑣 = 1.
Therefore, the tautological consequence Σ ⊨ 𝐴 holds.
Σ ⊢ 𝐴 holds by the completeness of Natural Deduction.
Exercise 129. Let Σ be a set of Predicate formulas and let 𝐴 be a Predicate formula.
If Σ ⊢ 𝐴, then Σ ∪ {(¬𝐴)} is unsatisfiable.
Exercise 130. Show that there is no formal deduction proof for {(∃𝑥 𝑃 (𝑥))} ⊢ 𝑃 (𝑡), where
𝑃 is a unary predicate, 𝑡 is a term and 𝑥 is a variable.
97
3 Program Verification
3.1 Partial and Total Correctness
Exercise 131. Consider the Hoare triple ⦇ (𝑥 > 0) ⦈ 𝐶1 ⦇ ((𝑦 ∗ 𝑦) < 𝑥) ⦈.
If we run 𝐶1 starting with the state (𝑥 = 5), (𝑦 = 5), 𝐶1 terminates in the state (𝑥 = 5), (𝑦 =
0).
Is the Hoare triple satisfied under partial correctness?
98
Exercise 133. Consider the Hoare triple ⦇ (𝑥 > 0) ⦈ 𝐶3 ⦇ ((𝑦 ∗ 𝑦) < 𝑥) ⦈.
If we run 𝐶3 starting with the state (𝑥 = −3), (𝑦 = 5), 𝐶3 terminates in the state (𝑥 =
−3), (𝑦 = 0).
Is the Hoare triple satisfied under partial correctness?
99
Exercise 135. Is the following Hoare triple satisfied under partial and/or total correctness?
⦇ (𝑥 = 1) ⦈
while ( 1 ) {
x = 0
};
⦇ (𝑦 = 1) ⦈
Solution: The triple is satisfied under partial correctness, and it is not satisfied under total
correctness.
The program does not terminate for any starting state. Therefore, partial correctness is
automatically satisfied. (If the program does not terminate for a starting state, then the
premise of the implication is false and the implication is vacuously true.)
The program does not terminate for any starting state. Therefore, total correctness is NOT
satisfied.
The key difference between partial and total correctness is that partial correctness does not
require program termination, whereas total correctness does.
Exercise 136. Is the following Hoare triple satisfied under partial and/or total correctness?
⦇ 𝑡𝑟𝑢𝑒 ⦈
y = 1;
z = 0;
while ( z != x ) {
z = z + 1;
y = y ∗ z;
}
⦇ (𝑦 = 𝑥!) ⦈
Solution: The triple is satisfied under partial correctness, and it is NOT satisfied under
total correctness.
The precondition is true. This means that there is no required precondition. In other words,
any starting state satisfies the precondition.
If the starting state has 𝑥 ≥ 0, we can verify that the program terminates and computes
𝑦 = 𝑥! correctly. (We are not able to prove this yet because we haven’t learned the techniques
to construct the proof. However, we could verify this on a case-by-case basis.) Therefore,
for this case, partial and total correctness are both satisfied.
If the starting state has 𝑥 < 0, the while loop runs forever and does not terminate. Therefore,
for this case, only partial correctness is satisfied. Total correctness is not satisfied because
the program does not terminate.
In summary, partial correctness is satisfied because it is satisfied in both cases. Total cor-
rectness is NOT satisfied because the program does not terminate for some starting states
where 𝑥 < 0.
100
3.2 Assignment Statements
Complete the following annotations.
⦇ ⦈
x = 2;
⦇ (𝑥 = 2) ⦈
Solution:
⦇ (2 = 2) ⦈
x = 2;
⦇ (𝑥 = 2) ⦈ assignment
⦇ ⦈
x = 2;
⦇ (𝑥 = 𝑦) ⦈
Solution:
⦇ (2 = 𝑦) ⦈
x = 2;
⦇ (𝑥 = 𝑦) ⦈ assignment
⦇ ⦈
x = 2;
⦇ (𝑥 = 0) ⦈
Solution:
⦇ (2 = 0) ⦈
x = 2;
⦇ (𝑥 = 0) ⦈ assignment
101
⦇ ⦈
x = x + 1;
⦇ (𝑥 = (𝑛 + 1)) ⦈
Solution:
⦇ ((𝑥 + 1) = (𝑛 + 1)) ⦈
x = x + 1;
⦇ (𝑥 = (𝑛 + 1)) ⦈ assignment
⦇ ⦈
x = y;
⦇ ((2 ∗ 𝑥) = (𝑥 + 𝑦)) ⦈
Solution:
⦇ ((2 ∗ 𝑦) = (𝑦 + 𝑦)) ⦈
x = y;
⦇ ((2 ∗ 𝑥) = (𝑥 + 𝑦)) ⦈ assignment
102
Exercise 137. Show that the following triple is satisfied under partial correctness.
⦇ (𝑦 = 6) ⦈
x = y + 1;
⦇ (𝑥 = 7) ⦈
Solution:
⦇ (𝑦 = 6) ⦈
⦇ ((𝑦 + 1) = 7) ⦈ i m p l i e d (A)
x = y + 1;
⦇ (𝑥 = 7) ⦈ assignment
Proof of implied (A):
Assume that 𝑦 = 6. Adding 1 to both sides, we get 𝑦 + 1 = 6 + 1 = 7.
Exercise 138. Show that the following triple is satisfied under partial correctness.
⦇ ((𝑥 = 𝑥0 ) ∧ (𝑦 = 𝑦0 )) ⦈
t = x;
x = y;
y = t;
⦇ ((𝑥 = 𝑦0 ) ∧ (𝑦 = 𝑥0 )) ⦈
Solution:
⦇ ((𝑥 = 𝑥0 ) ∧ (𝑦 = 𝑦0 )) ⦈
⦇ ((𝑦 = 𝑦0 ) ∧ (𝑥 = 𝑥0 )) ⦈ i m p l i e d (A)
t = x;
⦇ ((𝑦 = 𝑦0 ) ∧ (𝑡 = 𝑥0 )) ⦈ assignment
x = y;
⦇ ((𝑥 = 𝑦0 ) ∧ (𝑡 = 𝑥0 )) ⦈ assignment
y = t;
⦇ ((𝑥 = 𝑦0 ) ∧ (𝑦 = 𝑥0 )) ⦈ assignment
Proof of implied (A):
Assume that ((𝑥 = 𝑥0 ) ∧ (𝑦 = 𝑦0 )) is true. By the definition of ∧, 𝑥 = 𝑥0 and 𝑦 = 𝑦0 are
both true. By the definition of ∧, ((𝑦 = 𝑦0 ) ∧ (𝑥 = 𝑥0 )) is true.
103
3.3 Conditional Statements
Exercise 139. Show that the following triple is satisfied under partial correctness.
⦇ 𝑡𝑟𝑢𝑒 ⦈
if (x > y) {
max = x ;
} else {
max = y ;
}
⦇ (((𝑥 > 𝑦) ∧ (𝑚𝑎𝑥 = 𝑥)) ∨ ((𝑥 ≤ 𝑦) ∧ (𝑚𝑎𝑥 = 𝑦))) ⦈
Solution:
⦇ 𝑡𝑟𝑢𝑒 ⦈
if (x > y) {
⦇ (𝑥 > 𝑦) ⦈ i f −then−e l s e
⦇ (((𝑥 > 𝑦) ∧ (𝑥 = 𝑥)) ∨ ((𝑥 ≤ 𝑦) ∧ (𝑥 = 𝑦))) ⦈ i m p l i e d (A)
max = x ;
⦇ (((𝑥 > 𝑦) ∧ (𝑚𝑎𝑥 = 𝑥)) ∨ ((𝑥 ≤ 𝑦) ∧ (𝑚𝑎𝑥 = 𝑦))) ⦈ assignment
} else {
⦇ (¬(𝑥 > 𝑦)) ⦈ i f −then−e l s e
⦇ (((𝑥 > 𝑦) ∧ (𝑦 = 𝑥)) ∨ ((𝑥 ≤ 𝑦) ∧ (𝑦 = 𝑦))) ⦈ i m p l i e d (B)
max = y ;
⦇ (((𝑥 > 𝑦) ∧ (𝑚𝑎𝑥 = 𝑥)) ∨ ((𝑥 ≤ 𝑦) ∧ (𝑚𝑎𝑥 = 𝑦))) ⦈ assignment
}
⦇ (((𝑥 > 𝑦) ∧ (𝑚𝑎𝑥 = 𝑥)) ∨ ((𝑥 ≤ 𝑦) ∧ (𝑚𝑎𝑥 = 𝑦))) ⦈ i f −then−e l s e
104
Exercise 140. Show that the following triple is satisfied under partial correctness.
⦇ (𝑥 = 3) ⦈
i f ( x > 0) {
x = 1;
} else {
x = 0;
}
⦇ (𝑥 ≥ 0) ⦈
Solution:
⦇ (𝑥 = 3) ⦈
i f ( x > 0) {
⦇ ((𝑥 = 3) ∧ (𝑥 > 0)) ⦈ i f −then−e l s e
⦇ (1 ≥ 0) ⦈ i m p l i e d (A)
x = 1;
⦇ (𝑥 ≥ 0) ⦈ assignment
} else {
⦇ ((𝑥 = 3) ∧ (¬(𝑥 > 0))) ⦈ i f −then−e l s e
⦇ (0 ≥ 0) ⦈ i m p l i e d (B)
x = 0;
⦇ (𝑥 ≥ 0) ⦈ assignment
}
⦇ (𝑥 ≥ 0) ⦈ i f −then−e l s e
105
Exercise 141. Show that the following triple is satisfied under partial correctness.
⦇ 𝑡𝑟𝑢𝑒 ⦈
i f ( max < x ) {
max = x ;
}
⦇ (𝑚𝑎𝑥 ≥ 𝑥) ⦈
Solution:
⦇ 𝑡𝑟𝑢𝑒 ⦈
i f ( max < x ) {
⦇ (𝑚𝑎𝑥 < 𝑥) ⦈ i f −then
⦇ (𝑥 ≥ 𝑥) ⦈ i m p l i e d (A)
max = x ;
⦇ (𝑚𝑎𝑥 ≥ 𝑥) ⦈ assignment
}
⦇ (𝑚𝑎𝑥 ≥ 𝑥) ⦈ i f −then
i m p l i e d (B) ((¬(𝑚𝑎𝑥 < 𝑥)) → (𝑚𝑎𝑥 ≥ 𝑥))
106
Exercise 142. Show that the following triple is satisfied under partial correctness.
⦇ 𝑡𝑟𝑢𝑒 ⦈
i f ( x % 2 == 1 ) {
x = x + 1;
}
⦇ (∃𝑢 (𝑥 = (2 ∗ 𝑢))) ⦈
Solution:
⦇ 𝑡𝑟𝑢𝑒 ⦈
i f ( x % 2 == 1 ) {
⦇ ((𝑥%2) = 1) ⦈ i f −then
⦇ (∃𝑢 (𝑥 + 1 = (2 ∗ 𝑢))) ⦈ i m p l i e d (A)
x = x + 1;
⦇ (∃𝑢 (𝑥 = (2 ∗ 𝑢))) ⦈ assignment
}
⦇ (∃𝑢 (𝑥 = (2 ∗ 𝑢))) ⦈ i f −then
i m p l i e d (B) ((¬(𝑥%2 = 1)) → ((∃𝑢 (𝑥 = (2 ∗ 𝑢)))))
107
Exercise 143. Show that the following triple is satisfied under partial correctness.
⦇ 𝑡𝑟𝑢𝑒 ⦈
i f ( x < 5) {
r = 0;
} else {
i f ( x > 10) {
r = 0;
} else {
r = 1;
}
}
⦇ ((((𝑥 < 5) ∨ (𝑥 > 10)) ∧ (𝑟 = 0)) ∨ (((5 ≤ 𝑥) ∧ (𝑥 ≤ 10)) ∧ (𝑟 = 1))) ⦈
Solution:
⦇ 𝑡𝑟𝑢𝑒 ⦈
i f ( x < 5) {
⦇ 𝑡𝑟𝑢𝑒 ∧ (𝑥 < 5) ⦈ i f −then−e l s e
⦇ ((((𝑥 < 5) ∨ (𝑥 > 10)) ∧ (0 = 0)) ∨ (((5 ≤ 𝑥) ∧ (𝑥 ≤ 10)) ∧ (0 = 1))) ⦈ i m p l i e d (A)
r = 0;
⦇ ((((𝑥 < 5) ∨ (𝑥 > 10)) ∧ (𝑟 = 0)) ∨ (((5 ≤ 𝑥) ∧ (𝑥 ≤ 10)) ∧ (𝑟 = 1))) ⦈ assignment
} else {
⦇ 𝑡𝑟𝑢𝑒 ∧ (𝑥 ≥ 5) ⦈ i f −then−e l s e
i f ( x > 10) {
⦇ 𝑡𝑟𝑢𝑒 ∧ (𝑥 ≥ 5) ∧ (𝑥 > 10) ⦈ i f −then−e l s e
⦇ ((((𝑥 < 5) ∨ (𝑥 > 10)) ∧ (0 = 0)) ∨ (((5 ≤ 𝑥) ∧ (𝑥 ≤ 10)) ∧ (0 = 1))) ⦈ i m p l i e d (B)
r = 0;
⦇ ((((𝑥 < 5) ∨ (𝑥 > 10)) ∧ (𝑟 = 0)) ∨ (((5 ≤ 𝑥) ∧ (𝑥 ≤ 10)) ∧ (𝑟 = 1))) ⦈ assignment
} else {
⦇ 𝑡𝑟𝑢𝑒 ∧ (𝑥 ≥ 5) ∧ (𝑥 ≤ 10) ⦈ i f −then−e l s e
⦇ ((((𝑥 < 5) ∨ (𝑥 > 10)) ∧ (1 = 0)) ∨ (((5 ≤ 𝑥) ∧ (𝑥 ≤ 10)) ∧ (1 = 1))) ⦈ i m p l i e d (C)
r = 1;
⦇ ((((𝑥 < 5) ∨ (𝑥 > 10)) ∧ (𝑟 = 0)) ∨ (((5 ≤ 𝑥) ∧ (𝑥 ≤ 10)) ∧ (𝑟 = 1))) ⦈ assignment
}
⦇ ((((𝑥 < 5) ∨ (𝑥 > 10)) ∧ (𝑟 = 0)) ∨ (((5 ≤ 𝑥) ∧ (𝑥 ≤ 10)) ∧ (𝑟 = 1))) ⦈ i f −then−e l s e
}
⦇ ((((𝑥 < 5) ∨ (𝑥 > 10)) ∧ (𝑟 = 0)) ∨ (((5 ≤ 𝑥) ∧ (𝑥 ≤ 10)) ∧ (𝑟 = 1))) ⦈ i f −then−e l s e
108
3.4 Conditional Statements: Additional Exercises
Exercise 144. Show that the following triple is satisfied under partial correctness.
⦇ 𝑡𝑟𝑢𝑒 ⦈
x = a ∗ a;
y = b ∗ b;
z = x + y;
if (b > a) {
z = z + 2 ∗ a ∗ b;
} else {
z = z − 2 ∗ a ∗ b;
}
⦇ ((∃𝑢 (𝑢 ∗ 𝑢 = 𝑧)) ⦈
109
3.5 While Loops
Exercise 145. Show that the following triple is satisfied under partial correctness.
⦇ (𝑥 ≥ 0) ⦈
y = 1;
z = 0;
while ( z != x ) {
z = z + 1;
y = y ∗ z;
}
⦇ (𝑦 = 𝑥!) ⦈
Remark 20. There is a while loop in the program. To complete the proof, we need to come
up with an invariant for the while loop. We produce the following table, which contains
the values of all the variables in the program whenever the execution reaches the while test
𝑧! = 𝑥.
Note: We can choose any non-negative value for 𝑥. For the following table, we chose 𝑥 = 5.
Note: In the table, I wrote 𝑦 as a factorial. Doing this is helpful for seeing a relationship
between the variables (With this, it is easy to see that 𝑦 = 𝑧! in every row of the table). Also,
the post-condition says that 𝑦 should be a factorial. If we want to make progress towards that
post-condition, then it makes sense that 𝑦 is equal to some factorial at every iteration of the
loop.
x z y
5 0 1 = 0!
5 1 1 = 1!
5 2 2 = 2!
5 3 6 = 3!
5 4 24 = 4!
5 5 120 = 5!
Given the table, we can try to come up with relationship between the variables. For the
relationship to be an invariant, it has to be true in every row of the truth table.
For example,
• (¬(𝑧 = 𝑥)) is NOT an invariant. It is NOT true in the last row of the table.
• (𝑦 = 𝑥!) is NOT an invariant. It is only true in the last row of the table and not true
in any other row.
110
• ((𝑧 ≤ 𝑥) ∧ (𝑦 = 𝑧!)) IS an invariant.
Note: We can combine one or more invariants with an ∧ to produce new invariants. If 𝐴
and 𝐵 are invariants, then (𝐴 ∧ 𝐵) is an invariant as well.
So far, we have found three invariants: (𝑧 ≤ 𝑥), (𝑦 = 𝑧!), and ((𝑧 ≤ 𝑥) ∧ (𝑦 = 𝑧!)). Which
of these invariants will lead to valid proofs? It turns out that both the second and third
invariants will both lead to valid proofs.
How do I choose an invariant to complete my proof? The only sure way of answering this
question is to try completing the proof with the invariant. The proof is valid if and only if
we can prove all of the implied conditions using the invariant.
However, there are two strategies to speed up this process of selecting ani nvariant that works.
• The last implied condition (implied C) is often the most difficult to satisfy.
Thus, to test whether an invariant works, it may be more efficient to try proving implied
(C) first.
Solution:
⦇ (𝑥 ≥ 0) ⦈
⦇ (1 = 0!) ⦈ i m p l i e d (A)
y = 1;
⦇ (𝑦 = 0!) ⦈ assignment
z = 0;
⦇ (𝑦 = 𝑧!) ⦈ assignment
while ( z != x ) {
⦇ ((𝑦 = 𝑧!) ∧ (¬(𝑧 = 𝑥))) ⦈ p a r t i a l −while
⦇ ((𝑦 ∗ (𝑧 + 1)) = (𝑧 + 1)!) ⦈ i m p l i e d (B)
z = z + 1;
⦇ ((𝑦 ∗ 𝑧) = 𝑧!) ⦈ assignment
y = y ∗ z;
⦇ (𝑦 = 𝑧!) ⦈ assignment
}
⦇ ((𝑦 = 𝑧!) ∧ (¬(¬(𝑧 = 𝑥)))) ⦈ p a r t i a l −while
⦇ (𝑦 = 𝑥!) ⦈ i m p l i e d (C)
111
Proof of implied (A):
Assume that (𝑥 ≥ 0) is true. (1 = 0!) is true by the definition of factorial.
Proof of implied (B):
Assume that (𝑦 = 𝑧!) and (¬(𝑧 = 𝑥)) are true.
Multiplying (𝑧 + 1) on both sides of (𝑦 = 𝑧!), we get that 𝑦 ∗ (𝑧 + 1) = (𝑧 + 1)! is true.
Proof of implied (C):
Assume that (𝑦 = 𝑧!) and (¬(¬(𝑧 = 𝑥))) are true. By the definition of ¬, (¬(¬(𝑧 = 𝑥)))
is equivalent to (𝑧 = 𝑥). Since (𝑦 = 𝑧!) and (𝑧 = 𝑥) are both true, we know that (𝑦 = 𝑥!)
must be true.
112
Exercise 146. Show that the following triple is satisfied under partial correctness.
⦇ (𝑥 ≥ 0) ⦈
y = 1;
z = 0;
while ( z < x ) {
z = z + 1;
y = y ∗ z;
}
⦇ (𝑦 = 𝑥!) ⦈
Solution:
⦇ (𝑥 ≥ 0) ⦈
⦇ ((1 = 0!) ∧ (0 ≤ 𝑥)) ⦈ i m p l i e d (A)
y = 1;
⦇ ((𝑦 = 0!) ∧ (0 ≤ 𝑥)) ⦈ assignment
z = 0;
⦇ ((𝑦 = 𝑧!) ∧ (𝑧 ≤ 𝑥)) ⦈ assignment
while ( z < x ) {
⦇ (((𝑦 = 𝑧!) ∧ (𝑧 ≤ 𝑥)) ∧ (𝑧 < 𝑥)) ⦈ p a r t i a l −while
⦇ (𝑦 ∗ (𝑧 + 1) = (𝑧 + 1)!) ⦈ i m p l i e d (B)
z = z + 1;
⦇ (𝑦 ∗ 𝑧 = 𝑧!) ⦈ assignment
y = y ∗ z;
⦇ (𝑦 = 𝑧!) ⦈ assignment
}
⦇ (((𝑦 = 𝑧!) ∧ (𝑧 ≤ 𝑥)) ∧ (¬(𝑧 < 𝑥))) ⦈ p a r t i a l −while
⦇ (𝑦 = 𝑥!) ⦈ i m p l i e d (C)
113
3.6 While Loops: Additional Exercises
Exercise 147. Show that the following triple is satisfied under partial correctness.
⦇ ((𝑛 ≥ 0) ∧ (𝑎 ≥ 0)) ⦈
s = 1;
i = 0;
while ( i != n ) {
s = s ∗ a;
i = i + 1;
}
⦇ (𝑠 = 𝑎𝑛 ) ⦈
Exercise 148. Show that the following triple is satisfied under partial correctness.
⦇ ((𝑛 ≥ 0) ∧ (𝑎 ≥ 0)) ⦈
s = 1;
i = 0;
while ( i < n ) {
s = s ∗ a;
i = i + 1;
}
⦇ (𝑠 = 𝑎𝑛 ) ⦈
114
3.7 Array Assignments
Exercise 149. Show that the following triple is satisfied under partial correctness.
⦇ ((𝐴[𝑥] = 𝑥0) ∧ (𝐴[𝑦] = 𝑦0)) ⦈
t = A[ x ] ;
A[ x ] = A[ y ] ;
A[ y ] = t ;
⦇ ((𝐴[𝑥] = 𝑦0) ∧ (𝐴[𝑦] = 𝑥0)) ⦈ array assignment
Solution:
⦇ ((𝐴[𝑥] = 𝑥0) ∧ (𝐴[𝑦] = 𝑦0)) ⦈
⦇ ((𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝐴[𝑥]}[𝑥] = 𝑦0) ∧ (𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝐴[𝑥]}[𝑦] = 𝑥0)) ⦈ i m p l i e d
t = A[ x ] ;
⦇ ((𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝑡}[𝑥] = 𝑦0) ∧ (𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝑡}[𝑦] = 𝑥0)) ⦈ a s s i g n m e n t
A[ x ] = A[ y ] ;
⦇ ((𝐴{𝑦 ← 𝑡}[𝑥] = 𝑦0) ∧ (𝐴{𝑦 ← 𝑡}[𝑦] = 𝑥0)) ⦈ array assignment
A[ y ] = t ;
⦇ ((𝐴[𝑥] = 𝑦0) ∧ (𝐴[𝑦] = 𝑥0)) ⦈ array assignment
Proof of implied:
We will prove that ((𝐴[𝑥] = 𝑥0) ∧ (𝐴[𝑦] = 𝑦0)) → (((𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝐴[𝑥]}[𝑥] =
𝑦0) ∧ (𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝐴[𝑥]}[𝑦] = 𝑥0)).
Proof. Case 1: Assume that 𝑥 = 𝑦. Assume that 𝐴[𝑥] = 𝑥0 and 𝐴[𝑦] = 𝑦0 are true.
Since 𝑥 = 𝑦, we can re-write the conclusion as follows.
𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝐴[𝑥]}[𝑥] = 𝐴{𝑦 ← 𝐴[𝑦]}{𝑦 ← 𝐴[𝑦]}[𝑦] = 𝐴[𝑦] = 𝑦0, and
𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝐴[𝑥]}[𝑦] = 𝐴{𝑥 ← 𝐴[𝑥]}{𝑥 ← 𝐴[𝑥]}[𝑥] = 𝐴[𝑥] = 𝑥0.
Case 2: Assume that 𝑥 ≠ 𝑦. Assume that 𝐴[𝑥] = 𝑥0 and 𝐴[𝑦] = 𝑦0 are true.
Consider the array 𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝐴[𝑥]}. The first assignment {𝑥 ← 𝐴[𝑦]} changes
the 𝑥th element of the array to 𝐴[𝑦]. The second assignment {𝑦 ← 𝐴[𝑥]} changes the 𝑦th
element of the array to 𝐴[𝑥]. Since 𝑥 ≠ 𝑦, the two assignments are modifying two different
elements in the array and do not affect each other.
Therefore, we have that
𝐴{𝑥 ← 𝐴[𝑦]}{𝑦 ← 𝐴[𝑥]}[𝑦] = 𝐴[𝑥] = 𝑥0.
because the second assignment changes the 𝑦th element to 𝐴[𝑥].
115
3.8 Putting them together
Exercise 150. (Reversing an array)
Consider an array 𝑅 of 𝑛 integers, 𝑅[1], 𝑅[2], ..., 𝑅[𝑛].
Consider the following program which reverses the elements inside the array 𝑅.
Let 𝑟𝑥 denote the element at index 𝑥 in the array 𝑅 before the program execution.
Prove that the following triple is satisfied under total correctness.
⦇ ((∀𝑥 (1 ≤ 𝑥 ≤ 𝑛 → 𝑅[𝑥] = 𝑟𝑥 ))) ⦈
j = 1;
while (2 ∗ j <= n ) {
t = R[ j ] ;
R[ j ] = R[ n+1− j ] ;
R[ n+1− j ] = t ;
j = j + 1;
}
⦇ ((∀𝑥 (1 ≤ 𝑥 ≤ 𝑛 → 𝑅[𝑥] = 𝑟𝑛+1−𝑥 ))) ⦈
Solution: Since there is a while loop in the program, we need to come up with an invariant
for the while loop.
Consider the following invariant.
Using the above invariant, we complete the annotations for the program as shown below.
⦇ (∀𝑥 (1 ≤ 𝑥 ≤ 𝑛 → 𝑅[𝑥] = 𝑟𝑥 )) ⦈
⦇ 𝐼𝑛𝑣(1) ⦈ i m p l i e d (A)
j = 1;
⦇ 𝐼𝑛𝑣(𝑗) ⦈ assignment
while ( 2 ∗ j <= n ) {
⦇ (𝐼𝑛𝑣(𝑗) ∧ (2 ∗ 𝑗 ≤ 𝑛)) ⦈ p a r t i a l −while
⦇ 𝐼𝑛𝑣(𝑗 + 1)[𝑅{𝑗 ← 𝑅[𝑛 + 1 − 𝑗]}{𝑛 + 1 − 𝑗 ← 𝑅[𝑗]}/𝑅] ⦈ i m p l i e d (B)
t = R[ j ] ;
⦇ 𝐼𝑛𝑣(𝑗 + 1)[𝑅{𝑗 ← 𝑅[𝑛 + 1 − 𝑗]}{𝑛 + 1 − 𝑗 ← 𝑡}/𝑅] ⦈ a s s i g n m e n t
R [ j ] = R [ n+1− j ] ;
⦇ 𝐼𝑛𝑣(𝑗 + 1)[𝑅{𝑛 + 1 − 𝑗 ← 𝑡}/𝑅] ⦈ a r r a y a s s i g n m e n t
R [ n+1− j ] = t ;
⦇ 𝐼𝑛𝑣(𝑗 + 1) ⦈ array assignment
j = j + 1;
⦇ 𝐼𝑛𝑣(𝑗) ⦈ a s s i g n m e n t
}
116
⦇ (𝐼𝑛𝑣(𝑗) ∧ (¬(2 ∗ 𝑗 ≤ 𝑛))) ⦈ p a r t i a l −while
⦇ ((∀𝑥 (1 ≤ 𝑥 ≤ 𝑛 → 𝑅[𝑥] = 𝑟𝑛+1−𝑥 ))) ⦈ i m p l i e d (C)
It remains to prove the implied (A), (B), and (C).
To prove implied (C), we first prove Lemma 3 below.
Proof. Starting with the top formula is logically equivalent to the following formula
1≤𝑛+1−𝑦 →𝑦 ≤𝑛
𝑛 + 1 − 𝑦 ≤ (𝑛 + 1)/2 → 𝑦 ≥ (𝑛 + 1)/2
Thus, the inequality becomes:
(𝑛 + 1)/2 ≤ 𝑦 ≤ 𝑛
The formula becomes:
117
Implied (A):
(∀𝑥 (1 ≤ 𝑥 ≤ 𝑛 → 𝑅[𝑥] = 𝑟𝑥 )) → 𝐼𝑛𝑣(1)
Proof. Assume that the premise is true. Our goal is to prove that the conclusion is true.
Let’s simplify the conclusion below.
The conclusion is 𝐼𝑛𝑣(1). Take the invariant 𝐼𝑛𝑣(𝑗) and plug in 𝑗 = 1, we have
1 ≤ 𝑥 ≤ 0 is always false for any integer 𝑥. Thus the first part of the above formula is always
true. We can simplify the formula to the following.
We can further simplify 1 ≤ 𝑛/2 + 1 and get 0 ≤ 𝑛. The formula becomes the following:
Note that 0 ≤ 𝑛 is true because 𝑛 is positive. There is an implicit assumption that the array
has at least one element. By Lemma 3, formula 134 is logically equivalent to the premise.
Therefore, the implied holds.
118
To prove implied (C), we first prove Lemma 4 below.
Lemma 4. Assume that 𝑛 is odd (The array 𝑅 has an odd number of elements). The two
formulas below are logically equivalent.
Proof.
119
Implied (C):
(𝐼𝑛𝑣(𝑗) ∧ (¬(2 ∗ 𝑗 ≤ 𝑛))) → ((∀𝑥 (1 ≤ 𝑥 ≤ 𝑛 → 𝑅[𝑥] = 𝑟𝑛+1−𝑥 )))
Proof. Let’s simplify the premise.
120
Implied (B):
Proof. For convenience, let’s define 𝐼𝑛𝑣𝑝 (𝑗) to be the following formula:
For convenience, let 𝑅′ denote 𝑅{𝑗 ← 𝑅[𝑛 + 1 − 𝑗]}{𝑛 + 1 − 𝑗 ← 𝑅[𝑗]}. The conclusion of
implied (B) becomes
To prove implied (B), it is sufficient for us to prove the following two implications:
Implication 1: ((𝑗 ≤ 𝑛/2 + 1)) ∧ (2𝑗 ≤ 𝑛)) → (𝑗 ≤ 𝑛/2).
Proof of implication 1: Assume that (𝑗 ≤ 𝑛/2 + 1)) and (2𝑗 ≤ 𝑛) are true. (2𝑗 ≤ 𝑛) is
equivalent to (𝑗 ≤ 𝑛/2). Since 𝑛/2 < 𝑛/2 + 1, we know that (𝑗 ≤ 𝑛/2), which is the
conclusion that we need.
Implication 2: 𝐼𝑛𝑣𝑝 (𝑗) → 𝐼𝑛𝑣𝑝 (𝑗 + 1)[𝑅′ /𝑅].
Proof of implication 2: Let’s recall that what 𝐼𝑛𝑣𝑝 (𝑗) and 𝐼𝑛𝑣𝑝 (𝑗 + 1)[𝑅′ /𝑅] are.
Recall that 𝑅′ = 𝑅{𝑗 ← 𝑅[𝑛 + 1 − 𝑗]}{𝑛 + 1 − 𝑗 ← 𝑅[𝑗]}. The two assignments only
potentially affect the elements at indices 𝑗 and 𝑛 + 1 − 𝑗. Thus, for any index 𝑥 where
121
1 ≤ 𝑥 ≤ 𝑗 − 1, the element of 𝑅 is not affected. Thus, for any 1 ≤ 𝑥 ≤ 𝑗 − 1, 𝑅[𝑥] = 𝑅′ [𝑥].
Thus, the implication holds.
For 𝑗 + 1 ≤ 𝑥 ≤ (𝑛 + 1)/2,
Recall that 𝑅′ = 𝑅{𝑗 ← 𝑅[𝑛 + 1 − 𝑗]}{𝑛 + 1 − 𝑗 ← 𝑅[𝑗]}. The two assignments only
potentially affect the elements at indices 𝑗 and 𝑛 + 1 − 𝑗. Thus, for any index 𝑥 where
𝑗 + 1 ≤ 𝑥 ≤ (𝑛 + 1)/2, the element of 𝑅 is not affected. Thus, for any 𝑗 + 1 ≤ 𝑥 ≤ (𝑛 + 1)/2,
𝑅[𝑥] = 𝑅′ [𝑥]. Thus, the implication holds.
For 𝑥 = 𝑗,
by the first assignment {𝑗 ← 𝑅[𝑛+1−𝑗]} and by our assumption that 𝑅[𝑛+1−𝑗] = 𝑟𝑛+1−𝑗 .
122
4 Undecidability
4.1 Prove that a problem is decidable
Collected Wisdom:
• When you describe an algorithm, make sure that it terminates. For example, if a set
𝑆 is infinite, your algorithm cannot iterate through every element of 𝑆. For another
example, it is okay to draw the truth table of a given formula because the truth table
has finite size.
• An algorithm usually considers several cases. Make sure that you clearly indicate the
return value of the algorithm in every case.
Solution: We are given the propositional formula 𝐴. We will draw the truth table of 𝐴.
The formula 𝐴 must have a finite number of propositional variables in it. Therefore, the
truth table will have a finite size and we will need a finite amount of time to draw the truth
table.
We will go through every cell in the final column of the truth table, where the truth value
of 𝐴 is indicated. If we can find one row of the truth table in which 𝐴 is true, then 𝐴 is
satisfiable. Otherwise, if 𝐴 is false in every row of the truth table, then 𝐴 is not satisfiable.
123
4.2 The Halting Problem is Undecidable
Exercise 153. The Halting Problem: Given a program 𝑃 and an input 𝐼, does P terminate
when run with input 𝐼?
Prove that the Halting Problem is undecidable.
Solution: This proof is adapted from a proof by Luwei Zhang. Thanks, Luwei!
Proof by Contradiction. Assume that the halting problem is decidable. There exists an
algorithm 𝐻 such that 𝐻 takes a program 𝑃 and an input 𝐼 for 𝐼 and returns yes if 𝑃
terminates when run with input 𝐼 and no otherwise.
We will construct a program 𝑋 which takes a program 𝑌 as its input. 𝑋 works as follows.
• 𝑋 called 𝐻(𝑌 , 𝑌 ) to predict whether program 𝑌 will terminate when run with input
𝑌.
• If 𝐻(𝑌 , 𝑌 ) returns yes, 𝑋 goes into an infinite loop and does not terminate.
Now, consider what happens if we run the program 𝑋 with itself as input.
Suppose that 𝐻 predicts that 𝑋 terminates when run with input 𝑋. Then by the construc-
tion of 𝑋, when 𝐻(𝑋, 𝑋) returns yes, 𝑋 goes into an infinite loop and does not terminate.
𝐻’s prediction was wrong.
Suppose that 𝐻 predicts that 𝑋 does not terminate when run with input 𝑋. Then by the
construction of 𝑋, when 𝐻(𝑋, 𝑋) returns no, 𝑋 terminates immediately. 𝐻’s prediction
was wrong again.
Therefore, 𝐻 does not correctly predict whether 𝑋 terminates when run with input 𝑋. This
contradicts with our assumption that 𝐻 can decide the Halting Problem.
124
4.3 Prove that a problem is undecidable
Collected Wisdom:
• Suppose that we are trying to prove that problem 𝑋 is undecidable. In your reduction,
make the inputs to the algorithm for solving problem 𝑋 relate to 𝑃 and 𝐼. After all,
we are trying to construct an algorithm to determine whether 𝑃 terminates when run
with input 𝐼.
• To verify whether a reduction leads to a valid proof, consider two different cases: (1)
𝑃 terminates when run with input 𝐼. (2) 𝑃 does not terminate when run with input
𝐼. A reduction works if and only if the constructed algorithm gives the correct answer
for both cases.
125
Exercise 154. The halting-no-input problem: Given a program 𝑃 that requires no input,
does 𝑃 halt?
Prove that the halting-no-input problem is undecidable.
Solution:
Proof by Contradiction. Assume that there is an algorithm 𝐵 which solves the halting-no-
input problem. We will construct an algorithm 𝐴 to solve the halting problem.
Algorithm 𝐴 takes two inputs a program 𝑃 and an input 𝐼. It works as follows:
• Runs algorithm 𝐵 with the program 𝑃 ′ as the input and returns the result 𝐵(𝑃 ′ ).
126
Exercise 155. The both-halt problem: Given two programs 𝑃 1 and 𝑃 2 that take no input,
do both programs halt?
Prove that the both-halt problem is undecidable.
Solution:
Proof by Contradiction. Assume that there is an algorithm 𝐵 which solves the both-halt
problem. We will construct an algorithm 𝐴 to solve the halting problem.
Algorithm 𝐴 takes two inputs a program 𝑃 and an input 𝐼. It works as follows:
• Runs algorithm 𝐵 with the two programs 𝑃 ′ and 𝑃 ′ as its inputs and returns the
result 𝐵(𝑃 ′ , 𝑃 ′ ).
By our construction of algorithm 𝐴, both programs 𝑃 ′ and 𝑃 ′ halt if and only if 𝑃 halts on
input 𝐼. Therefore, if algorithm 𝐵 solves the both-halt problem for inputs 𝑃 ′ and 𝑃 ′ , then
the algorithm 𝐴 solves the halting problem for inputs 𝑃 and 𝐼.
By our assumption, algorithm 𝐵 solves the both-halt problem. Thus, algorithm 𝐴 solves the
halting problem.
This contradicts the fact that the halting problem is undecidable.
• Let 𝑃 1 contain an infinite loop. Let 𝑃 2 run 𝑃 with input 𝐼. (This does NOT work.)
127
Exercise 156. We say that two problems agree on all input if and only if, for every input
𝑥, either they both run forever, or they both halt and return the same value.
The program-agreement problem: Given two programs, do they agree on all inputs?
Prove that the program-agreement problem is undecidable.
128
Exercise 157. The total-correctness problem: Given a Hoare triple, is the triple satisfied
under total correctness?
Prove that the total correctness problem is undecidable.
129
Exercise 158. The partial-correctness problem: Given a Hoare triple, is the triple satisfied
under partial correctness?
Prove that the partial-correctness problem is undecidable.
Solution:
Proof by Contradiction. Assume that there is an algorithm 𝐵 which solves the total-correctness
problem. We will construct an algorithm 𝐴 to solve the halting problem.
Algorithm 𝐴 takes two inputs a program 𝑃 and an input 𝐼. It works as follows:
• Runs algorithm 𝐵 with the Hoare triple ⦇ 𝑡𝑟𝑢𝑒 ⦈ 𝑃 ′ ⦇ 𝑓𝑎𝑙𝑠𝑒 ⦈ as its input.
• Return the negation of the result 𝐵(⦇ 𝑡𝑟𝑢𝑒 ⦈ 𝑃 ′ ⦇ 𝑓𝑎𝑙𝑠𝑒 ⦈). (If 𝐵 returns true, then 𝐴
returns false, and vice versa.)
If the program 𝑃 ′ terminates, then the triple ⦇ 𝑡𝑟𝑢𝑒 ⦈ 𝑃 ′ ⦇ 𝑓𝑎𝑙𝑠𝑒 ⦈ is NOT satisfied under
partial correctness because the postcondition is false. Therefore, the only way for the triple
to be satisfied under partial correctness is when 𝑃 ′ does not terminate.
By our construction of algorithm 𝐴, 𝑃 halts on input 𝐼 if and only if 𝑃 ′ halts. 𝑃 ′ halts if
and only if the triple ⦇ 𝑡𝑟𝑢𝑒 ⦈ 𝑃 ′ ⦇ 𝑓𝑎𝑙𝑠𝑒 ⦈ is NOT satisfied under partial correctness. Thus,
𝑃 halts on input 𝐼 if and only if the triple ⦇ 𝑡𝑟𝑢𝑒 ⦈ 𝑃 ′ ⦇ 𝑓𝑎𝑙𝑠𝑒 ⦈ is NOT satisfied under
partial correctness.
Therefore, if algorithm 𝐵 solves the partial-correctness problem for input ⦇ 𝑡𝑟𝑢𝑒 ⦈ 𝑃 ′ ⦇ 𝑓𝑎𝑙𝑠𝑒 ⦈,
then the algorithm 𝐴 solves the halting problem for inputs 𝑃 and 𝐼.
By our assumption, algorithm 𝐵 solves the partial-correctness problem. Thus, algorithm 𝐴
solves the halting problem.
This contradicts the fact that the halting problem is undecidable.
130
Exercise 159. The exists-halting-input problem: Given a program 𝑃 , does there exist an
input 𝐼 such that 𝑃 halts with input 𝐼?
Prove that this problem is undecidable.
131
Exercise 160. The halt-every-input problem: Given a program 𝑃 , does 𝑃 halt for every
input?
Prove that the halt-every-input problem is undecidable.
132