Theory
Can you tell what a counter will read without running it? Build three proofs about a counter, from reading back its starting value to counting any number of ticks.
A test calls a function and checks the answer. A proof can be a function too: give it an input and it returns evidence about that input. We'll keep the counter and change where the evidence comes from.
Easy: compute. Read back the number you just stored.
Medium: use a promise. If two counts agree, will they still agree after a tick?
Hard: prove the next step. Start at zero and account for every tick.
At each stop, predict the answer, then open the question to compare your reasoning. To try a change yourself, choose Edit on the example, then Check. Rewind restores the published proof. You can also follow the questions and answers without running the editor.
Easy: compute the answer
What did the counter remember?
start takes a number and builds a record. Its ordinary type, Natural -> { count : Natural }, says you can read a number back. It doesn't tell you which number. Look at the return type of readStart: === is not a test that returns True or False. It forms a type whose values are evidence that the two sides are equal.
let start = \(n : Natural) -> { count = n }
let readStart : forall (n : Natural) -> (start n).count === n
= \n -> refl
in readStartThe compiler accepts this program
Why does the kernel accept refl?
Leave n unknown. Unfold start n to get { count = n }. Select count and you're back at n. The goal is now n === n; refl is the proof that a value equals itself. The proof program is \n -> refl, a function that supplies that evidence for any n. Its result type mentions its argument: that's a dependent function.
Suppose you store 3 instead. Does a passing test at 3 rescue the proof?
No. Change count = n to count = 3 and check. Reading the counter created with 3 still returns 3, but the proof now promises 3 === n for an unknown n. In particular, it would have to work for 4.
Medium: use a promise
Two counters start at a and b. You don't know either number, but the caller gives you same : a === b. Your job is to prove that ticking both counters preserves their agreement. refl alone won't do: a and b are different variables. std:Equal.cong takes a function and evidence that its inputs are equal, and gives back evidence that its outputs are equal.
let tick = \(n : Natural) -> n + 1
let together : forall (a b : Natural) -> a === b -> tick a === tick b
= \a b same -> std:Equal.cong tick same
in togetherThe compiler accepts this program
If a tick adds two instead of one, does the proof still work?
Yes. Change n + 1 to n + 2 and check. The proof uses the same function on both sides; it never uses the size of the increment. Now try replacing std:Equal.cong tick same with refl. That fails: it discards the only evidence connecting a to b.
Hard: prove the next step
Start at zero. Does a counter read n after n ticks? With an unknown n, the checker can't just run a loop n times. Instead, build the proof the way you'd write a recursive function: give an answer for zero, then turn the answer for k into one for k + 1. This is induction.
let tick = \(n : Natural) -> n + 1
let ticks = Natural/elim (\(_ : Natural) -> Natural) 0
(\(_ rest : Natural) -> tick rest)
let counted : forall (n : Natural) -> ticks n === n
= Natural/elim (\(k : Natural) -> ticks k === k)
refl
(\(k : Natural) (ih : ticks k === k) -> std:Equal.cong tick ih)
in countedThe compiler accepts this program
Read the two uses of Natural/elim side by side. The first builds a number: zero, or tick rest. The second builds a proof: at zero, ticks 0 computes to 0. In the step, ih is the proof returned for the smaller input, not a new assumption about all numbers. The medium proof's move gives tick (ticks k) === tick k. The left is how ticks (k + 1) is computed; the right is k + 1. That's precisely the next claim.
Change the tick to add two again. Which part of this proof breaks first?
The base case still checks. In the step, applying tick to ih now proves that the new count is k + 2, assuming the previous count was k. The goal still says k + 1. Try the edit, then rewind: this claim depends on the increment, unlike the medium claim.
The elaborator fills in details such as which equality refl is meant to prove. The kernel checks the resulting program against its type. These are claims about the functions above, not a guarantee about deployed bytecode. Next, step through a different induction proof in Learn or see what is checked, tested and assumed. For a contract author's use of these types, read Omegyu vs. Solidity.
References
Start with Coquand and Huet’s Calculus of Constructions for the idea behind readStart: a function can return evidence about its input.
Browse all references
Where the rules come from
These are the foundations, alternatives and limits cited in the language design notes. None proves the full kernel or EVM backend correct.
Checking a proof
Coquand & Huet, The Calculus of Constructions: dependent functions. Omegyu adds numbers, records and primitive equality.
Coquand, An Algorithm for Type-Checking Dependent Types; Abel & Coquand, Untyped Algorithmic Equality: compare functions at a fresh variable. Omegyu also compares records.
Lennon-Bertrand, What Does It Take to Certify a Conversion Checker?: why untyped comparison doesn't equate every unknown empty record with
{=}.De Santo & Weirich, Rebound: track variable scopes in types. Omegyu's evaluator uses environments rather than general substitution.
Filling in what the reader didn't write
Kovács, Elaboration With First-Class Implicit Function Types: infer omitted arguments before kernel checking. Code: elaboration-zoo for insertion; smalltt for retaining definition names.
Abel & Pientka, Higher-Order Dynamic Pattern Unification: pruning keeps inferred arguments within scope.
Gratzer et al., Controlling Unfolding in Type Theory: the paper offers explicit controls; Omegyu compares names before unfolding them automatically.
Records and their alternatives
Leijen, Extensible Records with Scoped Labels: repeated labels shadow. Morris & McKinna, Rows by Any Other Name: the wider family of row theories. Omegyu checks scoped-row equality directly.
Alternatives: Pottier & Rémy, The Essence of ML Type Inference, tracks absent labels; Chlipala’s Ur computes with record concatenation. Neither rule is needed for shadowing.
Hubers & Morris, Generic Programming with Extensible Data Types; Hubers et al., Abstracting Extensible Recursive Functions: alternatives for extensible cases. The latter draws on Allais et al., New Equations for Neutral Terms; Omegyu doesn't adopt those equations.
Universes and the limits of the proofs
Kovács, Generalized Universe Hierarchies and First-Class Universe Levels; Danielsson et al., Normalisation for First-Class Universe Levels: results for level parameters, not Omegyu's combination with an impredicative bottom universe.
Géran, A Canonical Form for Universe Levels: compare levels by decomposing
imaxexpressions into sublevels.Coquand, An Analysis of Girard’s Paradox; Hook & Howe, Impredicative Strong Existential Equivalent to Type:Type: why storing a large type in a small pair is unsafe.
Luo, An Extended Calculus of Constructions; Altenkirch, Constructions, Inductive Types and Strong Normalization: model and termination results for related calculi only.
Hurkens, A Simplification of Girard’s Paradox; Abel & Coquand, Failure of Normalization: cautions behind two restrictions—only one impredicative universe, and no proof-irrelevant equality.