Skip to content

Optimize Chudnovsky proof elaboration and build dependencies - #739

Queued
Vilin97 wants to merge 1 commit into
mainfrom
researcher/daily-optimize-20261103T1115
Queued

Vilin97 wants to merge 1 commit into
mainfrom
researcher/daily-optimize-20261103T1115

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Chudnovsky's modular-function chain waited for the full Ramanujan derivative development to obtain one elementary periodicity lemma. Several proofs also repeated kernel computations or long analytic arguments. This separates that dependency and simplifies the proofs while preserving every original declaration.

The final three-pair series reduced median clean-build wall time 11.33% and median whole-build peak memory 12.17%.

Changes

  • Move the existing periodicity lemma, with its statement, proof and public name unchanged, into Periodicity.lean; publicly re-export it from Ramanujan and replace four unnecessary derivative-module dependencies.
  • Share Bernoulli evaluations in BernoulliValues.lean, reuse the general Clausen theorem for its special case, and use a direct monic cubic witness and determinant identity.
  • Prove the parallelogram boundary theorem with FTC on opposite edges and Fubini. Recorded elaboration heartbeat counts fall about 76.5% for that theorem and 70.7% for the Clausen specialization.
  • Use a kernel-checked finite candidate sieve, targeted linear arithmetic, and coarser internal rational enclosures sufficient for the unchanged 1/2 tolerances. Remove 29 broad private import edges and add narrow dependencies; retain the namespace/instance imports needed to preserve the elaborated environment.
  • Regenerate only the selected project's import aggregate. LeanPool.lean, project metadata, toolchain pins, CI and gates are unchanged.

Declaration invariant

Base: ededf2dc890654488765f9f22dac63af8c047dab.
Head: f22c3485e96799d37643ffc19953442d0ba9c970.

Before editing, Lean environment inspection recorded both private and exported declarations. The audit loads with trust level 0 and extensions disabled, serializes expression DAGs for every type and every non-theorem value, and records universe parameters, declaration kinds, safety, reducibility and generated declaration metadata. The final comparison preserves all 2,306 original declarations, including 959 exported declarations, with identical types and non-theorem values. Nine supporting declarations are added; none is removed.

The one investigated metadata difference is the physical module of periodic_comp_ofComplex_of_vadd. Its source statement and proof are byte-identical and Ramanujan re-exports the same name. All other inspected fields are identical. A separate textual audit preserves all 1,173 original source signatures. Original private support declarations and generated auxiliaries are deliberately retained.

A transitive trust audit covers all 2,315 current declarations and 72,769 dependencies: the only axioms are Classical.choice, propext, and Quot.sound.

Controlled measurements

Separate base and candidate worktrees; delete only their own .lake/build before each run; reuse the same warm pinned dependency artifacts. Each native build uses LEAN_NUM_THREADS=4, CPU affinity 0–3, and /usr/bin/time. Whole-build memory is the transient cgroup's kernel memory.peak, captured while the cgroup is still alive. Three alternating base/candidate pairs were specified before observing results.

Pair Base wall (s) Candidate wall (s) Base peak (MiB) Candidate peak (MiB)
1 158.14 142.10 2309.32 2025.09
2 135.90 119.41 2334.58 2028.29
3 120.59 120.50 2137.33 2309.96
Median 135.90 120.50 2309.32 2028.29

Median CPU time: 279.03 → 270.55 s (3.04% lower). Median maximum single-compiler RSS: 1,962,496 → 1,954,708 KiB (0.40% lower). The memory target is met by the whole build's measured peak.

The VM is shared: the third pair is nearly flat on wall time and increases peak memory. These are observed medians, not a claim of a uniform speedup. The only post-measurement source change corrects the new Bernoulli file's attribution; normalized Lean code is identical.

Validation

  • lake --wfail build LeanPool.Chudnovsky.Imports
  • lake env lean --run scripts/ci/lint-project.lean with all 34 selected-project modules
  • lake exe lint-style LeanPool.Chudnovsky
  • lake exe mk_all --module --check
  • lake shake --force --keep-public LeanPool.Chudnovsky.Imports
  • Standard repository static quality checks, selected-project axiom and option/environment audits, and project-card declaration checks
  • Private/exported declaration manifests, textual signature comparison, and transitive axiom audit

All pass, with warning-free native builds. This uses current main's checked-in Lean/Mathlib v4.35.0-rc3 pins unchanged. Full-pool validation remains for CI; shake's --force avoids its unrelated whole-pool artifact sanity check. Audit scripts, manifests, source checkpoints and every timing sample are retained on the VM in /data/codex/scratch/researcher/optimization-20261103T1115/evidence.

This PR is open for protected CI and review. Auto-merge is disabled.

@greptile-apps

greptile-apps Bot commented Nov 3, 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 reviewed changes; external provenance and reported measurements remain independently unverified.

Summary

Separates elementary periodicity from the Ramanujan development, shares Bernoulli evaluations, and shortens several proofs without changing their stated results.

  • The parallelogram boundary proof uses opposite edges to cancel its integrals.
  • Chudnovsky modules get the periodicity result without importing derivative theory.
  • The Clausen specialization uses the general formula for its fixed parameters.
  • Several proofs reuse shared values for Bernoulli numbers four and six.
  • Coefficient bounds use shorter rational enclosures and keep their one-half tolerances.
  • The bounded three-prime test uses a finite sieve to identify its sole candidate.
  • Division-value proofs use direct polynomial witnesses and derivative rules.
  • Small arithmetic proofs use direct identities and narrower linear steps.

Reviews (1) · Last reviewed commit: "Optimize Chudnovsky proof elaboration an..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

lake build wall time (changed modules): 13.56 s (= 0.23 min) — user 4.08 s, sys 3.33 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 745 tracked declarations across 16 modified files kept their type; only proofs / definition bodies changed.

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

➕ Declarations added (5)
  • PeriodPair.continuous_edge — LeanPool/Chudnovsky/Liouville.lean
  • PeriodPair.integral_unitSquare_swap — LeanPool/Chudnovsky/Liouville.lean
  • Chudnovsky.QF.three_prime_bound — LeanPool/Chudnovsky/SingularModuli/FormReduction.lean
  • Chudnovsky.QF.three_prime_candidates — LeanPool/Chudnovsky/SingularModuli/FormReduction.lean
  • Chudnovsky.QF.three_prime_decidable — LeanPool/Chudnovsky/SingularModuli/FormReduction.lean
➖ Declarations removed (1)
  • Chudnovsky.periodic_comp_ofComplex_of_vadd — LeanPool/Chudnovsky/Ramanujan.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: 1,939,195 → 1,868,079 (-71,116, -3.7%). Commands: 787 → 796.

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

Files: 8 compared — 3 cheaper, 1 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/Liouville.lean +107/-201 386,269 337,747 -48,523 -12.6% 44.90 44.07
LeanPool/Chudnovsky/DivisionValues.lean +20/-35 722,250 701,567 -20,683 -2.9% 100.63 110.98
LeanPool/Chudnovsky/Clausen.lean +9/-57 313,099 305,923 -7,176 -2.3% 49.35 58.79
LeanPool/Chudnovsky/SingularModuli/FormReduction.lean +22/-1 129,171 133,048 +3,877 +3.0% 18.85 24.53
LeanPool/Chudnovsky/Coefficients.lean +80/-70 184,347 185,833 +1,486 +0.8% 35.35 35.19
LeanPool/Chudnovsky/SigmaZeta.lean +0/-6 160,751 160,665 -86 -0.1% 20.14 26.52
LeanPool/Chudnovsky/WeierstrassMore.lean +0/-6 42,722 42,714 -8 -0.0% 13.92 10.22
LeanPool/Chudnovsky/PicardFuchs.lean +1/-6 586 582 -4 -0.6% 3.15 2.83
Total +239/-382 1,939,195 1,868,079 -71,116 -3.7% 286.3 313.1

New files — absolute profile

Total heartbeats: 6,982 maxHeartbeats units across 2 valid files (97 added LOC).

Sum of lean --profile: 3411.2 ms (= 3.41 s) across 2 valid files. Import-excluded time: 417.2 ms (= 0.42 s).

Count-heartbeats wall-clock total: 3.53 s. Repeated import cost inside lean --profile: 2994.0 ms (= 2.99 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/BernoulliValues.lean 39 4,977 1.81 2.33 0.23 2.10 9 0
LeanPool/Chudnovsky/Periodicity.lean 38 2,006 1.72 1.08 0.19 0.89 8 0
LeanPool/Chudnovsky/Estimates.lean 6 — — — — — 0 1
LeanPool/Chudnovsky/Fourier.lean 2 — — — — — 0 1
LeanPool/Chudnovsky/Imports.lean 2 — — — — — 0 1
LeanPool/Chudnovsky/Ramanujan.lean 1 — — — — — 0 1
LeanPool/Chudnovsky/SingularModuli/JFunction.lean 6 — — — — — 0 1
LeanPool/Chudnovsky/SingularModuli/Kronecker.lean 1 — — — — — 0 1
LeanPool/Chudnovsky/SingularModuli/ModularPolynomialQ.lean 1 — — — — — 0 1
LeanPool/Chudnovsky/SingularModuli/ModularPolynomialZ.lean 1 — — — — — 0 1
Total 97 6,982 3.53 3.41 0.42 2.99 17 8

Aggregate phase totals

Phase Time
import 2994.0 ms (= 2.99 s)
interpretation 268.0 ms (= 0.27 s)
initialization 52.5 ms (= 0.05 s)
norm_num 20.4 ms (= 0.02 s)
typeclass inference 18.3 ms (= 0.02 s)
tactic execution 14.1 ms (= 0.01 s)
type checking 9.5 ms (= 0.01 s)
tacticAnalysis 9.2 ms (= 0.01 s)
simp 8.2 ms (= 0.01 s)
elaboration 5.9 ms (= 0.01 s)
linting 2.9 ms (= 0.00 s)
overlappingInstancesLinter 2.2 ms (= 0.00 s)

Slowest changed modules (from lake build)

Changed module Lake time
LeanPool.Chudnovsky.BernoulliValues 3.20 s
LeanPool.Chudnovsky.Periodicity 3.10 s
Per-file `lean --profile` output

LeanPool/Chudnovsky/BernoulliValues.lean

import took 2.1s
cumulative profiling times:
	attribute application 0.0181ms
	congr simp thm 0.249ms
	elaboration 2.9ms
	fix level params 0.134ms
	import 2.1s
	initialization 23.8ms
	instantiate metavars 0.0786ms
	interpretation 143ms
	let-to-have transformation 0.0261ms
	linting 1.34ms
	module linting 0.00147ms
	norm_num 20.4ms
	overlappingInstancesLinter 1.15ms
	parsing 1.06ms
	process pre-definitions 1.14ms
	share common exprs 0.999ms
	tactic execution 8.97ms
	tacticAnalysis 5.05ms
	type checking 8.51ms
	typeclass inference 11.8ms
real 2.85
user 0.84
sys 0.85

LeanPool/Chudnovsky/Periodicity.lean

import took 894ms
cumulative profiling times:
	attribute application 0.0129ms
	congr simp thm 0.324ms
	elaboration 3.02ms
	fix level params 0.0295ms
	import 894ms
	initialization 28.7ms
	instantiate metavars 0.0805ms
	interpretation 125ms
	let-to-have transformation 0.0176ms
	linting 1.6ms
	module linting 0.00156ms
	overlappingInstancesLinter 1.05ms
	parsing 1.05ms
	process pre-definitions 0.465ms
	share common exprs 0.251ms
	simp 8.18ms
	tactic execution 5.11ms
	tacticAnalysis 4.17ms
	type checking 0.979ms
	typeclass inference 6.5ms
real 1.62
user 0.82
sys 0.75

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

@Vilin97

Vilin97 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@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": "Reviewed the complete 18-file refactor at f22c348 against main ededf2d. Moving the unchanged periodicity lemma behind Ramanujan's public re-export removes an unnecessary derivative dependency; shared Bernoulli values, the general Clausen formula, explicit cubic witnesses and the named FTC/Fubini argument make the proofs easier to maintain. The rational rounding changes local enclosures while preserving the original hypotheses and one-half conclusions. The public profile covers eight modified-file comparisons and has eight measurement errors; it does not establish the claimed whole-project timing, memory or compiled-declaration invariant. The complete six-parent authored CI has been independently qualified. The requested configured review and native integration validation remain separate pending gates.",
"assessment": {
"scope": "proof and dependency refactor",
"introduces_tech_debt": false,
"maintainability": "improved",
"brittleness": "more_robust",
"risk": "medium",
"assessment_one_sentence": "The complete source refactor is acceptable, with explicit mathematical structure and existing public entry points preserved; the configured verdict and protected native integration remain pending."
},
"verdict": "approve",
"findings": []
}

@Vilin97

Vilin97 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: f22c3485e96799d37643ffc19953442d0ba9c970

Verdict: 🛑 request_changes

This separates shared periodicity and Bernoulli facts, narrows dependencies, and replaces duplicated analytic work with explicit theorem applications and FTC/Fubini arguments. The active proofs become clearer, but the boundary rewrite leaves an unused private helper layer. Local module validation was blocked by missing Mathlib artifacts; an isolated sieve check passed.

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

The main rewrites improve clarity and robustness, but remove the newly orphaned private integral helpers before merging.

Findings (1)

  • dead-leftover — LeanPool/Chudnovsky/Liouville.lean:951
    The rewrite removes the only consumers of double_integral_diff_apply, double_integral_conj_apply, integrableOn_diff_apply, and intervalIntegral_conj_comp. Those four lemmas and their intervalIntegral_conj helper now form an unused private block at lines 840–927. This retains roughly 90 lines of analytic proof code that still require elaboration and maintenance on Mathlib upgrades. Remove the obsolete helper block alongside this rewrite.

Tokens: 1,630,227 in / 9,231 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $6.6594 (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.
request_changes is an ask, not a close: of the reviewer's past request_changes verdicts, 39% were merged after a human looked. Read the findings before acting on the verdict.

@Vilin97

Vilin97 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer disposition for f22c3485e96799d37643ffc19953442d0ba9c970: retain the existing private integral-helper block.

The finding in configured review 2301 is factually correct: double_integral_diff_apply, double_integral_conj_apply, integrableOn_diff_apply, and intervalIntegral_conj_comp have no active proof callers; intervalIntegral_conj is used only within that block. The 89 lines are byte-identical to main. They were deliberately retained to satisfy this refactor’s stated preservation of original private and exported declarations, and both independent complete-source reviews explicitly considered that cost.

I accept this bounded retention as a source-quality tradeoff for this PR. The configured verdict remains recorded as request_changes; its sole finding is addressed by this explicit maintainer disposition, rather than being represented as an automated approval. No declaration removal or artificial caller is required.

The complete 18-file source review and proper six-parent authored CI (18 jobs, 72 steps, own canonical check) are qualified at this head. The public profile has eight valid modified-file comparisons and eight failed measurements; it does not establish whole-project timing, memory, or compiled-manifest claims.

Source acceptance therefore stands. Any native queue admission still requires fresh exact-head, current-main, owner, check, and protection guards; the actual cumulative merge-group must pass normal validation. The owner’s NOAUTO instruction remains in force.

@Vilin97
Vilin97 added this pull request to the merge queue Nov 3, 2026
Any commits made after this event will not be merged.

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.

1 participant