Skip to content

Commit

Permalink
chore: Move Equiv.sigmaEquivOptionOfInhabited (#10501)
Browse files Browse the repository at this point in the history
This has nothing to do with `Finset`
  • Loading branch information
YaelDillies committed Feb 13, 2024
1 parent 4ed1f68 commit 3b44754
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
23 changes: 1 addition & 22 deletions Mathlib/Data/Finset/Basic.lean
Expand Up @@ -3935,31 +3935,10 @@ end Pairwise
end Finset

namespace Equiv
variable [DecidableEq α] {s t : Finset α}

open Finset

/--
Inhabited types are equivalent to `Option β` for some `β` by identifying `default α` with `none`.
-/
def sigmaEquivOptionOfInhabited (α : Type u) [Inhabited α] [DecidableEq α] :
Σβ : Type u, α ≃ Option β :=
⟨{ x : α // x ≠ default },
{ toFun := fun x : α => if h : x = default then none else some ⟨x, h⟩
invFun := Option.elim' default (↑)
left_inv := fun x => by
dsimp only
split_ifs <;> simp [*]
right_inv := by
rintro (_ | ⟨x, h⟩)
· simp
· dsimp only
split_ifs with hi
· simp [h] at hi
· simp }⟩
#align equiv.sigma_equiv_option_of_inhabited Equiv.sigmaEquivOptionOfInhabited

variable [DecidableEq α] {s t : Finset α}

/-- The disjoint union of finsets is a sum -/
def Finset.union (s t : Finset α) (h : Disjoint s t) :
s ⊕ t ≃ (s ∪ t : Finset α) :=
Expand Down
14 changes: 14 additions & 0 deletions Mathlib/Logic/Equiv/Basic.lean
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Data.Option.Defs
import Mathlib.Data.Prod.Basic
import Mathlib.Data.Sigma.Basic
import Mathlib.Data.Subtype
Expand Down Expand Up @@ -547,6 +548,19 @@ def sigmaFiberEquiv {α β : Type*} (f : α → β) : (Σ y : β, { x // f x = y
#align equiv.sigma_fiber_equiv_symm_apply_fst Equiv.sigmaFiberEquiv_symm_apply_fst
#align equiv.sigma_fiber_equiv_symm_apply_snd_coe Equiv.sigmaFiberEquiv_symm_apply_snd_coe

/-- Inhabited types are equivalent to `Option β` for some `β` by identifying `default` with `none`.
-/
def sigmaEquivOptionOfInhabited (α : Type u) [Inhabited α] [DecidableEq α] :
Σ β : Type u, α ≃ Option β where
fst := {a // a ≠ default}
snd.toFun a := if h : a = default then none else some ⟨a, h⟩
snd.invFun := Option.elim' default (↑)
snd.left_inv a := by dsimp only; split_ifs <;> simp [*]
snd.right_inv
| none => by simp
| some ⟨a, ha⟩ => dif_neg ha
#align equiv.sigma_equiv_option_of_inhabited Equiv.sigmaEquivOptionOfInhabited

end

section sumCompl
Expand Down

0 comments on commit 3b44754

Please sign in to comment.