Rigor standard for theory boxes¶
This page is binding for every definition, theorem/proposition/lemma/corollary,
algorithm and proof box in the course (DEPTH_CONTRACT.md §2a). It exists because the
first draft of the course had 549 definition boxes that used symbols nobody had introduced.
./course validate enforces §2 mechanically (symbols warnings; errors under --strict).
The test for every box is the one a reader applies: can I check this statement without guessing what any symbol means? A box passes when every symbol in it has exactly one meaning that the box itself (or a reference it names) pins down.
1. The anatomy of a definition¶
A definition box has four parts, in this order.
- Signature. Name every object the definition talks about, with its type: the sets it
ranges over, the functions with domain and codomain, the parameters with their ranges.
Let $G = (N, E, r)$ be a flowgraph and $k \ge 1$ an integer. - The term being defined, in bold, with its notation if it has one:
A node $d$ **dominates** $n$, written $d \mathrel{\mathrm{dom}} n$, if … - The defining condition, as a precise predicate or construction. Quantifiers are
explicit (
for every path,there exists). Each clause is a mathematical statement, not an example. - Derived notation, with
\triangleq:$\mathrm{Dom}(n) \triangleq \{\, d \in N \mid d \mathrel{\mathrm{dom}} n \,\}$.
What does not belong in the box: examples ("source files, compiler flags"), motivation,
implementation remarks, and names of real systems. They go in the prose before the box or in
an !!! example box after it (DEPTH_CONTRACT R7). A parenthetical that lists instances is an
example, not a definition.
A theorem-like box has the same shape without part 2: signature (hypotheses with their quantifiers), then the conclusion. "If \(G\) is \(k\)-simplifiable" is a hypothesis only when \(G\) and \(k\) have been introduced in that sentence or earlier in the same box.
An algorithm box types its Input and Output with the sets of the definitions ("Input: a flowgraph \(G = (N, E, r)\) with \(r\) reachable to every node"), and every symbol in its pre/postconditions and invariants is introduced in the same way.
1.1 Operational terms are defined objects¶
An algorithm box may only do things the definitions give a meaning to. "Mark \(v\) green", "\(v\) is colored", "the previous session", "\(u\) is unchanged" are not self-explanatory: the state they refer to is a mathematical object and the operation is an update of it.
- State is a function introduced in a definition: a coloring \(c : V \to \{\bot, \mathrm{green}, \mathrm{red}\}\), with \(c(v) = \bot\) for uncolored.
- An operation is an update of that function with its meaning stated: "marking \(v\) green sets \(c(v) \triangleq \mathrm{green}\); it asserts \(\mathrm{val}(v) = \mathrm{val}_{\mathrm{old}}(v)\)."
- Anything the algorithm compares against the past is a named object: the previous session is the triple \((G_{\mathrm{old}}, \mathrm{val}_{\mathrm{old}}, \mathrm{fp}_{\mathrm{old}})\).
The test: every verb in the pseudo-code and every adjective applied to a node, edge, set or value appears in a definition box with a symbol, or the box says in words exactly what the verb changes.
2. Every symbol is introduced before use¶
A symbol is introduced in a box by one of these forms, and ./course validate recognises
exactly these:
| Form | Example |
|---|---|
| a binder word followed by the math | Let $S$ be a set, Fix $k \ge 2$, for every node $v \in N$, for a string $w$, where $m = \lvert E \rvert$, with $\sigma$ a state, write $u \leadsto v$ for …, Given $f : A \to B$ |
| a noun phrase naming the object | a node $v$, an integer $k$, the string $w$, each item $I$ |
| a typing or membership inside the math | $x \in S$, $A \subseteq N$, $f : A \to B$, $f \colon A \rightharpoonup B$ |
| a definitional equation | $\mathrm{Dom}(n) \triangleq \dots$ (introduces \(n\) and names \(\mathrm{Dom}\)), $G = (N, E, r)$, $n = \lvert N \rvert$ at the start of a formula |
| a bound variable | $\forall x \in S$, $\exists y$, $\sum_{i=1}^{k}$, $\bigcup_{p \in \mathrm{preds}(n)}$, $\{\, x \in S \mid P(x) \,\}$, $\{ (u, v) \mid u \in \mathrm{deps}(v) \}$, $\lambda x.\, e$ |
| the chapter Notation table or NOTATION.md, for named symbols only | $\mathrm{preds}(n)$, $\mathcal{D}$, $\varepsilon$, $\sigma$ listed in the README's ## Notation |
2.1 Letters are local to a box¶
A single Latin letter (\(n\), \(k\), \(G\), \(v\)) means different things in different boxes, so a box never inherits one from the README, from another lesson, or from the prose around it. Each box binds every letter it uses. "Let \(G = (N, E, r)\) be a flowgraph" costs one line and is repeated in every theorem about flowgraphs; that repetition is the convention of mathematical writing, not a defect.
Named symbols (\(\mathrm{Dom}\), \(\mathrm{FIRST}_k\), \(\mathcal{D}\), Greek letters with a
fixed chapter-wide meaning such as \(\sigma\) for a state) are chapter-wide once the README's
## Notation table lists them, and a definition box may use the names that earlier
definition boxes of the same lesson introduced.
2.2 Index letters¶
\(i\), \(j\), \(k\) that appear only inside subscripts, limits or \dots ranges
(\(a_1, \dots, a_k\); \(x_i\)) count as bound by that use. The moment \(k\) appears on its own
("\(k \ge 2\)", "in \(k\) rounds") it must be introduced.
2.3 Prose, proofs, examples and tables: lesson-wide scope¶
The rule is not limited to the numbered boxes. Every $…$ in a lesson, in the running text,
in a proof, an example, a worked-example trace, a comparison table or a real-world box, uses
only symbols that the lesson has introduced earlier (in a box, or in a sentence of prose
using the same forms: "for a program with \(n\) instructions", "write \(w\) for the input"). A
proof may introduce its own objects ("Let \(P\) be a shortest path"); it may not use \(P\)
without that sentence. A table cell with \(O(n \log m)\) needs \(n\) and \(m\) introduced before
the table. ./course validate reports the first use of each symbol that precedes its
introduction.
2.4 Prose stays out of math¶
Words inside $…$ are typeset as products of variables and are reported ("prose inside
math"). Write \text{red} for prose, \mathrm{red} for a name.
3. Theorems and proofs¶
- Hypotheses are complete. Every assumption the proof uses is in the statement: determinism, finiteness, reducibility, "collision-free hash", "the entry has no predecessors". An assumption introduced only in the proof ("assume the hash is injective") is a defect.
- Quantifiers are explicit and in the right order: "for every \(n \neq r\) there is a unique \(d\)" versus "there is a \(d\) such that for every \(n\)".
- Proofs name what they use. Each step cites the definition, earlier result or hypothesis it rests on ("by Definition 15.1.2", "by the induction hypothesis on \(\lvert P \rvert\)"). "Clearly", "it is easy to see" and "obviously" are never steps.
- Sketches are labelled and name where the full proof is (DEPTH_CONTRACT R3).
- A proof may introduce its own auxiliary objects ("Let \(P\) be a shortest such path") but never a hypothesis.
4. Worked rewrite¶
Before (the original Definition 0.1.11):
A query system is a set of input nodes (source files, compiler flags) and derived nodes \(v = q(k)\), each with a provider — a deterministic function that computes \(\mathrm{val}(v)\) from the values of the nodes it reads. Executing a provider records the sequence \(\mathrm{deps}(v)\) of nodes it read, in order. The recorded graph \((V, \{ (u, v) \mid u \in \mathrm{deps}(v) \})\) is the dependency graph …
What is wrong: \(q\), \(k\), \(u\), \(v\) and \(V\) are never introduced (\(V\) appears only inside a tuple); "the values of the nodes it reads" is not a mathematical object; the examples in parentheses are not part of the definition; "a hash … assumed to imply equal values" hides an assumption that the correctness theorem needs as a hypothesis.
After:
!!! definition "Definition 0.1.11 (Query system, dependency graph, fingerprint)"
Let $Q$ be a finite set of **query kinds** and $K$ a set of **keys**. A **query system**
over $(Q, K)$ consists of
- a set $V = I \cup D$ of **nodes**, where $I$ is the set of **input nodes** and
$D \subseteq Q \times K$ the set of **derived nodes**; a derived node $(q, k)$ is
written $q(k)$;
- a set $\mathcal{U}$ of **values** and, for every input node $x \in I$, its value
$\mathrm{val}(x) \in \mathcal{U}$;
- for every derived node $v \in D$, a **provider** $\mathrm{prov}_v$: a deterministic
procedure that reads a finite sequence of nodes $\langle u_1, \dots, u_m \rangle \in V^{*}$
and returns a value in $\mathcal{U}$, where each $u_{j+1}$ may depend on
$\mathrm{val}(u_1), \dots, \mathrm{val}(u_j)$.
Running $\mathrm{prov}_v$ defines $\mathrm{val}(v) \in \mathcal{U}$ and records
$\mathrm{deps}(v) \triangleq \langle u_1, \dots, u_m \rangle$, the sequence of nodes it
read, in reading order. The **dependency graph** is the directed graph
$G \triangleq (V, \{\, (u, v) \mid v \in D,\ u \in \mathrm{deps}(v) \,\})$; a query system is
**well-founded** if $G$ is acyclic.
A **fingerprint** is a function $\mathrm{fp} : \mathcal{U} \to \{0, 1\}^{b}$ for some
$b \ge 1$; it is **collision-free** on a run if $\mathrm{fp}(x) = \mathrm{fp}(y)$ implies
$x = y$ for all values $x, y$ that occur in that run. For a node $v$ we write
$\mathrm{fp}(v)$ for $\mathrm{fp}(\mathrm{val}(v))$.
Every letter is introduced where it first appears; the examples ("source files", "compiler
flags", "type_of") moved to the prose before the box; the hash assumption became a named
hypothesis ("collision-free") that Theorem 0.1.19 can state.
5. Revision procedure (for chapter agents)¶
For every lesson of the chapter, in order:
- Run
./course validate --strict 2>&1 | grep "<slug>"anduv run python -m course.symbols <lesson.md>is not needed:validateprints one line per box with the symbols it could not find. - Fix every box the checker reports, then read every remaining theory box against §1–§3 by hand: the checker finds missing introductions, not wrong or vague ones.
- Keep the numbering: do not add or remove numbered boxes unless a definition is genuinely missing (then renumber the lesson and update every cross-reference, the README Notation table, quiz explanations and flashcards that cite the number).
- Move examples and system names out of definition boxes into the prose or an
!!! examplebox. - Where a theorem gained an explicit hypothesis, check that its proof uses it and that the algorithm's Precondition states it.
- Re-run
./course validate --strictfor the chapter,./course quiz verify, and the strict site build; render the lesson and read it once more on the page.