← All posts

Cure v0.37.0 :: Proof Automation, Well-Founded Recursion, Proof-Carrying Releases & Agda G2/G3

by Aleksei Matiushkin

release tactics ring omega well-founded crdt releases mcp agda neovim performance

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:

  1. Richer kernel-checked proof automation & ergonomics — by ring commutative semiring normalization, by omega extended to Nat inequalities plus kernel-checked Farkas unsatisfiability soundness, conv lhs / conv rhs targeted rewriting, induction ... generalizing, obtain destructuring, @ext / by ext, and tabled cycle-safe typeclass resolution with diamond coherence and outParam lookup.
  2. Well-founded recursion with termination_by / decreasing_by — a kernel-checked Std.Proof.WellFounded library (Acc, wf_rec, nat_wf_rec, measure_wf_rec) and ergonomic post-body surface sugar certifying non-structural recursion @total true using Cure's existing termination checker.
  3. Verified BEAM concurrency, proof-carrying OTP releases & MCP proof synthesis — Core-checked Std.CRDT.Proof semilattice laws, the unified examples/verified_tx_coordinator.cure showcase (2PC FSM + QTT :linear lease + CRDT convergence), mix cure.release --with-proof + mix cure.verify --strict .cureproof receipts, and get_proof_state / try_tactic tools in Cure.MCP.Server.
  4. 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).
  5. Compiler speedups, Neovim goal view & interface-only macro grammars — DAG wave parallelism, a verified-root cache cutting stdlib load_roots/1 from 11.2 s to 41.3 ms warm, :CureGoals (<leader>cg) in neovim-cure, and source-free macro/tactic consumption from .cureinterface files.

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 of Equivalent(Nat, lhs, rhs) goals into canonical sorted sum-of-products polynomials and reconstructs kernel-checked Std.Equivalent proofs using newly added @total true semiring lemmas in Std.Proof and Std.Proof.Math — discharging identities such as (x + y)² = x² + 2xy + y² automatically.
  • by omega on Nat & Farkas soundness (Cure.Elab.Omega.NatProof, Std.Proof.LinearArithmetic.Semantics): by omega now handles Std.Proof.Math IsLessThanOrEqual and strict IsLessThan goals (zero, reflexivity, concrete comparisons, successor peeling, transitivity, and addition monotonicity). On the integer side, Std.Proof.LinearArithmetic.Semantics now contains @total true kernel-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] and conv 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] (and induction 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 Core case elimination.
    • @ext and by ext (Cure.Elab.Ext, Std.Tactic.ext/1) close reflexivity, nested structural constructor congruence, and cross-module @ext-registered extensionality lemmas without changing ModuleInterface schema 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-dependency outParam lookup (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 accessibility Acc(a, rel, x), @reducible nat_lt and measure_lt, and @total true nat_lt_wf, measure_wf, wf_rec, nat_wf_rec, and measure_wf_rec — all certified total by Cure's existing size-change and guarded-lambda checker.
  • termination_by / decreasing_by surface sugar (Cure.Elab.WellFounded): Functions can now attach contextual post-body termination_by <measure> and optional decreasing_by <proof> clauses (defaulting to by omega), desugaring directly to nat_wf_rec or measure_wf_rec. Non-structural halving recursion (log2_steps) and custom-ADT measure recursion certify @total true and 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 true Core-checked join-semilattice laws (idempotence, commutativity, associativity) for nat_max, gcounter2_merge, and bool_or.
  • Unified concurrency showcase (examples/verified_tx_coordinator.cure): Combines a compile-time-verified 2-phase commit fsm TxCoordinator, a quantitative :linear CommitLease resource handle, and @total true Core-checked Std.CRDT.Proof replica 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/3 binds a release's name, version, and every emitted .beam artifact under lib/*/ebin/*.beam to SHA-256 digests and a canonical receipt_sha256, writing releases/<vsn>/<name>.cureproof alongside start.boot, sys.config, and vm.args.
  • Offline verification via mix cure.verify --strict re-hashes every .beam on 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: Exposes Cure.Elab.SourceContext + Cure.Elab.ProofState over 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 captured simp? 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): Generalised Core.FlatContext to 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), proving eval-val-var-not-unbound and eval-val-var-safe for all in-bounds variables.
  • M5b (TypedEtaStability): Proved renaming and substitution stability (≈η-rename, ≈η-subst, eta-step-rename, eta-step-subst) for Core.TypedEta._≈η_.
  • M6 / G1 (ReleaseAdmission): Composed CheckedAdmission, ClosureContextTyping, FuelValueEval, and FailureImpossibility into a fail-closed admit-release driver emitting a ReleaseReceipt.
  • G2 (ProducerCorrespondence, G2Admission): Formalised the pure functional semantics of Cure.Core.ProofSnapshot.capture/1 over arbitrary finite ElixirEnv registries, proving universal family/global lookup agreement, constructor-order preservation, and AdapterChecks.Validated discharge, cross-checked against Elixir in test/cure/core/g2_producer_correspondence_test.exs.
  • G3 (TypedErasure, BeamLowering, G3Refinement): Proved grade-filtered forward simulation (erase-simulates with administrative let x = v in x collapse 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, and case dispatch), cross-checked live on the BEAM in test/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 and BodyElaborationTrace folding.
    • Eliminated 82× redundant merge_canonical_environments / SHA-256 re-validations and replaced a per-interface Task.async_stream that deep-copied ~5.3 GB across 84 tasks per load_roots/1 call with in-place verification plus a bounded :persistent_term verified-root cache — cutting stdlib load_roots/1 from 11,224 ms down to 665.6 ms cold and 41.3 ms warm.
    • 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.
  • Neovim live proof-goal view (neovim-cure/lua/cure/goals.lua): Added :CureGoals [toggle|open|close|refresh] and <leader>cg querying LSP cure/proofState with offset-encoding, document version, and cancellation support — bringing Neovim to parity with VS Code.
  • Interface-only macro grammar publication: Harvested syntax and tactic macro rules are now persisted in ModuleInterface.extension_payloads[:macro_rules] (authenticated by interface_hash, preserving schema v9) so consumers compile without provider .cure sources on disk.
  • Codebase & doc hygiene: Extracted Cure.Elab.Record, Cure.Elab.Binop, Cure.Compiler.Parser.Fixity, and Cure.Compiler.Parser.Literals (-689 LOC from elaborator.ex and parser.ex), removed dead legacy Cure.Types.Holes / Cure.Types.Synth, consolidated Lean 4 parity docs into docs/LEAN4_PARITY.md, and synced docs/SOUNDNESS.md and docs/KERNEL.md with 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.