Cure v0.37.0 :: Proof Automation, Well-Founded Recursion, Proof-Carrying Releases & Agda G2/G3
by Aleksei Matiushkin
Cure v0.37.0 ships 29 commits building directly on v0.36.0 — completing every planned engineering, proof-automation, metatheory, and BEAM-differentiator milestone in docs/PLAN_0.37.0.md without adding a single line to the trusted computing base (TCB) or a single postulate to the Agda formalisation.
In v0.36.0, Cure landed unbounded Agda-style universe polymorphism, interactive goal-state introspection, extensible tactics, and 238 modules of Agda metatheory. In v0.37.0, Cure pairs practical Lean 4-class proof ergonomics with capabilities unique to a dependently typed language on the BEAM:
- Richer kernel-checked proof automation & ergonomics —
by ringcommutative semiring normalization,by omegaextended toNatinequalities plus kernel-checked Farkas unsatisfiability soundness,conv lhs/conv rhstargeted rewriting,induction ... generalizing,obtaindestructuring,@ext/by ext, and tabled cycle-safe typeclass resolution with diamond coherence andoutParamlookup. - Well-founded recursion with
termination_by/decreasing_by— a kernel-checkedStd.Proof.WellFoundedlibrary (Acc,wf_rec,nat_wf_rec,measure_wf_rec) and ergonomic post-body surface sugar certifying non-structural recursion@total trueusing Cure's existing termination checker. - Verified BEAM concurrency, proof-carrying OTP releases & MCP proof synthesis — Core-checked
Std.CRDT.Proofsemilattice laws, the unifiedexamples/verified_tx_coordinator.cureshowcase (2PC FSM + QTT:linearlease + CRDT convergence),mix cure.release --with-proof+mix cure.verify --strict.cureproofreceipts, andget_proof_state/try_tactictools inCure.MCP.Server. - Agda metatheory extended from 238 to 252 modules (G1 → G2 → G3) — machine-checking closure-valued native typing replay (M3), fuel-indexed value evaluation (M4b), typed
ηstability (M5b), bounded release admission (M6/G1), universal Elixir-producer correspondence (G2), and typed erasure forward simulation + Erlang Abstract-Form BEAM lowering refinement (G3). - Compiler speedups, Neovim goal view & interface-only macro grammars — DAG wave parallelism, a verified-root cache cutting stdlib
load_roots/1from11.2 sto41.3 mswarm,:CureGoals(<leader>cg) inneovim-cure, and source-free macro/tactic consumption from.cureinterfacefiles.
1. Proof Automation, Tactics & Tabled Resolution
Every new proof command in v0.37.0 operates strictly outside the TCB: it synthesizes ordinary Core terms that Cure.Core.Kernel re-checks against the original obligation.
by ring(Cure.Elab.Ring,Std.Tactic.ring/1): Normalizes both sides ofEquivalent(Nat, lhs, rhs)goals into canonical sorted sum-of-products polynomials and reconstructs kernel-checkedStd.Equivalentproofs using newly added@total truesemiring lemmas inStd.ProofandStd.Proof.Math— discharging identities such as(x + y)² = x² + 2xy + y²automatically.by omegaonNat& Farkas soundness (Cure.Elab.Omega.NatProof,Std.Proof.LinearArithmetic.Semantics):by omeganow handlesStd.Proof.MathIsLessThanOrEqualand strictIsLessThangoals (zero, reflexivity, concrete comparisons, successor peeling, transitivity, and addition monotonicity). On the integer side,Std.Proof.LinearArithmetic.Semanticsnow contains@total truekernel-checked general Farkas unsatisfiability and classical refutation-to-proof theorems (farkas_contradiction_is_empty,farkas_fold_unsat,farkas_refute_to_le,farkas_refute_to_lt,farkas_refute_to_eq).- Targeted rewriting (
conv lhs/conv rhs):conv lhs => rewrite [backwards] using e [all]andconv rhs => ...restrict rewriting strictly to the left- or right-hand side of an equality goal, failing closed on non-equality goals. - Proof ergonomics:
induction x generalizing [y, z](andinduction x generalizing y) lowers cleanly via private universally-quantified helper declarations (Cure.Elab.Induction), making accumulator-style induction proofs straightforward while preserving@total true.obtain <pattern> = <expr>destructures proof witnesses inside proof blocks through exhaustiveness-checked Corecaseelimination.@extandby ext(Cure.Elab.Ext,Std.Tactic.ext/1) close reflexivity, nested structural constructor congruence, and cross-module@ext-registered extensionality lemmas without changingModuleInterfaceschema v9.
- Tabled typeclass resolution (
Cure.Elab.Resolve,Cure.Elab.Coherence): Dictionary resolution is now tabled and cycle-safe (resolve_dict_tabled/6), sharing identical Core dictionary terms across diamond constraint graphs in O(1) and failing closed on cycles ({:cyclic_instance, iface, head}), paired with diamond coherence checking (diamond_conflicts/2,merge_checked/2) and functional-dependencyoutParamlookup (out_param_lookup/3).
2. Well-Founded Recursion (Std.Proof.WellFounded & termination_by)
Structural recursion alone cannot certify algorithms like binary halving or custom-measure traversals. v0.37.0 adds well-founded recursion end to end with zero TCB changes:
Std.Proof.WellFounded(lib/std/proof_well_founded.cure): Provides strictly-positive accessibilityAcc(a, rel, x),@reduciblenat_ltandmeasure_lt, and@total truenat_lt_wf,measure_wf,wf_rec,nat_wf_rec, andmeasure_wf_rec— all certified total by Cure's existing size-change and guarded-lambda checker.termination_by/decreasing_bysurface sugar (Cure.Elab.WellFounded): Functions can now attach contextual post-bodytermination_by <measure>and optionaldecreasing_by <proof>clauses (defaulting toby omega), desugaring directly tonat_wf_recormeasure_wf_rec. Non-structural halving recursion (log2_steps) and custom-ADT measure recursion certify@total trueand execute natively on the BEAM, while bogus decrease arguments are rejected fail-closed by the kernel.
3. Beyond Proof Assistants: Verified Concurrency, Proof-Carrying Releases & MCP
v0.37.0 also lands three BEAM-native capabilities where Cure goes beyond traditional standalone proof assistants:
Verified Distributed & Concurrent OTP Systems
Std.CRDT.Proof(84th canonical stdlib module): Discharges@total trueCore-checked join-semilattice laws (idempotence, commutativity, associativity) fornat_max,gcounter2_merge, andbool_or.- Unified concurrency showcase (
examples/verified_tx_coordinator.cure): Combines a compile-time-verified 2-phase commitfsm TxCoordinator, a quantitative:linear CommitLeaseresource handle, and@total trueCore-checkedStd.CRDT.Proofreplica convergence theorems in a single BEAM-executable module — with negative compile-fail tests confirming QTT rejects lease leaks and duplications.
Proof-Carrying BEAM Releases
mix cure.release --with-proof&mix cure.verify --strict:Cure.Project.Proof.build_release_receipt/3binds a release's name, version, and every emitted.beamartifact underlib/*/ebin/*.beamto SHA-256 digests and a canonicalreceipt_sha256, writingreleases/<vsn>/<name>.cureproofalongsidestart.boot,sys.config, andvm.args.- Offline verification via
mix cure.verify --strictre-hashes every.beamon disk — failing closed on tampering, missing beams, or injected beams — and refuses permissive legacy SMT/totality stubs.
LLM-Native Verified Proof Synthesis (Cure.MCP.Server)
get_proof_state: ExposesCure.Elab.SourceContext+Cure.Elab.ProofStateover MCP, returning structured open goals, targets, and local hypotheses (whole-buffer or cursor-scoped) even for refused proof attempts.try_tactic: Substitutes candidate tactics at named holes (or the first?hole), kernel-checks the result in an isolated process subscribed to:simp_trace, and returns closure status, remaining goals, diagnostics, and capturedsimp?rule traces.
4. Agda Metatheory: 238 → 252 Modules (G1 → G2 → G3)
The Agda formalisation in proof/ grew by 14 modules to 252 modules, verified under Agda 2.8.0 with check-postulates.sh and check-hygiene.py (zero new postulates, zero holes, zero warnings):
- M3 (
ClosureContext,ClosureContextTyping): GeneralisedCore.FlatContextto full closure-valued semantic stores (Core.ClosureEval.Value) with defined-local preservation and per-slot native typing replay. - M4b (
FuelValueEval): Separated fuel-indexed value evaluation from its soundness proof (eval-val-sound), provingeval-val-var-not-unboundandeval-val-var-safefor all in-bounds variables. - M5b (
TypedEtaStability): Proved renaming and substitution stability (≈η-rename,≈η-subst,eta-step-rename,eta-step-subst) forCore.TypedEta._≈η_. - M6 / G1 (
ReleaseAdmission): ComposedCheckedAdmission,ClosureContextTyping,FuelValueEval, andFailureImpossibilityinto a fail-closedadmit-releasedriver emitting aReleaseReceipt. - G2 (
ProducerCorrespondence,G2Admission): Formalised the pure functional semantics ofCure.Core.ProofSnapshot.capture/1over arbitrary finiteElixirEnvregistries, proving universal family/global lookup agreement, constructor-order preservation, andAdapterChecks.Validateddischarge, cross-checked against Elixir intest/cure/core/g2_producer_correspondence_test.exs. - G3 (
TypedErasure,BeamLowering,G3Refinement): Proved grade-filtered forward simulation (erase-simulateswith administrativelet x = v in xcollapse and hole exclusion) and universal Erlang Abstract-Form lowering refinement (lower-refines,core-to-erl-refines— nullary constructors as bare atoms, n-ary constructors as tagged tuples, closures, andcasedispatch), cross-checked live on the BEAM intest/cure/elab/g3_beam_lowering_refinement_test.exs.
5. Compiler Performance, Neovim Goals & Interface Macro Grammars
v0.37.0 also delivers major pipeline, editor, and codebase-hygiene improvements:
- Warm-path speedups & heap-copy elimination:
- Partitioned topologically ordered SCC components into dependency waves (
component_waves/2) to check independent stale waves concurrently while keeping deterministic diagnostics andBodyElaborationTracefolding. - Eliminated 82× redundant
merge_canonical_environments/ SHA-256 re-validations and replaced a per-interfaceTask.async_streamthat deep-copied ~5.3 GB across 84 tasks perload_roots/1call with in-place verification plus a bounded:persistent_termverified-root cache — cutting stdlibload_roots/1from11,224 msdown to665.6 mscold and41.3 mswarm. - Added ETS caches for fixity harvesting and public re-exports, cached
Stdlib.Paths, skipped unchanged cache rewrites, and added an ASCII fast path to lexer token span attachment.
- Partitioned topologically ordered SCC components into dependency waves (
- Neovim live proof-goal view (
neovim-cure/lua/cure/goals.lua): Added:CureGoals [toggle|open|close|refresh]and<leader>cgquerying LSPcure/proofStatewith offset-encoding, document version, and cancellation support — bringing Neovim to parity with VS Code. - Interface-only macro grammar publication: Harvested
syntaxandtacticmacro rules are now persisted inModuleInterface.extension_payloads[:macro_rules](authenticated byinterface_hash, preserving schema v9) so consumers compile without provider.curesources on disk. - Codebase & doc hygiene: Extracted
Cure.Elab.Record,Cure.Elab.Binop,Cure.Compiler.Parser.Fixity, andCure.Compiler.Parser.Literals(-689 LOC fromelaborator.exandparser.ex), removed dead legacyCure.Types.Holes/Cure.Types.Synth, consolidated Lean 4 parity docs intodocs/LEAN4_PARITY.md, and synceddocs/SOUNDNESS.mdanddocs/KERNEL.mdwith Phase 5 universe polymorphism.
Summary of Changes
| Area | Milestone | Impact |
|---|---|---|
| Tactics & Solvers | by ring, by omega (Nat + Farkas), conv, by ext |
Kernel-checked algebraic, arithmetic, extensionality, and targeted subterm proofs with zero TCB expansion |
| Proof Ergonomics | induction ... generalizing, obtain, tabled resolution |
Accumulator induction, proof destructuring, O(1) diamond dictionary sharing, outParam lookup |
| Termination | Std.Proof.WellFounded, termination_by / decreasing_by |
Certified @total true non-structural recursion on BEAM with zero TCB changes |
| Verified OTP | Std.CRDT.Proof, examples/verified_tx_coordinator.cure |
Core-checked CRDT semilattice laws + 2PC FSM + QTT :linear leases in one BEAM module |
| Releases & MCP | mix cure.release --with-proof, Cure.MCP.Server |
Fail-closed .cureproof release receipts + get_proof_state / try_tactic MCP proof loop |
| Metatheory | 252-Module Agda Proof (M3–M6, G1–G3) | Closure-store replay, value eval, typed η, Elixir producer correspondence, erasure & BEAM lowering refinement |
| Performance & DX | Wave parallelism, root cache, :CureGoals, macro interfaces |
Stdlib load_roots/1 11.2 s → 41.3 ms warm, Neovim goal pane, source-free macro imports |
Looking Ahead
With v0.37.0, Cure pairs everyday proof-assistant automation (ring, omega, conv, ext, termination_by, induction ... generalizing) with capabilities built specifically for production BEAM systems: proof-carrying OTP releases, Core-checked CRDTs alongside linear FSM protocols, MCP-driven verified proof synthesis, and 252 Agda modules bridging Core typing all the way down to Erlang Abstract Forms.
Upgrade to Cure v0.37.0, try termination_by or by ring, inspect goals in Neovim with :CureGoals, and build a proof-carrying release with mix cure.release --with-proof.