refactor: route Core.approxPerm through Equiv.Perm.exists_extending_pair (−31 lines)#20
Merged
Merged
Conversation
The previous implementation built `approxPerm : Perm (Fin (permBound π n))`
by first constructing a 32-line subtype equivalence `approxEquiv` (between
`{x // x < n}` and `{x // ∃ j : Fin n, x = π j}`) and then calling
`.extendSubtype`. This is exactly the pattern mathlib's
`Equiv.Perm.exists_extending_pair` (landed via mathlib #34599) abstracts.
Refactor:
- Add `private theorem exists_approxPerm` packaging the existence witness
via `Equiv.Perm.exists_extending_pair` with
`f = Fin.castLE (le_permBound π n)` and
`g i = ⟨π i, lt_permBound_fin (π:=π) (n:=n) (i:=i)⟩`.
- `approxPerm` becomes `Classical.choose exists_approxPerm`.
- `approxPerm_apply_cast` becomes `Classical.choose_spec exists_approxPerm i`.
- `approxPerm_apply_cast_coe` (coercion wrapper) is unchanged.
The unused local helper `approxEquiv` is removed. `approxPerm`,
`approxPerm_apply_cast`, and `approxPerm_apply_cast_coe` keep their
signatures and behavior, so downstream callers (`marginals_perm_eq`) are
unaffected. The enclosing `noncomputable section` covers the new
`Classical.choose` usage; no new `noncomputable` keyword is needed.
Axiom footprint is identical: `Equiv.extendSubtype` already pulled in
`Classical.choice`.
- Exchangeability/Core.lean: -31 net lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Second in the post-bump series of targeted mathlib-refactor PRs (after #18). Routes
Core.approxPermthrough the sameEquiv.Perm.exists_extending_pairAPI (mathlib #34599) that PR #18 used forexists_perm_extending_strictMono.Net diff: 1 file, +14 / −45 (−31 lines) in
Exchangeability/Core.lean.Why this PR is focused on Core.approxPerm only
Core.approxPerm(line 547) and its supportingapproxEquiv(line 511) used the exact same pattern that PR #18 already removed fromContractability.lean: hand-built subtype equivalence +Equiv.extendSubtype+extendSubtype_apply_of_mem. TheEquiv.Perm.exists_extending_pairmathlib API collapses this directly.Per agreed scope, the
Fin.castLEconsistency cleanup is deferred to a tiny separate PR; this one is just theapproxPermrewrite.What changed
private theorem exists_approxPermpackaging the existence witness viaEquiv.Perm.exists_extending_pairwith:f := Fin.castLE (le_permBound (π:=π) (n:=n))(initial-segment inclusion)g := fun i => ⟨π i, lt_permBound_fin (π:=π) (n:=n) (i:=i)⟩(π-image inclusion)hf := Fin.castLE_injective _hg := fun _ _ hij => Fin.ext (π.injective (Fin.mk.inj hij))(lifts ℕ-injectivity ofπtoFin n-injectivity ofgviaFin.ext)approxPermbody becomesClassical.choose (exists_approxPerm (π:=π) (n:=n)).approxPerm_apply_castbody becomesClassical.choose_spec (exists_approxPerm (π:=π) (n:=n)) i.approxEquiv(the only caller wasapproxPermitself, now gone).approxPerm_apply_cast_coeunchanged (it's a coercion wrapper aroundapproxPerm_apply_cast).approxPerm,approxPerm_apply_cast, andapproxPerm_apply_cast_coekeep their signatures, so the downstream callermarginals_perm_eq(line 593+) is unaffected. Thenoncomputable sectionopened at line 52 already covers the newClassical.chooseusage, so no explicitnoncomputablekeyword is needed.approxEquivwas a publicdefwith no in-repo callers; removing it is a public-API deletion in the narrow sense. Calling it out explicitly: removes unused local helperapproxEquiv; keepsapproxPermand apply lemmas unchanged.Axiom footprint
Identical.
Equiv.extendSubtypealready pulled inClassical.choice; switching toClassical.chooseof anexists_extending_pair-based proof uses the same axiom.Verification
lake buildExchangeability+ForMathlib)Out of scope (planned next tiny PR)
Fin.castLEconsistency cleanup at two sites that don't touch lemma statements:Exchangeability/Contractability.lean:470(call site ofexists_perm_extending_strictMono)Exchangeability/Util/FinsetHelpers.lean:32(
Contractability.lean:408is inside a lemma statement via alet, so aFin.castLEsubstitution there would be statement-level cleanup, not proof-body-only. Deferred unless statement-level cleanup is explicitly in scope.)