Skip to content

Standardness: !!e, and steps that need a term to have a value - #2853

Draft
Negabinary wants to merge 18 commits into
prover-mainfrom
prover-standardness
Draft

Negabinary wants to merge 18 commits into
prover-mainfrom
prover-standardness

Conversation

@Negabinary

Copy link
Copy Markdown
Contributor

Stacked on #2823 (prover-main).

Quantifiers range over standard values: values whose parts are standard, where a function is standard when it gives a standard result on every standard argument. The checker relies on that wherever a step puts a term in a binder's place. On prover-main, Totality judged those terms, and a step at a term it couldn't judge was refused. This PR names the property, !!e, and makes each such step carry !!e as a condition the proof can discharge or leave for later. It also restricts four kernel rules that are unsound once terms can lack a value.

The language

  • !!e is a Bool expression. Evaluation evaluates e, then gives true for an atom and the && of !! over a tuple's, list's or constructor's parts. A function steps to forall (x : T) -> !!f(x), which is stuck: only a proof shows a function standard. So !!e is never false: !!(1 / 0) is an error and !!loop() loops.
  • !! is one token, so double negation is written !(!b).
  • forall (x : T !! h) => in a proof names the binder's fact, h : !!x.

Where a step needs a term standard

  • Instantiating a quantified binder: a cited rule's binders, its with, revert ... with. refl is the exception: it holds at every term, and needs nothing, not even domain conditions.
  • Splitting on a computed scrutinee with cases or induction.
  • assume on P ==> Q needs !!P. Without it, L = fix x -> x ==> false proves false (Curry's paradox).
  • step at a redex whose argument isn't a value. (fun x -> 0)(loop(0)) isn't 0.
  • algebra treats an Int or Nat subterm it can't verify itself, such as a call or a division, as an unknown, and each unknown must be standard. Without that, loop = fun x -> loop(x) + 1 gives a proof of 0 == -1.
  • funext applies only when the functions' argument type is data. At a function type, fun h -> !!h and fun h -> true agree on every standard argument but aren't equal.

None of these refuses the step. It incurs the condition as an obligation, shown with the others.

How !!e is discharged

The standardness routine reduces !!e to the domain conditions e needs, such as b != 0 for a / b, which discharge as they did before. It reads the term's shape, its definitions and their code: a structurally recursive function, or one that counts a number down under a guard (if n <= 0 then 1 else n * f(n - 1)), is standard on standard arguments. A partial primitive is standard through a builtin rule a proof can cite, such as div_standard : forall (a : Int) -> forall (b : Int) -> !!(a / b) == (b != 0). A branch's conditions hold under its guard, so if b == 0 then 0 else a / b needs nothing.

Where the routine can't judge e, the step incurs !!e itself. That discharges by a fact in scope that states it, by closed evaluation (which never runs recursive functions), or by one application of a quantified fact forall x̄ -> !!p. Otherwise it stays pending, to be proved by hand.

The builtin rule standard : forall x -> !!x, cited with rewrite, closes a !!e goal wherever the above shows e standard.

What changes for existing proofs

  • Totality is deleted, along with the PossiblyDivergentInstantiation and PossiblyDivergentScrutinee marks.
  • A proof that assumes something about an untyped binder shows a pending !! on assume: x > 0 isn't known standard when x could be a function. The affected tests annotate their binders.
  • A variable that focusing opens under a lambda, let or case arm of the goal is standard only when its type is data.
  • (fun x -> 0)(1 / 0) == 0 now rests on 0 != 0.

The UI

  • A !! condition's circle reads !!, under a "standardness" section. A pending one offers "Prove here" but not "Split on it", since !!e is never false.
  • The inspector's badge gives the routine's verdict at the cursor: "standard", "standard where z != 0", or why it can't tell.
  • ExplainThis says, for each step form, when the step needs a term standard.
  • A docs slide, Prover / Standardness.

Not in this PR

Existentials, whose witnesses would also need to be standard.

Commits

Seventeen, in reading order. The first four add !!e, funext's restriction, evaluation and the named binder. The next four build the routine, and the ninth switches the checker from Totality to !! conditions. The rest add a case each: refl, counting down, algebra, beta, quantified facts, assume, the rule standard, and the UI. Each was built and its targeted tests run on its own.

Status: quick suite 5417, the corpus (84) and make ci-check pass at the top, and DocSlides.ReparseBackuptext passes with the new slide. Checked in the browser: the !! circle open and closed, the inspector badge, and the slide.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.65973% with 368 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.15%. Comparing base (74ab4fb) to head (b5ac2df).

Files with missing lines Patch % Lines
src/language/proof/Standardness.re 76.52% 142 Missing ⚠️
src/language/dynamics/transition/Transition.re 52.38% 40 Missing ⚠️
src/language/proof/ProofCheck.re 83.41% 34 Missing ⚠️
src/language/proof/Bounds.re 69.56% 28 Missing ⚠️
src/web/app/inspector/CursorInspector.re 0.00% 17 Missing ⚠️
src/web/view/StepperView.re 0.00% 13 Missing ⚠️
src/menhirParser/AST.re 0.00% 10 Missing ⚠️
src/web/exercises/SyntaxTest.re 0.00% 9 Missing ⚠️
src/language/proof/StructuralRecursion.re 91.13% 7 Missing ⚠️
src/web/app/explainthis/ExplainThis.re 0.00% 6 Missing ⚠️
... and 27 more
Additional details and impacted files
@@               Coverage Diff               @@
##           prover-main    #2853      +/-   ##
===============================================
+ Coverage        51.75%   52.15%   +0.39%     
===============================================
  Files              510      511       +1     
  Lines            62847    63923    +1076     
===============================================
+ Hits             32528    33336     +808     
- Misses           30319    30587     +268     
Files with missing lines Coverage Δ
src/docslides/Slides.re 100.00% <ø> (ø)
src/haz3lcore/lang/Form.re 94.57% <100.00%> (+0.02%) ⬆️
src/haz3lcore/lang/MakeTerm.re 81.99% <100.00%> (+0.03%) ⬆️
src/language/dynamics/stepper/EvaluatorStep.re 54.58% <100.00%> (+0.54%) ⬆️
src/language/dynamics/transition/Ascriptions.re 89.58% <100.00%> (+0.05%) ⬆️
src/language/grammar/FormId.re 85.95% <100.00%> (+0.19%) ⬆️
src/language/proof/Axioms.re 100.00% <100.00%> (ø)
src/language/proof/Occurrence.re 74.79% <100.00%> (+0.20%) ⬆️
src/language/proof/ProofRule.re 53.98% <100.00%> (+2.13%) ⬆️
src/language/term/TermBase.re 62.40% <100.00%> (+0.18%) ⬆️
... and 39 more

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Negabinary and others added 18 commits November 25, 2026 14:03
Adds a prover to Hazel. A theorem's proof is checked as it is written,
and a stepper shows the proof as a chain of goals and writes steps for
you.

Theorems. `theorem t = <statement> proof <proof> in e`. The statement's
outer `forall`s are introduced automatically. A theorem is proven,
refuted or incomplete.

The proof language:
- `step`: one evaluation step at the root. Where evaluation has none,
  a function or `let` at the root takes its argument as it is (beta at
  any argument), so `from inc(2 + 3) do step end` gives `2 + 3 + 1`;
- `rewrite h end` and `rewriteleft h end`: rewrite with a fact, theorem
  or axiom, left to right or right to left;
- `algebra e end`: an algebraic rewrite, checked with Algebrite;
- `from p at n do <steps> end`: run steps on the nth occurrence of a
  subterm (`at 1` is the default);
- `forall`, `funext`, `revert`, `generalize` and `alias`;
- `assume P =>` on a goal `P ==> Q`, and `have P proof <proof> =>` on
  any goal. Their facts are named `assume` and `have`, or `h` when
  written `assume h = P` or `have h = P`. `assume` on any other goal is
  refused;
- `cases e`: a split on any expression. Each case has the case equation
  `e == pat`, named `case_eq`, and no inductive hypothesis. A nested
  split that needs the outer equation names it with `alias`;
- `induction e`: each case has inductive hypotheses `ih_<var>` and no
  case equation. A computed `e` is generalized first, and in each case
  the facts that mention the scrutinee leave scope. Nothing gives both: to
  carry a fact into the IH, `revert` it first.

Proof words are keywords only in proof syntax. Elsewhere both parsers
read them as ordinary names, so a program can still bind `from`, `at`,
`have` or `induction`; only `theorem` and `forall` are reserved.

The checker. `ProofCheck` records, for each proof node, its incoming and
outgoing goal, its marks, its obligations and its scope (`ProofMap`).
Goals are kept as written: a definition is unfolded only where a step
needs to look inside it.

Checking runs in the evaluation worker, as part of evaluation. Each
theorem's check is cached and reused while the theorem, the theorems it
can cite, their verdicts and the definitions it names are unchanged. The
checker reads the statics through `ProofStatics`: the full statics map in
the CLI and tests, and in the worker the `EvalInfo` sent with each
request, which carries types, coverage and theorem namespaces only for a
program that has theorems. A program without theorems sends and computes
nothing extra.

Algebra. The worker has its own Algebrite, loaded the first time a proof
has an `algebra` step. A step is verified when it is Int arithmetic (`+`,
`-`, `*`, powers) over literals and Int-typed variables, or Nat
arithmetic (`+`, `*`, powers) over Nat-typed ones, checked as integers.
Anything else, such as division, Nat's `monus` or a function call, stays
an open condition. Two built-in rules state the Nat facts algebra can't
check: `nat_succ_ne_zero` (`(m + 1 == 0) == false`) and `nat_add_sub`
(`monus(a + k, k) == a`).

Side conditions. Definedness (`x / y` needs `y != 0`) and rule premises
become obligations. Facts in scope or evaluation discharge them;
otherwise they stay open. Evaluating a closed condition stops at its
first error.

Citations. Theorems are checked in program order, each knowing the
verdicts of those before it. Citing a refuted theorem is an error on
that step. Citing an unfinished one is allowed: it is an assumption, not
a gap. A theorem that mentions a variable the program has rebound since
is about the old binding, so no step can cite it; the step is marked
with the variables that were rebound.

Status. A theorem reads:
- proven: finished, relying on nothing unproven;
- proven*: finished, but citing theorems that aren't; the star's tooltip
  names them;
- incomplete: a hole, or an open condition other than a citation, with
  a quiet count of the open conditions ("incomplete · 1 open"). Clicking
  the count scrolls to the first one;
- refuted.

An exercise's score counts proven theorems only, since a student could
cite an unproven lemma that states the theorem itself.

Equality. The polymorphic `==` equates exactly the values no program
can tell apart, so rewriting with it is sound: two NaNs are equal, which
`refl` needs, and `0.0` and `-0.0` are not, since `1.0 /. x` tells them
apart. Float patterns match as `==` compares. The Float-only `==.` stays
IEEE, so `0.0 ==. -0.0`.

The stepper is a projection of the proof. Each line between two goals is
a step, and structured steps (induction, `forall`, `have`, focus) draw as
blocks.
- Each side condition is a circle on its step's line. An open one is red,
  and its exits, "Prove here" (a `have`) and "Split on it" (a `cases`),
  patch the proof.
- The main interaction is a write box after an unfinished proof, with
  three tabs:
  - Write: type the goal you want next, and a bounded search finds steps
    that reach it. An empty box offers the next step or reflexivity,
    which Tab takes. With part of the goal selected, the offer is the
    outermost step in it, and the box rewrites just that part. Typing a
    rule's name lists its uses.
  - Step: green highlights on what can step. A click writes a focused
    step at that node.
  - Strategy: one button per structured step, each writing its form
    with holes for the user to fill.
- A block's header names the fact it introduces. What a focus works on
  shows as the underline in the goal above, not in the header.
- Every offer is checked before it's shown.
- Focus selectors are generalized with `$e`, so proofs survive edits.
- Stepper edits keep the user's comments and layout.

Writing steps out. For teaching: a student learns the rules of reduction
by writing each step out, so a "Write out steps" setting makes the
stepper help with none of it. The setting is in the stepper settings
beside "Proof steps" and in the stepper's gear menu. Theorem exercises
carry the same flag, toggled by an instructor; it turns the mode on and
can't turn the setting off. Saved settings and exercises without the
field load with it off.

In the mode, nothing in the theorem or cell stepper offers a step: there
is no Step tab or its goal marks, no ghost for Tab to take, no list of a
rule's uses, no "Try other direction" repair, and writing at a hole
doesn't bridge back to the steps after it. No completion is offered
either: the write box completes no name, and its editor suggests no
type-directed completion, so Tab inserts nothing. The box writes only a
goal one step reaches, and says when the typed goal is further away.
The Write and Strategy tabs, side condition exits, deleting a step and
undo stay.

The documentation slides get a Prover section: short slides on
theorems, the stepper, lemmas, induction and side conditions, and one
whose proofs use every step form. Clicking a step shows its docs entry,
titled by what the user types. ProverDocs checks each theorem on the
slides has the status its text gives.

Editor changes outside the prover:
- The holes completion adds inside a tile, such as the proof of a
  half-typed `theorem t = 1`, keep their ids across edits, so the stepper
  keeps its state while the statement is typed.
- Folding a selection that isn't a whole term, such as a `let ... in`
  header without its body, is refused. It used to crash the editor.
- A toggle that is on shows the accent color. The shared toggle's on and
  off tracks were two shades of one hue, so an off toggle looked on.

Known soundness gaps are pinned as tests in
`test/evaluator/Test_ProverKnownBugs.re`. Each asserts today's wrong
behaviour, so a fix shows up as a failing pin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`!!e` holds when e evaluates to a value whose parts are standard; a
function is standard when it gives a standard result on every standard
argument. The checker will use it where it needs a term to have a value:
instantiating a quantifier, splitting on an expression, and assuming an
antecedent.

This change adds the syntax: the expression form, the editor's `!!`
prefix token, the menhir rule (at `!`'s precedence), the printer, and
the statics, where `!!e` is a Bool whatever e's type. Evaluation leaves
it stuck for now; its rule follows.

`!!` is one token, so double negation is written `!(!b)`. The printer
already parenthesizes nested prefix operators; a test pins that, and the
step-search test and comment that spelled double negation `!!b` use
`!(!b)`. Typing `!` next to `!` in the editor makes the `!!` token
rather than a hole, and the form table gains one Exp form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With `!!` in the language, extensionality can't hold at every argument
type. Quantifiers range over standard values, and at a function type
some values aren't standard: `fun h -> !!h` and `fun h -> true` agree
on every standard h but not on `fun y -> loop()`. So `funext` applies
only when the functions' argument type is data: atoms, lists, tuples
and sums of these, with no function type and no unknown type in it.
Otherwise the step is marked FunextNotFirstOrder and the goal passes
through, and the stepper doesn't offer Funext.

Reading the argument type: a lambda's written ascription comes first,
then the parameter type the statics store in an elaborated lambda (the
syntactic fallback read that field as the whole arrow type, so an
annotated lambda outside the statics came out unknown). Of the two
sides, the first known domain wins, since the equation is at their
common type.

The funext tests and the stepper's `sum` fixture annotate their
lambdas' arguments; new tests pin the refusal at function and unknown
argument types, and acceptance at tuples, sums and recursive sums.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`!!e` evaluates e to a value, then steps on the value's shape:

- an atom, a label or a nullary constructor gives `true`;
- a tuple, list, cons, labelled value or applied constructor gives the
  `&&` of `!!` over its parts;
- a function whose parameter type is known steps to
  `forall (x : T) -> !!f(x)`, which is stuck: evaluation never shows a
  function standard, only a proof can. Recursive functions are lambdas
  under their closure by the time they are values, so they do the same;
- anything else, such as an error or a lambda with no parameter type,
  is stuck.

So `!!e` is never `false`: `!!(1 / 0)` is an error and `!!loop()`
loops. There is no evaluation rule for `!!(forall x -> p)`. The stepper
shows the step as "standardness".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A proof's `forall` step can name the fact that its binder is standard:
`forall (x : T !! h) =>` gives the body `h : !!x`, which holds because
quantifiers range over standard values. It is the way to prove a goal
that mentions `!!x` itself, such as the lemma
`forall f : (Int -> Int) -> !!f`. A theorem's own leading foralls are
introduced for it, so they are named through `generalize x => forall
(x : T !! h) =>`.

`p !! h` is a pattern form of its own, `Pat.Standard`, transparent
wherever a pattern binds: it binds what `p` binds, and `h` names a
fact, not a variable. Both parsers read it (looser than `:`, so
`x : T !! h` names `x : T`'s fact), the printer writes it, and the
statics mark it anywhere but a proof's `forall` step
(StandardFactOutsideForall). There the statics and the checker give the
body the fact `!!e`, with `e` the binder read as an expression without
its ascriptions, as goals mention it. The form table gains one Pat form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Standardness.check judges whether `!!e` holds by the shape of `e`, so
that a side condition `!!e` can discharge without a proof. It answers
Standard(conditions), `e` being standard wherever those hold, or
Unknown(reason).

- The conditions are domain conditions as DomainConditions states them
  (`b != 0` for a division, `is_finite(x)` for `int_of_float(x)`), so a
  step that comes to need `!!e` incurs the obligations it incurs for
  definedness today. A condition on a lambda's own argument can't be
  lifted out, so `fun x -> 1 / x` isn't standard; applied, its
  conditions take the argument, so `(fun x -> 1 / x)(2)` gives
  `2 != 0`.
- Recursion is judged as Totality judges it: a structurally recursive
  function is standard when its body is with its own calls standard.
  `case` has to cover its scrutinee's type, and `==` needs operands
  whose type holds no function.
- Operand types come from binders, literals and operators, never from
  the statics' type at a node, which an operand of unknown type takes
  from what it is analysed against: `fun x -> x + 1` is Unknown.
- A standard function is standard on standard arguments of its domain,
  so applying a quantified function, a definition or a builtin needs an
  argument known to be of the domain.
- Goals name definitions, so the routine judges a definition's value,
  closed and once, where a name for it is met, typing a recursive one's
  calls with the definition's own type.
- Primitive builtins: a list of total ones, and the partial ones whose
  condition DomainConditions states; any other is Unknown.

Nothing calls it yet: the next change puts it behind the checker's
`!!` conditions in place of Totality.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…code

Library functions like `length` and `map` are Hazel code with no
parameter types, and so is a user definition without annotations. The
routine judges such a function, where it is applied, by its code at its
argument's type: the parameter gets that type, the patterns the
recursion splits on give its parts theirs, and the recursive calls take
arguments of that type, as the induction on their size needs. Being of
the type isn't enough: StructuralRecursion.check also wants each
recursive call's argument to be a strict part of the parameter, at a
fixed position, so `f(n - 1)` doesn't pass. So
`!!length(xs)` holds for a standard list `xs`, and `!!map(xs, f)`
needs only what map's code needs of `f` and `xs`: `f` standard on
the list's elements.

- The function's result type is its declared one, or else the type its
  base case gives, if every branch then gives it. A `case` or `if` has a
  type only when its branches agree on it.
- A lambda with a known parameter type has an arrow type, so a typed
  lambda passed to `map` fits its domain.
- Evaluation leaves a user's recursive definition unrolled once, with
  its fixpoint inlined at its own calls; that fixpoint is the definition
  the routine judges.
- A primitive builtin met as a definition goes to the builtin rules.
- Tests: `length` and `map` (with a total and a partial lambda), an
  unannotated user `len` through a theorem's scope, and a recursion that
  isn't structural, which stays unknown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A partial primitive is standard exactly when its domain condition
holds, and that is now a builtin rule a proof can cite:

  div_standard : forall (a : Int) -> forall (b : Int) ->
                   !!(a / b) == (b != 0)

The routine has no division-specific code: where it meets a partial
primitive it finds that rule, checks each argument is standard and of
the binder's type, and leaves the rule's condition, which discharges as
today, by a fact in scope or by evaluation.

Rules (Axioms.standard_primitives): div_standard, sint_div_standard,
nat_div_standard, pow_standard, sint_pow_standard, int_mod_standard,
sint_mod_standard, nat_mod_standard, float_mod_standard,
int_of_float_standard and sint_of_float_standard. A primitive whose
condition can't be written as a Bool (int_of_string and the other
parsers) has no rule and is never shown standard. A builtin's name in a
rule matches only where it still names the builtin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…types

Once the routine gates instantiations, existing proofs depend on it:
the STLC milestone's `progress`, the ListFold library, the `Nt` round
trip, `rev`. Their terms need types the routine couldn't see. It now
reads:

- a `case`'s coverage through the statics' coverage check, so sums,
  recursive types and tuples of constructor patterns count, and unknown
  parts of the type aren't taken as covered;
- constructor payloads in patterns, and the constructor types
  elaboration leaves in values;
- a tuple parameter typed by its argument, its ascriptions refining it;
- a definition typed by its value, and a definition applied typed
  through its value;
- a recursive function met inlined (an explicit `fix`, or a definition
  that evaluation unrolled once), judged and typed at its argument's
  type as a named one is;
- a `[]` branch agreeing with a list type, and `[]` fitting a list
  domain;
- a cast to a partly unknown type passing a value consistent with it.

A destructuring lambda applied is now checked against its domain. It
was judged standard as a function with no check that the argument fits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A step needs a term standard where it instantiates a quantified binder
(a cited rule's binders, `revert ... with`) and where it splits on a
computed scrutinee. The standardness routine reduces `!!e`
to the domain conditions it holds under (`b != 0` for `a / b`), which
the step incurs as Definedness obligations, as before. Where the
routine can't judge the term, the step incurs `!!e` itself, as an
obligation of the new Standardness kind, discharged like the others by
a fact in scope or by closed evaluation. Nothing is refused any more:
instantiating at `loop(0)` leaves `!!loop(0)` pending.

The built-in `refl` holds at every term, so it needs no `!!`;
it still incurs its instantiations' domain conditions, so `8 / z ==
8 / z` by `refl` needs `z != 0` as before.

Binders: every proof binder ranges over standard values, except a
variable that focusing opens under a lambda, `let` or case arm of the
goal whose type isn't data. Such a variable takes whatever value it is
given, so it isn't standard. `SemanticCtx` records those, and binding
the name again clears it. A `forall`'s variable stays standard.

Deleted: `Totality`, and the PossiblyDivergentInstantiation and
PossiblyDivergentScrutinee marks. The inspector's totality badge shows
the routine's verdict instead.

Tests: FunctionTotality becomes StandardInstantiation, citing a lemma
that does what `refl` does; StructuralRecursion, Definedness,
Instantiation and ProofMap check pending `!!e` obligations instead of
marks. New: focus binders, and `div_ok`'s `z != 0` discharged by `nz`.

Some test binders are annotated, since the routine judges an operation
standard only on operands it knows the type of, and a binder with no
type could be a function:
- ClosureLibrary: `a1` and `b1` are `Int`, since splitting on
  `a1 != 0` needs it standard;
- Generalize: `ys` is `[Int]`, since `len(ys)` and `x :: ys` need it a
  list;
- StructuralRecursion: `snoc`'s and `rev`'s parameters, since without
  them `rev` has no result type the routine can infer from `snoc`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`refl` holds at every term, so citing it needs nothing of its
instantiation: `8 / z == 8 / z` by `refl` no longer incurs `z != 0`.

The division slides took their `z != 0` from `refl`. They now cite
`or_true` at `8 / z > 0`, whose instantiation has to be standard:
`div_open` still reads "incomplete · 1 open", and `div_ok` (and the
reference slide's `div_pos` and `div_neg`) still discharge `z != 0` by
the `have`. ProverDocs pins both theorems' conditions.

Tests that used `refl` to bring in a division's condition cite
`or_true` the same way, or a lemma that does what `refl` does, with
the binders typed so the condition is `z != 0` rather than `!!(y / z)`.
The Obligations sample's `f` no longer divides, since the routine sees
into it, and would add `y != 0`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A recursive function that counts a number down is standard where its
guards bound the number below: `if n <= 0 then 1 else n * f(n - 1)` on
an Int, `if n == 0 then 1 else n * f(monus(n, 1))` on a Nat.

- `Bounds` reads what a branch's guards say about variables compared
  with integer literals: `==`, `!=`, `<`, `<=`, `>`, `>=`, either way
  round, through `!`, `&&` where the guard holds and `||` where it
  doesn't, and the literals of a `case`'s earlier rules.
- Termination (`StructuralRecursion`): a call may pass the parameter
  made smaller, `x - k` on an Int with a lower bound in that branch, or
  `monus(x, k)` on a Nat known to be at least 1, `k` a positive literal.
  `x` minus the lowest of those bounds shrinks at every call and stays
  non-negative. Refused, and tested: `if n == 0 ... f(n - 1)` on an Int,
  `f(n + 1)`, `f(n - 0)`, a guard on another variable, `n` rebound after
  the guard, the call in the branch the guard doesn't cover, a Nat with
  no guard; `f(n / 2)` and a decrease through a helper stay unknown.
  SInt is left out.
- The routine: a branch's conditions are needed only under its guard.
  One the guard implies is dropped, so `if b == 0 then 0 else a / b`
  needs nothing; the rest become `guard ==> condition`. A `case` rule's
  guard is its scrutinee differing from the earlier rules' literals,
  and a variable pattern's conditions are about the scrutinee.
- The routine reads a builtin's type from the builtin context, which a
  proof's context doesn't hold, so `monus(n, 1)` fits its domain.

No Nat subtraction rule: Nat `-` is a static error ("use `monus`") and
never a value, so `!!(a - b) == (a >= b)` would be false. A Nat counts
down with `monus`, which is total.

Tests: the examples that stood for a recursion the routine can't judge
counted down under `n > 0`, which is now standard. They use
`if n == 0 then 0 else f(n - 1)` instead, which has no lower bound on
an Int. `if true then 1 else 1 / 0` needs `!true ==> 0 != 0`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`algebra` verifies Int and Nat arithmetic. Any other subterm the
standardness routine types Int or Nat, such as a call `sum(m + 1)` or
a division `a / b`, is now an unknown, and the same term (by
`Equality.semantic`, as the write box names its unknowns) is the same
unknown. A step that holds for every value of its unknowns is
verified, and incurs `!!t` for each unknown `t` through the same gate
as an instantiation: the routine reduces it to `t`'s conditions, or
leaves it to prove. So `sum` on a standard argument needs nothing more,
and `0 * f(0)` for `f = fun (x : Int) -> 1 / x` needs `0 != 0`.

Without the condition the prover would prove `0 == -1`. For
`loop = fun x -> loop(x) + 1`, `step` and `refl` give
`h : loop(0) == loop(0) + 1`; then `0 == loop(0) - loop(0)` by
algebra, the second `loop(0)` rewritten with `h`, and
`loop(0) - (loop(0) + 1) == -1` by algebra. Now both algebra steps
carry `!!loop(0)`, which the routine can't show, so the proof isn't
proven.

The goal is read as written rather than with its definitions
substituted, so a call stays one unknown. A definition whose value is
in the fragment, such as a literal, still counts as that value. A step
the CAS finds wrong is refused only when it has no unknowns, since the
unknowns' values might make it hold. A term of no numeric type, such as
a function, leaves the step's equation as an obligation, as before.

`Standardness.in_context` gives the routine's typing beside `check`,
for the unknowns.

Tests: the `0 == -1` derivation (every step applies, and the proof
rests on two `!!loop(0)`); the Gauss step
`2 * (m + 2 + sum(m + 1)) == 2 * (m + 2) + 2 * sum(m + 1)` proven;
`0 * f(0)` left with `0 != 0`; a function-typed term left as an algebra
obligation; `int_of_float(x)` as an unknown left with `is_finite(x)`;
`a / b - a / b == 0` left with `b != 0`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`step` contracts a redex whatever its argument: a lambda or `let` in
the evaluator, where a variable pattern matches anything, and a named
function that isn't recursive in `ProofCheck.Beta`. At an argument
that isn't a value, that equates terms that differ where the argument
has none: `(fun x -> 0)(loop(0))` isn't `0`. Beta holds only at
any value, or at a standard term with a `!!` condition on it.

So `Eval.check` reads the redex at the goal's root (`Beta.redex`), and
when its argument isn't a value (`Beta.is_value`: a variable, a
literal, a lambda, a constructor or builtin, and data built from them)
the step incurs what the argument needs to be standard, through the
same gate as an instantiation. The routine reduces that to the
argument's domain conditions, or leaves `!!arg`. This holds whichever
path contracts, and a Tab step at a selection, which writes `step`,
gets the same condition.

Tests: `(fun x -> 0)(1 / 0) == 0` was pinned as proven; it now rests
on `0 != 0`. New: a lambda, a named function and a `let` at `loop(0)`
each leave `!!loop(0)`; a lambda at `2 + 3` needs nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A `!!e` the routine can't judge, and that no fact in scope states
exactly and closed evaluation doesn't show, can now be discharged by
one application of a quantified fact in scope, `forall x̄ -> !!p`, of
which `!!e` is an instance: `forall (xs : [Int]) -> !!f(xs)`
discharges `!!f(ys)`. The obligation records the fact, as a lookup's
does. The instance's terms then have to be standard themselves, by the
routine, lookup or closed evaluation but not by a second application,
so `!!f([1 / 0])` leaves `0 != 0`.

Only a fact with no premises applies, and a binder with a type takes
only a term the routine types alike: the fact above doesn't discharge
`!!f(bs)` for a list of Bools. A theorem whose proof isn't finished
discharges nothing, as for lookup.

Tests: an instance discharged by the hypothesis; an instance whose
term needs a condition; an instance whose term the fact would match
again, left pending; an instance at another type, left pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`==>` is a Bool, and assuming an antecedent that has no value is
unsound: with `L = fix x -> x ==> false`, an unrestricted `assume`
proves `L ==> false`, which is `L` itself, and then `false` (Curry's
paradox). So `assume` on `P ==> Q` needs `!!P`. The step is
accepted either way, and `!!P` is an obligation the proof can leave
for later: the routine reduces it to `P`'s conditions, or leaves
it pending.

Untyped binders now show the pending `!!` on `assume`: `x > 0` isn't
known standard when `x` could be a function. The tests that assumed
comparisons of untyped binders annotate them `Int` (ProofMap,
FunContracts, Generalize).

The routine types `xs @ []` as `xs`'s list type: `[]` is a list of
anything. Without that, the reference slide's `app_nil_fun`, which
assumes `ys @ [] == ys`, read incomplete.

Tests: assuming a typed antecedent needs nothing; an untyped one leaves
`!!(x > 0)`; a looping one leaves `!!l(0)`, the step still accepted; a
division in the antecedent leaves `y != 0`. The tests of quantified `!!`
facts read the citing step's obligations, since assuming their
hypothesis, about a looping function, now needs its standardness too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`standard : forall x -> !!x` is a builtin rule. Cited with `rewrite`, it
reads as `!!x == true`, and its instantiation has to be standard like
any rule's, so it closes `!!e` exactly where the routine, a fact in
scope (quantified ones included) or closed evaluation shows `e`
standard. Otherwise the step goes through and leaves `e`'s conditions,
or `!!e` itself, to prove. Step search completes the name.

Tests: `!!(x + 1)` and `!!f(x)` for a quantified function are proven;
`!!(10 / y)` leaves `y != 0`; `!!loop(0)` leaves `!!loop(0)`; typing
`stand` offers `standard`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Side conditions: a `!!e` condition's circle reads `!!`, and its
  section is labelled "standardness". One closed by a quantified fact
  says it holds as "an instance of h"; one closed by evaluation or an
  exact fact reads as other conditions do. Its exits are the ones
  every condition gets, checked the same way.
- The inspector's badge shows, where a proof can use it (as the
  built-in axioms are listed, `ContextInspector.lists_axioms`), whether
  the term at the cursor is standard: "standard", the conditions under
  which it is, "standard where z != 0", or the routine's reason why it
  can't tell.
- ExplainThis: the step forms' entries say where a step needs a term
  standard and what that adds: `rewrite` (except `refl`) and its
  `with`, `revert ... with`, `algebra`'s unknowns, `step` at an
  argument that isn't a value, a computed `cases` or `induction`
  scrutinee, and `assume`'s antecedent. The `forall` step mentions
  `forall (x : T !! h) =>`. They no longer speak of terms that
  "visibly terminate".
- A docs slide, Prover / Standardness: `!!e`, a `!!` circle closed by
  evaluation and one left open, and the rule `standard`. ProverDocs
  pins its statuses and its two circles, and the exits of a `!!`
  condition are among those checked to write unmarked proofs.

The stepper's label for evaluating `!!e` reads "standardness", as
since `!!e` first evaluated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant