Skip to content

11.3.1 Tools and a worked proof

This part of Discrete math 1 problem set: sets, counting, proofs, induction, relations, bijections develops the worked mechanisms below.

Concepts from other sections (17)

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.

Learning objectives

  • Connect set, logic, counting, and induction tools to a worked argument.

Before the problems, here is a review of the definitions and methods they rely on, beginning with the notation:

SymbolMeaningType / shape
x∈Ax \in Axx is an element of the set AA
A⊆BA \subseteq Bevery element of AA is in BB
A∪B, A∩B, A∖BA \cup B,\ A \cap B,\ A \setminus Bunion (in either), intersection (in both), difference (in AA, not in BB)sets
AcA^ccomplement U∖AU \setminus A inside a universe UUset
∣A∣\lvert A \rvertthe number of elements of a finite setinteger
¬,∧,∨,⇒,  ⟺  \lnot, \land, \lor, \Rightarrow, \iffnot, and, or, implies, if and only ifpropositions
∀,∃\forall, \exists“for every”, “there exists”quantifiers
n!n!1⋅2⋯n1 \cdot 2 \cdots n, with 0!=10! = 1integer
(nk)\binom{n}{k}n!k!(n−k)!\frac{n!}{k!(n-k)!}, the number of kk-element subsets of an nn-setinteger
a∣ba \mid baa divides bb: b=kab = ka for an integer kkrelation
f:X→Yf: X \to Ya function: each x∈Xx \in X has exactly one image f(x)∈Yf(x) \in Y
g∘fg \circ fcomposition, x↦g(f(x))x \mapsto g(f(x))function

A set is an unordered collection of distinct elements, written by listing, {1,2,3}\{1, 2, 3\}, or by a rule, {x∈Z:x>0}\{x \in \mathbb{Z} : x > 0\}. Order and repetition do not matter: {2,1,2}={1,2}\{2, 1, 2\} = \{1, 2\}. Two sets are equal when each is a subset of the other, which is how set identities are proved: take an arbitrary element of one side and show it is in the other, then the reverse (“double inclusion”). The power set P(A)\mathcal{P}(A) is the set of all subsets of AA; it has 2∣A∣2^{\lvert A \rvert} elements, because each element is independently in or out.

A boolean mask is a set in disguise. An attention mask over TT positions is a subset of {0,…,T−1}2\{0, \dots, T-1\}^2, the pairs (query ii, key jj) that may interact, stored as a 0/1 matrix. The causal mask is {(i,j):j≤i}\{(i, j) : j \le i\}, a padding mask is {(i,j):j<L}\{(i, j) : j < L\}, and applying both is their intersection, elementwise AND.

A proposition is a statement that is true or false. Connectives build new ones, defined by truth tables: P∧QP \land Q is true when both are, P∨QP \lor Q when at least one is, ¬P\lnot P flips PP, and P⇒QP \Rightarrow Q is false only when PP is true and QQ false. Two propositions are logically equivalent when they agree on every row of the truth table. The contrapositive ¬Q⇒¬P\lnot Q \Rightarrow \lnot P is equivalent to P⇒QP \Rightarrow Q; the converse Q⇒PQ \Rightarrow P is not. De Morgan’s laws move a negation inward and swap the connective: ¬(P∨Q)  ⟺  ¬P∧¬Q\lnot (P \lor Q) \iff \lnot P \land \lnot Q and ¬(P∧Q)  ⟺  ¬P∨¬Q\lnot (P \land Q) \iff \lnot P \lor \lnot Q. For sets they read (A∪B)c=Ac∩Bc(A \cup B)^c = A^c \cap B^c.

A predicate P(x)P(x) becomes a proposition once xx is fixed. Quantifiers close it over a domain: ∀x P(x)\forall x\, P(x) (“for every xx”) and ∃x P(x)\exists x\, P(x) (“there exists xx”). Negation swaps them: ¬∀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). With nested quantifiers, swap each one and negate the innermost predicate.

Four rules count almost everything in this book.

  • Product rule. A choice made in kk independent steps with n1,…,nkn_1, \dots, n_k options has n1n2⋯nkn_1 n_2 \cdots n_k outcomes. Strings of length kk over an alphabet of size nn: nkn^k.
  • Ordered without repetition. Arranging kk of nn distinct items in order: n(n−1)⋯(n−k+1)=n!(n−k)!n(n-1)\cdots(n-k+1) = \frac{n!}{(n-k)!}. All nn of them: n!n!.
  • Unordered without repetition. Choosing a kk-subset: (nk)\binom{n}{k}, the ordered count divided by the k!k! orders of each subset.
  • Unordered with repetition (“stars and bars”). Placing nn identical items into kk distinct boxes is arranging nn stars and k−1k - 1 bars in a row: (n+k−1k−1)\binom{n + k - 1}{k - 1}.

The sum rule adds the sizes of disjoint cases. When the cases overlap, inclusion-exclusion corrects the double count: ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣\lvert A \cup B \rvert = \lvert A \rvert + \lvert B \rvert - \lvert A \cap B \rvert.

Model sizes are counts of this kind. A matrix of shape m×nm \times n holds mnmn numbers; a layer’s parameter count is the sum over its matrices and vectors. A matrix product C=ABC = AB with AA of shape m×km \times k and BB of shape k×nk \times n computes mnmn outputs, each a sum of kk products, so it takes mknmkn multiplications and as many additions: 2mkn2mkn floating-point operations (FLOPs). A forward pass over NN parameters costs about 2N2N FLOPs per token, and training about 6N6N (the backward pass costs twice the forward), so training on DD tokens costs about 6ND6ND. The KV cache stores one key vector and one value vector of length dhd_h per KV head per layer per token, at bb bytes per number: 2LHkvdhb2 L H_{kv} d_h b bytes per token.

A proof is a finite chain of statements, each a definition, an assumption, an earlier result, or a logical consequence of earlier lines, ending in the claim. The methods differ in what they assume first.

MethodTo prove P⇒QP \Rightarrow QUse it when
Directassume PP, derive QQdefinitions unfold forward (q17)
Contrapositiveassume ¬Q\lnot Q, derive ¬P\lnot P¬Q\lnot Q gives you something to compute with (q18)
Contradictionassume PP and ¬Q\lnot Q, derive a false statementthe claim says something does not exist (q19, q20)
Casessplit PP into exhaustive cases, prove eachparity, signs, ranges (q21)
Counterexampleexhibit one xx with ¬Q(x)\lnot Q(x)disproving a ∀\forall claim (q23)
Pigeonholemore than kk objects in kk boxes put two in one boxcollisions (q24)

Definitions are the raw material: an integer nn is even if n=2kn = 2k and odd if n=2k+1n = 2k + 1 for an integer kk; a number is rational if it is p/qp/q for integers p,qp, q with q≠0q \ne 0; an integer p≥2p \ge 2 is prime if its only positive divisors are 1 and pp.

Induction proves P(n)P(n) for every integer n≥n0n \ge n_0 in two steps: the base case P(n0)P(n_0), and the inductive step “if P(k)P(k) then P(k+1)P(k + 1)” for every k≥n0k \ge n_0. The assumption P(k)P(k) is the induction hypothesis, and the step must use it rather than the conclusion. Strong induction assumes P(m)P(m) for every mm with n0≤m<nn_0 \le m < n and proves P(n)P(n); it suits claims where nn breaks into smaller pieces of arbitrary size, such as factorizations.

A loop invariant is induction over iterations. To prove a loop correct, show three things: the invariant holds before the first iteration (initialization), one iteration preserves it (maintenance), and the loop stops (termination: some nonnegative integer strictly decreases). At exit, the invariant plus the exit condition imply the result. The online softmax kernel and the topological sort both rest on arguments of this shape.

A relation RR on a set XX is a set of ordered pairs from X×XX \times X; write xRyx R y for (x,y)∈R(x, y) \in R. It is reflexive if xRxx R x for every xx, symmetric if xRy⇒yRxx R y \Rightarrow y R x, antisymmetric if xRy∧yRx⇒x=yx R y \land y R x \Rightarrow x = y, and transitive if xRy∧yRz⇒xRzx R y \land y R z \Rightarrow x R z.

An equivalence relation is reflexive, symmetric, and transitive. Its equivalence classes [x]={y:xRy}[x] = \{y : x R y\} partition XX into disjoint nonempty blocks, and every partition comes from exactly one equivalence relation, so counting equivalence relations on an nn-set is counting its partitions (the Bell number BnB_n: B1=1,B2=2,B3=5B_1 = 1, B_2 = 2, B_3 = 5). A partial order is reflexive, antisymmetric, and transitive, like ≤\le on numbers, ⊆\subseteq on sets, or “must run before” on the nodes of a computation graph (Graphs, DAGs, and an iterative topological sort).

A function f:X→Yf: X \to Y is injective (one-to-one) if f(x)=f(x′)⇒x=x′f(x) = f(x') \Rightarrow x = x', surjective (onto) if every y∈Yy \in Y equals some f(x)f(x), and bijective if both; a bijection has an inverse f−1f^{-1}. Between finite sets of equal size, injective and surjective imply each other. The number of functions from a kk-set to an nn-set is nkn^k, the injective ones number n!(n−k)!\frac{n!}{(n-k)!}, and the bijections of an nn-set to itself number n!n!. To prove ff injective, take x≠x′x \ne x' and show f(x)≠f(x′)f(x) \ne f(x'), often by cases on where xx and x′x' lie.

These two examples are siblings of q11 and q26, not problems of the set, and they show the level of detail the answers use.

Count. SmolLM2-135M’s attention uses grouped-query attention: width d=576d = 576, 9 query heads and 3 key/value heads of size dh=64d_h = 64, no biases. How many parameters do its four projections hold?

The query projection maps width 576 to 9⋅64=5769 \cdot 64 = 576 outputs: a 576×576576 \times 576 matrix, 331,776331{,}776 parameters. The key and value projections each map 576 to 3⋅64=1923 \cdot 64 = 192 outputs: 576⋅192=110,592576 \cdot 192 = 110{,}592 each. The output projection maps the 576 concatenated head outputs back to 576: 331,776331{,}776. Total: 2⋅331,776+2⋅110,592=884,7362 \cdot 331{,}776 + 2 \cdot 110{,}592 = 884{,}736. Over 30 layers that is 26,542,08026{,}542{,}080, about a fifth of the model.

Proof. Claim: 1+3+5+⋯+(2n−1)=n21 + 3 + 5 + \dots + (2n - 1) = n^2 for every integer n≥1n \ge 1.

Method: induction on nn. Base case n=1n = 1: the left side is 1=121 = 1^2. Induction hypothesis: for some k≥1k \ge 1, ∑i=1k(2i−1)=k2\sum_{i=1}^{k} (2i - 1) = k^2. Inductive step: ∑i=1k+1(2i−1)=k2+(2(k+1)−1)\sum_{i=1}^{k+1} (2i - 1) = k^2 + (2(k+1) - 1) by the hypothesis, =k2+2k+1=(k+1)2= k^2 + 2k + 1 = (k+1)^2, the claim for n=k+1n = k + 1. By induction the claim holds for every n≥1n \ge 1.

What makes it a complete proof: the claim and every symbol are stated, the method is named, the base case is explicit, the hypothesis is stated for n=kn = k and used in the step (not the conclusion), and the last line restates the claim. The model proofs for q26 to q30 below have the same shape.

The problems follow the same order as the review: sets and logic, counting, proof techniques, induction and loop invariants, relations, and functions and bijections. Answers are exact (for example (103)\binom{10}{3} or 3/43/4, not 0.750.75). Lettered parts share one answer block. The tag after each problem says what kind of answer is expected.

  1. Why start a counting proof by defining the counted objects?

    Answer

    Without a clear sample space, formulas can count duplicates or solve a different problem.

Contents · Next: Sets, logic, and counting