Skip to content

Speed up MovingSofa certificate replay with a binary grid - #1043

Merged
Vilin97 merged 1 commit into
mainfrom
fix/moving-sofa-binary-grid-20261127
Nov 27, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
fix/moving-sofa-binary-grid-20261127

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Ready for review. MovingSofa’s clean build is 21.52% faster and all 250,112 original compiled records match.

Changes

MovingSofa ranked first in the repository’s cold CI cost table. The baseline attributed 1,260.2 summed Lake seconds to the Part E certificate bundles. Lean Pool build costs

  • Try a binary grid with unit 2⁻³⁰ in 30 Part E certificate bundles. The new proofs establish outward rounding for products, nonnegative scalar multiplication, the depth-ten Taylor remainder, and both residuals. The kernel checks the rounded coefficient tables against the existing rational coefficients.
  • Share the residual enclosure proof between the two grids. An inconclusive binary-grid check continues through the existing finer grid and sparse exact evaluator.
  • Schedule the 14 independent niche-area subtotal checks through the project’s existing kernel-certificate tactic. The original subtotal statements and numeric data are preserved.

Declaration audit

  • Base 6ed96f4ef304a1fd46ece1897225a8ac5d333f8a · Head 9e788e9c870edd830acf19274296ef43583ffbad
  • Before editing and after the final clean build, a local Lean inspector used Lean.readModuleDataParts on the exported, server and private parts of all 65 project modules. It recorded declaration ownership, visibility tier, name, universe parameters, structural type, declaration kind, safety, reducibility, inductive and recursor metadata, non-theorem values, and compiler-generated names. It strips kernel-irrelevant expression metadata. Theorem bodies may change.
  • All 250,112 base records matched. The 204 additional records belong to the binary-grid helpers and their generated declarations in FixedPointResiduals.
  • Compressed manifest SHA-256 values are 8343c0c4541ad645064903df202a6914ada24fa831f53ec5e388011bc1fd2817 for base and 0a99469ce424765137829b83a743bf1f61b7c38bd08418fff21e084638dba997 for head.

Measurements

Each run rebuilt all 65 project modules in the same Azure worktree on Lean 4.36.0 and Mathlib fc4f59e577feb1a4956671bc04ac18aaaf8cd842. Lake reused warm dependency, Isoperimetric and linter-plugin outputs. The project’s own compiled outputs were cleared before each build.

export LEAN_NUM_THREADS=4 PYTHONPATH=python
/usr/bin/time -v taskset -c 8-15 python3 -m lean_pool.build_time_limits watch \
  --base 6ed96f4ef304a1fd46ece1897225a8ac5d333f8a -- lake --wfail --no-ansi build +LeanPool.MovingSofa.Imports
Metric Base Head
Clean wall time 671.83 s 527.25 s
User and system CPU time 2984.89 s 2461.18 s
Maximum single-process RSS 2,778,056 KiB 2,774,556 KiB
Part E certificate module times, summed 1,260.2 s 919.1 s
Part E Bundle005 56 s 39 s
NicheAreaCertificate 90 s 89 s

The first optimized clean run took 559.56 s wall and 2532.35 s CPU. The final run includes documentation strings on the new helpers. A separate Base→Head→Head→Base replay of the full Bundle005 source used the same warm imports, the same scratch source path, LEAN_NUM_THREADS=2, and taskset -c 0-3 lake env lean with the project’s compiler options and linter plugin. Median wall time went from 46.065 to 30.500 s, and median CPU time from 48.685 to 39.235 s. The VM was shared, so host load and Lake scheduling contribute to the whole-project wall times.

Validation

  • Warning-free clean build, lake --wfail --no-build build +LeanPool.MovingSofa.Imports, and the repository build watchdog.
  • python3 -m lean_pool.build_time_limits check --log ../final.build --base 6ed96f4ef304a1fd46ece1897225a8ac5d333f8a across all 32 changed files.
  • lake env lean --run scripts/ci/lint-project.lean over all 65 modules and lake --wfail exe lint-style LeanPool.MovingSofa.Imports.
  • python -m lean_pool.quality --repo . --static-only, plus the repository’s compiled declaration, option, allowed-axiom and build-message audits scoped to MovingSofa. Whole-pool compiled validation runs in GitHub CI.
  • lake --wfail exe mk_all --module --check, python3 -m lean_pool.rebase_fastpath check-index, documentation toolchain and Mathlib pin parity, and git diff --check.
  • lake shake --force --keep-public --keep-implied --explain LeanPool.MovingSofa.Imports reviewed the import graph. The niche certificate keeps its explicit private tactic import.

@greptile-apps

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

No actionable defect was found in the changed certificate proofs or fallback paths.RetriggerView in Greptile

[Medium impact] No actionable defect was found in the changed certificate proofs or fallback paths.

Summary

Adds a binary-grid first pass to 30 Part E certificate bundles and shares the residual enclosure proof between grids.

  • Part E certificates try a binary grid before their finer checks.
  • The niche-area subtotal checks use the project’s kernel tactic.

Reviews (1) · Last reviewed commit: "Speed up MovingSofa certificate replay w..." · 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.

Approved on source review at 9e788e9c, pending required Lean CI.

  • The binary grid rounds outward, and the Lean proofs establish that each successful rejection implies rejection by the existing rational evaluator. The checked coefficient tables match the original rational coefficients under outward rounding. Inconclusive checks fall through to the existing fine grid and then the sparse exact evaluator.
  • The bundle diffs change only the selected decision instance and its comments. The 14 niche subtotal statements and literals are identical, and gerver_kernel_decide still uses the existing kernel-checked auxiliary theorem. The change is confined to MovingSofa source.
  • The reported clean build took 527 s versus 672 s, and the controlled Bundle005 replay shows a consistent reduction. The posted compiled-record audit reports that all 250,112 base records match. Validation and measurements

@Vilin97

Vilin97 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: 9e788e9c870edd830acf19274296ef43583ffbad

Verdict: 🛑 request_changes

The PR adds a binary-grid first pass to 30 Part E certificate bundles, with fallback to the finer grid and then the sparse exact evaluator. It also moves 14 niche-area subtotal checks to the existing kernel-certificate tactic. A targeted build of Part E Bundle005 and NicheAreaCertificate passed in a minimal Lake project on the pinned Lean and Mathlib, and Lean probes exercised both fallback stages. The whole-project timings are contributor-reported.

Aspect Value
Scope certificate replay optimization
Introduces tech debt 🛑 yes
Maintainability 🛑 regressed
Brittleness 🛑 more_brittle
Risk 🟡 medium

Keep the faster replay path, but separate the grid types and consolidate the residual formula before merging.

Findings (2)

  • grid-scale-mismatch — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean:739
    The binary conversion returns the same public SI type that the area certificate uses for decimal-grid intervals. Lean accepts two binary encodings of 1 as arguments to SI.mul, which gives an upper endpoint of 1 in binary units. The binary multiplication gives 1073741827. Give binary intervals a distinct type or index the shared representation by scale so a call using the wrong grid fails to elaborate.
  • duplicated-logic — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean:327
    The shared enclosure proof now relies on residualsFromGrid, residualsWithProduct, and residuals reducing to the same formula under the appropriate operations. A formula edit still has to be repeated across three bodies, and a missed edit can surface as a type mismatch in the enclosure proof. Lean confirms that the two existing evaluators are definitionally equal to specializations of the new helper. Keep their entry points as wrappers over one implementation and rerun the Bundle005 benchmark.

Tokens: 3,043,229 in / 13,537 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $12.3760 (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.

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

✅ No statements changed — all 49,538 tracked declarations across 32 modified files kept their type; only proofs / definition bodies changed.

Also: 43 declarations 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 (43)
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.Encloses — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.Encloses.add — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.Encloses.excludesZero — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.Encloses.mul — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.Encloses.mulFull — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.Encloses.neg — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.Encloses.ordered — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.Encloses.scaleNonnegative — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.Encloses.trans — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.cosineCoefficients — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.cosineCoefficients_eq — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.decidableRejected — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.decode — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.denominator — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.denominator_pos — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.floor — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.horner — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.horner_encloses — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.mul — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.mulFull — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.mulFull_comm — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.mulNonnegativeRight — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.mulNonnegativeRight_eq — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.ofRat — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.ofRat_encloses — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.point — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.point_encloses — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.rejected_of_check — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.rejects — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.remainder — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.remainderDenominator — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.remainder_bound — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.remainder_encloses — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.round_product_down — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.round_product_up — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.scaleNonnegative — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.sineCoefficients — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.sineCoefficients_eq — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.trig — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.BinaryGrid.trig_encloses — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.floor_scaled_fraction — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.residualsFromGrid — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean
  • GerverSofa.PartE.FixedPointResiduals.residualsFromGrid_encloses — LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.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: 359,434 → 382,874 (+23,440, +6.5%). Commands: 147 → 225.

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

Files: 2 compared — 0 cheaper, 1 costlier, 1 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/MovingSofa/GerverSofa/KernelOnly/PartE/FixedPointResiduals.lean +457/-38 29,030 52,471 +23,440 +80.7% 6.93 7.28
LeanPool/MovingSofa/Development/Geometry/Foundations/NicheAreaCertificate.lean +15/-14 330,404 330,404 -0 -0.0% 74.74 64.06
Total +472/-52 359,434 382,874 +23,440 +6.5% 81.7 71.3

New files — absolute profile

Total heartbeats: — maxHeartbeats units across 0 valid files (39 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/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle001.lean 1 — — — — — 5326 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle002.lean 2 — — — — — 3926 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle003.lean 2 — — — — — 3973 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle004.lean 2 — — — — — 1062 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle005.lean 2 — — — — — 1281 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle006.lean 2 — — — — — 1031 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle007.lean 2 — — — — — 1429 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle008.lean 1 — — — — — 1060 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle009.lean 2 — — — — — 1192 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle010.lean 1 — — — — — 1921 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle011.lean 2 — — — — — 955 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle012.lean 1 — — — — — 1368 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle013.lean 1 — — — — — 1984 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle014.lean 1 — — — — — 878 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle015.lean 1 — — — — — 385 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle016.lean 1 — — — — — 1124 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle017.lean 1 — — — — — 942 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle018.lean 1 — — — — — 433 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle019.lean 1 — — — — — 1193 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle020.lean 1 — — — — — 3777 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle021.lean 2 — — — — — 1498 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle022.lean 1 — — — — — 2471 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle023.lean 1 — — — — — 3314 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle024.lean 1 — — — — — 3069 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle025.lean 1 — — — — — 3315 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle026.lean 1 — — — — — 3186 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle027.lean 1 — — — — — 3191 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle028.lean 1 — — — — — 3074 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle029.lean 1 — — — — — 3280 1
LeanPool/MovingSofa/GerverSofa/KernelOnly/PartE/Certificates/Bundle030.lean 1 — — — — — 3171 1
Total 39 — 0.00 — — — 64809 30

Aggregate phase totals

Phase Time
Unavailable —

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

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