Skip to content

Prover: theorems with checked proofs, and a stepper that writes them - #2823

Draft
Negabinary wants to merge 1 commit into
devfrom
prover-main
Draft

Negabinary wants to merge 1 commit into
devfrom
prover-main

Conversation

@Negabinary

@Negabinary Negabinary commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

PRs that build on this one, each on its own: #2822 adds where patterns and what the prover does with them, #2827 the contradiction step, #2834 agent fill with proof tools, #2835 focusing on a run of an associative chain, #2833 patterns like m + 1, and #2853 standardness, !!e.

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 foralls 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.

Status

Draft. Locally: the quick suite passes (5375 tests), as do MenhirCorpus, FastParseCorpus, the docs slides' round trip (DocSlides.ReparseBackuptext) and the release-profile warnings check (make ci-check).

🤖 Generated with Claude Code

@Negabinary
Negabinary added this pull request to stack #2824 November 14, 2026 02:14
@Negabinary
Negabinary removed this pull request from stack #2824 November 16, 2026 20:19
@Negabinary
Negabinary changed the base branch from where-patterns to dev November 16, 2026 20:19
@Negabinary
Negabinary added this pull request to stack #2826 November 16, 2026 20:19
@Negabinary
Negabinary force-pushed the prover-main branch 5 times, most recently from 7731948 to 820592c Compare November 19, 2026 01:29
This was referenced Nov 19, 2026
@Negabinary
Negabinary force-pushed the prover-main branch 3 times, most recently from 4df9815 to 837e49c Compare November 20, 2026 20:38
@Negabinary
Negabinary removed this pull request from stack #2826 November 20, 2026 20:39
@Negabinary
Negabinary changed the base branch from dev to fix/pad-ids-order November 20, 2026 20:39
@Negabinary
Negabinary added this pull request to stack #2852 November 20, 2026 20:39
@Negabinary
Negabinary removed this pull request from stack #2852 November 20, 2026 22:09
@Negabinary
Negabinary changed the base branch from fix/pad-ids-order to dev November 20, 2026 22:10
@Negabinary
Negabinary added this pull request to stack #2854 November 20, 2026 22:10
@Negabinary
Negabinary force-pushed the prover-main branch 3 times, most recently from a1af677 to e8d52fa Compare November 23, 2026 21:35
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.09976% with 1524 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.77%. Comparing base (f7257dd) to head (3ee3b24).
⚠️ Report is 2 commits behind head on dev.

Files with missing lines Patch % Lines
src/web/app/editors/code/CodeEditable.re 0.00% 111 Missing ⚠️
src/web/app/editors/result/Theorems.re 38.46% 96 Missing ⚠️
src/language/proof/Induction.re 47.71% 80 Missing ⚠️
src/language/term/Proof.re 44.44% 80 Missing ⚠️
src/language/proof/ProofRule.re 53.02% 70 Missing ⚠️
src/language/proof/ProofCheck.re 89.98% 58 Missing ⚠️
src/language/term/Grammar.re 55.72% 58 Missing ⚠️
src/web/app/editors/result/EvalResult.re 52.84% 58 Missing ⚠️
src/web/app/editors/code/SubEditor.re 67.51% 51 Missing ⚠️
src/language/proof/StructuralRecursion.re 70.86% 44 Missing ⚠️
... and 77 more
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2823      +/-   ##
==========================================
+ Coverage   48.43%   51.77%   +3.33%     
==========================================
  Files         498      510      +12     
  Lines       57540    62878    +5338     
==========================================
+ Hits        27871    32553    +4682     
- Misses      29669    30325     +656     
Files with missing lines Coverage Δ
src/docslides/Slides.re 100.00% <ø> (ø)
src/haz3lcore/CachedSyntax.re 64.91% <100.00%> (+1.27%) ⬆️
src/haz3lcore/Editor.re 60.31% <100.00%> (+7.09%) ⬆️
src/haz3lcore/derived/CachedStatics.re 61.64% <ø> (ø)
src/haz3lcore/derived/CanonicalCompletion.re 91.89% <100.00%> (+0.16%) ⬆️
src/haz3lcore/lang/Precedence.re 96.22% <100.00%> (+2.10%) ⬆️
src/haz3lcore/pretty/PadIds.re 89.39% <ø> (+1.33%) ⬆️
src/haz3lcore/projectors/ProjectorPerform.re 16.97% <100.00%> (+1.44%) ⬆️
src/haz3lcore/tiles/Base.re 84.44% <100.00%> (ø)
src/haz3lcore/tiles/Tile.re 95.60% <100.00%> (ø)
... and 135 more

... and 25 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.

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>

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