The areas / V01. The language of Mathlib
Mathlib.Logic.Equiv.Sum
59 declarations. Mathlib docs · Source
Equivalence between sum types
In this file we continue the work on equivalences begun in Mathlib/Logic/Equiv/Defs.lean, defining
-
canonical isomorphisms between various types: e.g.,
-
Equiv.sumEquivSigmaBoolis the canonical equivalence between the sum of two typesα ⊕ βand the sigma-typeΣ b, bif b then β else α; -
Equiv.prodSumDistrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)shows that type product and type sum satisfy the distributive law up to a canonical equivalence;
-
More definitions of this kind can be found in other files.
E.g., Mathlib/Algebra/Group/TransferInstance.lean does it for Group,
Mathlib/Algebra/Module/TransferInstance.lean does it for Module, and similar files exist for
other algebraic type classes.
Tags
equivalence, congruence, bijective map
def Equiv.psumEquivSum E1 #
(α : Type u_9) → (β : Type u_10) → α ⊕' β ≃ α ⊕ β
PSum is equivalent to Sum.
def Equiv.sumCongr E1 #
{α₁ : Type u_9} → {α₂ : Type u_10} → {β₁ : Type u_11} → {β₂ : Type u_12} → α₁ ≃ α₂ → β₁ ≃ β₂ → α₁ ⊕ β₁ ≃ α₂ ⊕ β₂
If α ≃ α' and β ≃ β', then α ⊕ β ≃ α' ⊕ β'. This is Sum.map as an equivalence.
theorem Equiv.sumCongr_apply E0 #
∀ {α₁ : Type u_9} {α₂ : Type u_10} {β₁ : Type u_11} {β₂ : Type u_12} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (a : α₁ ⊕ β₁),
(ea.sumCongr eb) a = Sum.map (⇑ea) (⇑eb) a
theorem Equiv.sumCongr_trans E0 #
∀ {α₁ : Type u_9} {α₂ : Type u_10} {β₁ : Type u_11} {β₂ : Type u_12} {γ₁ : Type u_13} {γ₂ : Type u_14} (e : α₁ ≃ β₁)
(f : α₂ ≃ β₂) (g : β₁ ≃ γ₁) (h : β₂ ≃ γ₂), (e.sumCongr f).trans (g.sumCongr h) = (e.trans g).sumCongr (f.trans h)
theorem Equiv.sumCongr_symm E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} {δ : Type u_12} (e : α ≃ β) (f : γ ≃ δ),
(e.sumCongr f).symm = e.symm.sumCongr f.symm
theorem Equiv.sumCongr_refl E0 #
∀ {α : Type u_9} {β : Type u_10}, (Equiv.refl α).sumCongr (Equiv.refl β) = Equiv.refl (α ⊕ β)
def Equiv.psumCongr E1 #
{α : Sort u_1} → {β : Sort u_4} → {γ : Sort u_7} → {δ : Sort u_8} → α ≃ β → γ ≃ δ → α ⊕' γ ≃ β ⊕' δ
If α ≃ α' and β ≃ β', then α ⊕' β ≃ α' ⊕' β'.
def Equiv.psumSum E1 #
{α₁ : Sort u_2} → {β₁ : Sort u_5} → {α₂ : Type u_9} → {β₂ : Type u_10} → α₁ ≃ α₂ → β₁ ≃ β₂ → α₁ ⊕' β₁ ≃ α₂ ⊕ β₂
Combine two Equivs using PSum in the domain and Sum in the codomain.
def Equiv.sumPSum E1 #
{α₂ : Sort u_3} → {β₂ : Sort u_6} → {α₁ : Type u_9} → {β₁ : Type u_10} → α₁ ≃ α₂ → β₁ ≃ β₂ → α₁ ⊕ β₁ ≃ α₂ ⊕' β₂
Combine two Equivs using Sum in the domain and PSum in the codomain.
def Equiv.subtypeSum E1 #
{α : Type u_9} → {β : Type u_10} → {p : α ⊕ β → Prop} → { c // p c } ≃ { a // p (Sum.inl a) } ⊕ { b // p (Sum.inr b) }
A subtype of a sum is equivalent to a sum of subtypes.
abbrev Equiv.Perm.sumCongr E1 #
{α : Type u_9} → {β : Type u_10} → Equiv.Perm α → Equiv.Perm β → Equiv.Perm (α ⊕ β)
Combine a permutation of α and of β into a permutation of α ⊕ β.
theorem Equiv.Perm.sumCongr_apply E0 #
∀ {α : Type u_9} {β : Type u_10} (ea : Equiv.Perm α) (eb : Equiv.Perm β) (x : α ⊕ β),
(ea.sumCongr eb) x = Sum.map (⇑ea) (⇑eb) x
theorem Equiv.Perm.sumCongr_trans E1 #
∀ {α : Type u_9} {β : Type u_10} (e : Equiv.Perm α) (f : Equiv.Perm β) (g : Equiv.Perm α) (h : Equiv.Perm β),
Equiv.trans (e.sumCongr f) (g.sumCongr h) = Equiv.Perm.sumCongr (Equiv.trans e g) (Equiv.trans f h)
theorem Equiv.Perm.sumCongr_symm E1 #
∀ {α : Type u_9} {β : Type u_10} (e : Equiv.Perm α) (f : Equiv.Perm β),
Equiv.symm (e.sumCongr f) = Equiv.Perm.sumCongr (Equiv.symm e) (Equiv.symm f)
theorem Equiv.Perm.sumCongr_refl E1 #
∀ {α : Type u_9} {β : Type u_10}, Equiv.Perm.sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α ⊕ β)
def Equiv.boolEquivPUnitSumPUnit E1 #
Bool ≃ PUnit.{u + 1} ⊕ PUnit.{v + 1}
Bool is equivalent the sum of two PUnits.
def Equiv.sumComm E1 #
(α : Type u_9) → (β : Type u_10) → α ⊕ β ≃ β ⊕ α
Sum of types is commutative up to an equivalence. This is Sum.swap as an equivalence.
theorem Equiv.sumComm_apply E0 #
∀ (α : Type u_9) (β : Type u_10), ⇑(Equiv.sumComm α β) = Sum.swap
theorem Equiv.sumComm_symm E0 #
∀ (α : Type u_9) (β : Type u_10), (Equiv.sumComm α β).symm = Equiv.sumComm β α
def Equiv.sumAssoc E1 #
(α : Type u_9) → (β : Type u_10) → (γ : Type u_11) → (α ⊕ β) ⊕ γ ≃ α ⊕ β ⊕ γ
Sum of types is associative up to an equivalence.
theorem Equiv.sumAssoc_apply_inl_inl E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (a : α), (Equiv.sumAssoc α β γ) (Sum.inl (Sum.inl a)) = Sum.inl a
theorem Equiv.sumAssoc_apply_inl_inr E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (b : β),
(Equiv.sumAssoc α β γ) (Sum.inl (Sum.inr b)) = Sum.inr (Sum.inl b)
theorem Equiv.sumAssoc_apply_inr E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (c : γ), (Equiv.sumAssoc α β γ) (Sum.inr c) = Sum.inr (Sum.inr c)
theorem Equiv.sumAssoc_symm_apply_inl E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (a : α), (Equiv.sumAssoc α β γ).symm (Sum.inl a) = Sum.inl (Sum.inl a)
theorem Equiv.sumAssoc_symm_apply_inr_inl E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (b : β),
(Equiv.sumAssoc α β γ).symm (Sum.inr (Sum.inl b)) = Sum.inl (Sum.inr b)
theorem Equiv.sumAssoc_symm_apply_inr_inr E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (c : γ), (Equiv.sumAssoc α β γ).symm (Sum.inr (Sum.inr c)) = Sum.inr c
def Equiv.sumSumSumComm E1 #
(α : Type u_9) → (β : Type u_10) → (γ : Type u_11) → (δ : Type u_12) → (α ⊕ β) ⊕ γ ⊕ δ ≃ (α ⊕ γ) ⊕ β ⊕ δ
Four-way commutativity of sum. The name matches add_add_add_comm.
theorem Equiv.sumSumSumComm_apply E0 #
∀ (α : Type u_9) (β : Type u_10) (γ : Type u_11) (δ : Type u_12) (a : (α ⊕ β) ⊕ γ ⊕ δ),
(Equiv.sumSumSumComm α β γ δ) a =
(⇑(Equiv.sumAssoc (α ⊕ γ) β δ) ∘
Sum.map (⇑(Equiv.sumAssoc α γ β).symm) id ∘
Sum.map (Sum.map id ⇑(Equiv.sumComm β γ)) id ∘
Sum.map (⇑(Equiv.sumAssoc α β γ)) id ∘ ⇑(Equiv.sumAssoc (α ⊕ β) γ δ).symm)
a
theorem Equiv.sumSumSumComm_symm E0 #
∀ (α : Type u_9) (β : Type u_10) (γ : Type u_11) (δ : Type u_12),
(Equiv.sumSumSumComm α β γ δ).symm = Equiv.sumSumSumComm α γ β δ
def Equiv.sumEmpty E1 #
(α : Type u_9) → (β : Type u_10) → [IsEmpty β] → α ⊕ β ≃ α
Sum with IsEmpty is equivalent to the original type.
theorem Equiv.sumEmpty_symm_apply E0 #
∀ (α : Type u_9) (β : Type u_10) [inst : IsEmpty β] (val : α), (Equiv.sumEmpty α β).symm val = Sum.inl val
theorem Equiv.sumEmpty_apply_inl E0 #
∀ {α : Type u_9} {β : Type u_10} [inst : IsEmpty β] (a : α), (Equiv.sumEmpty α β) (Sum.inl a) = a
def Equiv.emptySum E1 #
(α : Type u_9) → (β : Type u_10) → [IsEmpty α] → α ⊕ β ≃ β
The sum of IsEmpty with any type is equivalent to that type.
theorem Equiv.emptySum_symm_apply E0 #
∀ (α : Type u_9) (β : Type u_10) [inst : IsEmpty α] (a : β), (Equiv.emptySum α β).symm a = Sum.inr a
theorem Equiv.emptySum_apply_inr E0 #
∀ {α : Type u_9} {β : Type u_10} [inst : IsEmpty α] (b : β), (Equiv.emptySum α β) (Sum.inr b) = b
def Equiv.sumEquivSigmaBool E1 #
(α β : Type u_9) → α ⊕ β ≃ (b : Bool) × bif b then β else α
α ⊕ β is equivalent to a Sigma-type over Bool. Note that this definition assumes α and
β to be types from the same universe, so it cannot be used directly to transfer theorems about
sigma types to theorems about sum types. In many cases one can use ULift to work around this
difficulty.
def Equiv.sigmaFiberEquiv E1 #
{α : Type u_9} → {β : Type u_10} → (f : α → β) → (y : β) × { x // f x = y } ≃ α
sigmaFiberEquiv f for f : α → β is the natural equivalence between
the type of all fibres of f and the total space α.
theorem Equiv.sigmaFiberEquiv_apply E0 #
∀ {α : Type u_9} {β : Type u_10} (f : α → β) (x : (y : β) × { x // f x = y }), (Equiv.sigmaFiberEquiv f) x = ↑x.snd
theorem Equiv.sigmaFiberEquiv_symm_apply_fst E0 #
∀ {α : Type u_9} {β : Type u_10} (f : α → β) (x : α), ((Equiv.sigmaFiberEquiv f).symm x).fst = f x
theorem Equiv.sigmaFiberEquiv_symm_apply_snd_coe E0 #
∀ {α : Type u_9} {β : Type u_10} (f : α → β) (x : α), ↑((Equiv.sigmaFiberEquiv f).symm x).snd = x
def Equiv.sigmaEquivOptionOfInhabited E1 #
(α : Type u) → [Inhabited α] → [DecidableEq α] → (β : Type u) × (α ≃ Option β)
Inhabited types are equivalent to Option β for some β by identifying default with none.
def Equiv.sumCompl E1 #
{α : Type u_9} → (p : α → Prop) → [DecidablePred p] → { a // p a } ⊕ { a // ¬p a } ≃ α
For any predicate p on α,
the sum of the two subtypes {a // p a} and its complement {a // ¬ p a}
is naturally equivalent to α.
See subtypeOrEquiv for sum types over subtypes {x // p x} and {x // q x}
that are not necessarily IsCompl p q. See also Equiv.Set.sumCompl for a version on sets.
theorem Equiv.sumCompl_apply_inl E0 #
∀ {α : Type u_9} {p : α → Prop} [inst : DecidablePred p] (x : { a // p a }), (Equiv.sumCompl p) (Sum.inl x) = ↑x
theorem Equiv.sumCompl_apply_inr E0 #
∀ {α : Type u_9} {p : α → Prop} [inst : DecidablePred p] (x : { a // ¬p a }), (Equiv.sumCompl p) (Sum.inr x) = ↑x
theorem Equiv.sumCompl_symm_apply_of_pos E0 #
∀ {α : Type u_9} {p : α → Prop} [inst : DecidablePred p] {a : α} (h : p a), (Equiv.sumCompl p).symm a = Sum.inl ⟨a, h⟩
theorem Equiv.sumCompl_symm_apply_of_neg E0 #
∀ {α : Type u_9} {p : α → Prop} [inst : DecidablePred p] {a : α} (h : ¬p a), (Equiv.sumCompl p).symm a = Sum.inr ⟨a, h⟩
theorem Equiv.sumCompl_symm_apply_pos E0 #
∀ {α : Type u_9} {p : α → Prop} [inst : DecidablePred p] (x : { x // p x }), (Equiv.sumCompl p).symm ↑x = Sum.inl x
theorem Equiv.sumCompl_symm_apply_neg E0 #
∀ {α : Type u_9} {p : α → Prop} [inst : DecidablePred p] (x : { x // ¬p x }), (Equiv.sumCompl p).symm ↑x = Sum.inr x
def Equiv.prodSumDistrib E1 #
(α : Type u_9) → (β : Type u_10) → (γ : Type u_11) → α × (β ⊕ γ) ≃ α × β ⊕ α × γ
Type product is left distributive with respect to type sum up to an equivalence.
theorem Equiv.prodSumDistrib_apply_left E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (a : α) (b : β),
(Equiv.prodSumDistrib α β γ) (a, Sum.inl b) = Sum.inl (a, b)
theorem Equiv.prodSumDistrib_apply_right E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (a : α) (c : γ),
(Equiv.prodSumDistrib α β γ) (a, Sum.inr c) = Sum.inr (a, c)
theorem Equiv.prodSumDistrib_symm_apply_left E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (a : α × β),
(Equiv.prodSumDistrib α β γ).symm (Sum.inl a) = (a.1, Sum.inl a.2)
theorem Equiv.prodSumDistrib_symm_apply_right E0 #
∀ {α : Type u_9} {β : Type u_10} {γ : Type u_11} (a : α × γ),
(Equiv.prodSumDistrib α β γ).symm (Sum.inr a) = (a.1, Sum.inr a.2)
def Equiv.sigmaSumDistrib E1 #
{ι : Type u_11} → (α : ι → Type u_9) → (β : ι → Type u_10) → (i : ι) × (α i ⊕ β i) ≃ (i : ι) × α i ⊕ (i : ι) × β i
An indexed sum of disjoint sums of types is equivalent to the sum of the indexed sums. Compare
with Equiv.sumSigmaDistrib which is indexed by sums.
theorem Equiv.sigmaSumDistrib_symm_apply E0 #
∀ {ι : Type u_11} (α : ι → Type u_9) (β : ι → Type u_10) (a : (i : ι) × α i ⊕ (i : ι) × β i),
(Equiv.sigmaSumDistrib α β).symm a = Sum.elim (Sigma.map id fun x ↦ Sum.inl) (Sigma.map id fun x ↦ Sum.inr) a
theorem Equiv.sigmaSumDistrib_apply E0 #
∀ {ι : Type u_11} (α : ι → Type u_9) (β : ι → Type u_10) (p : (i : ι) × (α i ⊕ β i)),
(Equiv.sigmaSumDistrib α β) p = Sum.map (Sigma.mk p.fst) (Sigma.mk p.fst) p.snd
def Equiv.sumSigmaDistrib E1 #
{α : Type u_10} →
{β : Type u_11} → (t : α ⊕ β → Type u_9) → (i : α ⊕ β) × t i ≃ (i : α) × t (Sum.inl i) ⊕ (i : β) × t (Sum.inr i)
A type indexed by disjoint sums of types is equivalent to the sum of the sums. Compare with
Equiv.sigmaSumDistrib which has the sums as the output type.
theorem Equiv.sumSigmaDistrib_symm_apply E0 #
∀ {α : Type u_10} {β : Type u_11} (t : α ⊕ β → Type u_9) (a : (i : α) × t (Sum.inl i) ⊕ (i : β) × t (Sum.inr i)),
(Equiv.sumSigmaDistrib t).symm a = Sum.elim (fun a ↦ ⟨Sum.inl a.fst, a.snd⟩) (fun b ↦ ⟨Sum.inr b.fst, b.snd⟩) a
theorem Equiv.sumSigmaDistrib_apply E0 #
∀ {α : Type u_10} {β : Type u_11} (t : α ⊕ β → Type u_9) (x : (i : α ⊕ β) × t i),
(Equiv.sumSigmaDistrib t) x =
match x with
| ⟨Sum.inl x, y⟩ => Sum.inl ⟨x, y⟩
| ⟨Sum.inr x, y⟩ => Sum.inr ⟨x, y⟩