Skip to content

Verify HasPrimitives conservation - #32

Draft
kim-em wants to merge 125 commits into
digama0:masterfrom
kim-em:agent/hasprimitives-conservation
Draft

Verify HasPrimitives conservation#32
kim-em wants to merge 125 commits into
digama0:masterfrom
kim-em:agent/hasprimitives-conservation

Conversation

@kim-em

@kim-em kim-em commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • verify the primitive-definition recognizer and its reflected arithmetic/bitwise conditions
  • prove preservation of VEnv.HasPrimitives through primitive definitions, mutual definitions, quotient initialization, and declaration dispatch
  • keep the inductive-declaration boundary explicit
  • preserve kernel-compatible mutual-definition behavior: each member is checked under its own universe parameters, and duplicate names retain last-entry-wins executable semantics
  • make distinct mutual names an explicit model/theorem hypothesis instead of an executable rejection
  • simplify the mutual proof relations with named fields and fresh per-member checker runs
  • document the intentional opaque-header checking divergences

Stacked dependency

This PR is necessarily stacked on #28: the conservation proof is formulated over the VEnvs.WF/TrEnv verified-environment model and reuses the verified declaration-header, body-checking, and front-end dispatch lemmas introduced there. Reproducing those foundations here would duplicate #28 rather than remove the dependency.

The branch is rebased on the current #28 head (5bd5d86), including its opaque-body closure fix. GitHub does not allow a branch in a fork to serve as the base of another PR in this repository, so this draft targets master and temporarily includes the #28 commits in its displayed diff. Review of the new work should use kim-em:verify-environment-frontend...kim-em:agent/hasprimitives-conservation until #28 merges.

Review and simplification

An independent simplification review has been acted on in the branch. In particular, the mutual-definition implementation and conservation argument no longer impose the recovered branch’s stricter common-universe/unique-name runtime behavior.

A first economy pass factored the verified type/zero/successor equation chain shared by Nat.add, Nat.sub, Nat.mul, and Nat.pow, but saved only 14 net lines: most of the size was in constructing the typed translations. A systematic second round therefore lets shared evidence own those translations outright. On the checker side, the NatBinaryEvidence pack with the generic checkNatBinaryTyped.WF, checkNatBinaryBoolTyped.WF, and checkNatShiftTyped.WF theorems covers the binary Nat, Nat → Nat → Bool, and shift primitives, and the bitwise WF_typed lemmas now perform the value-shape split themselves. On the environment side, checkSafePrimitiveDefinition.WF, addDefinition.WF_safe_primitive, and the VEnvs.WF.addConst_ext scaffolding absorb the per-primitive checker, conservation, and extension boilerplate, and the checker layer superseded by WF_typed is deleted outright. Together with generic recurrence lemmas for the add/sub/mul/pow reflection arguments and the HasPrimitives.defKit scaffolding, this removes about 3,600 net lines, with every theorem statement consumed elsewhere left unchanged. The substantive bitwise and mod/div reflection mathematics is deliberately untouched, and no specification/certificate interpreter turned out to be needed.

Checks

  • Lean 4.32.2 full lake build (157/157) ✅
  • lake build Lean4Lean.Verify.Primitive
  • lake build Lean4Lean.Verify.Environment
  • git diff --check
  • no new sorry in the changed environment files ✅

digama0 and others added 30 commits July 29, 2026 14:36
- State addDecl.WF, the intended main theorem of the Verify development,
  as a sorry in the new Verify/Environment.lean.
- Update the 'currently false' comments in Verify/Axioms.lean: the
  lean4#8554 fix is long since merged, so the cached-flag axioms should
  now be provable from mkData_eq (but this has not been done yet).
- Document that AddInduct (an empty inductive) is essentially a sorry.
- divergences.md: the new level algorithm is not in fact complete
  (max 2 v >= imax 2 v fails, reachable from the inductive ctor
  universe check); plan of record is to verify the original algorithm.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kim-em
kim-em force-pushed the agent/hasprimitives-conservation branch from 9b323af to 8bee9c5 Compare August 4, 2026 01:34
kim-em added 5 commits August 4, 2026 01:51
# Conflicts:
#	Lean4Lean/Environment.lean
#	Lean4Lean/Inductive/Add.lean
#	Lean4Lean/Verify.lean
#	Lean4Lean/Verify/Axioms.lean
#	Lean4Lean/Verify/Environment.lean
#	Lean4Lean/Verify/Environment/Basic.lean
#	Lean4Lean/Verify/Environment/Lemmas.lean
#	divergences.md
@kim-em
kim-em force-pushed the agent/hasprimitives-conservation branch from 041c498 to 2283ffe Compare August 4, 2026 02:10
kim-em and others added 12 commits August 4, 2026 02:38
Introduce a NatBinaryEvidence pack (contexts, bound-variable and value
translations, and the generic recursive-call translation) together with a
generic checkNatBinaryTyped.WF theorem covering the uniform part of the
Nat.add/Nat.sub/Nat.mul/Nat.pow typed checker proofs. Each per-primitive
WF_typed proof now supplies only its required-constant facts and the typed
translations of its two equation right-hand sides.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Remove the unused plain .WF and .WF.conservesHasPrimitives checker
theorem families for all primitives, together with their now-orphaned
helpers: the verified environment layer consumes only the WF_typed
variants.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Introduce checkSafePrimitiveDefinition.WF covering the checker program
shared by all safe primitive definitions; each per-primitive theorem now
supplies only its WF_typed lemma (plus, for the evidence-pack cases, the
level-parameter projection).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Add VEnv.LE.contains, .mono transport lemmas for the four primitive
evidence packs, and a generic addDefinition.WF_safe_primitive theorem;
each per-primitive WF_safe theorem now supplies only its checker theorem
and the conservation argument for its own evidence.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Restate checkPrimitiveDef.nat{Xor,Land,Lor}.WF_typed without the
value-shape hypothesis: the proofs now split on the checker's own match
on v.value. This lets the three checkSafe*Definition.WF theorems ride
the generic checker theorem and replaces the success_*_value_shape
monad-stack dissections (and their maxSteps workaround) with direct
WF_safe members.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Introduce checkNatBinaryBoolTyped.WF covering the checker program shared
by Nat.beq and Nat.ble; the two WF_typed proofs now supply only the
translations of their three boolean right-hand sides.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Introduce checkNatShiftTyped.WF for the binary Nat primitives that
recurse on their first argument; Nat.shiftLeft and Nat.shiftRight now
supply only their required constant and successor right-hand side over
the shared NatBinaryEvidence pack.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Add List.Forall₂.forall_left/forall_right to Std.Basic and reduce the
mutual-header/body projection lemmas to one-line applications of these
and Forall₂.imp; delete the unused mutualHeader_toFinal. Collapse the
six inductive-name dispatcher cases and drop its maxRecDepth bump.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
The Forall₂ lemmas live under the Lean4Lean namespace prefix (core owns
List.Forall₂), so dot notation cannot resolve them; apply them by name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Introduce of_unary_step_equations (Nat.add via Nat.succ, Nat.sub via
Nat.pred) and of_binop_step_equations (Nat.mul via Nat.add, Nat.pow via
Nat.mul), each carrying the shared literal-evaluation induction once;
the four per-primitive of_*_equations lemmas become instantiations.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Rewrite addNatPred/addNatAdd/addNatSub as addPrimitiveDefEq wrappers
instead of hand-built HasPrimitives records, and introduce
HasPrimitives.defKit carrying the shared typing/defeq scaffolding of the
add*Def theorems; nine members now supply only their equation semantics.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
Introduce addConst_all (the per-safety addConst construction) and the
generic addConst_ext / addConst_ext_ite scaffolding theorems covering
the unthresholded and thresholded environment extensions; the nine
VEnvs.WF.add* theorems become short instantiations with their
per-declaration translation and primitives steps.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017b11HQL6K7r3R6La5nNadk
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.

2 participants