Skip to content

Reduce MarkoffModP numerical certificate compiler memory - #1056

Merged
Vilin97 merged 1 commit into
mainfrom
vilin/optimize-markoff-numeric-certificates-20261127
Nov 27, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
vilin/optimize-markoff-numeric-certificates-20261127

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Ready for review. Peak anonymous compiler memory for MarkoffModP is 25.41% lower in the clean build comparison.

Proof change

MarkoffModP builds 615 modules. Its largest compiler process in the baseline compiled ExplicitNumericCertificates.lean. The published source profile attributes 5.60 seconds to explicit_lowOrder_forces_corvajaZannier_cube in the same source revision of that file. Lean Pool source profile

Use mul_pow, pow_mul, associativity, and pow_succ' in that proof to keep the ninth-moment coefficient symbolic through the power comparisons. The patch changes three proof steps in one file and records the modification in its attribution notice.

Declaration audit

  • Base bb99e52c3f05626056b5718b442ec2f84ece1122 and head 6510f55af58cbbf7b9eaef3b1946cbcb5a6e5913 use Lean 4.36.0 and Mathlib fc4f59e577feb1a4956671bc04ac18aaaf8cd842.
  • Read the public and private Lean module data for every owned module before editing and after the clean optimized build. The compressed manifests compared all kernel declarations by name, including generated declarations. They record fully elaborated expression structure, binding annotations, universe parameters, kind, visibility, safety, and non-theorem values and reduction rules. The audit omits theorem proof bodies and kernel-irrelevant expression metadata.
  • All 15,192 declarations are preserved. 15,191 records match exactly. The remaining record, private auxiliary theorem _proof_1_11 under the edited theorem, differs solely in the macro scope counter on one inaccessible binder (1028 → 1089). Its type is alpha-identical and its other fields match. The source statement check also found zero statement changes, binder renames, additions, or removals.

Measurements

Metric Base Optimized Change
Project build wall time 565.474 s 596.791 s 5.54% higher
Largest Lean process, anonymous memory 632,400 KiB 471,700 KiB 25.41% lower
Peak simultaneous Lean anonymous memory 1,384,224 KiB 1,326,724 KiB 4.15% lower
Edited file, Lake compile time 9.6s 3.6s
Edited file, anonymous memory 632,400 KiB 262,752 KiB 58.45% lower

Both measurements compiled all 615 project modules afresh in the same Azure worktree with warm, identical external dependency and compiler-plugin artifacts. The sampler covered all 615 modules in each run and read RssAnon plus VmSwap from the Lean process tree about every 100 ms. An initial clean base run was repeated because its process discovery missed 50 compiler starts. The peak shifted from ExplicitNumericCertificates.lean to ExactConstantExtensionDifferentCoefficient.lean.

With dependencies cached, separate targeted builds of the edited file measured 8.684 → 3.027 seconds for the Lake command and 619,828 → 275,276 KiB of sampled anonymous memory. Whole-project wall times and simultaneous memory are observations from a shared VM.

python3 ../repeat-base.py bb99e52c3f05626056b5718b442ec2f84ece1122
LEAN_NUM_THREADS=4 python3 ../measure.py ../head1 \
  lake --no-cache --no-ansi build LeanPool.MarkoffModP.Imports
LEAN_NUM_THREADS=4 python3 ../measure.py ../cert-head-target \
  lake --no-cache --no-ansi build LeanPool.MarkoffModP.BGS.Markoff.ExplicitNumericCertificates

Validation

  • Warning-free project build with LeanPoolLinters, plus the original stored compiler-message audit and changed-file timing gate.
  • Slow declaration linters via lake env lean --run scripts/ci/lint-project.lean for all 615 owned modules, and lake exe lint-style LeanPool.MarkoffModP.Imports.
  • Repository-wide lean_pool.quality --static-only, plus the repository's compiled axiom dependency, option and axiom-injection, and registered declaration audits scoped to MarkoffModP. A separate axiom traversal checked all 31 declarations in the edited module, including its private auxiliaries.
  • lake exe mk_all --module --check, documentation workspace pin comparison, source index check through lean_pool.rebase_fastpath check-index, and git diff --check.
  • lake shake --force --keep-public --gh-style for the edited module returned identical dependency suggestions at base and head. Full-pool compiled integration remains with hosted CI.

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Advisory cross-file review against Lean Pool's supervisory rubric. This is not by itself a significance, source-verification, or merge verdict.

No blocking issue was found in this proof-only change.RetriggerView in Greptile

[Low impact] No blocking issue was found in this proof-only change.

Summary

Replaces three ring calls in explicit_lowOrder_forces_corvajaZannier_cube with explicit power and multiplication identities.

  • The low-order certificate keeps its power comparisons symbolic.

Reviews (1) · Last reviewed commit: "Reduce MarkoffModP numerical certificate..." · Reviewed by Greptile

@Vilin97 Vilin97 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Source review passed at 6510f55af58cbbf7b9eaef3b1946cbcb5a6e5913.

  • The three symbolic power rewrites prove the same inequalities with the same constants. The low-order certificate and its assembly alias retain their statements. The existing copyright remains in place, and the change is recorded in the source.
  • I matched the measured source to this head and checked the stored declaration audit and compiler samples. Both clean runs covered 615 modules. The edited file's anonymous-memory peak fell from 632,400 to 262,752 KiB, and the largest compiler process fell from 632,400 to 471,700 KiB. The separate single-file comparison also showed lower memory and runtime.
  • The single whole-project wall-time comparison was 5.54% slower. The measured benefit is lower peak compiler memory. Required hosted Lean CI is running. Lean Action CI

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

✅ No statements changed — all 23 tracked declarations across 1 modified file kept their type; only proofs / definition bodies changed.

Statements are compared textually against the merge base (comments and whitespace ignored; by proof terms embedded in a type are treated as proof-irrelevant), the same method as physlib's /check-golf. Anonymous instances and examples are not tracked.

Compile cost of modified files — base → head

Heartbeats: 88,620 → 68,552 (-20,068, -22.6%). Commands: 32 → 32.

Per-file wall sum: 22.1 s → 17.9 s (-18.9%). Wall clock is measured under parallel load and is noisy; heartbeats are deterministic and are the regression signal.

Files: 1 compared — 1 cheaper, 0 costlier, 0 within noise (threshold: |Δ heartbeats| ≥ 1,000 and ≥ 1%).

Both sides are elaborated against the merge-base build of the pool — sound when only proofs and definition bodies change; a file whose statements changed may fail there and is flagged ⚠. Heartbeats come from disjoint root command traces with trace.profiler.useHeartbeats and synchronous elaboration, converted to maxHeartbeats units. Failed measurements are not classified as cheaper or costlier. Δ lines counts added/deleted lines from this PR diff.

File Δ lines HB base HB head Δ HB Δ HB % Wall base (s) Wall head (s)
LeanPool/MarkoffModP/BGS/Markoff/ExplicitNumericCertificates.lean +8/-3 88,620 68,552 -20,068 -22.6% 22.13 17.94
Total +8/-3 88,620 68,552 -20,068 -22.6% 22.1 17.9

Advisory only — never blocks merge. Full log uploaded as the proof-profile artifact.

@Vilin97

Vilin97 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 LLM review — refactor (gpt-6.2-sol)

Reviewed head: 6510f55af58cbbf7b9eaef3b1946cbcb5a6e5913

Verdict: ✅ approve

The low-order Markoff certificate replaces three ring calls with explicit power and multiplication identities. It keeps the ninth-moment coefficient symbolic and preserves the named bounds and calculation steps. The targeted Lake build passed, and CI reports 22.6% fewer heartbeats for the edited file. In two local runs per revision, the module compiled in 1.45 s at head versus 4.98–5.22 s at base, with average peak RSS 338 MiB lower. The whole-project figures come from the contributor’s shared-VM runs.

Aspect Value
Scope symbolic power proof rewrite
Introduces tech debt ✅ no
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

The explicit identities give maintainers a specific rewrite to inspect if a step fails and leave more elaboration headroom for future changes.


Tokens: 1,943,791 in / 12,859 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $7.9680 (Standard API equivalent; uncached input) (long-context rate)
Automated review against .github/REFACTOR_REVIEW_RULES.md. Disagree? Reply on the PR; rules can be updated in a PR of their own.

@Vilin97
Vilin97 added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 1044203 Nov 27, 2026
27 checks passed
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