Skip to content

Optimize LeanModularForms proofs and elaboration - #782

Merged
Vilin97 merged 1 commit into
mainfrom
codex/daily-optimize-20261108T1705
Nov 9, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
codex/daily-optimize-20261108T1705

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

LeanModularForms repeatedly elaborates large arithmetic/simplifier contexts and duplicate FTC transport arguments. This pass replaces bespoke proofs with library lemmas, shares the FTC argument, and narrows elaboration dependencies while preserving every existing declaration.

The selected completed project has 190 owned modules and about 68,000 lines. Initial clean builds and declaration profiles identified expensive residue-limit, boundary, iterated-derivative and Hecke-algebra proofs, alongside redundant private imports.

Changes:

  • Use iterated-derivative and matrix injectivity/determinant lemmas directly; reuse commutation results for powers.
  • Add LogDerivFTC.intervalIntegrable_integral_eq_congr_ae and use it in both boundary FTC telescopes, removing repeated integrability/equality transport and redundant interval assembly.
  • Replace broad arithmetic and simplifier searches with explicit dependencies or direct proof terms; retain 201 direct AC proofs after build and invariant validation.
  • Remove 84 redundant private imports and add three required imports, for 81 fewer direct edges. Every public import list is unchanged; the complete project's Mathlib closure is unchanged.

Invariant audit:

  • Exact base: faac47acb64cd8e2022370e59892faf9f5688c43; head: c26c93c48f731f943964b5e5408afa6431fab801.
  • Before editing, export the Lean environment with private declarations and bodies. Structurally serialize expression ASTs, universe parameters, names, ownership, safety and constant metadata. Compare non-theorem values literally; ignore only theorem proof bodies and expression metadata.
  • All 7,362 original declarations compare identically, including all 841 definitions and generated helpers: zero missing, zero changed. Head has 7,679 declarations: one new named FTC lemma and 316 new generated proof theorems.
  • Independently compare source signatures: all 3,451 original declarations and all 190 public import lists are identical. Experimental edits that changed generated helper types or values were restored, not exempted.
  • Base manifest SHA-256: b8bb0d01d000220303da39266dc6bc65eef1e2600ff6d49c4baacf380a100767. Final aggregate source SHA-256: 8fbbd584ab157c69c8aec28a729dba17f2ba9b7a3a910de77aeeb55196604925.

Measurements:

Run Version Wall seconds User CPU seconds Max child RSS KiB
optimized-8 head 493.92 746.32 1780288
baseline-9 base 533.65 789.36 1772288
baseline-10 base 517.89 781.87 1778144
optimized-9 head 474.08 745.00 1773276
Mean base 525.770 785.615 1775216
Mean head 484.000 745.660 1776782

Observed mean wall reduction: 7.94%; user CPU reduction: 5.09%. Largest-child RSS reduction: -0.09%. Negative reductions denote increases.

Each sample deletes only this project's build/IR artifacts, retains the same warm pinned dependencies and lint plugin, and runs /usr/bin/time -v env LEAN_NUM_THREADS=2 lake --wfail build LeanPool.LeanModularForms.Imports. The predeclared balanced order is head–base–base–head; all four samples are included, with no other Lean compiler from this task running concurrently. Settings and source hashes are recorded per sample. GNU time RSS is the largest child process, not total simultaneous build memory. Shared VM workloads limit timing precision.

The six-hour optimization effort threshold was reached. The 10% whole-project wall/RAM target was not established. The significant hot-proof allocation reductions and reusable proof simplifications are the material improvements retained from the pass.

Final diagnostic allocation profiles covered 17 modules and 420 matched primitive theorem commands, with macro/include wrappers excluded. Examples: aut_iter_deriv 80.66% fewer allocations; mulVecLin_injective_of_det_ne_zero 96.25%; cpv_at_endpoint 50.54%; right/left FTC telescopes 44.44%/41.86%; EQ22 78.06%. These are elaboration counters, not whole-project time or RAM measurements.

Validation passed:

  • Selected project warning-as-error build, including all four clean measurements.
  • Production scripts/ci/lint-project.lean over all 190 owned modules; lake exe lint-style LeanPool.LeanModularForms.Imports.
  • Unmodified production quality functions scoped to the project: headers, forbidden constructs, size, reachability, card, option settings, axiom audit and option-backdoor audit; selected generated index matches the production renderer.
  • Structural environment comparison, source-signature/public-import audit and git diff --check.

Uses the unchanged repository pins: Lean 4.35.0 and Mathlib 56a005855ea17e0b0958f73ec801ae140b0a1679. Only this project's Lean sources change. No index or card update is needed; no new modules are introduced. Whole-pool CI and independent refactor review remain required. The tested base is preserved rather than rebased to chase main; current main 2b205bf904013a5e06d8ef03069430dd79e1c8bd has identical selected-project sources/card, pins, applicable policies and validation tools.

This optimization run does not request queue entry, auto-merge or a merge. Existing rollout and protected-review requirements remain in force.

Reuse calculus and Hecke-algebra lemmas, share FTC transport, and narrow
proof searches and private imports while preserving all original declarations.
@greptile-apps

greptile-apps Bot commented Nov 8, 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.

RetriggerView in Greptile

[Medium impact] No blocking code issue was found; the separately required CI and independent review remain outstanding.

Summary

This refactor replaces repeated proof searches with explicit dependencies and library lemmas. It also shares integral transport between the two boundary proofs and removes private imports.

  • Derivative and matrix proofs use library results instead of rebuilding them.
  • Boundary winding proofs share one lemma for carrying integral facts across equalities.

Reviews (1) · Last reviewed commit: "Optimize LeanModularForms proofs and ela..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

✅ No statements changed — all 3,290 tracked declarations across 147 modified files kept their type; only proofs / definition bodies changed.

Also: 1 declaration added, 0 removed. A reorganization moves declarations between files, which shows up here as an add in one file and a remove in another.

➕ Declarations added (1)
  • LogDerivFTC.intervalIntegrable_integral_eq_congr_ae — LeanPool/LeanModularForms/GeneralizedResidueTheory/LogDerivFTC.lean

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: 17,178,792 → 16,023,651 (-1,155,141, -6.7%). Commands: 8,063 → 8,064.

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

Files: 145 compared — 81 cheaper, 3 costlier, 61 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/LeanModularForms/ValenceFormula/OnCurvePV/EndpointCorner.lean +36/-35 358,500 237,467 -121,033 -33.8% 48.88 18.15
LeanPool/LeanModularForms/HeckeRIngs/GL2/MultiplicationTable.lean +31/-26 858,479 738,032 -120,447 -14.0% 83.52 52.51
LeanPool/LeanModularForms/GeneralizedResidueTheory/HomologicalCauchy/Meromorphic.lean +3/-4 158,858 63,332 -95,526 -60.1% 9.98 7.03
LeanPool/LeanModularForms/HeckeRIngs/GLn/DiagonalCosets.lean +57/-53 649,812 589,855 -59,957 -9.2% 41.17 37.82
LeanPool/LeanModularForms/ValenceFormula/PVChain/ResidueSideInfra.lean +21/-14 311,123 262,159 -48,964 -15.7% 20.25 17.24
LeanPool/LeanModularForms/Modularforms/Eisensteinqexpansions.lean +12/-12 119,216 81,146 -38,070 -31.9% 13.78 9.41
LeanPool/LeanModularForms/ValenceFormula/WindingWeights/RhoPlusOne.lean +18/-18 464,428 429,408 -35,020 -7.5% 28.97 25.59
LeanPool/LeanModularForms/ValenceFormula/Boundary/Winding/UnitArc.lean +19/-20 196,887 162,624 -34,263 -17.4% 15.56 11.76
LeanPool/LeanModularForms/HeckeRIngs/GLn/CosetDecomposition.lean +22/-14 75,178 45,340 -29,838 -39.7% 5.99 6.29
LeanPool/LeanModularForms/ValenceFormula/Boundary/Winding/UnitArcHelpers.lean +31/-29 253,830 224,678 -29,152 -11.5% 34.11 20.36
LeanPool/LeanModularForms/ValenceFormula/PVChain/Helpers.lean +40/-19 237,135 208,160 -28,975 -12.2% 17.46 15.25
LeanPool/LeanModularForms/ValenceFormula/OnCurvePV/Main.lean +33/-34 224,415 202,121 -22,293 -9.9% 33.39 29.19
LeanPool/LeanModularForms/GeneralizedResidueTheory/Residue/MultipointPV/DominatedConvergence.lean +8/-6 107,725 86,710 -21,015 -19.5% 9.38 8.26
LeanPool/LeanModularForms/HeckeRIngs/AbstractHeckeRing/Associativity.lean +17/-10 234,897 213,896 -21,000 -8.9% 14.37 11.29
LeanPool/LeanModularForms/Modularforms/JacobiTheta.lean +62/-40 281,040 260,288 -20,752 -7.4% 24.77 18.41
LeanPool/LeanModularForms/ValenceFormula/RectHomotopy/WindingBase.lean +10/-11 224,764 205,008 -19,757 -8.8% 29.08 16.37
LeanPool/LeanModularForms/HeckeRIngs/AbstractHeckeRing/Module.lean +3/-3 73,534 53,801 -19,733 -26.8% 5.86 4.94
LeanPool/LeanModularForms/ValenceFormula/RectHomotopy/RadialHomotopy.lean +30/-16 206,843 188,000 -18,843 -9.1% 15.81 10.44
LeanPool/LeanModularForms/Modularforms/SummableLems.lean +57/-46 430,075 411,483 -18,592 -4.3% 78.32 50.83
LeanPool/LeanModularForms/HeckeRIngs/GLn/CoprimeMul.lean +22/-22 557,967 539,623 -18,344 -3.3% 42.82 28.18
LeanPool/LeanModularForms/HeckeRIngs/GLn/Degree.lean +12/-9 166,869 149,707 -17,162 -10.3% 24.05 16.46
LeanPool/LeanModularForms/Modularforms/DimensionFormulas.lean +14/-7 216,276 202,160 -14,116 -6.5% 11.65 10.60
LeanPool/LeanModularForms/GeneralizedResidueTheory/Homotopy/Integrality.lean +6/-4 101,053 87,780 -13,273 -13.1% 9.12 8.07
LeanPool/LeanModularForms/HeckeRIngs/AbstractHeckeRing/Ring.lean +3/-1 29,191 17,869 -11,322 -38.8% 4.45 3.34
LeanPool/LeanModularForms/GeneralizedResidueTheory/HomologicalCauchy/DixonProof.lean +15/-15 158,594 148,321 -10,273 -6.5% 24.75 17.30
LeanPool/LeanModularForms/ValenceFormula/WindingWeights/I.lean +16/-17 494,076 484,095 -9,981 -2.0% 30.08 25.68
LeanPool/LeanModularForms/Modularforms/Delta.lean +30/-20 148,259 138,710 -9,548 -6.4% 18.19 16.17
LeanPool/LeanModularForms/Modularforms/Cauchylems.lean +16/-9 75,618 66,106 -9,512 -12.6% 11.33 9.59
LeanPool/LeanModularForms/Modularforms/Eisenstein.lean +33/-23 317,722 308,453 -9,269 -2.9% 19.70 21.23
LeanPool/LeanModularForms/HeckeRIngs/GLn/Basic.lean +14/-8 99,962 91,008 -8,954 -9.0% 8.98 6.13
LeanPool/LeanModularForms/Modularforms/Iteratedderivs.lean +12/-58 19,421 10,672 -8,749 -45.0% 7.62 3.18
LeanPool/LeanModularForms/ValenceFormula/Boundary/Bounds.lean +17/-15 103,813 95,114 -8,699 -8.4% 7.07 10.07
LeanPool/LeanModularForms/ValenceFormula/RectHomotopy/BoundaryHomotopySmooth.lean +5/-5 152,083 143,607 -8,475 -5.6% 10.62 8.94
LeanPool/LeanModularForms/GeneralizedResidueTheory/Bridges.lean +2/-2 10,587 2,180 -8,406 -79.4% 9.07 10.19
LeanPool/LeanModularForms/ValenceFormula/RectHomotopy/AngleAnalysis.lean +17/-10 144,051 135,701 -8,349 -5.8% 21.96 12.66
LeanPool/LeanModularForms/HeckeRIngs/GL2/HeckeAction.lean +4/-2 107,556 99,284 -8,272 -7.7% 15.31 10.56
LeanPool/LeanModularForms/GeneralizedResidueTheory/PVInfrastructure/RemainderAnalysis.lean +7/-5 70,365 62,515 -7,850 -11.2% 7.56 6.92
LeanPool/LeanModularForms/Modularforms/QExpansion.lean +5/-4 41,390 33,895 -7,496 -18.1% 5.75 4.92
LeanPool/LeanModularForms/GeneralizedResidueTheory/Homotopy/Invariance.lean +9/-7 71,428 64,057 -7,371 -10.3% 14.52 9.73
LeanPool/LeanModularForms/GeneralizedResidueTheory/Residue/GeneralizedTheoremBase.lean +2/-3 79,813 73,091 -6,722 -8.4% 12.25 8.10
LeanPool/LeanModularForms/ValenceFormula/PVChain/ArcContribution.lean +8/-9 252,799 246,120 -6,678 -2.6% 15.87 14.36
LeanPool/LeanModularForms/Modularforms/E2.lean +4/-3 72,722 66,373 -6,348 -8.7% 11.73 8.99
LeanPool/LeanModularForms/GeneralizedResidueTheory/Residue/SectorCurve.lean +16/-14 72,538 66,463 -6,075 -8.4% 15.88 10.68
LeanPool/LeanModularForms/Modularforms/EtaCleanup.lean +20/-17 171,996 165,922 -6,074 -3.5% 15.65 14.80
LeanPool/LeanModularForms/ValenceFormula/TextbookForm.lean +28/-13 317,865 312,102 -5,763 -1.8% 23.67 17.22
LeanPool/LeanModularForms/HeckeRIngs/AbstractHeckeRing/Commutativity.lean +3/-3 119,785 114,199 -5,586 -4.7% 10.05 9.87
LeanPool/LeanModularForms/Modularforms/Generators/Defs.lean +3/-2 78,034 72,501 -5,533 -7.1% 5.75 5.41
LeanPool/LeanModularForms/ValenceFormula/PVChain/OnCurveCapture.lean +9/-7 67,761 62,333 -5,428 -8.0% 10.42 8.20
LeanPool/LeanModularForms/ValenceFormula/WindingWeights/Rho.lean +5/-6 382,956 377,788 -5,168 -1.3% 36.83 24.97
LeanPool/LeanModularForms/GeneralizedResidueTheory/Residue/MultipointPV.lean +3/-4 91,710 86,632 -5,077 -5.5% 14.85 11.00
… +95 more files, each with a smaller move (≤ 4,984 HB); full table in the run's step summary
Total +1,444/-1,185 17,178,792 16,023,651 -1,155,141 -6.7% 1960.1 1532.3

New files — absolute profile

Total heartbeats: — maxHeartbeats units across 0 valid files (75 added LOC).

Sum of lean --profile: — across 0 valid files. Import-excluded time: —.

Count-heartbeats wall-clock total: 0.00 s. Repeated import cost inside lean --profile: —.

Heartbeat values sum disjoint root command traces with trace.profiler.useHeartbeats and synchronous elaboration, converted from raw allocations to maxHeartbeats units by dividing by 1000. They include command elaboration and kernel checking, exclude imports, and include profiler overhead; they are not comparable to the deprecated linter's totals. Per-file wall clocks are measured under parallel load and are noisier than heartbeats.

LOC counts added lines in the profiled Lean files from this PR diff.

File LOC Heartbeats (maxHB) Count wall (s) lean --profile (s) Without import (s) Import (s) Commands Errors
LeanPool/LeanModularForms/ValenceFormula/Boundary/Winding/LeftEdge.lean 33 — — — — — 57 1
LeanPool/LeanModularForms/ValenceFormula/Boundary/Winding/RightEdge.lean 42 — — — — — 84 1
Total 75 — 0.00 — — — 141 2

Aggregate phase totals

Phase Time
Unavailable —

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

@Vilin97

Vilin97 commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: c26c93c48f731f943964b5e5408afa6431fab801

Verdict: ✅ approve

This refactor replaces broad proof searches with explicit dependencies, reuses library calculus and matrix lemmas, shares FTC transport, and removes redundant private imports. The substantive proofs retain their intermediate facts and endpoint calculations. The supplied /profile reports 6.7% fewer heartbeats across measured files; local compilation was blocked by HTTP 403 fetching pinned Mathlib. No actionable maintainability regression was found.

Aspect Value
Scope proof optimization and dependency cleanup
Introduces tech debt ✅ no
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

The refactor reduces duplicated proof machinery and implicit tactic dependencies while preserving useful proof structure and reusable helpers.


Tokens: 3,804,095 in / 6,938 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $15.3204 (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 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.

Reviewed exact head c26c93c48f731f943964b5e5408afa6431fab801 under the refactor rubric. No blocking findings; the source is acceptable for protected integration.

The 147 changed files preserve existing written declaration headers and non-theorem values. All 190 public import lists are unchanged. The private import cleanup removes 84 edges and adds three, without removing project modules or changing gates.

The shared LogDerivFTC.intervalIntegrable_integral_eq_congr_ae correctly transports both integrability and the evaluated integral on the unordered interval. Its ten uses retain the left/right telescopes’ actual intervals, cutoff bounds, logarithm signs and endpoint cancellation. The iterated derivative proof keeps the integer translation, factorial and denominator formula while reusing the existing derivative API. The Hecke commutation and diagonal/matrix proofs likewise reuse the relevant library facts on the original objects. The remaining changes generally replace broad search with explicit facts or associative/commutative normalization; no material loss of proof structure was found.

The public profile reports 6.7% fewer heartbeats across 145 compared files. LeftEdge and RightEdge have no usable timings, so this does not establish a whole-project speedup or the stated 10% target. Profiling remains advisory.

The six applicable workflow namespaces pass at the reviewed head. I independently bound their actual checkout to these source changes combined with current main 2b205bf, including the full planned 190-module project and current control files. The configured refactor review also approves this exact head. Queue validation must still pass normally; no waiver or branch update is needed.

@Vilin97
Vilin97 added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit 4069505 Nov 9, 2026
28 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