Skip to content

Chapter 11: Discrete Math 1

Discrete mathematics is the mathematics of distinct, separated structures, as opposed to the continuous structures of calculus. Its central activity is proof: constructing airtight logical arguments. Every concept in it appears directly in computer science. Sets become data structures, logic becomes boolean algebra and type systems, induction becomes recursive correctness arguments, relations become database schemas, and functions become the foundation of programming. Counting, meanwhile, is how you size anything: a model’s parameters, the FLOPs of a forward pass, the bytes of a cache.

Concepts from other sections (15)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

This chapter starts where the rest of the book needs it most. Its problem set builds the vocabulary and the proof habits that later chapters assume: sets and logic, counting, the standard proof methods, induction and loop invariants, relations, and functions. Its two build sections then put two of those ideas to work. The first counts a transformer’s parameters, FLOPs, KV-cache bytes, and training memory exactly, from a handful of config integers. The second uses injective, surjective, and bijective to derive the byte-to-character map that every GPT-2 style tokenizer depends on. The survey after the section list covers the wider territory of a first discrete math course, following Hammack’s Book of Proof, with a worked example for each topic.

Learning objectives

  • Read and write rigorous proofs: direct, contrapositive, contradiction, cases, and induction, including loop invariants.
  • Use the language of sets, logic, and quantifiers, including negating nested quantifiers.
  • Count with the product rule, permutations, combinations, and stars and bars, and apply them to parameter, FLOP, and KV-cache counts.
  • Classify relations, and recognize equivalence relations as partitions.
  • Prove functions injective, surjective, or bijective, and explain why only bijections have inverses.

The chapter needs no earlier mathematics beyond high-school algebra. For the counting section, powers of ten and logarithms from Exponents, logarithms, and units of information help with reading counts like 6.7×1096.7 \times 10^9. The problem set comes last in the list below by file order, but it is designed to be worked first.

  1. Counting: parameters, FLOPs, KV bytes, and memory plans: counts a decoder’s parameters per component so they match Hugging Face exactly for dense, GQA, MoE, and MLA models, and derives KV-cache bytes, FLOPs per token, and a training memory plan, all as exact integers.
  2. Injective, surjective, bijective: the GPT-2 byte map: builds the three definitions as checks on a dict, and derives GPT-2’s bijection from the 256 bytes to 256 visible characters that byte-level BPE vocabularies are written in.
  3. Discrete math 1 problem set: problems with worked answers and model proofs on sets and logic, counting, proof techniques, induction and loop invariants, relations, and functions and bijections. Work it before the two sections above.

The sections above focus on the parts of discrete math that code depends on. The rest of this opening surveys a first course in the subject, following Hammack’s Book of Proof. Each topic gives the key definitions and theorems, worked examples, and the textbook exercises to practice on.

Book of Proof chapter 1, sections 1.1 to 1.8. A set is an unordered collection of distinct elements, described by listing, {1,2,3}\{1,2,3\}, or in set-builder notation, {x∈Z:x>0}\{x \in \mathbb{Z} : x > 0\}. AA is a subset of BB if every element of AA is in BB. The power set P(A)\mathcal{P}(A) is the set of all subsets of AA. The union is A∪B={x:x∈A or x∈B}A \cup B = \{x : x \in A \text{ or } x \in B\}, the intersection is A∩B={x:x∈A and x∈B}A \cap B = \{x : x \in A \text{ and } x \in B\}, and the complement is Ac={x∈U:x∉A}A^c = \{x \in U : x \notin A\}. The Cartesian product is A×B={(a,b):a∈A,b∈B}A \times B = \{(a,b) : a \in A, b \in B\}, with ∣A×B∣=∣A∣⋅∣B∣\lvert A \times B \rvert = \lvert A \rvert \cdot \lvert B \rvert.

Three results recur. De Morgan’s laws, (A∪B)c=Ac∩Bc(A \cup B)^c = A^c \cap B^c and (A∩B)c=Ac∪Bc(A \cap B)^c = A^c \cup B^c, say that “not (this or that)” is “not this and not that”: negation swaps union and intersection. Inclusion-exclusion for two sets, ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣\lvert A \cup B \rvert = \lvert A \rvert + \lvert B \rvert - \lvert A \cap B \rvert, corrects the double count of the overlap. And ∣P(A)∣=2∣A∣\lvert \mathcal{P}(A) \rvert = 2^{\lvert A \rvert}, because each element is independently in or out.

For example, prove A∩(B∪C)=(A∩B)∪(A∩C)A \cap (B \cup C) = (A \cap B) \cup (A \cap C). Let x∈A∩(B∪C)x \in A \cap (B \cup C). Then x∈Ax \in A and x∈B∪Cx \in B \cup C. If x∈Bx \in B, then x∈A∩Bx \in A \cap B, so xx is in the right side. If x∈Cx \in C, then x∈A∩Cx \in A \cap C, so again xx is in the right side. The reverse inclusion is similar.

Practice: Hammack chapter 1 exercises 1 to 8, 13 to 18, and 25 to 30; for a challenge, 31 to 36.

Book of Proof chapter 2, sections 2.1 to 2.10. A proposition is a statement that is either true or false. P∧QP \land Q is true only when both are; P∨QP \lor Q when at least one is; ¬P\lnot P reverses the truth value. The conditional P⇒QP \Rightarrow Q is false only when PP is true and QQ is false, and the biconditional P  ⟺  QP \iff Q is true when PP and QQ have the same truth value. A predicate is a statement with a variable, such as P(x)P(x) = ”xx is even”. The universal quantifier ∀x P(x)\forall x\, P(x) asserts PP for every xx in the domain; the existential quantifier ∃x P(x)\exists x\, P(x) asserts it for at least one.

P⇒QP \Rightarrow Q is equivalent to ¬P∨Q\lnot P \lor Q: “if PP then QQ” fails only when PP is true and QQ is false. It is also equivalent to its contrapositive ¬Q⇒¬P\lnot Q \Rightarrow \lnot P: “if it rained then the ground is wet” is the same as “if the ground is dry then it didn’t rain.” And negation swaps quantifiers, ¬∀x P(x)  ⟺  ∃x ¬P(x)\lnot \forall x\, P(x) \iff \exists x\, \lnot P(x) and ¬∃x P(x)  ⟺  ∀x ¬P(x)\lnot \exists x\, P(x) \iff \forall x\, \lnot P(x), just as De Morgan’s laws swap AND and OR.

For example, negate “for every ϵ>0\epsilon > 0 there exists δ>0\delta > 0 such that ∣x−a∣<δ|x - a| < \delta implies ∣f(x)−L∣<ϵ|f(x) - L| < \epsilon.” The negation is “there exists ϵ>0\epsilon > 0 such that for all δ>0\delta > 0 there exists xx with ∣x−a∣<δ|x - a| < \delta and ∣f(x)−L∣≥ϵ|f(x) - L| \ge \epsilon.” Each quantifier flips, and the implication becomes a conjunction with the consequent negated.

Practice: Hammack chapter 2 exercises 1 to 10 and 15 to 22; for a challenge, 23 to 28.

Book of Proof chapter 3, sections 3.1 to 3.5. The multiplication principle: if task 1 has mm outcomes and task 2 has nn, the sequence has mnmn. The addition principle: if the tasks are mutually exclusive, the total is m+nm + n. A permutation is an ordered arrangement, P(n,k)=n!/(n−k)!P(n,k) = n!/(n-k)!; a combination is an unordered selection, (nk)=n!/(k!(n−k)!)\binom{n}{k} = n!/(k!(n-k)!), read ”nn choose kk”.

The binomial theorem is (x+y)n=∑k=0n(nk)xn−kyk(x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k: expanding (x+y)n(x+y)^n, each term chooses xx from some factors and yy from the rest, and there are (nk)\binom{n}{k} ways to choose the kk factors for yy. Pascal’s identity, (nk)=(n−1k−1)+(n−1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}, says that to choose kk items from nn, you either include item nn (then choose k−1k-1 from the remaining n−1n-1) or exclude it (choose kk from n−1n-1). Stars and bars: the number of ways to distribute nn identical objects into kk distinct bins is (n+k−1k−1)\binom{n+k-1}{k-1}, the arrangements of nn stars and k−1k-1 dividers in a row.

Two examples. How many 5-card poker hands contain exactly 2 aces? Choose 2 aces from 4, (42)=6\binom{4}{2} = 6, and the remaining 3 cards from the 48 non-aces, (483)=17296\binom{48}{3} = 17296, for 6⋅17296=1037766 \cdot 17296 = 103776. How many bit strings of length 8 have exactly 3 ones? Choose the positions of the ones: (83)=56\binom{8}{3} = 56.

Practice: Hammack chapter 3 exercises 1 to 12 and 17 to 24; for a challenge, 25 to 30.

Book of Proof chapter 4, sections 4.1 to 4.5. A direct proof of P⇒QP \Rightarrow Q assumes PP and uses definitions, theorems, and logical reasoning to conclude QQ. The technique is always the same: assume the hypothesis, unpack the definitions, manipulate using known results, and arrive at the conclusion.

Prove that if nn is odd, then n2n^2 is odd. Assume nn is odd, so n=2k+1n = 2k + 1 for some integer kk. Then n2=(2k+1)2=4k2+4k+1=2(2k2+2k)+1n^2 = (2k+1)^2 = 4k^2 + 4k + 1 = 2(2k^2 + 2k) + 1. Since 2k2+2k2k^2 + 2k is an integer, n2n^2 has the form 2m+12m + 1, so it is odd.

Prove that if a∣ba \mid b and b∣cb \mid c, then a∣ca \mid c. Since a∣ba \mid b, b=akb = ak for some integer kk; since b∣cb \mid c, c=bjc = bj for some integer jj. Then c=(ak)j=a(kj)c = (ak)j = a(kj), and since kjkj is an integer, a∣ca \mid c.

Practice: Hammack chapter 4 exercises 1 to 8, 13 to 18, and 23 to 28; for a challenge, 29 to 34.

Book of Proof chapter 5, sections 5.1 to 5.3. A contrapositive proof of P⇒QP \Rightarrow Q proves the logically equivalent ¬Q⇒¬P\lnot Q \Rightarrow \lnot P instead. Use it when the negation of QQ gives you more to work with than assuming PP directly.

Prove that if n2n^2 is even, then nn is even. The contrapositive is: if nn is odd, then n2n^2 is odd. Assume n=2k+1n = 2k + 1; then n2=4k2+4k+1=2(2k2+2k)+1n^2 = 4k^2 + 4k + 1 = 2(2k^2 + 2k) + 1, which is odd. This avoids the difficulty of working directly from ”n2n^2 is even.”

Prove that if 5x+35x + 3 is odd, then xx is even. The contrapositive: if xx is odd, x=2k+1x = 2k + 1, then 5x+3=10k+5+3=10k+8=2(5k+4)5x + 3 = 10k + 5 + 3 = 10k + 8 = 2(5k + 4), which is even.

Practice: Hammack chapter 5 exercises 1 to 8 and 11 to 16; for a challenge, 17 to 20.

Book of Proof chapter 6, sections 6.1 to 6.4. A proof by contradiction assumes the statement is false and derives a logical contradiction: reason until you reach an impossibility (a number that is both even and odd, or a rational that is irrational), and conclude that the original statement must be true.

Prove that 2\sqrt2 is irrational. Assume 2=a/b\sqrt2 = a/b in lowest terms, gcd⁡(a,b)=1\gcd(a, b) = 1. Then 2=a2/b22 = a^2/b^2, so a2=2b2a^2 = 2b^2. Thus a2a^2 is even, so aa is even (by the contrapositive proof above). Write a=2ca = 2c. Then 4c2=2b24c^2 = 2b^2, so b2=2c2b^2 = 2c^2, and bb is even. But then both aa and bb are even, contradicting gcd⁡(a,b)=1\gcd(a, b) = 1.

Prove that there are infinitely many primes. Assume there are finitely many, p1,p2,…,pnp_1, p_2, \dots, p_n, and consider N=p1p2⋯pn+1N = p_1 p_2 \cdots p_n + 1. NN is not divisible by any pip_i (the remainder is 1), so NN is either prime itself or has a prime factor not in the list. Either way, the list was not complete: a contradiction.

Practice: Hammack chapter 6 exercises 1 to 8 and 13 to 18; for a challenge, 19 to 24.

Book of Proof chapter 7, sections 7.1 to 7.4. Some statements are not a single implication. An if-and-only-if proof proves both directions, P⇒QP \Rightarrow Q and Q⇒PQ \Rightarrow P. An existence proof shows that an object with the desired property exists, constructively or not. A uniqueness proof shows at most one object has the property: assume two, and show they are equal. A proof by cases breaks the claim into exhaustive cases and proves each separately.

Prove that nn is odd if and only if n2n^2 is odd. (⇒\Rightarrow) If n=2k+1n = 2k + 1, then n2=4k2+4k+1=2(2k2+2k)+1n^2 = 4k^2 + 4k + 1 = 2(2k^2 + 2k) + 1 is odd. (⇐\Leftarrow) By contrapositive: if n=2kn = 2k, then n2=4k2=2(2k2)n^2 = 4k^2 = 2(2k^2) is even. Both directions are established.

Practice: Hammack chapter 7 exercises 1 to 8, 13 to 18, and 25 to 30; for a challenge, 31 to 36.

Book of Proof chapter 10, sections 10.1 to 10.4. Weak induction proves P(base)P(\text{base}), then assumes P(k)P(k) and proves P(k+1)P(k+1), and concludes P(n)P(n) for all n≥basen \ge \text{base}. Strong induction assumes P(j)P(j) for all base≤j≤k\text{base} \le j \le k and proves P(k+1)P(k+1). Structural induction inducts on recursively defined structures such as trees, lists, and formulas. Underneath all three is the well-ordering principle: every nonempty subset of the natural numbers has a least element. It is logically equivalent to induction: if induction failed, there would be a smallest counterexample, contradicting well-ordering.

Prove 1+2+⋯+n=n(n+1)/21 + 2 + \dots + n = n(n+1)/2. Base case n=1n = 1: the left side is 1 and the right side is 1⋅2/2=11 \cdot 2/2 = 1. Inductive step: assume 1+2+⋯+k=k(k+1)/21 + 2 + \dots + k = k(k+1)/2. Then 1+2+⋯+k+(k+1)=k(k+1)/2+(k+1)=(k+1)(k/2+1)=(k+1)(k+2)/21 + 2 + \dots + k + (k+1) = k(k+1)/2 + (k+1) = (k+1)(k/2 + 1) = (k+1)(k+2)/2, the formula with n=k+1n = k + 1.

Prove 2n>n2^n > n for all n≥1n \ge 1, in strong induction style. Base: 21=2>12^1 = 2 > 1. Assume 2j>j2^j > j for all 1≤j≤k1 \le j \le k. Then 2k+1=2⋅2k>2k≥k+12^{k+1} = 2 \cdot 2^k > 2k \ge k + 1, since k≥1k \ge 1.

By structural induction, every binary tree with nn internal nodes has n+1n + 1 leaves. Base: a tree with 0 internal nodes has 1 leaf. Inductive step: a tree with a root has a left subtree (nLn_L internal nodes, nL+1n_L + 1 leaves) and a right subtree (nRn_R internal, nR+1n_R + 1 leaves). Its internal nodes total nL+nR+1n_L + n_R + 1, and its leaves (nL+1)+(nR+1)=nL+nR+2(n_L + 1) + (n_R + 1) = n_L + n_R + 2, which is the internal count plus 1.

Practice: Hammack chapter 10 exercises 1 to 10, 15 to 22, and 27 to 32; for a challenge, 33 to 38.

Book of Proof chapter 11, sections 11.1 to 11.6. A relation on AA is a subset RR of A×AA \times A; write a R ba\,R\,b for (a,b)∈R(a,b) \in R. It is reflexive if a R aa\,R\,a for all aa, symmetric if a R ba\,R\,b implies b R ab\,R\,a, and transitive if a R ba\,R\,b and b R cb\,R\,c imply a R ca\,R\,c. An equivalence relation has all three properties, and the equivalence class of aa is [a]={x∈A:x R a}[a] = \{x \in A : x\,R\,a\}. A partition is a collection of nonempty, pairwise disjoint subsets whose union is AA. A partial order is reflexive, antisymmetric (a R ba\,R\,b and b R ab\,R\,a imply a=ba = b), and transitive.

The fundamental theorem of equivalence relations says the equivalence classes of an equivalence relation on AA form a partition of AA, and conversely every partition defines an equivalence relation. They are the same concept viewed from two angles: “being equivalent” means “being in the same part.”

For example, on Z\mathbb{Z} define a∼ba \sim b if and only if 3∣(a−b)3 \mid (a - b), congruence mod 3. It is reflexive, since 3∣(a−a)=03 \mid (a - a) = 0; symmetric, since 3∣(a−b)3 \mid (a - b) implies 3∣−(a−b)=(b−a)3 \mid -(a - b) = (b - a); and transitive, since 3∣(a−b)3 \mid (a - b) and 3∣(b−c)3 \mid (b - c) imply 3∣(a−b)+(b−c)=(a−c)3 \mid (a - b) + (b - c) = (a - c). Its classes are [0]={…,−6,−3,0,3,6,… }[0] = \{\dots, -6, -3, 0, 3, 6, \dots\}, [1]={…,−5,−2,1,4,7,… }[1] = \{\dots, -5, -2, 1, 4, 7, \dots\}, and [2]={…,−4,−1,2,5,8,… }[2] = \{\dots, -4, -1, 2, 5, 8, \dots\}, which partition Z\mathbb{Z}.

Practice: Hammack chapter 11 exercises 1 to 10 and 15 to 22; for a challenge, 23 to 28.

Book of Proof chapter 12, sections 12.1 to 12.6. A function from AA to BB is a relation in which every element of AA is related to exactly one element of BB. It is an injection (one-to-one) if f(a)=f(b)f(a) = f(b) implies a=ba = b, a surjection (onto) if every b∈Bb \in B has some aa with f(a)=bf(a) = b, and a bijection if both, a one-to-one correspondence. Composition is (g∘f)(x)=g(f(x))(g \circ f)(x) = g(f(x)), and the inverse f−1f^{-1} exists if and only if ff is a bijection, with f−1(f(a))=af^{-1}(f(a)) = a.

Four theorems organize the topic. Composition preserves the properties: if ff and gg are injective, so is g∘fg \circ f, and likewise for surjective; composing two “no-collision” maps gives a “no-collision” map, and composing two “everything is hit” maps gives an “everything is hit” map. ff has an inverse if and only if it is a bijection: to undo a function, every output must come from exactly one input. Cantor’s theorem, ∣A∣<∣P(A)∣\lvert A \rvert < \lvert \mathcal{P}(A) \rvert for any set AA (there is no surjection from AA onto its power set), says there are always more subsets than elements, which is the source of different sizes of infinity. Schröder-Bernstein: if there are injections A→BA \to B and B→AB \to A, there is a bijection between them; if each set fits inside the other, they are the same size.

Two examples. f:Z→Zf: \mathbb{Z} \to \mathbb{Z}, f(n)=2n+1f(n) = 2n + 1, is injective but not surjective. If 2a+1=2b+12a + 1 = 2b + 1 then a=ba = b; but 2n+1=42n + 1 = 4 requires n=3/2∉Zn = 3/2 \notin \mathbb{Z}, so 4 has no preimage. And f:R→Rf: \mathbb{R} \to \mathbb{R}, f(x)=x3f(x) = x^3, is a bijection: if a3=b3a^3 = b^3 then a=ba = b (the cube root is well defined on R\mathbb{R}), and for any yy, x=y1/3x = y^{1/3} satisfies f(x)=yf(x) = y. Its inverse is f−1(y)=y1/3f^{-1}(y) = y^{1/3}.

Practice: Hammack chapter 12 exercises 1 to 10, 15 to 22, and 27 to 34; for a challenge, 35 to 40.

Much of the skill in the subject is recognizing which method fits a claim. This table pairs each with when to reach for it:

TechniqueWhen to useKey formula or idea
Direct proofprove P⇒QP \Rightarrow Q when definitions lead forwardassume PP, derive QQ
ContrapositiveP⇒QP \Rightarrow Q is hard; ¬Q⇒¬P\lnot Q \Rightarrow \lnot P is easiernegate both, reverse the direction
Contradictionexistence, uniqueness, or irrationality proofsassume the negation, derive an impossibility
Weak inductionprove P(n)P(n) for all n≥n \ge basebase case, plus P(k)⇒P(k+1)P(k) \Rightarrow P(k+1)
Strong inductionP(k+1)P(k+1) depends on several prior casesbase case, plus (all P(j)P(j) for j≤kj \le k) ⇒P(k+1)\Rightarrow P(k+1)
Structural inductionproperties of recursive structures (trees, lists)base structure, plus induction on construction
Proof by casesthe domain splits naturallyprove each case; make sure the cases are exhaustive
Counting (multiplication)sequential independent choicesmultiply the options at each stage
Counting (combinations)unordered selections(nk)=n!/(k!(n−k)!)\binom{n}{k} = n!/(k!(n-k)!)
Bijective proofshow two counts are equalfind a one-to-one correspondence
  • Power set: the set P(A)\mathcal{P}(A) of all subsets of AA; it has 2∣A∣2^{\lvert A \rvert} elements because each element is independently in or out of a subset.
  • Cartesian product: A×B={(a,b):a∈A,b∈B}A \times B = \{(a, b) : a \in A, b \in B\}, the set of all ordered pairs, with ∣A×B∣=∣A∣⋅∣B∣\lvert A \times B \rvert = \lvert A \rvert \cdot \lvert B \rvert; relations and functions are subsets of it.
  • De Morgan’s laws: (A∪B)c=Ac∩Bc(A \cup B)^c = A^c \cap B^c and (A∩B)c=Ac∪Bc(A \cap B)^c = A^c \cup B^c, and likewise ¬(P∨Q)  ⟺  ¬P∧¬Q\lnot(P \lor Q) \iff \lnot P \land \lnot Q; negation swaps union with intersection and OR with AND.
  • Universal quantifier / existential quantifier: ∀x P(x)\forall x\, P(x) asserts PP for every xx in the domain, and ∃x P(x)\exists x\, P(x) for at least one; negating a statement flips each quantifier, ¬∀x P(x)  ⟺  ∃x ¬P(x)\lnot \forall x\, P(x) \iff \exists x\, \lnot P(x).
  • Multiplication principle: if one task has mm outcomes and a second has nn for each of them, the sequence has mnmn outcomes; with the addition principle for mutually exclusive cases, it is the basis of all counting.
  • Binomial theorem: (x+y)n=∑k=0n(nk)xn−kyk(x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k, because each term picks yy from kk of the nn factors, which can be done in (nk)\binom{n}{k} ways.
  • Stars and bars: the number of ways to distribute nn identical objects into kk distinct bins is (n+k−1k−1)\binom{n+k-1}{k-1}, counted as arrangements of nn stars and k−1k - 1 dividers in a row.
  • Direct proof: a proof of P⇒QP \Rightarrow Q that assumes PP, unpacks the definitions, and reasons forward with known results until it reaches QQ.
  • Proof by contradiction: a proof that assumes the statement is false and derives an impossibility, so the statement must be true; it is the standard route to results such as the irrationality of 2\sqrt 2.
  • Strong induction: induction in which the step assumes P(j)P(j) for every jj from the base case up to kk, not just P(k)P(k), before proving P(k+1)P(k+1); it fits claims where a case depends on several earlier ones.
  • Structural induction: induction over a recursively defined structure such as a list, tree, or formula: prove the property for the base structures, then show that each construction rule preserves it.
  • Well-ordering principle: every nonempty set of natural numbers has a least element; it is logically equivalent to induction, since a failed induction would have a smallest counterexample.
  • Equivalence class: for an equivalence relation RR on AA, the set [a]={x∈A:x R a}[a] = \{x \in A : x\,R\,a\} of everything equivalent to aa; the classes partition AA, and every partition defines an equivalence relation.
  • Partial order: a relation that is reflexive, antisymmetric (a R ba\,R\,b and b R ab\,R\,a imply a=ba = b), and transitive, such as ≤\le or “is a subset of”; some pairs may be incomparable, which is why dependency graphs need a topological sort.
  • Cantor’s theorem: ∣A∣<∣P(A)∣\lvert A \rvert < \lvert \mathcal{P}(A) \rvert for every set AA, because no function from AA onto its power set exists; it shows there are different sizes of infinity.
  • Schröder-Bernstein theorem: if there are injections A→BA \to B and B→AB \to A, there is a bijection between AA and BB; if each set fits inside the other, they have the same size.

These ideas surface throughout computing. Propositional logic is boolean algebra, circuit design, and SAT solving; quantifiers and predicates are the WHERE clauses of database queries. Induction proves recursive algorithms correct, and loop invariants prove iterative ones, as in Graphs, DAGs, and an iterative topological sort. Sets underlie data structures such as hash sets and tree sets, and type systems. Equivalence relations underlie union-find and database normalization, and partial orders underlie topological sort and dependency resolution. Bijections are the basis of encoding and decoding, hashing, and encryption, and Modular arithmetic, hashing, and PCG32 continues in that direction. Counting and combinatorics drive algorithm analysis, from average cases and expected values in Probability and statistics to the binomial sums in divide-and-conquer recurrences.

  • Richard Hammack, Book of Proof (CC BY-ND), the textbook this chapter follows. Write your proofs by hand in complete sentences and compare them with Hammack’s solutions for style and rigor.