Skip to content

Add pinned Lean-library imports, glossary generation, wrappers and axiom auditing - #362

Draft
humuhumu33 wants to merge 29 commits into
release/v0.5from
feat/mathlib-import
Draft

humuhumu33 wants to merge 29 commits into
release/v0.5from
feat/mathlib-import

Conversation

@humuhumu33

@humuhumu33 humuhumu33 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

This draft prepares pinned Lean-library imports, glossary generation, specialisation wrappers and axiom auditing. Imported declarations are loaded from the pinned environment and signature-checked; this implementation does not replay their dependency closure. Generated project modules retain the required kernel replay and axiom checks. Design: docs/proposals/mathlib-import.md.

Closes #335, #336, #341.

The closing scope is limited to glossary generation, specialisation and the reviewed design document, after the outstanding source/schema/status corrections, coordinated regeneration and complete final-head gate. #333, #337, #338, #339 and #340 remain open: a cache library unused by verify, a closure-replay prototype and the current demo do not complete their acceptance criteria. #334 remains open pending an actual measured cold deps fetch run; file timestamps are not that measurement. The design document and imported-status wording must be updated to the accepted scope before landing. Cache integration, additional semantic proof forms and a new imported-closure checker are outside this integration.

What this adds

Issue Change Register rows Codes
#334 [[lean_library]] config (HTTPS, exact 40-hex revision), lock rows, explicit lexlean deps fetch; every other command stays offline ML-01 to ML-04 LLC0109, LLC0110, LLV7019, LLV7020
#335 lexlean deps glossary: generates kind = "lean" entries from Lean declarations, byte-deterministic, with a coverage report; untranslatable declarations are refused CL-25, GL-19, GL-20 LLT4101 to LLT4107
#336 Specialisation wrappers: a concrete instance of a class-polymorphic declaration as a pure proof term in the host library, and a strict signature probe GL-21, VR-24 LLT4017, LLT4018
#337 Measurements and a closure-replay prototype (tooling/mathlib-speed/); no Rust or SPEC change none none
#338 Content-addressed replay cache keyed by ADR-015 digest sets; a library, not yet used by verify (design decision D6) RC-01 to RC-06 LLV7021, LLV7022
#339 Axiom audit and status wording for imported declarations VR-25, VR-26 LLV7023 to LLV7025
#340 BLAKE3 G acceptance demo under demos/mathlib-blake3-g, a new verify-demos task and .github/workflows/mathlib.yml (it runs lexlean deps fetch, then verifies the demo) see ids.toml none
#341 The design document none none

The register now has 477 IDs.

Collisions resolved while merging

The nine pieces were built in parallel and collided. These were renumbered here: the specialisation row GL-19 is now GL-21; its SPEC section 13.12 is now 13.13 (section 13.12 is the glossary); the replay-cache codes LLV7019/LLV7020 are now LLV7021/LLV7022 (the fetch codes keep LLV7019/LLV7020); the probe-binders row VR-25 is now VR-27.

Checks, honestly

Passed locally on the tip (7c6467d94): fmt, model validation (477 IDs), spec-links, clippy, features, test inventory and the verify-demos task.

Passed locally on the merge just before the demo restructure (f1ea14fe0): cargo deny, and the new conformance cases GL-19 to GL-21, ML-01 to ML-04, RC-01 to RC-06 and VR-24. They have not been rerun on the tip.

Not completed locally: the full unit-test run and most bdd parts. WSL repeatedly killed the long runs; one run was OOM-killed on the 4.5 GB lane. CI on this PR is the first complete run of those. Findings so far:

  • formatter_is_idempotent_on_every_example peaks near 6.8 GB on its own and passes when run alone.
  • end_children::a_signal_the_host_did_not_handle_ends_it_by_default failed once under nohup and has not been checked on clean main.
  • conformance_rp_11 failed on main after the README refresh removed the capability table; this PR restores the table (502f9f843).

Known limits (full list in the design document): one toolchain and one Mathlib commit (520045ab14e26149ee970e2e617ca04b09bde5d6, tag v4.32.1) on x86_64 Linux; a cold lake exe cache get took about 5.4 minutes and 7 GB; deps glossary takes a module or name list and a Lake require is still written by hand; the replay cache is not used by verify.

🤖 Generated with Claude Code

Ilya Paveliev and others added 29 commits October 29, 2026 11:38
A replayed unit is keyed by a Merkle DAG of PrismPM ADR-015 DigestSets
({sha256, blake3}, label blake3:<hex>) over one canonical serialisation of a
declaration (name, universe parameters, kind attributes, type, value digest),
the keys of what it names, the Lean toolchain and the Mathlib revision. A unit
is a set of declaration keys, so the cache serves per-declaration and
per-module replay alike. Entries are canonical JSON named by key, carry the
executable digest that produced the result and a digest of their own bytes;
changed bytes, a foreign key, a forged environment or a malformed file are
LLV7019, malformed facts LLV7020. Facts come from the pinned Lean through an
embedded exporter (replay_facts.lean).

Adds rows RC-01..RC-06 (register, SPEC 31, scenarios, cases), SPEC 22.13, the
blake3 dependency (SPEC 8.5 table; deny.toml allows BSD-2-Clause for its
arrayref), a falsifiability record in VERIFICATION.md, and notes for #341 in
docs/proposals/mathlib-import-notes-338.md. lexlean verify does not use the
cache.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ps fetch (Refs #334)

[[lean_library]] (language 1.2) declares an external Lean library once, by HTTPS
URL and exact commit. The lock pins it with the digest of the library's own
lake-manifest.json and the digest of its glossary, and the Lake workspace must
require it as declared. lexlean deps fetch is the only command that acquires it
(lake exe cache get); lock, check, build, fmt and verify stay offline and fail
with LLV7019 when it is absent.

Registers ML-01..ML-04 and LLC0109, LLC0110, LLV7019, LLV7020. The schema change
that would move the language-1.2 identity is held back; see
docs/proposals/mathlib-import-notes-334.md. Mathlib pin: 520045ab14e2 (tag v4.32.1).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…9, VR-24, #336)

A class-polymorphic Lean declaration is specialised at a concrete type as one
public term declaration of the host library, LexLeanSpec.<tag>.<declaration>,
emitted by lexlean::wrappers (and cargo xtask emit-wrappers) from a
lexlean/wrappers/1 request. The external-interface probe holds an entry that
denotes a wrapper to (signature) = (type_of% @wrapper) := rfl; a signature that
differs is LLT4017, a request outside the term grammar is LLT4018.

Register rows GL-19 and VR-24 (459 IDs), SPEC 13.12 and 18.8, scenarios, failing
named tests, fixture tests/fixtures/specialisation, planted defects in
VERIFICATION.md, notes in docs/proposals/mathlib-import-notes-336.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…pe (#337)

Measurement scripts under tooling/mathlib-speed (targeted vs umbrella import,
leanchecker module vs fresh vs declaration-closure replay, byte-reproducibility
of Mathlib modules built twice), a small Lean closure-replay tool, a
planted-defect module pair, and the notes for the design document.
No LexLean Rust or SPEC change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
lexlean deps glossary runs a Lean metaprogram under the pinned toolchain
and writes a lexicon package of kind-lean entries plus a coverage report.
LSE signatures are translated from the kernel type (binder modes kept,
implicit and instance arguments left out of applications, annotations
erased), names and surfaces follow a documented scheme, inductive types
get eliminator descriptors, and anything LSE cannot express is refused
with a registered code (LLT4101-LLT4107) and never weakened.

Register rows CL-25, GL-19, GL-20; SPEC 13.12 and 23.4; fixtures under
tests/glossary; working notes in docs/proposals.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
docs/proposals/mathlib-import.md covers the config surface, commands, lock
rows, cache keys, the trust statement, diagnostics, limits and refusal
reasons, the measurements of #334 to #338, and the owner decisions (D1 to D15).
Sections for the axiom audit (#339) and the acceptance demo (#340) are marked
PENDING.

Check run: all 18 diagnostic codes named in the document have an entry in
ERRORS.md; every section number cited exists in SPEC.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Section 13 now states the import axiom audit (VR-25, VR-26, LLV7023 to
LLV7025) from note 339, with its findings and owner decisions (D15). The
three codes are in the ERRORS.md of the #339 tree and not yet on the
integration branch. The #340 demo section stays PENDING.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ons (VR-25, VR-26, #339)

The probe module prints #print axioms for each used external whose Lean module
is outside Init, Std, Lean, Lake and LexLeanRuntime; the observed sets are
recorded in the attestation (imports) with the status "replayed in the pinned
environment", and an import that depends on sorryAx (LLV7023),
Lean.ofReduceBool (LLV7024) or Lean.trustCompiler / a native_decide axiom
(LLV7025) is refused unless an axiom policy of the document names it.

Schemas are untouched (identity move held back; see the notes).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
VR-25: the external-interface probe wrote an unreferenced instance binder
with a name, which pinned Lean lints and a warning fails verification, and
it ascribed a numeral the type of a caller local when the caller local was
named like a binder of the callee (a, the type parameter of Eq).
ML-05: fmt copied the project to a scratch directory without the declared
library, so it failed with LLV7019 on any project that declares one.

Also: xtask links the example Lake workspace into the clean copy instead of
copying it, and audit-deferral skips .lake (fetched libraries).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Registers total 476.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
examples/mathlib-blake3-g: four language-1.2 modules proving, for BitVec 32
and UInt32, (a + b) - b = a, (a ^^^ b) ^^^ b = a, rotl (rotr a n) n = a for
n in {7, 8, 12, 16}, and that the eight-step inverse of the BLAKE3 G
function recovers its inputs, citing Lean core and Mathlib lemmas through a
generated glossary. Verified offline against the pinned Mathlib; expected/
holds the build and verification goldens. Notes for the design document in
docs/proposals/mathlib-import-notes-340.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Section 10.7 now holds the demo results from note 340 (statements, proof
forms with external lemmas, measurements, coverage, the three defects found,
what verified and what did not). D3 and D4 are rewritten: prose proofs with
external lemmas work in a language-1.2 project, so the gap is semantic
modules. New decisions D16 (CI for an example that needs the library) and
D17 (the demo choices); new gaps in sections 12 and 15.

Checked against the merged branch: all 23 diagnostic codes named are in
ERRORS.md, all 17 register IDs named are in model/ids.toml, 476 IDs in
model/ids.toml and SPEC.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The demo needs a fetched Mathlib, which no default gate has: demos live under
demos/, nothing under examples/ declares a lean_library, cargo xtask
verify-demos gives a demo the example gate plus its golden build and a
reproducibility check, and .github/workflows/mathlib.yml fetches the library
and runs it in a job of its own, outside the acceptance gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@humuhumu33 humuhumu33 added this to the Mathlib milestone Oct 30, 2026

@afflom afflom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer review.

  1. Base. Retarget to release/v0.5 (AGENTS.md, release lines: main takes a line only at its tag).
  2. CI red (run 41034507088, rest + 4 hosts):
    • RP-05: xtask/Cargo.toml description omits verify-demos.
    • RP-11: README range EX-01..EX-09 must end at EX-10.
    • SP-17: Lean syntax literal ") := rfl" at crates/lexlean/src/backend/lean.rs:2541.
  3. mathlib.yml cost. It fetches ~7 GB on every PR and push, whatever changed. Add a paths: filter (demos/**, crates/lexlean/**, xtask/**, lean-toolchain, Cargo.lock, the workflow itself).
  4. CI budget. Please convert to draft until rest is green; each push to a ready PR runs the whole gate (~500 runner-min).

Generated by Claude Code

@afflom

afflom commented Nov 2, 2026

Copy link
Copy Markdown
Member

The numeral capture also fails outside the probe, in a glossary defined value. At 3877351, an entry with

value = "(lam ((explicit a (const lexlean.std.nat::nat))) (app (const lexlean.core::eq) (local a) (nat 0)))"

used as \(iszero(0)\). generates (fun (x0 : Nat) => Eq x0 (0 : x0)) 0 and fails with LLV7002: type expected, got (x0 : Nat). Renaming the binder to b verifies. print_defined_value reaches the same parameter_types, so #362's rename should cover it (not run against the branch), but tests/fixtures/probe-binders as described covers only the probe. A defined-value case would keep that path from regressing.

This PR targets main. The fix also needs to reach release/v0.5, which holds downstream pins such as afflom/rule30's and still has the old code at backend/lean.rs:635.

afflom commented Nov 3, 2026

Copy link
Copy Markdown
Member

Follow-up maintenance review at 7c6467d: the prior review is still outstanding. I am moving this PR to draft and retargeting it to release/v0.5 as already requested, so incomplete work does not keep triggering the full gate.

Two additional concrete acceptance gaps need correction before the identity wave:

For the initial integration, retain the current pinned toolchain, generic deps commands and language-1.2 scope. Do not add semantic proof forms or a cache to this already large PR just to anticipate future use. Keep the disclosed imported-workspace trust boundary, and use accurate loaded from the pinned environment status for imported declarations until their closure is actually replayed. Generated-module replay and exact axiom auditing remain required. No extra closure checker is required solely to rename that status accurately.

Please also include the defined-value numeral-capture reproduction in the existing regression coverage, alongside the probe case. The prior CI corrections and scoped Mathlib workflow trigger remain required. Publish the resulting final scope/issue-closing list before requesting the full gate.

@afflom
afflom marked this pull request as draft November 3, 2026 06:47
@afflom
afflom changed the base branch from main to release/v0.5 November 3, 2026 06:47
@afflom afflom mentioned this pull request Nov 3, 2026

afflom commented Nov 3, 2026

Copy link
Copy Markdown
Member

Maintainer coordination at unchanged head 7c6467d94: I am preparing the previously requested VR-27 defined-value numeral-capture regression in an isolated checkout, alongside the existing probe coverage. The shared renamer is already present and will remain unchanged. This is narrow review preparation only: no contributor-branch update, schema/identity regeneration, cache integration or imported-closure checker. I will report actual generated-code and pinned-Lean results before publication.

@afflom afflom changed the title Mathlib import: pin, glossary, wrappers, axiom audit, replay cache, demo, design (closes milestone 5) Add pinned Lean-library imports, glossary generation, wrappers and axiom auditing Nov 3, 2026

afflom commented Nov 3, 2026

Copy link
Copy Markdown
Member

I audited the proposed closing list against the actual child criteria and corrected the title/body. The prospective closure is now #335, #336 and #341 only, conditional on the remaining corrections and final gate. No issue was closed.

#334 still needs a measured cold fetch (the design currently derives 5.4 minutes from file timestamps). #337/#338 do not have integrated imported-closure replay or warm-after-edit verify evidence. #339's current acceptance asks for replay wording this implementation cannot claim; accurately saying loaded from the pinned environment does not by itself complete that issue. #340's broad demo acceptance and parent #333 remain open. The design document must describe these boundaries consistently before its own #341 closure.

A register coordination detail: #391 had proposed VR-24 for a distinct single-kernel replay/publication guard. That issue now reserves VR-28, preserving this PR's existing VR-24–27 claims. No renumbering or extra identity wave is requested here.

afflom commented Nov 3, 2026

Copy link
Copy Markdown
Member

The requested ordinary defined-value regression is reviewed and available for this PR's source integration: commit 7d43d86d5 on maintainer branch fix/vr27-defined-value. It is a direct child of unchanged contributor head 7c6467d94; remote tree 39365b557a1f1171f0a04fa8d64d89571310ea40 matches the independently reviewed local tree. No new PR was opened, no contributor branch moved, and the corrected title/body were preserved.

This changes only VR-27 coverage, its existing fixture and verification evidence. The defined iszero predicate binds a : Nat around Eq a 0, and an ordinary theorem states iszero(0). The shared renamer, schemas, identity inputs, cache and imported-closure behavior are unchanged. Generated-text assertions run before the host gate; normative-host execution retains the original focused probe and also verifies the ordinary document. That separate probe is necessary: ordinary verification reaches Nat/Nat.add, not the otherwise-unused HXor.hXor and UInt32.xor_self signatures whose exact text and empty process output the original assertions cover.

Actual evidence: the historical printer generated (fun (x0 : Nat) => Eq x0 (0 : x0)) 0 and pinned Lean refused it with LLV7002, type expected. The current printer generates (fun (x0 : Nat) => Eq x0 0) 0; direct CLI lock/build/verify passes under pinned Lean 4.32.1 on the final canonical fixture, with both theorem axiom sets []. CLI build, lexlean/repo-conformance all-target/all-feature Clippy with warnings denied, source/Rust formatting and whitespace checks pass. The full VR-27 harness and complete acceptance gate were not run locally; these direct pinned-Lean results are not a claim that either gate passed.

Please include this single reviewed commit in the existing #362 source refresh before the coordinated schema/status corrections and official identity writers. The remaining review findings, final integration and acceptance evidence still belong to this PR; this prepared branch claims no issue closure or completed Mathlib milestone. Its feature-branch push matches none of the current workflow push filters, including Mathlib's, and no Actions run was created for the commit at the verification check.

afflom commented Nov 3, 2026

Copy link
Copy Markdown
Member

Maintainer coordination at unchanged head 7c6467d94: the next isolated source-preparation step will build on reviewed VR-27 commit 7d43d86d5 and supply the four missing closed schema contracts (project-v2, lock-v2, and both attestation schemas), plus the accepted accurate imported status, loaded from the pinned environment, in emitted records and their matching tests/normative text/docs. Existing required fields and additionalProperties: false will remain intact. This will not add a cache, proof form or imported-closure checker. Because the schemas are identity inputs, no pins, expected artifacts or identity regeneration are being updated in this preparation; coordinated integration, official writers and final full acceptance remain required. The contributor branch will remain untouched pending review.

afflom commented Nov 3, 2026

Copy link
Copy Markdown
Member

Reviewed source follow-up is published: 0734d13cc on fix/mathlib-schemas-status, directly atop reviewed VR-27 commit 7d43d86. Tree 5edb43d85fd0b435e1ed96f9b59939736183eda8 matches independent review. The contributor branch remains untouched; this belongs in existing #362, not a duplicate PR.

The four missing closed schemas now match existing library/import writers, preserving every prior required field. Library presence requires language 1.2 even for []. Writer, VR-26, normative text and current docs consistently say loaded from the pinned environment; historical evidence remains intact. No cache integration or imported-closure replay is claimed.

Passed: seven focused Rust units (including actual row serialization/schema binding), 48 schema refusal cases, official model projection, correctly rooted canonical/model audit (477 IDs/104 codes), formatting and whitespace checks. The initial ENOSPC compile ran no tests and is not evidence.

All three language identities are affected by the shared attestation schema. Pins/artifacts remain unchanged and intentionally stale; no verification or full gate ran on them. Integrate this reviewed source before official regeneration. Coordinate the final v0.5 wave with the accepted Lean 4.33.1 upgrade #420; current evidence remains from the existing 4.32.1 line. Remaining review findings, final integration and complete acceptance are still required. No readiness or issue closure is claimed.

afflom commented Nov 3, 2026

Copy link
Copy Markdown
Member

The remaining small source-readiness fixes are independently reviewed and published atop the earlier schema/regression preparation: 1144608af on fix/mathlib-source-readiness, tree 5bab1329f92af6e8e615508cc5d0edade342bfaa. This includes parents 0734d13 and 7d43d86; the contributor branch remains unchanged.

The xtask description now includes its existing verify-demos and emit-wrappers commands; README's example range includes EX-10. SignatureExample reuses the renderer's existing assignment token, preserving its exact equality/rfl output and line mapping. SP-17's scanner and allow-list remain unchanged, including all planted-template refusals.

The separate Mathlib workflow now limits push/PR execution to relevant build, embedded, demo and workflow inputs. Dispatch, branch selection, all job commands and normative ci.yml remain unchanged. Conservative demo/crate paths still include their documentation.

Passed: exact rendering unit; SP-17/RP-05/RP-11/EX-10 with explicitly verified checkout roots; existing plants; 21 workflow-path cases; all-target/all-feature Clippy, formatting and whitespace checks. No library fetch, verification or full gate was run. The schema changes still require the coordinated identity/artifact wave and complete final acceptance, aligned with #420. These follow-ups address source findings, not readiness or closure of the broad Mathlib issues.

afflom commented Nov 4, 2026

Copy link
Copy Markdown
Member

The combined forward-source review found a concrete integration prerequisite: DigestSetWriter streams through sha2, but landed SL-06 requires the compiler to use the certified stdlib SHA-256 and forbids that shipped dependency. The existing package exports only whole-message hashing; using its Vec-buffering wrapper would change the new executable-file and declaration-group callers’ memory behavior. There is no existing exported incremental API to substitute directly.

I opened scoped #438 (SL-15, assigned to me) for the minimum certified incremental interface and DigestSet adaptation. It belongs in this existing Mathlib integration and coordinated v0.5 source freeze, not a duplicate Mathlib PR or separate writer wave. The contract retains digest/framing/BLAKE3 bytes, bounded state/chunk memory, closed FIPS-length handling, existing SL-02/SL-06 guarantees and full final acceptance. No dependency exception, arbitrary size refusal or runtime implementation has been introduced.

The remaining source union is being independently reviewed now, with strict schema/status/Host/#396 retention. It remains explicitly unbuildable at the unresolved hashing boundary; no compilation or successful Mathlib execution is claimed.

afflom commented Nov 4, 2026

Copy link
Copy Markdown
Member

Correction to the dependency decision above: independent call-site review confirms the streaming consumers are confined to the unused replay-cache prototype. DigestSet itself has no initial CLI/glossary/loaded-import consumer; those paths already hash through certified Sha256Digest::of. The SHA conflict is real in the unsplit source, but does not justify blocking initial Mathlib delivery on a new capability.

I am separating that future #338 preparation explicitly: preserve all cache source, RC-01–06 claims/scenarios/tests, LLV7021/7022, exporter and normative/dependency mirrors together. The initial candidate will carry none of those delivery claims or disabled tests. The #341 design document may retain clearly labeled future cache designs and historical measurements. This preserves work and acceptance rather than removing requirements from #338.

#438 is now correctly scoped to the future cache integration; its unexecuted design is preserved and implementation paused. Initial #362 remains scoped to #335/#336/#341, with #337/#338 and other broad trackers open. No new runtime feature, writer, source-branch mutation or test run was performed for this decision.

afflom commented Nov 13, 2026

Copy link
Copy Markdown
Member

Stays draft on release/v0.5 (a feature, so not v0.4). It conflicts and its source/schema corrections and coordinated regeneration are outstanding. It lands after #405; before it is marked ready, .github/workflows/mathlib.yml must not run on every PR, and the Mathlib pin must follow the Lean pin chosen at #433.


Generated by Claude Code

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.

Mathlib import: seamless, fast, precise (tracking)

3 participants