Proving Implications and Iff
Most theorems have the shape "if then ", written or . Others say " if and only if ", written or . This lesson gives the standard templates for proving each kind.
When is an implication true?
is false in exactly one situation: is true and is false. In particular, an implication with a false hypothesis is true ("vacuously true").
| T | T | T |
| T | F | F |
| F | T | T |
| F | F | T |
So to prove , you only have to deal with the case where is true.
Method 1: assume , show
Write "Assume ." Then argue until you reach .
Theorem. If , then .
Proof. Assume . Then , and are all non-negative, so . Expanding, . Adding 1 gives .
The hard part was finding the factorization; the written proof is short. Scratch work is often needed before the clean proof appears.
import numpy as np
xs = np.linspace(0, 2, 2001)
vals = -xs ** 3 + 4 * xs + 1
print("minimum on [0, 2]:", round(float(vals.min()), 6), "at x =", float(xs[vals.argmin()]))minimum on [0, 2]: 1.0 at x = 0.0
The numeric check agrees: the minimum value 1 is reached at both ends of the interval.
Method 2: prove the contrapositive
The contrapositive of is . They are logically equivalent: both are false exactly when is true and is false. Sometimes the contrapositive is much easier.
Theorem. If is even, then is even.
Proof. We prove the contrapositive: if is odd, then is odd. Let . Then , which is odd.
Starting from " is even" directly gives , and there is no easy way to get at from that. The contrapositive turns it into a computation.
Note: The converse is not equivalent to . "If it is a square then it is a rectangle" is true; its converse "if it is a rectangle then it is a square" is false.
from itertools import product
imp = lambda a, b: (not a) or b
rows = []
for P, Q in product([True, False], repeat=2):
rows.append((P, Q, imp(P, Q), imp(not Q, not P), imp(Q, P)))
print("P Q P->Q contra converse")
for r in rows:
print(" ".join(f"{str(v):5}" for v in r))
print("P->Q equivalent to contrapositive:", all(r[2] == r[3] for r in rows))
print("P->Q equivalent to converse:", all(r[2] == r[4] for r in rows))P Q P->Q contra converse
True True True True True
True False False False True
False True True True False
False False True True True
P->Q equivalent to contrapositive: True
P->Q equivalent to converse: False
Proving "if and only if"
means both and . There are two templates:
- Prove both directions separately. Label them "()" and "()".
- Chain of iffs: , where every step is reversible.
Theorem. For an integer , is even if and only if is even.
Proof. () If , then is even. () This is the theorem proved above by contrapositive.
A chain-of-iffs example: for real numbers, the standard deviation of is 0 the sum of squared deviations is 0 every squared deviation is 0 (they are all ) every equals the mean. Each step works in both directions.
In software
A function's documentation often states an implication: "if the input is sorted, then binary_search returns the index of the key or -1". It promises nothing when the input is unsorted, just as says nothing when is false. Tests for an "iff" property need both directions too: is_valid(x) should accept every valid input and reject every invalid one.
Exercises
Exercise 1: Contrapositive and converse
Write the contrapositive and the converse of "If a number is divisible by 6, then it is divisible by 3". Which of them are true?
Answer
Contrapositive: "If a number is not divisible by 3, then it is not divisible by 6" (true). Converse: "If a number is divisible by 3, then it is divisible by 6" (false, e.g. 9).
Solution
The original is true because . The contrapositive is equivalent to it, so it is true too. The converse is a different statement, and 9 is a counterexample: it is divisible by 3 but not by 6.
Exercise 2: Prove by contrapositive
Prove: if for integers , then or .
Answer
Contrapositive: if and , then and , so .
Solution
The negation of " or " is " and ". Assume that. Since are integers, and , so
which is the negation of the hypothesis. So the contrapositive holds, and with it the theorem.
Exercise 3: An iff with divisibility
Prove that an integer is divisible by 3 if and only if is divisible by 3. Check the remainders in Python first.
Answer
() gives . () by contrapositive: if or , then .
Solution
for r in range(3):
print(f"n = 3k + {r}: n^2 mod 3 = {(r * r) % 3}")n = 3k + 0: n^2 mod 3 = 0
n = 3k + 1: n^2 mod 3 = 1
n = 3k + 2: n^2 mod 3 = 1
() If is not divisible by 3, then or . In the first case ; in the second . Either way leaves remainder 1, so it is not divisible by 3.
Test yourself
When is false?
- When is false
- When is true
- When is true and is false
- When both are false
Which statement is logically equivalent to ?
How many implications do you prove for an 'if and only if' statement (using the two-direction template)?
- One
- Two
- Three
- Four