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.
- causal mask: the rule ; each position reads itself and the past. Read more: 11.2 Masks: causal, padding, sliding window, additive in AI Engineering
- Padding mask: a per-step boolean that freezes a finished sequence’s state and zeros its output. Read more: 9.2 LSTM (torch gate order) in AI Engineering
- FLOPs per token: for the matmul parameters touched plus the parameter-free attention term; three times that for a training step. Read more: 11.1 Counting: parameters, FLOPs, KV bytes, and memory plans
- KV cache: the stored keys and values of earlier tokens, bytes per token. Read more: 11.1 Counting: parameters, FLOPs, KV bytes, and memory plans
- Bytes per token (): total UTF-8 bytes of the val texts over their tokens; converts loss per token into bits per byte. Read more: 5.7 Tokenize and pack to llm.c .bin in Data Engineering
- Exit condition: the measurable criterion, here a minimum window plus a period of zero use, that makes removal safe. Read more: 7.2 Deprecation policy in Software Engineering
- online softmax: computing the maximum and the normalizer in one read by rescaling the running sum whenever the maximum grows. Read more: 22.4 Softmax in C: three-pass and online two-pass in AI Engineering
- Equivalence relation: a reflexive, symmetric, transitive relation; its classes partition the set. Read more: 11.3.4 Relations, functions, and validation
- Computation graph: a graph with one node per value and an edge from each value to the values it was computed from. Read more: 12.1 Graphs, DAGs, and an iterative topological sort
- One-to-one: different inputs always give different outputs; exactly the functions with an inverse. Read more: 6.5 Problem set: functions, logarithms, trigonometry, series, polynomials, and inequalities
- Bijection: a function that is both injective and surjective, and so has an inverse. Read more: 11.3.4 Relations, functions, and validation
- Injective: no two inputs share an output; for a dict, no value appears twice. Read more: 11.2 Injective, surjective, bijective: the GPT-2 byte map
- Grouped-query attention (GQA): query heads share key/value heads, each serving a contiguous group of query heads. Read more: 13.5 Grouped-Query Attention with a Cache Hook, Windows, and Sinks in AI Engineering
- Base case: an input on which a recursive function returns directly without calling itself; together with an input that strictly shrinks on every call, it guarantees that the recursion terminates. Read more: Chapter 13: Recursion and divide-and-conquer in Programming and Algorithms
- Induction hypothesis: the assumption used to prove . Read more: 11.3.4 Relations, functions, and validation
- Loop invariant: a statement that holds before a loop, survives each iteration, and with the exit condition implies the result. Read more: 11.3.4 Relations, functions, and validation
- Sample space: the set of all possible outcomes of an experiment; an event is a subset of , and probability assigns each event a number between 0 and 1. Read more: Chapter 13: Probability and Statistics
Learning objectives
- Connect set, logic, counting, and induction tools to a worked argument.
The ideas you will use
Section titled “The ideas you will use”Before the problems, here is a review of the definitions and methods they rely on, beginning with the notation:
| Symbol | Meaning | Type / shape |
|---|---|---|
| is an element of the set | ||
| every element of is in | ||
| union (in either), intersection (in both), difference (in , not in ) | sets | |
| complement inside a universe | set | |
| the number of elements of a finite set | integer | |
| not, and, or, implies, if and only if | propositions | |
| “for every”, “there exists” | quantifiers | |
| , with | integer | |
| , the number of -element subsets of an -set | integer | |
| divides : for an integer | relation | |
| a function: each has exactly one image | ||
| composition, | function |
A set is an unordered collection of distinct elements, written by listing, , or by a rule, . Order and repetition do not matter: . 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 is the set of all subsets of ; it has elements, because each element is independently in or out.
A boolean mask is a set in disguise. An attention mask over positions is a subset of , the pairs (query , key ) that may interact, stored as a 0/1 matrix. The causal mask is , a padding mask is , and applying both is their intersection, elementwise AND.
Logic and quantifiers
Section titled “Logic and quantifiers”A proposition is a statement that is true or false. Connectives build new ones, defined by truth tables: is true when both are, when at least one is, flips , and is false only when is true and false. Two propositions are logically equivalent when they agree on every row of the truth table. The contrapositive is equivalent to ; the converse is not. De Morgan’s laws move a negation inward and swap the connective: and . For sets they read .
A predicate becomes a proposition once is fixed. Quantifiers close it over a domain: (“for every ”) and (“there exists ”). Negation swaps them: , and . With nested quantifiers, swap each one and negate the innermost predicate.
Counting
Section titled “Counting”Four rules count almost everything in this book.
- Product rule. A choice made in independent steps with options has outcomes. Strings of length over an alphabet of size : .
- Ordered without repetition. Arranging of distinct items in order: . All of them: .
- Unordered without repetition. Choosing a -subset: , the ordered count divided by the orders of each subset.
- Unordered with repetition (“stars and bars”). Placing identical items into distinct boxes is arranging stars and bars in a row: .
The sum rule adds the sizes of disjoint cases. When the cases overlap, inclusion-exclusion corrects the double count: .
Model sizes are counts of this kind. A matrix of shape holds numbers; a layer’s parameter count is the sum over its matrices and vectors. A matrix product with of shape and of shape computes outputs, each a sum of products, so it takes multiplications and as many additions: floating-point operations (FLOPs). A forward pass over parameters costs about FLOPs per token, and training about (the backward pass costs twice the forward), so training on tokens costs about . The KV cache stores one key vector and one value vector of length per KV head per layer per token, at bytes per number: bytes per token.
Proof methods
Section titled “Proof methods”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.
| Method | To prove | Use it when |
|---|---|---|
| Direct | assume , derive | definitions unfold forward (q17) |
| Contrapositive | assume , derive | gives you something to compute with (q18) |
| Contradiction | assume and , derive a false statement | the claim says something does not exist (q19, q20) |
| Cases | split into exhaustive cases, prove each | parity, signs, ranges (q21) |
| Counterexample | exhibit one with | disproving a claim (q23) |
| Pigeonhole | more than objects in boxes put two in one box | collisions (q24) |
Definitions are the raw material: an integer is even if and odd if for an integer ; a number is rational if it is for integers with ; an integer is prime if its only positive divisors are 1 and .
Induction and loop invariants
Section titled “Induction and loop invariants”Induction proves for every integer in two steps: the base case , and the inductive step “if then ” for every . The assumption is the induction hypothesis, and the step must use it rather than the conclusion. Strong induction assumes for every with and proves ; it suits claims where 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.
Relations
Section titled “Relations”A relation on a set is a set of ordered pairs from ; write for . It is reflexive if for every , symmetric if , antisymmetric if , and transitive if .
An equivalence relation is reflexive, symmetric, and transitive. Its equivalence classes partition into disjoint nonempty blocks, and every partition comes from exactly one equivalence relation, so counting equivalence relations on an -set is counting its partitions (the Bell number : ). A partial order is reflexive, antisymmetric, and transitive, like on numbers, on sets, or “must run before” on the nodes of a computation graph (Graphs, DAGs, and an iterative topological sort).
Functions and bijections
Section titled “Functions and bijections”A function is injective (one-to-one) if , surjective (onto) if every equals some , and bijective if both; a bijection has an inverse . Between finite sets of equal size, injective and surjective imply each other. The number of functions from a -set to an -set is , the injective ones number , and the bijections of an -set to itself number . To prove injective, take and show , often by cases on where and lie.
A count and a proof, worked by hand
Section titled “A count and a proof, worked by hand”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 , 9 query heads and 3 key/value heads of size , no biases. How many parameters do its four projections hold?
The query projection maps width 576 to outputs: a matrix, parameters. The key and value projections each map 576 to outputs: each. The output projection maps the 576 concatenated head outputs back to 576: . Total: . Over 30 layers that is , about a fifth of the model.
Proof. Claim: for every integer .
Method: induction on . Base case : the left side is . Induction hypothesis: for some , . Inductive step: by the hypothesis, , the claim for . By induction the claim holds for every .
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 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
Section titled “The problems”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 or , not ). Lettered parts share one answer block. The tag after each problem says what kind of answer is expected.
Review questions
Section titled “Review questions”-
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.