Inside judge: where a run needs a statement

A step-through of how judge (lib/rules.disp) proves a function type for ten small definitions, and of the two places it stops and needs a fact about some other function. Each case list below was recorded from the real checker; the steps inside each case are written out from the machine's rules in lib/machine.disp and the evaluator in lib/confirm.disp, with the line that does each one.

xs.tail an input piece: one unknown argument (or a part of one), "some List(Nat), not saying which" rev(xs.tail) the hypothesis's answer: what the recursive call returns, known only by its type cat(…) a lemma's answer: a call to an already-proved function, known only by that function's type

1. Only one rule looks at its argument

The checker runs the program's tree on the machine in lib/machine.disp, the same step function that runs plain trees (m_rule, line 72). The evaluator in lib/confirm.disp (sapply_from, line 574) adds one thing: an application that would read an unknown value's shape is held back from the rules and answered separately (held, line 526). Four of the five rules only build, drop or copy the argument. Only the triage rule asks for its shape, so every is_leaf, is_zero, .fst and if on data ends up there.

What triage can be handed

The rule is t (t a b) c z. Pick what z is:

2. A stream is a tree

Both checkers below read a stream, and in disp a stream is an ordinary tree: a step function and a state, paired (lib/stream.disp). Nothing runs until something pulls it. A pull, c_out, runs the step function on the state once; what comes back says what the stream emitted and holds the next stream, which is the same pair with the new state.

c_new :: {fmap : (X -> Y) -> F(X) -> F(Y), stepper : St -> F(St), state : St} -> Coalgebra(F) :=> pair(fmap, pair(stepper, state))
c_out :: {c : Coalgebra(F)} -> F(Coalgebra(F)) :=> c.c_fmap(c_with(c), c.c_stepper(c.c_state))
s_new :: {stepper : St -> Step(Ending, Emit(Option(V), St)), state : St} -> Items(V) :=> c_new(item_map, stepper, state)

A stream of possible counterexamples is decided by verdict: pull until something is yielded (Refuted, with it) or the stream ends (Exhausted: Proved; Spent: Open, with the reason). Two different streams feed it on this page.

verdict :: {witnesses : Bounded(Items(Tree))} -> Verdict :=> c_fold({recurse, step} =>
	if (step.is_finished) { ending_verdict(step.finished_result) }
	else if (step.step_draw.is_yield) { refuted(step.step_draw.yielded_item) }
	else { recurse(step.step_rest) }
, witnesses)

// brute force (lib/claim.disp): every tree, smallest first; keep the ones the program fails
honest :: {source : Items(Tree), claim : Claim, w : Tree, budget : Nat} -> Verdict :=>
	verdict(source.s_filter({c} => not(claim(w, c))).bounded(budget))

// what judge runs (lib/confirm.disp): a work list of cases, read for its counterexamples
search_steps :: {checks : List(Val -> Res), ground : Val -> Option(Tree), instances : Val -> List(Val), start : List(Pair(Val, Nat))} -> Items(Step) :=>
	s_steps(settle_case(checks, ground, instances), start)
// (lib/stream.disp) what a work list yielded
s_yielded :: {steps : Items(Pair(I, Outcome(V, I)))} -> Items(V) :=> steps.s_filter({step} => step.snd.is_yield).s_map({step} => step.snd.yielded_item)
steps_verdict :: {steps : Items(Step)} -> Verdict :=>
	verdict(s_yielded(steps))
search_g :: {checks : List(Val -> Res), ground : Val -> Option(Tree), instances : Val -> List(Val), input : Val, depth : Nat} -> Verdict :=>
	steps_verdict(search_steps(checks, ground, instances, [pair(input, depth)]))

s_filter and bounded do not run anything either: each builds a new stream whose step function calls the old one and rewrites what it emitted (a kept item becomes a skip; the last unit of fuel becomes the end). The work list is a stream whose state is a pair: the cases still to do, and the reasons noted so far.

s_steps :: {settle : I -> Outcome(V, I), start : List(I)} -> Items(Pair(I, Outcome(V, I))) :=> s_new({st} => {
	let todo := st.fst
	let notes := st.snd
	if (todo.is_nil) { finished(if (notes.is_nil) { exhausted } else { spent_on(notes.head) }) }
	else {
		let out := settle(todo.head)
		let rest := if (out.fst == "Split") { pair(out.snd.snd.append(todo.tail), notes) }
			else if ((out.fst == "Noted") && (notes.is_nil)) { pair(todo.tail, [out.snd]) }
			else { pair(todo.tail, notes) }
		running(emit(yield(pair(todo.head, out)), rest))
	}
}, pair(start, []))

So the "work list" in the next section is not a separate structure: it is this state, and each case in the case tree is one pull. The stream yields every case with what settled it; s_yielded keeps only the counterexamples, so to verdict a settled case is a skip. The settle function is settle_case; an item is a pair of the case's arguments and the splits left. The same list read back as data is derivation (lib/rules.disp, line 293).

3. Step through a proof

Pick a definition. Step walks the run of the next case; the last step of each case is one pull of the work-list stream, which settles the case with settle_case (lib/confirm.disp:872). Every case is run exactly first. Where definitions already Proved are given as lemmas and that run does not settle the case, it is run again with them read by their types. A case a run answers Yes for is done for every input it stands for, and the Yes says what it rests on besides the run: the hypothesis (induction), a lemma; a case whose run needs an input piece's shape is split into that type's cases; a stuck run is noted and makes the verdict Open; a known input that fails is a counterexample and ends the search.

The work list

Inside the case

    The work-list stream, as a tree

    The stream verdict reads (the work list with its counterexamples kept): the real value after each pull, recorded with c_out. Each two-slot box is a fork t(left, right); t alone is the leaf, which is also the empty list. The highlighted item is the one the next pull settles.

    The honest stream, for comparison

    The first 48 pulls of honest(Trees.as_items, claim, w, 48), recorded: every tree, smallest first. A tree outside the domain passes the claim trivially and becomes a skip; a member is run, and kept (yielded) only if the output is not in the codomain. The tag on a member is the case of the work list that covers it, filled in as cases settle.

    4. Where the optimization is

    Nothing rewrites one stream into a faster one. The speed-up is the choice of source: verdict reads either stream the same way, and the work list is built so that it never disagrees with the honest one.

    honest streamwork-list stream
    one pull handlesone treeone case: every input it matches
    most pulls areskips of trees outside the domainsplits, or a case answered Yes
    can end Exhausted (Proved)only over a finite listed source (over, lib/claim.disp)yes, when the list runs out with nothing noted
    why its verdict is rightit is the definitionthe rule atoms in lib/rules.disp (case split, generic run, induction), each a lens into the honest claim, proved by hand once
    the same thing as a lenssteps_lens (lib/rules.disp): each split sends a tree to the case that covers it, and composed they send every argument to the case that settled it. Its law, steps_law, is attacked by search in lib/tests/rules.test.disp
    checked against the otherlib/tests/confirmer.test.disp cross-checks every Proved against the enumeration refuter (TYPES.html section 9)

    A stream-to-stream optimizer is only sketched (TYPES.html section 10): dropping skips gives the same stream at the weak quotient and a faster one at the strong type. None is implemented.

    5. Where the statement comes in

    Run the ten definitions and the pattern is short.

    Why not split the hypothesis's answer as if it were an input? Splitting it would be sound, since every list is [] or a cons. But cat would then recurse on the tail of that answer, with no hypothesis of its own: that is the wrap situation. Either way the missing piece is an induction on cat, and its statement is what the annotation on cat supplies. (The checker does not try this; the paragraph is the reason it would not help.)

    6. How these were recorded

    Every case list and verdict above is the output of derivation and judge_with (lib/rules.disp) on the working tree, re-run on 2026-11-10 with the probe below. The work list reads itself back, so the probe no longer repeats the checker's logic.

    The stream states and the honest stream's 48 pulls were recorded on 2026-11-09 by a second probe that pulls the real streams with c_out and describes each state. The cases, their order and what settles each are the same now, so those states still hold. The text of each step is not recorded: it is the path the evaluator takes for that case, written out by hand, with the line responsible.

    The probe

    Companion to TYPES.html (what the verdicts mean) and lib/theories/checked.disp (the world that uses lemmas).