Across the track: Types, proofs and programs
Questions whose answers draw on more than one essay. Attempt each group after the last essay of its stage.
Programs inferred and searched
A question whose answer draws on both essays of the stage. Attempt it after What Should a Program Inherit?
One pattern, three uses
The pattern \operatorname{pair}(p,p), the most specific generalization of \operatorname{pair}(a,a) and \operatorname{pair}(b,b), appears in two essays. What does the repeated hole do in each of its three uses?
Answer
In What Must Be True? the repeated hole is the point.
Generalizing one successful example per case as specifically as possible
keeps the agreements a joint answer needs, and this reformulates the
existence of an answer (section).
In What Should a Program Inherit? the same hole is an obstacle
to recombination. It allows 2 offspring
where the linear pattern \operatorname{pair}(p,q) allows 4, which is why the 2002 draft required
linear schemata (section).
Installed as a function, duplicate(p), the dependency
becomes a reusable operation, and it hides a choice that later variation
may need (section).
One mathematical object answers three questions differently: what it
says about its instances, what it saves, and what variations it makes
available.
Promises in types and proofs
Questions whose answers draw on both essays of the stage. Attempt them after the postscript.
A pair, used as a pair
The Lean essay gives a table of what counts as evidence for each
logical connective. The postscript prints one proof whole, that
add keeps a search tree ordered. Say where the proof uses
two rows of that picture: evidence for a conjunction, and a proof of a
statement that holds for every tree.
Answer
In the Lean essay, evidence for P\land
Q is a proof of each conjunct, and a proof of \forall x:A,\,P(x) is a dependent function
that supplies a proof of P(x) for every
x (there).
In the postscript the invariant for a node is a conjunction of four
clauses, and the proof takes a proof of it apart with the pattern
⟨o1, o2, a1, a2⟩, as it would a tuple. It builds the result
the same way, from four proofs. The theorem is a function defined by
cases on the tree: given a tree and a proof that it is ordered, it
returns a proof for the tree with the key added. Its call to itself on a
subtree is the induction (there).
Reading an axioms line
The postscript shows this line of output:
'BTree.find_remove' depends on axioms: [propext, sorryAx, Quot.sound].
Using the Lean essay, say what two of the three names are and why they
are no cause for alarm. Using the postscript, say what the third is.
Which of the Lean essay’s four questions about a formalization does the
command answer?
Answer
propext is propositional extensionality, which turns an
equivalence P ↔︎ Q into an equality P = Q.
Quot.sound says that related elements have equal classes in
a quotient, and Lean derives function extensionality from it. The Lean
essay’s own example of #print axioms reports exactly these
two (there).
sorryAx is different: it is the unproved assumption that
Lean puts in place of a proof that failed, and here it appeared although
no gap was written in the source file (there).
The command answers the second question, whether the proof depends only
on acceptable assumptions (there).
Four questions, four difficulties
The Lean essay ends with four separate questions about an individual formalization. The postscript gives four difficulties in proving with agents. Match what can be matched, and say what the postscript adds that the earlier table has no row for.
Answer
The Lean essay asks whether the statement expresses what was intended, whether the proof depends only on acceptable assumptions, whether the checker implements its rules correctly, and whether those rules are consistent. It adds that success at one level does not discharge the others: “A correct kernel can check an unintended theorem.”
- The postscript’s second difficulty, the statement, is the first question. Its example is a theorem that says deletion returns a valid red-black tree and does not say the tree keeps exactly the other keys.
- The misleading source file, with
sorryAxstanding in for a failed proof, falls under the second question. - The fourth difficulty, the boundary, touches the third question. The Lean essay warns that a theorem about one checker may omit parts of the runtime used to execute it, and the postscript reports an audit that found an error in Lean’s runtime and none in the proved code.
The postscript adds two things. An agent’s own report of what it did with the proof assistant can be wrong while the checker is right. And a failed proof says less than a failed test, which hands over an input. It also notes that the proof was about a transcription of the book’s OCaml, and nothing proves the transcription matches.
Why not prove it in OCaml
The postscript says OCaml is the wrong place to give the proof that the book describes. The Lean essay says that expressive specifications are not yet a logic. State the common reason. Then say how the same reason shows up when the book’s Datalog loop is written in Lean.
Answer
In OCaml a computation may diverge or raise an exception at any result type, so every type is inhabited and a type is a weaker claim than a proposition. The Lean essay makes the point about Haskell and OCaml alike, and adds that the rules controlling proofs matter independently of how richly a datatype can be indexed (there). Lean’s kernel checks inductive declarations and their recursors, and surface recursive definitions are compiled into those principles, with well-founded recursion when needed (there). So a recursion must come with a reason why it ends. The Datalog loop, which runs until a round adds nothing, is rejected with “fail to show termination” until that reason is given: every round stays inside a finite set of possible facts (there).
In the type and out of it
The Lean essay closes on “Reading Lean means seeing those promises in the type.” The postscript says it is about the promises that are not in the type. For the reader’s promise in the book’s file module, say where each of the four languages puts it. Then say what the postscript concludes a reader gains from a promise that has been moved into a statement.
Answer
In OCaml the promise is in a comment and is kept by a flag at run
time. In OxCaml it is a mode in a signature, @ local,
checked by the compiler. In Rust it is the default: the file is a value,
and a reference that would outlive it is refused. In Lean it is not
checked and does no harm, since the handle is closed when its last
reference goes (there).
For laws, Lean lets a theorem be read in place of a test, provided
someone reads the theorem. The postscript does not conclude that what
must be read becomes small. The search tree’s laws took more lines to
state than the program has, and laws, like tests, need not shorten the
meaning. They give another way into it, in pieces that can each be read
alone and that a machine holds the program to (there).