Proofs
Proofs are the heart of mathematics β the part the examiner reads most carefully. Direct, contrapositive, contradiction, cases, induction, and the rules of inference that connect each line.
2.1 What is a Proof?
A proof is a finite sequence of statements, each of which is either an axiom, a previously proved theorem, a hypothesis, or follows from earlier statements by a rule of inference. The last statement is the conclusion.
- Consistent: you cannot derive both a proposition and its negation.
- (Ideally) Complete: every true statement can be derived. (GΓΆdel showed this is impossible for systems strong enough to do arithmetic.)
Why proofs?
- Certainty. A computer experiment showing 10βΉ cases works gives evidence, not certainty. Goldbach has been checked to absurd bounds but is unproven.
- Insight. A good proof tells you why something is true, not just that it is.
- Communication. Proofs are the universal language: a peer in Tokyo can verify your work line-by-line.
An argument is "valid" iff
β¦ it is impossible for all the premises to be true while the conclusion is false. Equivalently, $(P_1 \land P_2 \land \cdots \land P_n) \to Q$ is a tautology.
2.2 Rules of Inference
For propositional logic
| Rule | Form | Tautology |
|---|---|---|
| Modus Ponens | $p,\;\; p\to q \;\;\therefore q$ | $(p\land(p\to q))\to q$ |
| Modus Tollens | $\lnot q,\;\; p\to q \;\;\therefore \lnot p$ | $(\lnot q\land(p\to q))\to \lnot p$ |
| Hypothetical syllogism | $p\to q,\;\; q\to r \;\;\therefore p\to r$ | $((p\to q)\land(q\to r))\to(p\to r)$ |
| Disjunctive syllogism | $p\lor q,\;\; \lnot p \;\;\therefore q$ | $((p\lor q)\land\lnot p)\to q$ |
| Addition | $p \;\;\therefore p\lor q$ | $p\to(p\lor q)$ |
| Simplification | $p\land q \;\;\therefore p$ | $(p\land q)\to p$ |
| Conjunction | $p,\;\; q \;\;\therefore p\land q$ | $(p\land q)\to(p\land q)$ |
| Resolution | $p\lor q,\;\; \lnot p\lor r \;\;\therefore q\lor r$ | $((p\lor q)\land(\lnot p\lor r))\to(q\lor r)$ |
Modus Ponens vs Modus Tollens (the two you'll use most)
MP "fires forward": if we have $p$ and $p \to q$, we get $q$.
MT "fires backward via contrapositive": if we have $\lnot q$ and $p \to q$, we get $\lnot p$.
For quantified statements
| Rule | Form |
|---|---|
| Universal Instantiation | $\forall x\, P(x) \;\;\therefore P(c)$ for any element $c$ |
| Universal Generalization | $P(c)$ for an arbitrary $c$ $\;\;\therefore \forall x\, P(x)$ |
| Existential Instantiation | $\exists x\, P(x) \;\;\therefore P(c)$ for some specific (new!) name $c$ |
| Existential Generalization | $P(c)$ for some particular $c$ $\;\;\therefore \exists x\, P(x)$ |
Existential instantiation gotcha
When you do EI from $\exists x\,P(x)$ you must introduce a new constant not used before. You can't claim it's some specific value β you only know some $x$ satisfies $P$.
Common fallacies (the marks-eating mistakes)
| Fallacy | Wrong form | Why wrong |
|---|---|---|
| Affirming the consequent | $p\to q,\;\; q \;\;\therefore p$ | $q$ might be true for many reasons besides $p$. |
| Denying the antecedent | $p\to q,\;\; \lnot p \;\;\therefore \lnot q$ | $q$ can be true even if $p$ is false. |
| Affirming a disjunct | $p \lor q,\;\; p \;\;\therefore \lnot q$ | Inclusive OR allows both. |
| Begging the question | Assuming what you're trying to prove | Circular reasoning. |
Worked example: build a formal proof
Premises.
- If it does not rain or it is not foggy, then the sailing race is held and the lifesaving demonstration goes on.
- If the sailing race is held, then the trophy is awarded.
- The trophy was not awarded.
Conclusion. It rained.
Variables. $R$ = "it rains," $F$ = "it is foggy," $S$ = "sailing race held," $L$ = "lifesaving demo on," $T$ = "trophy awarded."
Formalised premises.
- $(\lnot R \lor \lnot F) \to (S \land L)$
- $S \to T$
- $\lnot T$
Goal. Derive $R$.
- $\lnot T$ [Premise 3]
- $S \to T$ [Premise 2]
- $\lnot S$ [Modus Tollens, 1 & 2]
- $\lnot S \lor \lnot L$ [Addition, 3]
- $\lnot (S \land L)$ [De Morgan, 4]
- $(\lnot R \lor \lnot F) \to (S \land L)$ [Premise 1]
- $\lnot(\lnot R \lor \lnot F)$ [Modus Tollens, 5 & 6]
- $R \land F$ [De Morgan + double negation, 7]
- $R$ [Simplification, 8] β
2.3 Types of Proofs
Every proof of $p \to q$ (or of a statement that can be cast that way) uses one of a small number of strategies. Pick the one whose shape fits your premises.
Direct Proof
Goal. Prove $p \to q$.
Method. Assume $p$. Through a chain of logical steps, deduce $q$. Done.
Example. If $n$ is odd, then $n^2$ is odd.
Proof. Assume $n$ is odd. Then $n = 2k+1$ for some integer $k$. Then $$n^2 = (2k+1)^2 = 4k^2 + 4k + 1 = 2(2k^2 + 2k) + 1.$$ Since $2k^2 + 2k$ is an integer, $n^2$ has the form $2m+1$, i.e., $n^2$ is odd. β
Example. Show that the square of an even integer is even.
Proof. Let $n = 2k$. Then $n^2 = 4k^2 = 2(2k^2)$. Hence $n^2$ is even. β
Proof by Contraposition
Goal. Prove $p \to q$.
Method. Prove $\lnot q \to \lnot p$ directly. Logically equivalent.
When to use it
Use contrapositive when the negation of $q$ gives you something concrete to manipulate (like "$n$ is odd" instead of "$n$ is not even"), but $p$ itself doesn't.
Example. If $n^2$ is even, then $n$ is even. (Contrapositive of "$n$ odd βΉ $n^2$ odd.")
Proof (contrapositive). Assume $n$ is odd. Write $n = 2k+1$. Then $n^2 = 4k^2 + 4k + 1 = 2(2k^2+2k) + 1$ is odd. Hence $\lnot(n \text{ even}) \to \lnot(n^2 \text{ even})$. By contraposition, $n^2$ even βΉ $n$ even. β
Example. If $3n+2$ is even, then $n$ is even.
Proof (contrapositive). Suppose $n$ is odd. Then $n = 2k+1$, so $3n+2 = 6k+3+2 = 6k+5 = 2(3k+2)+1$, which is odd. Contrapositive proven; original follows. β
Proof by Contradiction
Goal. Prove $q$.
Method. Assume $\lnot q$. Derive a contradiction (some $r \land \lnot r$). Hence $\lnot q$ is false, so $q$ holds.
Example. $\sqrt{2}$ is irrational.
Proof. Suppose, for contradiction, that $\sqrt{2} = a/b$ in lowest terms (so $\gcd(a,b)=1$). Squaring: $2b^2 = a^2$, so $a^2$ is even, so $a$ is even (by the previous example). Write $a = 2c$. Then $2b^2 = 4c^2$, so $b^2 = 2c^2$, so $b^2$ is even, so $b$ is even. But $a, b$ both even contradicts $\gcd(a,b)=1$. β
Example. $\log_2 3$ is irrational.
Proof. Suppose $\log_2 3 = p/q$ with $p,q \in \mathbb{Z}$, $q \neq 0$. Then $2^{p/q} = 3$, so $2^p = 3^q$. LHS is even (assuming $p \geq 1$), RHS is odd β contradiction. If $p = 0$, $2^0 = 1 \neq 3^q$ for any $q$. β
Example. If $3n+2$ is even, then $n$ is even (by contradiction).
Proof. Suppose $3n+2$ is even but $n$ is odd. Then $n = 2k+1$, so $3n+2 = 6k+5 = 2(3k+2)+1$ is odd. Contradicts "$3n+2$ even." β
Proof by Cases (Exhaustion)
Goal. Prove $p$ where the universe splits into cases $C_1, C_2, \ldots, C_n$ that exhaust all possibilities.
Method. Prove $p$ in each case.
Example. For every integer $n$, $n \leq n^2$.
Proof (by cases).
- Case 1: $n \geq 1$. Multiply $n \geq 1$ by the positive number $n$ to get $n^2 \geq n$.
- Case 2: $n = 0$. Then $0 = 0^2$ β.
- Case 3: $n \leq -1$. Then $n < 0$ but $n^2 \geq 1 > 0$, so $n < n^2$. β
All integers covered. β
Example. The square of any integer leaves remainder 0 or 1 modulo 4.
Proof. Every integer is $4k, 4k+1, 4k+2,$ or $4k+3$.
- $(4k)^2 = 16k^2 \equiv 0\pmod 4$.
- $(4k+1)^2 = 16k^2 + 8k + 1 \equiv 1 \pmod 4$.
- $(4k+2)^2 = 16k^2 + 16k + 4 \equiv 0 \pmod 4$.
- $(4k+3)^2 = 16k^2 + 24k + 9 \equiv 1 \pmod 4$.
Hence the only remainders are 0 and 1. β
Mathematical Induction
Goal. Prove $\forall n \in \mathbb{N},\, P(n)$.
Method.
- Base case: show $P(0)$ (or $P(1)$, whatever the smallest case is).
- Inductive step: assume $P(k)$ for an arbitrary $k$ (the inductive hypothesis); prove $P(k+1)$.
- By the principle of induction, $P(n)$ holds for all $n$.
Example. $1 + 2 + 3 + \cdots + n = \dfrac{n(n+1)}{2}$ for all $n \geq 1$.
Base. $n=1$: LHS $=1$, RHS $= 1 \cdot 2 / 2 = 1$ β.
Step. Assume $1 + \cdots + k = k(k+1)/2$. Then $$1+\cdots+k+(k+1) = \frac{k(k+1)}{2} + (k+1) = (k+1)\cdot\frac{k+2}{2} = \frac{(k+1)(k+2)}{2}.$$ So $P(k+1)$ holds. β
Strong induction. Sometimes you assume $P(0), P(1), \ldots, P(k)$ to derive $P(k+1)$. Equivalent in power to ordinary induction but often easier to apply.
Example. Every integer $n \geq 2$ is a product of primes. Base: $2$ is prime. Step: assume the claim for all $2 \leq m \leq k$. If $k+1$ is prime, done. Else $k+1 = ab$ with $2\leq a, b \leq k$; by IH, $a$ and $b$ each factor into primes, so $k+1$ does too. β
Existence proofs and counterexamples
- Constructive existence: show how to build an example. ("There exist irrationals $a,b$ with $a^b$ rational" β e.g., $\sqrt{2}^{\log_2 9} = 3$.)
- Non-constructive existence: prove existence without exhibiting one. Often by contradiction.
- Disproving a universal: just exhibit one counterexample. ("The product of two irrationals is irrational" is false: $\sqrt{2}\cdot\sqrt{2}=2$, rational.)
Proving equivalences of multiple statements
To show $p_1, p_2, p_3, p_4$ are all equivalent, it suffices to show a cycle: $p_1 \to p_2 \to p_3 \to p_4 \to p_1$. That's 4 implications instead of $\binom{4}{2}\cdot 2 = 12$. You can also use any other set of implications whose transitive closure covers all pairs.
2.4 Program Correctness & Loop Invariants
A program is correct with respect to a specification (precondition $P$, postcondition $Q$) if whenever the precondition holds before execution, the postcondition holds after. We write this as a Hoare triple: $$\{P\}\; \text{Program}\; \{Q\}.$$
Two flavours
- Partial correctness: if the program terminates, $Q$ holds.
- Total correctness: the program terminates AND $Q$ holds.
Verifying simple sequences
For straight-line code, trace the state.
Swap.
temp := x
x := y
y := temp
Precondition: $x = a \land y = b$ for some specific values $a, b$.After line 1: $\text{temp} = a, x = a, y = b$.
After line 2: $\text{temp} = a, x = b, y = b$.
After line 3: $\text{temp} = a, x = b, y = a$.
Postcondition $x = b \land y = a$ achieved. β
Loop invariants
A loop invariant is a predicate that:
- Holds before the loop starts (initialization).
- If it holds before an iteration, holds after (maintenance).
- When the loop terminates, it (combined with the negation of the loop condition) implies the postcondition (termination).
Example. Prove that the following code computes $n!$:
i := 1
fact := 1
while i <= n:
fact := fact * i
i := i + 1
// claim: fact == n!
Invariant: $\text{fact} = (i-1)!$ and $1 \leq i \leq n+1$.
- Init. Before loop: $i=1$, $\text{fact}=1=0!=(i-1)!$. β
- Maintenance. Suppose $\text{fact}=(i-1)!$. Body sets $\text{fact} \gets \text{fact}\cdot i = (i-1)!\cdot i = i!$ and then $i \gets i+1$. After: $\text{fact} = (i_{\text{new}}-1)!$. β
- Termination. Loop exits when $i > n$, i.e., $i = n+1$. Then $\text{fact} = (i-1)! = n!$. β
Done. β
Example. Linear search returns the smallest index of $\text{target}$ in $A[1..n]$ (or $-1$).
i := 1
while i <= n:
if A[i] == target: return i
i := i + 1
return -1
Invariant: $\text{target} \notin A[1..i-1]$.
- Init. $i=1$, $A[1..0]$ is empty, so vacuously target not in it.
- Maintenance. Before iteration: target not in $A[1..i-1]$. If $A[i]=\text{target}$, we return correctly. Else, target not in $A[1..i]$; we increment $i$.
- Termination. If loop exits without finding, $i = n+1$, so target $\notin A[1..n]$. Return $-1$ is correct.
Writing invariants β a checklist
- What's true before the loop? After every iteration?
- How does the loop progress toward the goal?
- What does the invariant + loop-exit condition imply about the final state?
If you can answer these three, you have your invariant.
Interactive β Inference rule trainer
Quick reps for the most-tested skill: looking at premises and naming the rule that gets you the conclusion. Each round is one inference; click the rule you think applies. The site shuffles automatically.
Problem Bank β Proofs
Premises: P1: Research will not be completed on time. P2: If the project is funded, we will buy new equipment. P3: If we buy new equipment, the research will be completed on time. P4: The grant is not renewed or the project is funded. What conclusion follows?
Show solution
Let $C$ = "completed on time," $F$ = "funded," $E$ = "buy equipment," $R$ = "grant renewed." Premises: $\lnot C$, $F\to E$, $E\to C$, $\lnot R \lor F$.
- $F\to E,\ E\to C \;\Rightarrow\; F\to C$ [hypothetical syllogism]
- $F\to C,\ \lnot C \;\Rightarrow\; \lnot F$ [Modus Tollens]
- $\lnot R \lor F,\ \lnot F \;\Rightarrow\; \lnot R$ [disjunctive syllogism]
Conclusion: The grant was not renewed ($\lnot R$).
P1: If $1+1 = 11$, then 7 is odd. P2: 7 is even. Conclusion: $1+1 \neq 11$. Comment on validity.
Show solution
Let $p$ = "$1+1=11$", $q$ = "7 is odd." Premises: $p\to q$, $\lnot q$ (since 7 is even, not odd). Modus Tollens gives $\lnot p$, i.e., $1+1\neq 11$. The argument is valid. Note: the premise "if 1+1=11 then 7 is odd" is true vacuously (antecedent is false). The argument's validity depends on the form, not the truth of premises.
(a) The university is not closed today. If it snows, the university will close. Therefore, it did not snow today.
(b) If I stay in the sun too long, I sunburn. If I go swimming, I stay too long. Therefore, if I swim, I sunburn.
Show solution
(a) $\lnot C$, $S \to C \;\therefore \lnot S$. Modus Tollens.
(b) $S \to L$, $W \to S$ $\;\therefore W \to L$. Hypothetical syllogism.
"If I play hockey, I am sore." "If I am sore, I use the whirlpool." "I did not use the whirlpool." Conclusion?
Show solution
$H\to S$, $S\to W$, $\lnot W$. By HS, $H\to W$. By MT, $\lnot H$. I did not play hockey.
"I did not win the lottery." "I am clever or lucky." "If I am lucky, I will win the lottery." Conclusion?
Show solution
$\lnot W$, $C\lor L$, $L\to W$. By MT, $\lnot L$. By disjunctive syllogism on $C\lor L$ and $\lnot L$: $C$. I am clever.
"Tony will train or use a gadget." "If Tony trains, he is stronger." "Tony did not defeat villains." "If Tony is stronger, he can defeat villains." What follows?
Show solution
$T\lor G$, $T\to S$, $\lnot D$, $S\to D$.
$S\to D, \lnot D \Rightarrow \lnot S$ [MT].
$T\to S, \lnot S \Rightarrow \lnot T$ [MT].
$T\lor G, \lnot T \Rightarrow G$ [Disjunctive syllogism]. Tony used a gadget.
(a) If $n > 1$ then $n^2 > 1$. Suppose $n^2 > 1$. Then $n > 1$. Valid?
(b) If $n > 3$ then $n^2 > 9$. Suppose $n^2 \leq 9$. Then $n \leq 3$.
Show solution
(a) Invalid β affirming the consequent. Counter: $n = -2$, $n^2 = 4 > 1$ but $n < 1$.
(b) Valid β Modus Tollens applied to $n > 3 \to n^2 > 9$ with $\lnot(n^2 > 9)$.
"Every PL with garbage collection is slow. C does not use garbage collection. Therefore C is slow." Valid?
Show solution
$\forall x\,(G(x) \to S(x))$, $\lnot G(C)$, $\therefore S(C)$.
This is denying the antecedent β a fallacy. C might or might not be slow; the premises don't tell us.
If hacked, then user error OR design flaw. Computer was hacked. The computer did not have a design flaw. Conclude: user error. Valid?
Show solution
$H \to (U \lor D)$, $H$, $\lnot D$. MP: $U \lor D$. Disjunctive syllogism with $\lnot D$: $U$. Valid.
Given: $\forall x\, (P(x) \to (Q(x) \land S(x)))$ and $\forall x\, (P(x) \land R(x))$. Show $\forall x\, (R(x) \land S(x))$ is true.
Show solution
Take arbitrary $c$. UI gives $P(c) \land R(c)$ and $P(c) \to (Q(c) \land S(c))$.
Simplification: $P(c)$; modus ponens: $Q(c)\land S(c)$; simplification: $S(c)$.
Also simplification: $R(c)$.
Conjunction: $R(c) \land S(c)$.
$c$ was arbitrary, so UG: $\forall x\,(R(x)\land S(x))$. β
Let $m, n, p$ be integers. Suppose $m+n$ and $n+p$ are even. Prove $m+p$ is even.
Show solution
Proof (direct). Write $m + n = 2a$ and $n + p = 2b$. Then $$m + p = (m+n) + (n+p) - 2n = 2a + 2b - 2n = 2(a+b-n),$$ so $m+p$ is even. β
Prove or disprove: "The product of two irrational numbers is always irrational."
Show solution
Disproof by counterexample. Take $a = b = \sqrt{2}$. Both are irrational, but $ab = 2$ is rational. β
If $mn$ is even, then $m$ is even or $n$ is even.
Show solution
Proof (contrapositive). Suppose $m$ and $n$ are both odd: $m = 2a+1$, $n = 2b+1$. Then $$mn = (2a+1)(2b+1) = 4ab + 2a + 2b + 1 = 2(2ab+a+b)+1,$$ which is odd. Contrapositive established. β
Drawer contains only blue and black socks. Show: pulling three socks guarantees a matching pair.
Show solution
Proof (pigeonhole / contradiction). Suppose no pair: at most one blue and at most one black, so at most $2$ socks. But we pulled $3$. Contradiction. Hence some pair exists. β
Show that among any 25 days, at least 3 fall in the same month.
Show solution
Proof (pigeonhole). $12$ months are the pigeonholes. If every month had at most $2$ days, total $\leq 24 < 25$. Contradiction. Some month must have $\geq 3$ days. β
For real $a, b$, show these are equivalent: (i) $a < b$, (ii) $\tfrac{a+b}{2} > a$, (iii) $\tfrac{a+b}{2} < b$.
Show solution
Show (i) βΉ (ii) βΉ (iii) βΉ (i).
- (i)βΉ(ii): $a < b \Rightarrow a+a < a+b \Rightarrow 2a < a+b \Rightarrow a < (a+b)/2$.
- (ii)βΉ(iii): $a < (a+b)/2 \Rightarrow 2a < a+b \Rightarrow a < b$. Now $(a+b)/2 < b \iff a+b < 2b \iff a < b$. β
- (iii)βΉ(i): $(a+b)/2 < b \Rightarrow a + b < 2b \Rightarrow a < b$.
All three equivalent. β
(a) Explain proof by contraposition. (b) Prove: if $n^2 - 6n + 5$ is even, then $n$ is odd.
Show solution
(a) To prove $p \to q$ by contraposition, assume $\lnot q$ and derive $\lnot p$. Since $p\to q \equiv \lnot q\to\lnot p$, this proves the original.
(b) Contrapositive: if $n$ is even, then $n^2 - 6n + 5$ is odd.
Let $n = 2k$. Then $n^2 - 6n + 5 = 4k^2 - 12k + 5 = 2(2k^2 - 6k + 2) + 1$, which is odd. β
Prove by induction: $1^3 + 2^3 + \cdots + n^3 = \left(\dfrac{n(n+1)}{2}\right)^2$.
Show solution
Base. $n=1$: LHS $= 1$, RHS $= 1$. β
Step. Assume $1^3+\cdots+k^3 = \left(k(k+1)/2\right)^2$. Then
$$\sum_{i=1}^{k+1} i^3 = \left(\tfrac{k(k+1)}{2}\right)^2 + (k+1)^3 = (k+1)^2\left(\tfrac{k^2}{4} + (k+1)\right) = (k+1)^2\cdot\tfrac{k^2+4k+4}{4} = \left(\tfrac{(k+1)(k+2)}{2}\right)^2.$$
β
Prove $2^n > n^2$ for all $n \geq 5$.
Show solution
Base. $n=5$: $2^5 = 32 > 25 = 5^2$. β
Step. Assume $2^k > k^2$ for some $k\geq 5$. Then
$$2^{k+1} = 2\cdot 2^k > 2k^2.$$
We need $2k^2 \geq (k+1)^2 = k^2 + 2k + 1$, i.e., $k^2 - 2k - 1 \geq 0$. For $k \geq 5$, $k^2 - 2k - 1 = 25 - 10 - 1 = 14 > 0$. (Generally for $k \geq 3$.) So $2^{k+1} > (k+1)^2$. β
Prove the following program computes the sum $1 + 2 + \cdots + n$ for $n \geq 1$:
i := 1; s := 0
while i <= n:
s := s + i
i := i + 1
return s
Show solution
Invariant: $s = 1 + 2 + \cdots + (i-1) = \dfrac{(i-1)i}{2}$ and $1 \leq i \leq n+1$.
- Init. $i=1, s=0 = 0\cdot 1/2$. β
- Maintenance. Suppose invariant. Body: $s\gets s+i = \tfrac{(i-1)i}{2} + i = \tfrac{i(i+1)}{2}$, then $i\gets i+1$. Now $s = \tfrac{(i_{\text{new}}-1)i_{\text{new}}}{2}$. β
- Termination. Loop exits when $i > n$, i.e., $i = n+1$. Then $s = \tfrac{n(n+1)}{2} = \sum_{k=1}^n k$. β
Hence the program is correct. β
- Choose the right strategy first. Direct if the hypothesis is concrete; contrapositive if "$\lnot$ goal" is concrete; contradiction if "$\lnot$ goal" leads to something impossible.
- Cite the rule. When asked to construct a formal proof, label each line with the rule name (MP, MT, HS, DS, Addition, Simplification, etc.).
- End with β or QED. Examiners love a clean ending.
- Induction has three parts β never skip the base case, never skip stating the inductive hypothesis.
- Loop invariants need initialisation, maintenance, termination β exactly three things to show.