Skip to content

refactor: thin exists_perm_extending_strictMono via mathlib API (−46 lines)#18

Merged
cameronfreer merged 2 commits into
mainfrom
refactor-perm-extension
May 18, 2026
Merged

refactor: thin exists_perm_extending_strictMono via mathlib API (−46 lines)#18
cameronfreer merged 2 commits into
mainfrom
refactor-perm-extension

Conversation

@cameronfreer

@cameronfreer cameronfreer commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

First in the post-bump series of targeted mathlib-refactor PRs. Replaces the local 58-line proof of exists_perm_extending_strictMono in Contractability.lean with a 13-line wrapper around mathlib's Equiv.Perm.exists_extending_pair (landed via mathlib #34599) plus Fin.castLE / Fin.castLE_injective for the initial-segment inclusion, and updates two stale docstrings that still described the old subtype-equivalence construction.

Net diff: 1 file, +15 / −61 (−46 lines), across two commits.

Why now

The exchangeability-papers#1 camera-ready revisions explicitly flagged the local permutation-extension code as a candidate for refactoring against existing mathlib infrastructure, and mathlib #34599 landed exactly this API. With the toolchain now at v4.30.0-rc2 (PR #17), Equiv.Perm.exists_extending_pair is directly available.

Commits

Commit Scope
07695a91 — refactor: thin exists_perm_extending_strictMono via mathlib API Replaces the 58-line proof body with a 13-line wrapper. Statement, signature, and the single call site (contractable_of_exchangeable) are unchanged.
c6d3cb95 — docs: update Contractability docstrings to match refactored proof Module header (lines 55–58) and the lemma's own docstring no longer describe the deleted subtype-equivalence construction; they now point at Equiv.Perm.exists_extending_pair.

What the new proof body looks like

let f : Fin m → Fin n := Fin.castLE hmn
let g : Fin m → Fin n := fun i => ⟨k i, hk_bound i⟩
have hf : Function.Injective f := Fin.castLE_injective hmn
have hg : Function.Injective g := fun i j hij =>
  hk_mono.injective (Fin.mk.inj hij)
obtain ⟨σ, hσ⟩ := Equiv.Perm.exists_extending_pair f g hf hg
exact ⟨σ, fun i => congrArg Fin.val (hσ i)⟩

Verification

Check Baseline (main) This branch
lake build clean (3531 jobs) clean (3531 jobs)
Axioms (11 theorem decls) standard only standard only
Sorries (Exchangeability + ForMathlib) 0 0
Proof-file churn 1 file, +15 / −61

Out of scope (planned follow-up PR)

The refactor exposes some spillover cleanup that does not belong here:

  • Three open-coded fun i => ⟨i.val, Nat.lt_of_lt_of_le i.isLt hmn⟩ inclusions that could become Fin.castLE hmn (Contractability.lean:410, :472, Util/FinsetHelpers.lean:32).
  • Core.approxPerm and its companion approxEquiv use the same Equiv.extendSubtype pattern (~32 lines of approxEquiv machinery) and can collapse via the same Equiv.Perm.exists_extending_pair route, saving ~35 lines.

Both will land as a single follow-up PR after this merges.

Notes for review

Reduces the local proof from 58 lines of hand-built subtype
equivalences + `Equiv.extendSubtype` to a 13-line wrapper around
`Equiv.Perm.exists_extending_pair` (landed in mathlib via PR
#34599) plus `Fin.castLE` / `Fin.castLE_injective` for the
initial-segment inclusion.

Statement is unchanged; only the proof body is touched. The
single call site (`contractable_of_exchangeable`) is unaffected.

- Exchangeability/Contractability.lean: -44 net lines.
Two docstrings still described the old subtype-equivalence
construction, which no longer matches the refactored proof body.

- Module header (lines 55-58): "uses `Equiv.extendSubtype` to
  extend a bijection between subtypes" -> "thin wrapper around
  mathlib's `Equiv.Perm.exists_extending_pair`".
- `exists_perm_extending_strictMono` docstring: 4-step
  "Construction outline" describing domain/codomain partition +
  manual `extendSubtype` -> short note pointing at
  `Equiv.Perm.exists_extending_pair` with the choice of `f` and
  `g`.

Statement, signature, and behavior are unchanged.
@cameronfreer cameronfreer changed the title refactor: thin exists_perm_extending_strictMono via mathlib API (−44 lines) refactor: thin exists_perm_extending_strictMono via mathlib API (−46 lines) May 18, 2026
@cameronfreer cameronfreer marked this pull request as ready for review May 18, 2026 01:23
@cameronfreer cameronfreer merged commit bd32ed2 into main May 18, 2026
cameronfreer added a commit that referenced this pull request May 18, 2026
)

Mines safe-subset replacements from the PR #16 autoGolf draft and applies
them to current main, skipping the suspicious subset (lia / bare
assumption / Real.ext_cauchy / grind only on non-arithmetic goals).

`fun_prop` adoptions (replace hand-built `Measurable.const_mul +
Finset.measurable_sum + .comp` chains):

- `DeFinetti/ViaKoopman/BlockAverage.lean`     (1 site)
- `DeFinetti/ViaL2/BlockAvgDef.lean`           (1 site)
- `DeFinetti/ViaL2/AlphaConvergence.lean`      (2 sites)
- `DeFinetti/ViaL2/CesaroConvergence.lean`     (3 sites)
- `DeFinetti/ViaL2/DirectingMeasureIntegral.lean` (4 sites, incl. one
  Integrable wrap via `fun_prop`)
- `DeFinetti/ViaL2/MainConvergence.lean`       (1 site)
- `DeFinetti/ViaMartingale/PairLawEquality.lean` (1 site,
  `measurable_consRV` → fun_prop)
- `Ergodic/ShiftInvariantRepresentatives.lean` (1 site,
  `measurable_coe_real_ereal.comp …` → fun_prop)
- `Core.lean:683` — collapse `simpa using (show … from by fun_prop)` to
  bare `fun_prop`.

Named-lemma replacements:

- `DeFinetti/ViaL2/DirectingMeasureIntegral.lean` 2× hand-built
  `IsPiSystem` proof for `Set.range Iic` → `isPiSystem_Iic`.
- `Contractability.lean:perm_range_eq` — 4-line `ext`+`use`+`simp` →
  `Finset.image_univ_equiv σ`.

Minor `by exact` removals in `BlockAvgDef.lean`.

Out of scope (per the audit, suspicious-category from #16):
- `BlockAverage.lean:82` `congr 1; ring` → `lia` swap (opaque substitution
  on non-arithmetic context).
- The proof-golfing-branch reversion of #18's
  `exists_perm_extending_strictMono` refactor.

Net -62 lines across 10 files. Build clean (3527 jobs), axioms standard,
0 sorries. No statement or signature changes.
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