Skip to content

Reduce Chudnovsky proof elaboration cost - #811

Merged
Vilin97 merged 3 commits into
mainfrom
codex/optimize-project-20261113T1308
Nov 13, 2026
Merged

Vilin97 merged 3 commits into
mainfrom
codex/optimize-project-20261113T1308

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Chudnovsky repeatedly normalizes large arithmetic expressions and carries real interval certificates in its final modular-form module. This separates the certificates and restructures the convergence, Wronskian and main-theorem proofs while preserving every existing elaborated declaration.

Six-hour daily optimization cycle completed. The whole-project 10% wall-time/RAM target was not established. The primary clean-commit experiment shows 7.01% lower mean wall time, 3.25% lower mean CPU time and essentially unchanged RSS; the source-declaration profile uses 4.71% fewer allocation-counter ticks. Shared-VM timing variation limits precision.

Changes

  • Cancel the old Pochhammer/factorial factors before taking norms in generalizedHypergeometricSeries_radius_eq_one. Reuse one linear-ratio limit argument and avoid redundant norm simplification and nonvanishing obligations.
  • Prove Wronskian vanishing directly from the unweighted squared modulus and its zero limit, removing the exponential-weight argument.
  • Apply the main theorem's differential identity after multiplication by the square, avoiding an intermediate quotient. Use the existing norm bound to prove the branch denominator is nonzero.
  • Prove the real interval certificates in independent NumericalBounds, with smaller rounded factor enclosures for the scaled s₂ estimate. Keep both original private declarations as exact-type wrappers. Narrow the new module's imports with lake shake.
  • Replace suitable algebraic normalization, broad simplification, nonlinear arithmetic, casts and continuity automation with direct lemmas or explicit inputs. Restore edits that fail the strict invariant or have negligible measured benefit/regressions.

Invariant audit

Base: 701389c04bdd56aabf8dbb9ad729165fdba772b5. Head: 5127d9273c98e54df93f8bbd96586e039c5dc293.

A Lean environment exporter was run on the base before editing and again on the complete compiled candidate. It imports all owned modules at private visibility with extensions disabled, records every owned constant including private/generated declarations, and compares exact structural expression DAGs. The comparison includes fully elaborated types, universe/binder parameters, declaration kind, safety, reducibility and inductive/recursor metadata, plus complete values for every non-theorem. Only theorem proof bodies and expression metadata are omitted.

All 2,316 original declarations are unchanged: zero missing, zero changed. This includes 2,121 theorems and 195 non-theorem declarations. The additions are two supporting theorems and 50 generated proof helpers, all theorems. Every difference found during development was investigated and the owning edits were restored where needed, including generated-helper type differences.

An independent source audit preserves all theorem signatures and non-proof commands in the 34 original files, including 157 immutable non-theorem source blocks. Existing public imports, names, definitions, instances, notation and namespaces are preserved. The generated project aggregate gains NumericalBounds; the pool discovery root stays fixed.

Manifest SHA-256: base 294d1dd1ea288b2252ba6161d26fae3950a2ce1e648c65bb85937bb901c191c5; head 1b79118b9f6f6d47be9379b4b7241e6071b3ed97197a5e0872c5b69a0520537d.

Controlled resource measurements

Each run deletes only Chudnovsky's compiled library/IR outputs and rebuilds its entire target: 34 modules at base, 35 at head. Pinned dependencies and the compiler-linter plugin remain warm. The primary experiment switches between clean exact-commit checkouts in the same isolated worktree, checking clean Git status and source/configuration fingerprints. The original branch is restored afterwards. The fixed command is:

taskset -c 8-11 env LEAN_NUM_THREADS=4 lake build LeanPool.Chudnovsky.Imports

No other Lean build/profile from this task overlaps either series. GNU time supplies wall/CPU time and largest-process RSS; a 0.1-second process-tree sampler supplies aggregate RSS, which includes shared mappings. The primary experiment uses all runs from two predeclared base/head/head/base blocks (four runs per revision).

Run Revision Wall s CPU s Largest-process RSS KiB Sampled aggregate RSS KiB
1 base 210.73 297.10 1,977,728 8,011,080
2 head 187.02 285.52 1,977,248 7,950,916
3 head 170.52 277.83 1,969,328 8,125,784
4 base 187.14 289.47 1,980,228 8,056,012
5 base 179.58 288.83 1,975,148 7,798,216
6 head 177.98 281.11 1,983,900 7,956,180
7 head 136.02 262.92 1,969,884 7,804,296
8 base 144.70 269.20 1,974,340 7,989,896
Metric, arithmetic mean Base Head Reduction
Wall seconds 180.537 167.885 7.01%
CPU seconds 286.150 276.845 3.25%
Largest-process RSS KiB 1,976,861.000 1,975,090.000 0.09%
Sampled aggregate RSS KiB 7,963,801.000 7,959,294.000 0.06%

Wall-time ranges: base: 144.70–210.73 s; head: 136.02–187.02 s. Wall-time medians: base: 183.360 s; head: 174.250 s. The balanced blocks give 10.14%, 3.17% wall-time reductions. These are observed measurements on a shared VM; they do not establish an exclusive-machine performance guarantee.

Earlier 12-run source-swap observations at 5127d92

These used identical source/configuration fingerprints but left the base tree dirty relative to the candidate commit. This possible bookkeeping confound is why the clean-commit series above is primary. All earlier observations are preserved.

Run Revision Wall s CPU s Largest-process RSS KiB Sampled aggregate RSS KiB
1 base 191.29 303.68 1,973,652 8,203,232
2 head 183.48 290.39 1,968,100 7,843,140
3 head 195.73 296.14 1,962,784 7,850,256
4 base 268.17 328.75 1,966,304 7,913,080
5 base 194.93 295.14 1,980,080 7,899,108
6 head 244.31 314.49 1,973,100 7,835,964
7 head 194.07 308.42 1,966,568 7,889,452
8 base 222.23 300.65 1,975,208 8,184,964
9 base 214.42 302.47 1,966,588 8,091,100
10 head 183.00 288.11 1,970,108 8,126,020
11 head 209.52 311.57 1,967,756 7,812,648
12 base 156.74 271.65 1,975,476 8,021,032

Declaration profile

A separate synchronous command profile on the exact head totals 2,940,080,919 → 2,801,664,669 raw allocation-counter ticks (4.71% fewer). It covers 1,179 original source declarations and the two new certificate theorems, taking the maximum per declaration to avoid double-counting elaboration wrappers. This diagnostic is separate from whole-project wall time and RAM.

  • generalizedHypergeometricSeries_radius_eq_one: 33,540,478 → 17,128,879 ticks (48.93% fewer).
  • Chudnovsky.WrC_eq_zero: 23,856,685 → 18,720,139 ticks (21.53% fewer).
  • Chudnovsky.thm42: 23,407,679 → 15,019,787 ticks (35.83% fewer).

The hosted advisory profile reports 5.0% fewer heartbeats across 25 compared files, but its merge-base environment cannot find the new NumericalBounds.olean when profiling Coefficients and Imports. Those two advisory measurements fail; the actual head build and the local profile of all 35 modules succeed. The hosted partial result is not used as the whole-project resource measurement.

Validation

  • Fresh warning-free project builds using the repository's pinned Lean/Mathlib 4.35.0, plus exact declaration and source-contract comparisons.
  • lake env lean --run scripts/ci/lint-project.lean <all 35 owned modules>: 2,367 declarations pass Mathlib linters.
  • lake exe lint-style LeanPool.Chudnovsky.Imports and git diff --check.
  • Repository quality/trust helpers scoped to every owned module/card: headers, size limits, reachability, metadata, allowed axioms, option/axiom backdoors and main declarations.
  • lake exe mk_all --module --check --repo <selected-project fixture> plus exact aggregate and canonical-root checks.
  • lake shake --force --keep-public --explain LeanPool.Chudnovsky.Imports: no remaining suggestions. Here --force skips the whole-package stale-olean preflight for unrelated projects; the selected project is fully built before analysis.

Applicable hosted validation on this exact head also passed: project build, index, Mathlib lint, style, repository quality, Python, workflow/separation/port/exposition checks, Documentation preflight and proof profiling. Lean validation run. Local validation covers all 35 owned modules; a cold full-pool build was not run locally. No repository gates, settings, waivers, unrelated projects or project statements/definitions are changed.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

lake build wall time (changed modules): 21.31 s (= 0.36 min) — user 5.26 s, sys 2.47 s.

This build covers the added modules and their dependency cones on top of the measurement environment; modified files are measured without rebuilding the pool.

Statement changes

✅ No statements changed — all 1,114 tracked declarations across 27 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: 4,483,540 → 4,259,498 (-224,042, -5.0%). Commands: 2,388 → 2,388.

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

Files: 25 compared — 21 cheaper, 0 costlier, 4 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/Chudnovsky/Clausen.lean +52/-68 305,214 265,922 -39,292 -12.9% 46.25 28.11
LeanPool/Chudnovsky/ComplexMult.lean +22/-18 309,080 276,091 -32,989 -10.7% 31.12 18.99
LeanPool/Chudnovsky/SingularModuli/ModularPolynomialZ.lean +27/-18 155,915 136,513 -19,402 -12.4% 20.27 11.61
LeanPool/Chudnovsky/Kummer.lean +50/-70 245,487 227,619 -17,868 -7.3% 24.65 15.39
LeanPool/Chudnovsky/Estimates.lean +19/-19 386,548 368,979 -17,569 -4.5% 49.48 33.76
LeanPool/Chudnovsky/MainTheorem.lean +31/-39 183,771 171,069 -12,702 -6.9% 26.64 15.69
LeanPool/Chudnovsky/DivisionValues.lean +65/-60 701,429 689,300 -12,129 -1.7% 90.99 58.76
LeanPool/Chudnovsky/SigmaZeta.lean +32/-27 160,580 149,267 -11,314 -7.0% 21.60 13.63
LeanPool/Chudnovsky/Fourier.lean +30/-25 161,450 151,251 -10,199 -6.3% 18.92 11.65
LeanPool/Chudnovsky/SingularModuli/Kronecker.lean +29/-24 77,696 69,330 -8,366 -10.8% 10.78 6.87
LeanPool/Chudnovsky/SingularModuli/FormReduction.lean +5/-5 134,461 126,878 -7,583 -5.6% 20.65 11.98
LeanPool/Chudnovsky/Ramanujan.lean +18/-16 191,110 185,021 -6,089 -3.2% 20.81 14.99
LeanPool/Chudnovsky/SingularModuli/MasserA1.lean +8/-8 219,216 213,238 -5,978 -2.7% 23.55 15.55
LeanPool/Chudnovsky/SingularModuli/CosetOrbit.lean +8/-5 175,673 170,703 -4,970 -2.8% 19.92 9.51
LeanPool/Chudnovsky/SingularModuli/ModularPolynomialQ.lean +17/-12 253,018 249,152 -3,866 -1.5% 29.57 17.52
LeanPool/Chudnovsky/WeierstrassMore.lean +20/-14 42,709 40,060 -2,650 -6.2% 10.07 5.45
LeanPool/Chudnovsky/SingularModuli/JFunction.lean +19/-17 103,633 101,000 -2,633 -2.5% 13.40 10.66
LeanPool/Chudnovsky/Liouville.lean +10/-8 338,546 336,749 -1,797 -0.5% 32.91 21.33
LeanPool/Chudnovsky/SingularModuli/Rationality.lean +4/-4 112,914 111,267 -1,647 -1.5% 12.37 10.48
LeanPool/Chudnovsky/SingularModuli/QuadraticPoints.lean +1/-1 31,029 29,419 -1,610 -5.2% 6.17 4.24
LeanPool/Chudnovsky/Quasiperiods.lean +11/-9 75,490 74,276 -1,214 -1.6% 9.32 8.39
LeanPool/Chudnovsky/SingularModuli/Valence.lean +24/-24 95,565 94,429 -1,136 -1.2% 15.28 10.77
LeanPool/Chudnovsky/BernoulliValues.lean +3/-3 4,974 4,397 -577 -11.6% 6.66 3.54
LeanPool/Chudnovsky/Periodicity.lean +3/-3 2,020 1,625 -395 -19.6% 3.09 2.01
LeanPool/Chudnovsky/Basic.lean +4/-4 16,011 15,945 -66 -0.4% 8.12 4.45
Total +512/-501 4,483,540 4,259,498 -224,042 -5.0% 572.6 365.3

New files — absolute profile

Total heartbeats: 46,743 maxHeartbeats units across 1 valid file (175 added LOC).

Sum of lean --profile: 3146.9 ms (= 3.15 s) across 1 valid file. Import-excluded time: 2202.9 ms (= 2.20 s).

Count-heartbeats wall-clock total: 5.35 s. Repeated import cost inside lean --profile: 944.0 ms (= 0.94 s).

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/Chudnovsky/NumericalBounds.lean 171 46,743 5.35 3.15 2.20 0.94 7 0
LeanPool/Chudnovsky/Coefficients.lean 3 — — — — — 0 1
LeanPool/Chudnovsky/Imports.lean 1 — — — — — 0 1
Total 175 46,743 5.35 3.15 2.20 0.94 7 2

Aggregate phase totals

Phase Time
import 944.0 ms (= 0.94 s)
tactic execution 365.0 ms (= 0.36 s)
interpretation 351.0 ms (= 0.35 s)
typeclass inference 254.0 ms (= 0.25 s)
norm_num 248.0 ms (= 0.25 s)
share common exprs 204.0 ms (= 0.20 s)
type checking 203.0 ms (= 0.20 s)
ring 195.0 ms (= 0.20 s)
linting 134.0 ms (= 0.13 s)
elaboration 103.0 ms (= 0.10 s)
process pre-definitions 82.6 ms (= 0.08 s)
initialization 25.2 ms (= 0.03 s)

Slowest changed modules (from lake build)

Changed module Lake time
LeanPool.Chudnovsky.NumericalBounds 3.60 s
Per-file `lean --profile` output

LeanPool/Chudnovsky/NumericalBounds.lean

import took 944ms
share common exprs took 177ms
type checking took 141ms
linting took 113ms
cumulative profiling times:
	attribute application 0.0319ms
	congr simp thm 0.481ms
	declTypeLinter 1.87ms
	dsimp 1.52ms
	elaboration 103ms
	fix level params 4.45ms
	import 944ms
	initialization 25.2ms
	instantiate metavars 18.3ms
	interpretation 351ms
	let-to-have transformation 0.0594ms
	linting 134ms
	module linting 0.00826ms
	norm_num 248ms
	parsing 5.59ms
	process pre-definitions 82.6ms
	ring 195ms
	share common exprs 204ms
	simp 4.15ms
	tactic execution 365ms
	tacticAnalysis 1.66ms
	type checking 203ms
	typeclass inference 254ms
real 2.94
user 2.69
sys 0.78

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

@Vilin97

Vilin97 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: 5127d9273c98e54df93f8bbd96586e039c5dc293

Verdict: ✅ approve

This extracts the interval certificates, simplifies the convergence and Wronskian arguments, and applies the main differential identity more directly. Named intermediate steps remain, while explicit simplification inputs reduce dependence on ambient automation. The hosted profile reports lower cost across 25 compared modules; independent rational certificate checks passed, but local Lean validation was blocked by missing Mathlib dependencies. The remaining maintenance issue is stale documentation describing the removed Wronskian weight.

Aspect Value
Scope proof optimization and certificate module split
Introduces tech debt 🛑 yes
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

The proofs are simpler and more explicit overall, with minor documentation debt that does not warrant blocking the refactor.

Findings (1)

  • dead-leftover — LeanPool/Chudnovsky/Kummer.lean:738
    The section roadmap at lines 220–223 and the lemma description at lines 685–687 still describe the exponentially weighted modulus. This proof now establishes monotonicity and the zero limit directly for the squared modulus. Update both descriptions so readers can follow the roadmap without looking for the removed exponential-weight argument.

Tokens: 2,415,961 in / 9,606 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $9.8079 (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 changed the title WIP: Reduce Chudnovsky proof elaboration cost Reduce Chudnovsky proof elaboration cost Nov 13, 2026
@Vilin97
Vilin97 marked this pull request as ready for review November 13, 2026 19:01
@greptile-apps

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

[Low impact] No blocking code issue was found in the proof refactor or the new certificate module.

Summary

The PR reduces repeated proof work in the Chudnovsky development without changing the existing source-level mathematical contracts.

  • The hypergeometric coefficient proof reaches the same unit-radius result with less repeated arithmetic.
  • The Wronskian proof follows its squared modulus directly along vertical lines.
  • The differential-identity proof multiplies by the hypergeometric square directly.
  • The real interval certificates have their own lightweight module.
  • Proof scripts across the Chudnovsky modules use more explicit simplification steps.

Vilin97 explicitly retains the private wrappers to preserve the exact declaration contract. Removing them would conflict with that stated goal. Vilin97 also explicitly states that the whole-project 10% improvement target was not established and distinguishes the observed timings from a performance guarantee.

Reviews (1) · Last reviewed commit: "Narrow numerical certificate imports wit..." · 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.

{
"summary": "This refactor isolates two real interval certificates and simplifies the hypergeometric-radius, Wronskian and final differential-identity arguments while retaining their intermediate mathematical reasoning. The remaining edits mainly make simplification and arithmetic inputs explicit. The existing written interfaces and computational definitions are preserved; the change improves maintainability without adding material technical debt.",
"assessment": {
"scope": "proof optimization and numerical-certificate module split",
"introduces_tech_debt": false,
"maintainability": "improved",
"brittleness": "more_robust",
"risk": "low",
"assessment_one_sentence": "The refactor keeps the mathematical contracts and readable proof structure while reducing repeated elaboration and separating elementary certificates from the analytic development."
},
"verdict": "approve",
"findings": [],
"reviewed_commit": "5127d9273c98e54df93f8bbd96586e039c5dc293",
"evidence": {
"source": "Compared complete current35/Main34 Lean modules and unchanged project card; all1184 retained written declaration headers and157 nonproof blocks are literal. The203 retained proof-body edits and two new certificate theorems were reconciled. Substantive analytic arguments, actual providers/callers and15 exact rational certificate margins were independently checked.",
"hosted_validation": "Exact-head Lean Action CI run43474513212 passed. All28 changed files compiled freshly;32 total fresh module compilations had maximum24 seconds. Lint checked35 modules/2367 declarations; style, quality and all applicable required contexts passed.",
"limits": "Written-source preservation is not a claim to reproduce the author's private compiled inventory or performance experiments. The reported timing-table arithmetic checks out, but shared-host measurements do not establish a universal speedup. The advisory profile's partial failures and voluntary10percent target do not block this source assessment.",
"integration": "The configured report currently visible covers fcba3dc, so a fresh configured assessment at5127d927 is still needed before protected queue admission."
}
}

@Vilin97

Vilin97 commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@Vilin97
Vilin97 added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit 2a4b27a Nov 13, 2026
38 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