Discrete Math and Proof
Logic, quantifiers, and the anatomy of a proof
The grammar of rigorous mathematical argument
"It seems to work" is not the standard. A program is correct when a claim holds for every input, not most - and to reason about "every," you need a language sharper than English. That language is logic: propositions glued by connectives (), scoped by quantifiers (), and argued by proof. Get fluent here and "it seems to work" becomes "it cannot fail."
The idea in one line
Propositions, connectives, and truth
Take two atomic propositions: = "it rained" and = "the ground is wet." Four connectives combine them, and each is defined by what it outputs for every combination of inputs:
- Negation - "not ." Flips true and false.
- Conjunction - " and ." True only when both hold.
- Disjunction - " or ." True when at least one holds (inclusive or).
- Implication - "if then ." The workhorse of every proof - and the one that trips people up.
The surprise is implication. is false in exactly one situation: when is true but is false (you promised, and broke the promise). Whenever is false, the implication is vacuously true - an unfired promise is never broken. Flip the switches below and watch that single false cell appear.
Build it: truth tables and a proof you assemble
Two labs in one. First, flip and like switches and watch the truth value of every expression light up - including the columns that reveal why the contrapositive is trustworthy and the converse is not. Then, use that fact to build a real proof: drag the rule that justifies each line into its gap before the next line unlocks.
1Flip the inputs, read the connectives
Each switch sets a proposition to true or false. The matching row of the truth table highlights, and the two blue columns ( and its contrapositive ) stay identical no matter what you do - while the amber column (the converse ) does not.
| T | T | F | T | T | T | T | T |
| T | F | F | F | T | F | F | T |
| F | T | T | F | T | T | T | F |
| F | F | T | F | F | T | T | T |
p = T, q = T → p ⇒ q is TRUE - both sides hold.
The and columns are identical in all four rows - a statement and its contrapositive are the same claim. The converse differs (rows 2 and 3), so it proves nothing about the original.
2Assemble the proof: derive from and
A two-line derivation. Drag the correct rule into each gap. A wrong rule bounces back; the right one turns green and unlocks the next line.
- premise
- premise
- drag a rule here
- unlocks after line 3
Line 3 rewrites premise 1 by swapping and negating both sides. Which rule licenses that? Drag it into the gap.
Implication, contrapositive, and converse - precisely
Implication has a clean algebraic form. "If then " is defined to be true except when holds and fails, which is exactly:
From this, the contrapositive is provably the same statement, while the converse is a different one:
That single equivalence powers proof by contrapositive: to prove , you may instead prove , whichever is easier. It is a rewrite you are always entitled to make.
Quantifiers, and how to negate anything
Propositions describe a single situation. To make claims about collections - "sorted for all inputs," "there is an index where..." - you need quantifiers. The universal reads "for all , holds"; the existential reads "there exists an with ." A specification like "the array is sorted" unfolds to .
The single most useful move is negation, because disproving a claim means proving its negation. Negation swaps the quantifiers and pushes the inward - the quantifier version of De Morgan's laws:
The negation rules you will use constantly
To break a "for all" claim you exhibit one counterexample (). To break a "there exists" claim you must show it fails everywhere (). "Every prime is odd" is refuted by the single witness ; "some list is unsortable" would demand you rule out every list.
For a developer, these rules are already muscle memory in another form - Python's all() is , any() is , and negating one gives the other:
# all() is the ∀ ("for all") ; any() is the ∃ ("there exists")
nums = [4, 8, 15, 16, 23, 42]
all_even = all(n % 2 == 0 for n in nums) # ∀n. even(n) -> False
some_even = any(n % 2 == 0 for n in nums) # ∃n. even(n) -> True
# Negating a "for all" yields a "there exists" (De Morgan for quantifiers):
# ¬(∀n. even(n)) == ∃n. ¬even(n)
not_all_even = not all_even
exists_odd = any(n % 2 != 0 for n in nums)
assert not_all_even == exists_odd # same truth value, alwaysWith connectives, quantifiers, and negation in hand, a proof is just a finite chain of statements where each one is a premise, a definition, or follows from earlier lines by a rule you are allowed to use. A direct proof assumes and marches to . A proof by contradiction assumes the claim is false, then derives an impossibility like - since a contradiction can never hold, the assumption must have been wrong.
Check yourself
Negate the claim “every prime is odd.” The correct negation is:
Which statement always has the same truth value as p ⇒ q?
Recall: what is the difference between the converse and the contrapositive of “if p then q,” and which one may you safely use to prove the original?
Try to state it, then check.
Lock it in
- A proposition is exactly true or false; the connectives build bigger propositions, and a truth table pins down precisely what each one means.
- Implication is false in only one case - true, false - and equals ; it is vacuously true whenever is false.
- The contrapositive always shares the truth value of , so you may prove either; the converse is a different statement.
- Negation swaps the quantifiers: and - one counterexample breaks a "for all."
- A proof is a finite chain of justified steps: a direct proof marches from to , while a proof by contradiction assumes the claim false and derives an impossibility.
Primary source
Richard Hammack, Book of Proof (free, full PDF)Book of Proof is the gentlest complete tour of logic, quantifiers, and proof techniques - direct, contrapositive, and contradiction each get their own chapter. For the computer-science framing, MIT's 6.042J Mathematics for Computer Science (OpenCourseWare) opens with exactly this material and connects it straight to reasoning about algorithms.
Ask your teacher