Skip to content

Optimize LeanModularForms proof elaboration - #698

Merged
Vilin97 merged 1 commit into
mainfrom
codex/optimize-20261020T2115
Oct 21, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
codex/optimize-20261020T2115

Conversation

@Vilin97

@Vilin97 Vilin97 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

LeanModularForms spends substantial time searching large local contexts for arithmetic and simplification proofs and synthesizing routine analytic properties. This constrains those searches to explicit facts and replaces several expensive arguments with direct Mathlib lemma chains. It also removes 45 redundant private imports identified by lake shake --force --keep-public --explain.

The selected project has 190 modules and 67,906 baseline source lines. The source hashes of all 190 modules match the source profile used for selection (about 756 seconds in summed module durations), which identified the analytic and geometric bottlenecks addressed here. The exact base is 66f6943c594e459c4d2bd2901d66f6f6ab677f8b. The repository's pinned Lean/Mathlib 4.35.0-rc3 is used throughout.

Concrete changes include inverse/conjugation and norm invariance for the complex reflection argument; direct differentiability/composition lemmas for exponential series and eta products; explicit square-root and chord bounds; direct interval/set arguments; and bounded arithmetic and simplifier inputs.

The invariant audit imports the complete project at Lean's private environment level and serializes every kernel declaration's name, declaration kind, universe parameters, fully elaborated expression tree, safety flags, inductive/constructor/recursor metadata, and every non-theorem body. Only expression metadata is omitted; theorem proof bodies may change. It covers public, private, and compiler-generated declarations. All 6,865 pre-existing declarations compare identically on the audited fields, with zero removed. The resulting environment contains 496 additional generated proof helpers. A separate textual audit finds no changed signatures or binder names; all public imports are preserved.

Metric (two-sample mean) Baseline Optimized Reduction
Whole-project elapsed 282.71 s 248.95 s 11.94%
Summed CPU 895.47 s 809.06 s 9.65%
Mean peak compiler RSS 1,710,772.00 KiB 1,697,776.00 KiB 0.76%

Elapsed samples: baseline 272.942 / 292.478 s; optimized 248.353 / 249.555 s.

The whole-project benchmark re-elaborates and kernel-checks every module against imports built from the same revision, using its generated Lake setup and pinned options. Each Lean process uses -j1, with four compiler workers. The order is baseline → optimized → optimized → baseline, with two samples per revision and warm dependency artifacts. Elapsed figures are the complete sweep, CPU figures sum user+system time, and RSS averages each sweep’s largest individual compiler process. These measurements exclude cold dependency fetching and artifact/C emission; hosted CI timing is unmeasured. The VM is shared.

The synchronous command profiler also confirms the following heartbeat reductions (the outer declaration command, in standard heartbeat units):

Declaration Baseline Optimized Reduction
norm_shift_neg_inv_eq 68,249.10 1,033.20 98.5%
eta_logDeriv' 101,971.61 10,136.60 90.1%
tsum_uexp_contDiffOn 123,964.57 25,664.50 79.3%
avoids_chord_i_to_rho 128,348.59 19,932.27 84.5%
avoids_chord_rho'_to_i 107,569.08 20,290.62 81.1%

Validation passed:

  • lake build LeanPool.LeanModularForms.Imports, with no warnings.
  • Full Lean environment manifest comparison, including private/generated declarations and definition bodies.
  • lake exe runLinter --no-build LeanPool.LeanModularForms.Imports and lake exe lint-style LeanPool.LeanModularForms.Imports.
  • Lean Pool's selected-project header, forbidden-code, size, card, public-declaration axiom and all-declaration option/trust audits: 190 modules, zero errors.
  • lake exe mk_all --module --check and git diff --check.
  • Four complete timing sweeps, 190/190 successful module compilations in each.

No merge or auto-merge is requested. Repository CI and independent review remain applicable.

Validated head: c1cabfd5a66380143891085980d5d20ba47f4c56.

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

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 defect was found in the proof changes or private-import removals.

Summary

This PR narrows proof searches across LeanModularForms and removes 45 private imports.

  • Lean proofs use more focused tactic inputs and direct analytic lemma chains.

Reviews (1) · Last reviewed commit: "Optimize LeanModularForms proof elaborat..." · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

✅ No statements changed — all 2,921 tracked declarations across 122 modified files 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: 20,674,479 → 16,314,715 (-4,359,764, -21.1%). Commands: 7,187 → 7,187.

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

Files: 122 compared — 87 cheaper, 0 costlier, 35 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/RectHomotopy/WindingBase.lean +95/-68 703,807 225,246 -478,561 -68.0% 54.07 14.87
LeanPool/LeanModularForms/ValenceFormula/Boundary/Winding/UnitArc.lean +64/-41 490,841 198,193 -292,648 -59.6% 25.84 20.30
LeanPool/LeanModularForms/ValenceFormula/Boundary/Winding/RightEdge.lean +68/-60 633,362 349,479 -283,883 -44.8% 80.31 28.02
LeanPool/LeanModularForms/ValenceFormula/Boundary/Winding/LeftEdge.lean +75/-53 521,077 273,353 -247,724 -47.5% 23.58 37.25
LeanPool/LeanModularForms/GeneralizedResidueTheory/Residue/FlatnessTransfer/CutoffInfrastructure.lean +19/-10 420,211 181,624 -238,587 -56.8% 20.50 24.73
LeanPool/LeanModularForms/ValenceFormula/PVChain/Assembly.lean +40/-54 393,995 166,900 -227,096 -57.6% 17.24 19.98
LeanPool/LeanModularForms/ValenceFormula/PVChain/ResidueSideInfra.lean +37/-30 472,375 309,744 -162,632 -34.4% 19.40 29.79
LeanPool/LeanModularForms/GeneralizedResidueTheory/PVInfrastructure/SingularAnnulus.lean +24/-20 274,411 114,959 -159,451 -58.1% 18.09 17.71
LeanPool/LeanModularForms/ValenceFormula/PVChain/Helpers.lean +17/-16 387,304 237,222 -150,082 -38.8% 11.49 22.76
LeanPool/LeanModularForms/ValenceFormula/WindingWeights/I.lean +115/-75 639,214 494,574 -144,640 -22.6% 67.84 24.98
LeanPool/LeanModularForms/ValenceFormula/WindingWeights/Rho.lean +77/-48 525,249 383,080 -142,169 -27.1% 22.25 34.06
LeanPool/LeanModularForms/ValenceFormula/OnCurvePV/Main.lean +172/-131 365,220 224,413 -140,807 -38.6% 66.28 34.08
LeanPool/LeanModularForms/Modularforms/EtaCleanup.lean +25/-8 305,144 172,420 -132,724 -43.5% 23.79 17.64
LeanPool/LeanModularForms/Modularforms/SummableLems.lean +38/-26 551,219 428,258 -122,960 -22.3% 45.29 67.34
LeanPool/LeanModularForms/ValenceFormula/WindingWeights/RhoPlusOne.lean +97/-54 569,893 464,490 -105,403 -18.5% 49.36 27.86
LeanPool/LeanModularForms/ValenceFormula/PVChain/Assembly/ResidueSide.lean +18/-13 195,592 104,942 -90,650 -46.3% 22.17 6.26
LeanPool/LeanModularForms/ValenceFormula/Boundary/Winding/UnitArcHelpers.lean +59/-46 340,929 253,661 -87,268 -25.6% 42.68 20.25
LeanPool/LeanModularForms/ValenceFormula/TextbookForm.lean +41/-33 398,681 313,685 -84,995 -21.3% 53.92 21.13
LeanPool/LeanModularForms/ValenceFormula/PVChain/ArcContribution.lean +19/-13 323,769 250,982 -72,786 -22.5% 25.11 13.85
LeanPool/LeanModularForms/GeneralizedResidueTheory/WindingNumber/CrossingAnalysis.lean +30/-7 382,280 311,983 -70,296 -18.4% 20.79 32.13
LeanPool/LeanModularForms/SpherePacking/ViazovskaMagicFunction.lean +44/-36 185,343 119,522 -65,821 -35.5% 34.58 18.79
LeanPool/LeanModularForms/ContourIntegral/CrossingLimit.lean +11/-5 83,271 24,250 -59,021 -70.9% 13.09 11.07
LeanPool/LeanModularForms/GeneralizedResidueTheory/GeneralizedResidueTheorem.lean +2/-2 77,608 31,751 -45,858 -59.1% 15.24 4.71
LeanPool/LeanModularForms/ValenceFormula/RectHomotopy/HomotopyDef.lean +14/-11 251,753 215,214 -36,539 -14.5% 16.70 27.87
LeanPool/LeanModularForms/ValenceFormula/RectHomotopy/AngleAnalysis.lean +51/-39 179,515 144,047 -35,468 -19.8% 11.14 21.79
LeanPool/LeanModularForms/GeneralizedResidueTheory/Homotopy/Integrality.lean +10/-6 136,027 100,758 -35,269 -25.9% 9.97 18.25
LeanPool/LeanModularForms/GeneralizedResidueTheory/OnCurvePV/Basic.lean +16/-15 122,362 87,585 -34,777 -28.4% 7.36 13.11
LeanPool/LeanModularForms/GeneralizedResidueTheory/Residue/Flatness.lean +10/-4 62,386 28,291 -34,095 -54.7% 6.45 9.47
LeanPool/LeanModularForms/GeneralizedResidueTheory/Residue/GeneralizedTheoremBase.lean +13/-7 112,573 80,020 -32,553 -28.9% 14.25 7.27
LeanPool/LeanModularForms/HeckeRIngs/GLn/DiagonalCosets.lean +7/-5 678,567 646,546 -32,022 -4.7% 71.72 36.91
LeanPool/LeanModularForms/ValenceFormula/PVChain/OnCurveCapture.lean +24/-20 98,453 67,751 -30,702 -31.2% 27.19 9.99
LeanPool/LeanModularForms/ValenceFormula/RectHomotopy/BoundaryHomotopySmooth.lean +18/-7 180,443 151,945 -28,499 -15.8% 11.55 14.81
LeanPool/LeanModularForms/GeneralizedResidueTheory/CauchyPrimitive.lean +11/-5 99,359 75,864 -23,495 -23.6% 8.09 11.43
LeanPool/LeanModularForms/ValenceFormula/CoreIdentity.lean +21/-17 205,462 183,783 -21,679 -10.6% 14.91 24.63
LeanPool/LeanModularForms/ValenceFormula/RectHomotopy/RadialHomotopy.lean +42/-33 228,395 206,882 -21,513 -9.4% 13.13 21.45
LeanPool/LeanModularForms/ValenceFormula/OnCurvePV/EndpointCorner.lean +25/-17 377,895 358,216 -19,679 -5.2% 24.40 39.01
LeanPool/LeanModularForms/ValenceFormula/RectHomotopy/MainTheoremBound.lean +16/-10 81,338 61,786 -19,551 -24.0% 10.17 5.42
LeanPool/LeanModularForms/GeneralizedResidueTheory/Homotopy/Invariance.lean +1/-1 90,582 71,269 -19,313 -21.3% 12.85 6.78
LeanPool/LeanModularForms/ContourIntegral/PVSplit.lean +14/-12 30,237 12,091 -18,146 -60.0% 11.46 7.21
LeanPool/LeanModularForms/Modularforms/Derivative.lean +20/-14 206,714 188,863 -17,851 -8.6% 35.78 17.75
LeanPool/LeanModularForms/GeneralizedResidueTheory/HomologicalCauchy/DixonProof.lean +37/-33 174,021 157,577 -16,444 -9.4% 13.77 26.90
LeanPool/LeanModularForms/GeneralizedResidueTheory/PVInfrastructure/AnnulusBounds.lean +14/-14 139,204 124,481 -14,723 -10.6% 19.32 10.42
LeanPool/LeanModularForms/GeneralizedResidueTheory/Residue/MultipointPV/DominatedConvergence.lean +10/-10 122,236 107,546 -14,689 -12.0% 16.70 8.86
LeanPool/LeanModularForms/ValenceFormula/Boundary/Smooth.lean +25/-17 202,306 188,368 -13,938 -6.9% 14.74 29.55
LeanPool/LeanModularForms/Modularforms/Generators/Injectivity.lean +14/-3 287,639 273,967 -13,673 -4.8% 32.21 12.84
LeanPool/LeanModularForms/GeneralizedResidueTheory/PVInfrastructure/RemainderAnalysis.lean +5/-5 82,825 70,310 -12,515 -15.1% 8.90 7.19
LeanPool/LeanModularForms/GeneralizedResidueTheory/Residue.lean +17/-11 85,285 74,296 -10,989 -12.9% 12.96 8.89
LeanPool/LeanModularForms/Modularforms/EisensteinAsymptotics.lean +10/-8 91,772 81,181 -10,591 -11.5% 7.99 12.64
LeanPool/LeanModularForms/Modularforms/Eisensteinqexpansions.lean +2/-2 125,379 115,294 -10,085 -8.0% 23.69 12.73
LeanPool/LeanModularForms/GeneralizedResidueTheory/PVInfrastructure/StepBounds.lean +22/-16 171,783 162,294 -9,490 -5.5% 22.76 11.32
… +72 more files, each with a smaller move (≤ 9,363 HB); full table in the run's step summary
Total +2,074/-1,503 20,674,479 16,314,715 -4,359,764 -21.1% 2080.8 1756.6

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

@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_head": "c1cabfd5a66380143891085980d5d20ba47f4c56",
"summary": "This refactor replaces broad proof search with explicit arithmetic and simplifier inputs, reuses direct analytic lemma chains, and removes private imports while retaining the public interfaces. The inverse/conjugation reflection proof and the eta differentiability proofs expose the mathematical argument more directly.",
"assessment": {
"scope": "proof search restriction, analytic lemma reuse and private import pruning",
"introduces_tech_debt": false,
"maintainability": "improved",
"brittleness": "more_robust",
"risk": "low",
"assessment_one_sentence": "The complete 122-file refactor improves maintainability without an actionable new robustness problem."
},
"verdict": "approve",
"findings": [],
"validation": {
"source_review": "All 642 changed hunks reviewed across the team; full base/head Git hashes and boundaries checked. No independent build or reproduction of the author's compiled-manifest/timing audit.",
"advisory_profile": "Comment6303807189 reports all122 files compared:20,674,479 to16,314,715 heartbeats,87 cheaper/0 costlier/35 within noise. Wall-time measurements remain noisy; the report is advisory.",
"own_CI": "Run39511302121/core118932858698 remains pending complete validation.",
"independent_configured_review": "Existing automatic job2241 at this exact head is queued; no duplicate request.",
"integration": "Source assessment is favorable. Configured review, complete current-head CI and every normal protection/native-queue requirement still apply."
}
}

@Vilin97

Vilin97 commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: c1cabfd5a66380143891085980d5d20ba47f4c56

Verdict: ✅ approve

This refactor makes simplifier and arithmetic inputs explicit, replaces expensive analytic searches and coordinate calculations with direct lemma chains, and removes 45 private imports. The substantive rewrites retain explanatory steps and reusable helpers. The supplied /profile reports 21.1% fewer heartbeats, with no files classified as costlier. Independent elaboration was blocked by missing Mathlib dependencies in this checkout.

Aspect Value
Scope proof elaboration optimization and private-import pruning
Introduces tech debt ✅ no
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

Explicit proof dependencies and preserved argument structure improve maintainability without introducing actionable technical debt.


Tokens: 5,305,564 in / 7,586 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $21.3360 (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 Oct 21, 2026
Merged via the queue into main with commit bc5d793 Oct 21, 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