Kayavak / Foundations of Computing / CS·05 Discrete Mathematics / Deeper
Deeper · Foundations of Computing
Discrete Mathematics
The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.
Why does this exist?
Each branch of discrete mathematics started with a concrete puzzle. Probability began with a gambling question that Blaise Pascal and Pierre de Fermat settled in letters in 1654: how to split the stakes of a game interrupted before the end. Graph theory began in 1736 when Leonhard Euler proved that nobody could walk across all seven bridges of Königsberg exactly once, by throwing away everything except which land touched which bridge. Logic as algebra began with George Boole's The Laws of Thought (1854), which treated true and false as values you can calculate with. Set theory came from Georg Cantor's work on infinity in the 1870s.
For a long time these looked like separate curiosities. Then in 1937 Claude Shannon's master's thesis showed that Boole's algebra describes relay switching circuits exactly, which made it the design language of every digital computer. Computing gathered the rest: proofs to show programs correct, counting to size search spaces, graphs for networks and dependencies, probability for hashing, sampling and randomised algorithms.
The mental model
Try it yourself first: write your own model in the Mental Model Explorer, then compare.
Discrete mathematics is the mathematics of things you can count and separate: the natural language for programs, which manipulate finite, distinct values.
| Question | Answer |
|---|---|
| What is it? | Sets, relations, functions, logic, proof, counting, graphs and probability over discrete objects |
| Problem it solves | Stating precisely what a program should do, and proving or estimating what it will do |
| Parts | Objects (sets, graphs), claims about them (logic), ways to establish claims (proofs), ways to size them (counting, probability) |
| How it works | Define things exactly, then reason step by step; each step justified by a definition or an earlier result |
| Assumptions | Objects are distinct and well defined; claims are either true or false |
| When they change | Continuous quantities (time, measurements) need calculus and real numbers; vague categories need other logics |
| Where it fails | Real systems have failures and timing the model leaves out; a proof is only as good as its definitions |
| Related ideas | Recurrences analyse algorithms (ch04); Boolean algebra is circuits (ch07); probability underpins hashing (ch03) |
What if?
What if a hash function were perfect?
Reason it through, then open
Collisions would still happen. If there are more possible keys than buckets, the pigeonhole principle guarantees two keys share a bucket, however clever the function. A perfect hash can only spread keys evenly, and even then the birthday effect (derived below) makes a first collision likely after only about the square root of the number of buckets. That's why every hash table needs a collision strategy.
What if you proved the step of an induction but forgot the base case?
Reason it through, then open
You can "prove" false things. Claim: every n satisfies n = n + 1. Step: if n = n + 1, add one to both sides and get n + 1 = n + 2. The step is valid; there's just no starting point where the claim is true, so the chain never begins. In code, this is a recursive function whose recursive case is right but whose base case is wrong or missing.
Where the boundary is
| Aspect | "If A then B" (implication) | "If B then A" (converse) |
|---|---|---|
| Example | If it's a prime greater than 2, it's odd | If it's odd, it's a prime greater than 2 |
| True here? | Yes | No: 9 is odd and not prime |
| Equivalent to | "If not B then not A" (contrapositive) | "If not A then not B" (inverse) |
| Confused because | Everyday speech often means "if and only if" | |
| In code | A precondition implies a property; it doesn't follow from it |
Derive it
The birthday bound: why collisions come so early.
- Put k items into N equally likely buckets. The chance the second avoids the first is 1 − 1/N, the third avoids both is 1 − 2/N, and so on.
- So P(no collision) = (1 − 1/N)(1 − 2/N)…(1 − (k−1)/N).
- For small x, 1 − x ≈ e⁻ˣ. Multiplying the approximations adds the exponents: P ≈ e^−(1 + 2 + … + (k−1))/N = e^−k(k−1)/(2N).
- Set this to ½ and solve: k(k−1) ≈ 2N ln 2, so k ≈ √(2 ln 2 · N) ≈ 1.18 √N.
- For birthdays, N = 365 gives k ≈ 22.5, so 23 people. For a 32-bit hash, N = 2³² gives k ≈ 77,000: the same numbers the chapter quotes. Collisions arrive near √N, not N.
How sure are we?
| Claim | How it's known | Where from |
|---|---|---|
| Collisions become likely near 1.18 √N items | Theorem, with an approximation | The derivation above; exact for uniform, independent hashing |
| Boolean algebra describes switching circuits | Theorem | Shannon's 1937 thesis |
| Independent failures multiply into tiny probabilities | Model | Fails when failures share a cause (one power supply, one data centre) |
| Euler founded graph theory with Königsberg | Historical | Euler's 1736 paper |
Still open
Much of discrete mathematics behind computing is settled, but some of its central questions aren't: P versus NP (chapter 4), how hard factoring really is (the basis of RSA), and many problems in graph theory and combinatorics. Formal proof of real software, using tools such as Coq, Lean or TLA⁺, is advancing fast but still costly enough that few programs are verified end to end.
What would change your mind? If correlated failures turned out to be rare in practice, the chapter's warning about multiplying probabilities would matter less. Outage reports keep showing the opposite.
Recall
When does a first collision become likely for N buckets?
Around 1.18 √N items (the birthday bound), e.g. 23 people for 365 days.
What is the contrapositive of "if A then B", and is it equivalent?
"If not B then not A"; yes, it's logically equivalent.
Why does a perfect hash function still collide?
With more possible keys than buckets, the pigeonhole principle forces it.
What two parts must every induction have?
A base case that's true, and a step showing the claim for n implies it for n + 1.
Why can't you multiply failure probabilities for servers in one data centre?
Their failures aren't independent; a shared cause takes them down together.
Reflect
Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.