Skip to content

Optimize ClassificationOfSurfaces elaboration and imports - #692

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

Vilin97 merged 1 commit into
mainfrom
codex/optimize-20261020

Conversation

@Vilin97

@Vilin97 Vilin97 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

ClassificationOfSurfaces repeatedly unfolds barycentric maps and their certificates where coordinate formulas suffice. This refactor uses projection lemmas, shared affine identities and direct proofs, and removes 246 unused private imports across the existing project’s 134 modules (143,564 source lines at the base). Profiling identified adaptive affine proofs costing 172,244 and 99,555 heartbeats as concrete starting points.

  • Reuse affine-combination injectivity between the adaptive and marked fans; the two existing generic lemmas retain their names and source signatures in the shared IntrinsicComplex dependency.
  • Add coordinate weighted-sum identities and use them for affine evaluation, avoiding repeated expansion of realization certificates.
  • Factor restriction-coordinate equality into one generic helper used by four existing chart lemmas. Remove one redundant finite-enumeration instance and one redundant change, and constrain a reflexivity application.
  • Reuse affine line-map evaluation, cancel nonnegative sums and nonzero products directly, factor the midpoint bracketing argument, and reuse thin-kite endpoint witnesses. Give selected arithmetic calls their required scalar facts.
  • Replace two broad propositional searches with direct disjunction constructions, 60 unnecessary simplifier calls with direct terms, and duplicate chosen path lifts with covering-map uniqueness.
  • Retain every public import and protect the API facade with shake: keep-all. The aggregate transitive module closure remains 4,672 modules; the import cleanup removes redundant edges.

Base: 2aaa7220788257635be774b855528c4f0be6f3bd. Optimized head: eaaddb0e9c4f72c30250eb58d8f1aa0ea573f0e9. Only 86 existing ClassificationOfSurfaces Lean files change (361 insertions, 605 deletions). Before committing, refreshed origin/main was 15542c175fbeeb83666dc46fc20c4f18f0783e12; the selected project, its card, contribution/review rules and dependency pins are unchanged since the measured base. The branch retains its validated base without a rebase. The pinned Lean 4.35.0-rc3, Mathlib, project card, generated aggregate, and pool index are unchanged.

The pre-edit Lean environment manifest covers 16,961 existing declarations, including private and generated declarations. It serializes constructor-level expression DAGs, universe parameters, declaration kinds, safety and reducibility/constructor metadata, non-theorem values, and export visibility. Only theorem proof values are omitted. The comparison preserves every existing kernel type, non-theorem value and public name; no declarations or exports disappear. There are 14 supporting additions: six source lemmas and eight generated equation/simplification lemmas.

Of the original records, 16,953 are byte-identical. Every other raw difference was investigated: two anonymous instance binder labels reflect the verbatim relocation of the generic lemmas; four diagnostic source-position records map through unchanged source spans (−49 bytes in FiniteCyclicWordReduction, −191 in FiniteCyclicWordReductionCore); two internal bound-variable hygiene counters change when arithmetic proofs elaborate differently. These differences affect neither kernel expressions modulo bound-variable names and diagnostic metadata nor any universe parameter, expression child/flag, declaration metadata or definition value. An independent source audit preserves all 7,758 existing source signatures and source binder names. Original-module visibility was also checked for the two moved lemmas and three lazily generated helpers whose owning module changed.

Manifest SHA256:

  • Base: d0f91e53f4f0f2ebaf3b3affa555e7abc2aca187ec8c20ee51beaf98311ce10b
  • Optimized: 0268891cd1db53609881f31b8bedb2cb225899c64dddd17f8e5d0914bbcee052

Final frozen-source measurements, clean builds in base → optimized → optimized → base order, with LEAN_NUM_THREADS=2:

Run Wall seconds User CPU seconds Peak compiler RSS (KiB)
1: base 434.93 918.71 1,831,944
2: optimized 387.25 838.02 1,761,648
3: optimized 402.69 839.62 1,776,048
4: base 458.38 939.42 1,827,580

Mean wall time: 446.655 → 394.970 seconds (11.57% lower). Mean user CPU: 929.065 → 838.820 seconds (9.71% lower). Maximum compiler RSS across each pair: 1,831,944 → 1,776,048 KiB (3.05% lower). All four builds passed and compiled all 134 modules. This final sequence meets the 10% wall-time target on this VM. The six-hour optimization window also elapsed before final validation.

These are observations on a shared 16-core VM, not a guarantee of the same speedup elsewhere. An earlier checkpoint measured 4.5% wall improvement with two compiler threads and 5.4% with the normal 16-thread setting; final-source performance at 16 threads was not remeasured. Scheduling noise remains a limitation.

For each clean measurement, only that isolated worktree’s .lake/build is deleted; both worktrees retain identical pinned prebuilt dependencies. The command is /usr/bin/time -v lake --wfail build LeanPool.ClassificationOfSurfaces.Imports, with LEAN_NUM_THREADS fixed to the table’s setting. No other Lean compiler jobs from this cycle run during a timing sequence. Peak RSS is GNU time’s maximum child-process RSS, not aggregate VM memory. Shared-VM scheduling limits precision; repeated runs and CPU time accompany wall time.

Diagnostic theorem-command profiling (-DElab.async=false, no raised limits) covers all 18 modules with proof changes, including every newly added helper: 3,132,603 → 1,995,522 heartbeats (36.30% lower) across 1,648 base and 1,654 optimized theorem commands. These totals cover the edited modules, not the entire project. Representative reductions are affine vertex evaluation (99,555 → 693), chart coordinate equivalence (61,806 → 605), and marked-token separation (50,414 → 938).

Validation on the final source:

  • lake --wfail build LeanPool.ClassificationOfSurfaces.Imports: both optimized clean builds pass with warnings treated as errors.
  • lake env lean --run scripts/ci/lint-project.lean <all 134 selected-project modules>: production Mathlib linter driver passes.
  • lake exe lint-style LeanPool.ClassificationOfSurfaces.Imports: passes.
  • uv run --project python --locked python /data/codex/scratch/vasilin97/optimization-20261020/check-project.py: selected-project execution of unchanged production quality functions passes: headers, forbidden constructs/options, proof/file sizes, card/main declarations, axiom closure and all-constant trust audit.
  • Generated selected-project Imports.lean matches the production generator format exactly; the pool index is byte-identical to base.
  • lake shake --force --keep-public LeanPool.ClassificationOfSurfaces.Imports: passes with no remaining suggestions; --force bypasses the unrelated full-pool build preflight after the complete project build.
  • Fresh post-build base/head manifests and source-signature audit pass; dependency revisions and tracked dependency trees match the pins; git diff --check passes.

Full-repository checks remain with protected CI. No gates, options, linter settings, waivers or unrelated projects change. Raw benchmark logs, the environment inspector, manifests, comparison/investigation reports, source audit and frozen checkpoints are retained under /data/codex/scratch/vasilin97/optimization-20261020 on the VM. Auto-merge is not enabled.

@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 actionable regression was found in the proof refactor or import cleanup.

Summary

This PR shortens proofs and removes private imports across 86 existing ClassificationOfSurfaces files.

  • Fan maps use coordinate sums to cut repeated proof work.
  • Chart mesh comparisons share one coordinate-equality helper.
  • Geometry proofs use direct identities and narrower arithmetic steps.
  • The project drops redundant private imports without changing its public interface.

No actionable regression was found. The project card and headline theorem were checked against the change scope. External source fidelity and the reported benchmark logs were not independently verified. Builds, linters and performance measurements were not rerun.

Reviews (1) · Last reviewed commit: "Optimize ClassificationOfSurfaces elabor..." · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

✅ No statements changed — all 5,270 tracked declarations across 86 modified files kept their type; only proofs / definition bodies changed.

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

➕ Declarations added (8)
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.TriangleMesh.restrictTriangles_coordinateEmbed_eq_iff — LeanPool/ClassificationOfSurfaces/Moise/ChartInductionCore.lean
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.IntrinsicTwoComplex.affineCombination_injective_of_affineIndependent — LeanPool/ClassificationOfSurfaces/Moise/IntrinsicComplex.lean
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.IntrinsicTwoComplex.affineMap_apply_weighted_sum — LeanPool/ClassificationOfSurfaces/Moise/IntrinsicComplex.lean
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.IntrinsicTwoComplex.simplex_affineCombination_eq_weighted_sum — LeanPool/ClassificationOfSurfaces/Moise/IntrinsicComplex.lean
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.IntrinsicTwoComplex.simplex_eq_of_weighted_sum_eq_of_affineIndependent — LeanPool/ClassificationOfSurfaces/Moise/IntrinsicComplex.lean
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.IntrinsicTwoComplex.EdgeMarking.fanFaceMap_val — LeanPool/ClassificationOfSurfaces/Moise/IntrinsicMarkedFan.lean
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.thinKitePatch_leftBase_mem — LeanPool/ClassificationOfSurfaces/Moise/ThinKiteMove.lean
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.thinKitePatch_rightBase_mem — LeanPool/ClassificationOfSurfaces/Moise/ThinKiteMove.lean
➖ Declarations removed (2)
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.IntrinsicTwoComplex.affineCombination_injective_of_affineIndependent — LeanPool/ClassificationOfSurfaces/Moise/AdaptiveFanComplex.lean
  • LeanEval.Topology.ClassificationOfSurfaces.Moise.IntrinsicTwoComplex.simplex_eq_of_weighted_sum_eq_of_affineIndependent — LeanPool/ClassificationOfSurfaces/Moise/AdaptiveFanComplex.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: 8,890,499 → 7,653,830 (-1,236,669, -13.9%). Commands: 7,839 → 7,853.

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

Files: 82 compared — 12 cheaper, 1 costlier, 69 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/ClassificationOfSurfaces/Moise/ChartInduction.lean +3/-11 2,152,976 1,505,276 -647,700 -30.1% 234.56 121.06
LeanPool/ClassificationOfSurfaces/Moise/ChartInductionCore.lean +39/-33 681,165 506,193 -174,972 -25.7% 72.33 93.03
LeanPool/ClassificationOfSurfaces/FiniteCyclicWordReduction.lean +2/-6 458,309 370,893 -87,416 -19.1% 44.09 86.55
LeanPool/ClassificationOfSurfaces/Moise/ThinKiteMove.lean +67/-53 419,831 362,344 -57,487 -13.7% 46.86 69.66
LeanPool/ClassificationOfSurfaces/Moise/Brouwer.lean +7/-9 124,995 73,371 -51,624 -41.3% 19.45 9.56
LeanPool/ClassificationOfSurfaces/DiskSquare.lean +14/-16 354,834 307,035 -47,799 -13.5% 68.38 46.07
LeanPool/ClassificationOfSurfaces/Moise/PolygonalArc.lean +13/-14 256,445 209,484 -46,961 -18.3% 37.59 39.75
LeanPool/ClassificationOfSurfaces/P2DegenerateDisk.lean +8/-10 258,308 219,391 -38,918 -15.1% 27.27 42.89
LeanPool/ClassificationOfSurfaces/Moise/FacewiseComparison.lean +9/-12 221,939 183,864 -38,075 -17.2% 30.26 49.36
LeanPool/ClassificationOfSurfaces/Moise/PlaneComplex.lean +15/-30 168,763 142,514 -26,248 -15.6% 37.41 23.96
LeanPool/ClassificationOfSurfaces/Moise/LineSubdivision.lean +60/-60 792,545 778,395 -14,150 -1.8% 135.14 96.81
LeanPool/ClassificationOfSurfaces/Moise/NoRetraction.lean +5/-11 62,374 58,169 -4,205 -6.7% 18.18 13.35
LeanPool/ClassificationOfSurfaces/Moise/IntrinsicComplex.lean +48/-0 57,555 61,074 +3,518 +6.1% 11.72 13.97
LeanPool/ClassificationOfSurfaces/Moise/DualConnectivity.lean +0/-3 6,330 5,432 -898 -14.2% 5.02 4.02
LeanPool/ClassificationOfSurfaces/FiniteCyclicDerivedRewrites.lean +0/-4 34,472 33,976 -496 -1.4% 11.65 17.95
LeanPool/ClassificationOfSurfaces/FiniteCyclicSignedRealization.lean +0/-4 27,785 27,385 -400 -1.4% 8.98 7.17
LeanPool/ClassificationOfSurfaces/FiniteCyclicP2Realization.lean +0/-4 72,933 72,605 -328 -0.5% 16.72 14.33
LeanPool/ClassificationOfSurfaces/Moise/EmbeddedComplexValence.lean +0/-3 67,046 66,775 -272 -0.4% 19.86 14.97
LeanPool/ClassificationOfSurfaces/StrongVertexStar.lean +0/-4 20,605 20,378 -227 -1.1% 4.00 8.65
LeanPool/ClassificationOfSurfaces/SphereHemisphere.lean +0/-4 14,278 14,089 -189 -1.3% 3.10 7.29
LeanPool/ClassificationOfSurfaces/FiniteCyclicWordReductionCore.lean +0/-4 206,839 206,661 -179 -0.1% 56.49 33.08
LeanPool/ClassificationOfSurfaces/Moise/ChartPatch.lean +0/-3 233,530 233,352 -178 -0.1% 37.55 37.72
LeanPool/ClassificationOfSurfaces/FiniteCyclicP2DegenerateRealization.lean +0/-4 36,491 36,328 -163 -0.4% 7.26 10.35
LeanPool/ClassificationOfSurfaces/Moise/LocallyFiniteControlledApproximation.lean +0/-3 64,459 64,323 -136 -0.2% 8.82 9.20
LeanPool/ClassificationOfSurfaces/CanonicalCoordinates.lean +0/-4 63,071 62,962 -108 -0.2% 20.24 14.56
LeanPool/ClassificationOfSurfaces/Moise/ChartExtraction.lean +0/-3 47,783 47,687 -96 -0.2% 8.73 13.24
LeanPool/ClassificationOfSurfaces/Moise/HalfPlanePolygon.lean +0/-4 34,939 34,843 -96 -0.3% 5.41 6.63
LeanPool/ClassificationOfSurfaces/Moise/AdaptiveControlledApproximation.lean +0/-3 26,770 26,682 -88 -0.3% 10.92 7.91
LeanPool/ClassificationOfSurfaces/FiniteCyclicP1Realization.lean +0/-4 86,032 85,949 -83 -0.1% 10.69 22.84
LeanPool/ClassificationOfSurfaces/FiniteCyclicCancellation.lean +0/-4 22,070 21,989 -81 -0.4% 6.39 8.78
LeanPool/ClassificationOfSurfaces/GeometricTriangulationRealization.lean +0/-3 67,837 67,777 -59 -0.1% 7.99 19.41
LeanPool/ClassificationOfSurfaces/Moise/BoundaryInvariant.lean +0/-3 26,616 26,561 -55 -0.2% 6.49 6.33
LeanPool/ClassificationOfSurfaces/FiniteCyclicReduction.lean +0/-4 68,021 67,974 -47 -0.1% 9.18 16.69
LeanPool/ClassificationOfSurfaces/FiniteCyclicFaceMerge.lean +0/-4 23,086 23,052 -34 -0.1% 6.03 8.29
LeanPool/ClassificationOfSurfaces/Moise/PuncturedSurface.lean +0/-3 14,409 14,375 -34 -0.2% 7.12 5.53
LeanPool/ClassificationOfSurfaces/FiniteCyclicTriangulation.lean +0/-4 36,232 36,199 -33 -0.1% 7.05 10.64
LeanPool/ClassificationOfSurfaces/FiniteCyclicTerminalNormalization.lean +0/-4 130,926 130,896 -30 -0.0% 31.78 22.55
LeanPool/ClassificationOfSurfaces/FiniteCyclicDyck.lean +0/-4 7,625 7,595 -30 -0.4% 5.91 3.97
LeanPool/ClassificationOfSurfaces/FiniteCyclicP1.lean +0/-4 37,926 37,898 -27 -0.1% 13.14 10.33
LeanPool/ClassificationOfSurfaces/Triangulation.lean +0/-3 20,040 20,013 -27 -0.1% 5.75 5.11
LeanPool/ClassificationOfSurfaces/SphereQuotientHomeomorph.lean +0/-4 37,262 37,236 -26 -0.1% 11.51 8.23
LeanPool/ClassificationOfSurfaces/FiniteCyclicUnorientedRealization.lean +0/-4 26,783 26,760 -23 -0.1% 6.56 5.58
LeanPool/ClassificationOfSurfaces/CanonicalWords.lean +0/-4 72,051 72,030 -21 -0.0% 10.78 16.87
LeanPool/ClassificationOfSurfaces/FiniteCyclicPresentation.lean +0/-4 35,908 35,889 -19 -0.1% 7.11 9.51
LeanPool/ClassificationOfSurfaces/FiniteCyclicP2.lean +0/-4 27,804 27,787 -17 -0.1% 7.73 9.51
LeanPool/ClassificationOfSurfaces/Moise/Countermodels.lean +0/-4 6,366 6,352 -15 -0.2% 2.67 5.31
LeanPool/ClassificationOfSurfaces/Moise/ElementaryMove.lean +4/-4 405,074 405,060 -14 -0.0% 38.51 75.99
LeanPool/ClassificationOfSurfaces/FiniteCyclicCrosscap.lean +0/-4 11,635 11,623 -12 -0.1% 6.62 5.08
LeanPool/ClassificationOfSurfaces/FiniteCyclicSphereRealization.lean +0/-4 10,156 10,145 -11 -0.1% 3.41 5.45
LeanPool/ClassificationOfSurfaces/NormalForm.lean +0/-4 1,250 1,239 -11 -0.9% 3.51 2.24
… +32 more files, each with a smaller move (≤ 9 HB); full table in the run's step summary
Total +295/-491 8,890,499 7,653,830 -1,236,669 -13.9% 1421.5 1446.7

Per-project compile cost (top 2 of 2 projects by |Δ heartbeats|):

Project Files HB base HB head Δ HB Δ HB %
ClassificationOfSurfaces 81 8,890,498 7,653,829 -1,236,669 -13.9%
(root) 1 1 1 -0 -2.9%

New files — absolute profile

Total heartbeats: — maxHeartbeats units across 0 valid files (66 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/ClassificationOfSurfaces/Moise/AdaptiveFanAffine.lean 13 — — — — — 39 1
LeanPool/ClassificationOfSurfaces/Moise/AdaptiveFanComplex.lean 25 — — — — — 164 1
LeanPool/ClassificationOfSurfaces/Moise/GraphPolygonalization.lean 5 — — — — — 175 1
LeanPool/ClassificationOfSurfaces/Moise/IntrinsicMarkedFan.lean 23 — — — — — 198 1
Total 66 — 0.00 — — — 576 4

Aggregate phase totals

Phase Time
Unavailable —

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

@Vilin97

Vilin97 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

/review

Exact head: eaaddb0e9c4f72c30250eb58d8f1aa0ea573f0e9.

@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 ClassificationOfSurfaces refactor replaces repeated barycentric-map unfolding with coordinate projection lemmas and shared affine identities, factors the chart-restriction comparison, and uses explicit arithmetic premises, direct terms and covering-map uniqueness in existing proofs. The shared helper placement and preserved public import facade improve maintainability. The advisory profile reports 13.9% fewer heartbeats across 82 valid file comparisons; four modified-file measurements failed, so it does not establish a complete project-wide speedup.",
"assessment": {
"scope": "Proof elaboration and private-import refactor",
"introduces_tech_debt": false,
"maintainability": "improved",
"brittleness": "more_robust",
"risk": "low",
"assessment_one_sentence": "The refactor exposes reusable mathematical steps and reduces unnecessary elaboration without an actionable maintenance regression."
},
"verdict": "approve",
"findings": []
}

@Vilin97

Vilin97 commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: eaaddb0e9c4f72c30250eb58d8f1aa0ea573f0e9

Verdict: ✅ approve

The refactor shares affine and coordinate lemmas, factors repeated arguments, narrows automation, and removes 246 private imports while preserving every public import. Proof structure and reuse improve. Independent compilation passed all 134 project modules with warnings treated as errors. Three profiling failures came from missing helpers in base dependencies; the fourth was a typeclass timeout reported at both base and head. Protected CI remains running. The claimed wall-time speedup was not independently remeasured.

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

Shared interfaces and explicit proof steps reduce duplication and automation dependence without introducing actionable maintenance debt.


Tokens: 7,120,927 in / 25,389 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $28.8645 (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.

CI was not green for this commit at review time; this review does not replace CI.

@Vilin97
Vilin97 added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit 7639c3c Oct 20, 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