Skip to content

Optimize DomainTheory imports and repeated proofs - #718

Open
Vilin97 wants to merge 1 commit into
mainfrom
vilin/optimize-20261024-evening
Open

Vilin97 wants to merge 1 commit into
mainfrom
vilin/optimize-20261024-evening

Conversation

@Vilin97

@Vilin97 Vilin97 commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

DomainTheory repeatedly loads broad numeric-tactic dependencies and recomputes finite-set and functor facts. This refactor reduces that compilation work while preserving every pre-existing declaration. The completed project has 148 mathematical modules and about 51,000 lines, providing both import and proof-reuse opportunities.

Base: edbe5bd56f476cc2965564676b66199f281ab714. Head: d8a4e4a1ff57584e2eab3617a079d850ab5a8fde.

Changes:

  • Remove unused private numeric-tactic imports, retain explicit parser dependencies with shake: keep, and prune redundant import edges. The entry module uses 84 terminal public imports instead of 148, with the same transitive public module coverage.
  • Bound simplification with explicit lemma lists and replace suitable tactic calls with direct theorem applications.
  • Add four support lemmas for inclusion relations, projection uniqueness, pointwise suprema of Scott maps, and preservation of directed suprema. Reuse them in the functor and function-space proofs.
  • Reuse 22 existing intersection lemmas in Example 1.4; replace finite case searches with singleton-set lemmas, explicit intersection cases, and direct membership witnesses. Remove the unused finite-case imports from Examples 1.2–1.4.
  • Preserve Theorem614's original import prefix so source coordinates embedded in a generated default-argument type remain literally identical.

The declaration audit imports all 150 owned modules with importAll, including private/generated declarations. It compares raw Expr representations of types and all non-theorem values, declaration kinds, universe parameters, safety, partiality, and names. Theorem proof bodies are the only omitted values. All 6,783 base declarations are retained with zero differences, without normalization exceptions. The head has 7,380 declarations: four new source support lemmas and 593 generated proof auxiliaries. Four canonical congr_simp caches have different import-origin metadata; their names and types are unchanged. An independent source audit finds no statement, binder, definition-body, attribute, or other code edits outside theorem proofs/imports and the four new lemmas. All 218,113 old exported names remain; exactly the four support lemmas are added.

LEAN_NUM_THREADS Base runs (s) Optimized runs (s) Median base → optimized (s) Reduction
2 115.032677, 112.726160, 114.077600 102.402979, 101.230770, 102.877253 114.077600 → 102.402979 10.233929%
16 56.838827, 57.087467, 58.104517 52.394688, 53.263786, 54.366793 57.087467 → 53.263786 6.697935%

Each timing run starts with empty project build outputs and the same warm pinned dependency cache, using env LEAN_NUM_THREADS=N lake --wfail build LeanPool.DomainTheory. The order is base/head/head/base/base/head, with three repetitions per revision. Both variants build the same 148 mathematical modules plus the entry module. The two-thread runs include the same lightweight process-tree sampler; the sixteen-thread runs use GNU time only. Source hashes are checked after restoring the optimized tree. The raw runs and medians are reported, without selecting the fastest run.

Validation passed on the exact frozen source:

  • env LEAN_NUM_THREADS=2 lake --wfail build LeanPool.DomainTheory.Imports
  • Full raw declaration-manifest comparison and strict source/signature comparison
  • lake env lean --run scripts/ci/lint-project.lean <all 150 owned modules>: 7,380 declarations
  • lake exe lint-style LeanPool.DomainTheory.Imports
  • Repository quality checks restricted to this project: static checks, axiom audit of 3,577 source declarations, compiled environment/option audit, and project-card/declaration checks
  • lake exe mk_all --module --check and git diff --check

lake shake --force --keep-public --explain LeanPool.DomainTheory was also run for import analysis. It reports remaining redundant imports; parser dependencies, public coverage, and the source-coordinate-sensitive prefix are preserved. Its --force flag skips the workspace-wide freshness precheck because unrelated projects are unbuilt; the selected project was rebuilt warning-free.

No gates, configuration, toolchain, project registry, generated indexes, or other projects changed. The base already pins Lean 4.35.0-rc3 and Mathlib c55e6e786f49471c72fbddbec5415808896aec1e; those pins are unchanged.

These measurements are observations from a shared Azure VM, not a uniform speedup guarantee across thread counts. No 10% physical-RAM improvement is claimed. Full-pool hosted CI and independent review remain pending. Do not merge automatically; the infrastructure priority hold and all normal protections remain in force. Audit manifests, source checkpoints, commands, and timing logs are retained under /data/codex/scratch/vilin/optimization-20261024-evening.

@greptile-apps

greptile-apps Bot commented Oct 25, 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] The changes affect proof building across the DomainTheory library.

No blocking defect was found; replacing the generated helper call would make the proof easier to maintain.

Findings

  1. P2 Proof depends on generated helper ▶

Summary

Refactors DomainTheory imports and proofs without changing existing source statements or definition bodies.

  • DomainTheory lists fewer imports while keeping the same public modules available.
  • Shared lattice and neighborhood facts replace repeated proof work.
  • DomainTheory proofs use direct set facts and narrower simplification steps.

Vilin97 explicitly describes the finite intersection cases as intentional and the retained import prefix in Theorem614.lean as necessary for source-coordinate compatibility.

Review covered the full diff and relevant source relationships. The reported timings and raw declaration audit were not independently rerun. External source fidelity, upstream license evidence, and Mathlib-wide prior art were not independently verified.

Reviews (1) · Last reviewed commit: "Optimize DomainTheory imports and repeat..." · Reviewed by Greptile

· have hsub : ({m} : Set ℕ) ⊆ {n} :=
(flat.principal_le_iff (flat_mem_singleton n) (flat_mem_singleton m)).mp hle
simp_all
exact principal.congr_simp flat (congrArg singleton (hsub rfl)) (flat_mem_singleton m)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Proof depends on generated helper

flat_atom_maximal now calls principal.congr_simp directly. This is a generated helper, so changes to how Lean generates congruence proofs can break this proof even when principal is unchanged. Derive m = n from hsub rfl, substitute it, and finish with rfl instead.

Suggested change
exact principal.congr_simp flat (congrArg singleton (hsub rfl)) (flat_mem_singleton m)
have hmn : m = n := hsub rfl
subst m
rfl

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

✅ No statements changed — all 3,516 tracked declarations across 127 modified files kept their type; only proofs / definition bodies changed.

Also: 4 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 (4)
  • Domain.ContinuousLattice.ScottMap.iSup_apply — LeanPool/DomainTheory/ContinuousLattice/FunctionSpaces.lean
  • Domain.ContinuousLattice.ScottMap.map_iSup_of_directed — LeanPool/DomainTheory/ContinuousLattice/FunctionSpaces.lean
  • Domain.Neighborhood.ApproximableMap.relation_iff_subset_of_diagonal — LeanPool/DomainTheory/Neighborhood/Approximable.lean
  • Domain.Neighborhood.Exercise619.Subsystem.projection_eq_of_projection_pair — LeanPool/DomainTheory/Neighborhood/Exercise623.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,181,799 → 938,674 (-243,125, -20.6%). Commands: 4,885 → 4,888.

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

Files: 120 compared — 29 cheaper, 0 costlier, 91 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/DomainTheory/Neighborhood/Example14.lean +250/-153 64,442 15,711 -48,732 -75.6% 16.15 5.88
LeanPool/DomainTheory/Neighborhood/FunctionSpace.lean +24/-19 53,563 23,075 -30,487 -56.9% 14.01 3.71
LeanPool/DomainTheory/Neighborhood/Theorem75.lean +40/-36 69,492 42,301 -27,191 -39.1% 13.75 4.82
LeanPool/DomainTheory/ContinuousLattice/FunctionSpaces.lean +55/-27 96,625 74,294 -22,330 -23.1% 22.43 13.08
LeanPool/DomainTheory/Neighborhood/Recursive.lean +17/-11 52,866 41,875 -10,991 -20.8% 10.82 5.38
LeanPool/DomainTheory/Neighborhood/Theorem614.lean +5/-3 25,481 15,309 -10,171 -39.9% 6.87 3.58
LeanPool/DomainTheory/Neighborhood/Theorem616.lean +3/-7 17,105 7,780 -9,325 -54.5% 4.60 2.65
LeanPool/DomainTheory/Neighborhood/Exercise328.lean +8/-9 13,629 6,170 -7,459 -54.7% 3.96 2.34
LeanPool/DomainTheory/Neighborhood/Exercise516Overlap.lean +4/-9 29,227 22,331 -6,896 -23.6% 7.13 3.43
LeanPool/DomainTheory/Neighborhood/Proposition77.lean +20/-10 52,520 47,184 -5,336 -10.2% 14.48 13.57
LeanPool/DomainTheory/Neighborhood/Exercise510.lean +17/-16 25,577 20,617 -4,959 -19.4% 7.60 5.73
LeanPool/DomainTheory/ContinuousLattice/Injective.lean +3/-3 7,376 2,762 -4,614 -62.5% 4.73 4.48
LeanPool/DomainTheory/Neighborhood/Example62.lean +11/-7 11,270 6,947 -4,323 -38.4% 5.08 2.37
LeanPool/DomainTheory/Neighborhood/Example62C.lean +18/-16 52,400 48,234 -4,166 -8.0% 11.89 6.26
LeanPool/DomainTheory/Neighborhood/Exercise118.lean +27/-13 10,879 7,316 -3,564 -32.8% 5.05 3.56
LeanPool/DomainTheory/Neighborhood/Exercise317.lean +14/-16 13,579 10,301 -3,278 -24.1% 5.54 2.34
LeanPool/DomainTheory/ContinuousLattice/Constructions.lean +8/-7 20,922 18,029 -2,893 -13.8% 9.61 5.94
LeanPool/DomainTheory/Neighborhood/Example62A.lean +8/-6 14,484 11,601 -2,882 -19.9% 4.01 5.26
LeanPool/DomainTheory/ContinuousLattice/ScottMaps.lean +6/-6 11,938 9,453 -2,485 -20.8% 4.84 5.02
LeanPool/DomainTheory/Neighborhood/Exercise629.lean +9/-9 14,386 12,300 -2,086 -14.5% 5.45 4.95
LeanPool/DomainTheory/Neighborhood/Approximable.lean +13/-2 11,504 9,519 -1,985 -17.3% 5.08 3.38
LeanPool/DomainTheory/Neighborhood/Exercise115.lean +20/-18 5,918 4,024 -1,894 -32.0% 3.80 1.86
LeanPool/DomainTheory/Neighborhood/Exercise222.lean +3/-6 12,350 10,528 -1,822 -14.8% 3.68 3.91
LeanPool/DomainTheory/Neighborhood/Example13.lean +27/-27 4,911 3,125 -1,786 -36.4% 3.05 1.67
LeanPool/DomainTheory/Neighborhood/Example12.lean +26/-24 4,720 3,087 -1,633 -34.6% 3.49 2.77
LeanPool/DomainTheory/Neighborhood/Exercise618.lean +6/-12 12,845 11,360 -1,485 -11.6% 6.04 3.14
LeanPool/DomainTheory/Neighborhood/Product.lean +14/-11 14,559 13,146 -1,413 -9.7% 5.49 3.17
LeanPool/DomainTheory/Neighborhood/Exercise318.lean +18/-15 13,419 12,036 -1,383 -10.3% 4.89 4.60
LeanPool/DomainTheory/Neighborhood/Theorem69.lean +4/-8 6,741 5,384 -1,357 -20.1% 4.13 1.73
LeanPool/DomainTheory/Neighborhood/Exercise515.lean +5/-5 11,198 10,274 -924 -8.3% 5.06 2.73
LeanPool/DomainTheory/Neighborhood/Theorem76.lean +8/-11 6,977 6,134 -843 -12.1% 3.30 2.71
LeanPool/DomainTheory/Neighborhood/Exercise514.lean +0/-2 5,733 4,940 -794 -13.8% 3.66 3.04
LeanPool/DomainTheory/Neighborhood/Exercise421.lean +6/-5 5,011 4,235 -776 -15.5% 3.48 2.91
LeanPool/DomainTheory/Neighborhood/Exercise419.lean +8/-14 15,998 15,252 -746 -4.7% 3.79 3.56
LeanPool/DomainTheory/Neighborhood/Exercise425.lean +7/-10 3,714 2,968 -746 -20.1% 3.10 2.82
LeanPool/DomainTheory/Neighborhood/Theorem56.lean +1/-7 7,455 6,711 -743 -10.0% 3.42 2.13
LeanPool/DomainTheory/Neighborhood/ExampleB.lean +3/-4 2,787 2,152 -636 -22.8% 2.97 1.77
LeanPool/DomainTheory/Neighborhood/Exercise221.lean +8/-8 4,901 4,340 -561 -11.4% 2.92 1.83
LeanPool/DomainTheory/Neighborhood/Example44.lean +5/-9 2,915 2,361 -554 -19.0% 2.65 1.64
LeanPool/DomainTheory/Neighborhood/Example61.lean +32/-21 17,722 17,177 -545 -3.1% 6.96 5.28
LeanPool/DomainTheory/Neighborhood/Exercise415.lean +3/-7 1,513 1,019 -494 -32.7% 2.61 2.13
LeanPool/DomainTheory/Neighborhood/Exercise123.lean +2/-3 5,485 4,999 -485 -8.8% 3.55 1.92
LeanPool/DomainTheory/Neighborhood/Exercise125.lean +1/-1 8,252 7,848 -404 -4.9% 2.91 3.68
LeanPool/DomainTheory/Neighborhood/Example43.lean +6/-10 3,172 2,811 -361 -11.4% 2.61 2.29
LeanPool/DomainTheory/Neighborhood/Lemma615.lean +1/-7 10,810 10,462 -347 -3.2% 2.67 3.03
LeanPool/DomainTheory/Neighborhood/Exercise117.lean +1/-1 2,328 2,002 -326 -14.0% 3.50 2.49
LeanPool/DomainTheory/Neighborhood/Exercise627.lean +0/-7 12,361 12,070 -292 -2.4% 5.81 4.46
LeanPool/DomainTheory/Neighborhood/Exercise408.lean +1/-7 1,915 1,633 -282 -14.8% 2.36 2.31
LeanPool/DomainTheory/Neighborhood/Theorem56Full.lean +8/-11 21,210 20,954 -256 -1.2% 7.67 8.16
LeanPool/DomainTheory/Neighborhood/Exercise513.lean +2/-2 5,335 5,102 -233 -4.4% 2.99 2.30
… +70 more files, each with a smaller move (≤ 233 HB); full table in the run's step summary
Total +1,007/-1,153 1,181,799 938,674 -243,125 -20.6% 499.9 355.8

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

Project Files HB base HB head Δ HB Δ HB %
DomainTheory 119 1,181,799 938,673 -243,125 -20.6%
(root) 1 1 1 -0 -0.5%

New files — absolute profile

Total heartbeats: — maxHeartbeats units across 0 valid files (215 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/DomainTheory/ContinuousLattice/FunctionSpaceTower.lean 19 — — — — — 82 1
LeanPool/DomainTheory/ContinuousLattice/InverseLimits.lean 9 — — — — — 76 1
LeanPool/DomainTheory/Neighborhood/Exercise617.lean 12 — — — — — 145 1
LeanPool/DomainTheory/Neighborhood/Exercise617Gen.lean 39 — — — — — 636 1
LeanPool/DomainTheory/Neighborhood/Exercise619PartB.lean 23 — — — — — 129 1
LeanPool/DomainTheory/Neighborhood/Exercise621.lean 22 — — — — — 169 1
LeanPool/DomainTheory/Neighborhood/Exercise623.lean 91 — — — — — 165 1
Total 215 — 0.00 — — — 1402 7

Aggregate phase totals

Phase Time
Unavailable —

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

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