Module docstring
{"# Disjoint union of types
Theorems about the definitions introduced in Init.Data.Sum.Basic.
","### Sum.elim ","### Sum.map ","### Sum.swap "}
{"# Disjoint union of types
Theorems about the definitions introduced in Init.Data.Sum.Basic.
","### Sum.elim ","### Sum.map ","### Sum.swap "}
Sum.forall
theorem
{p : α ⊕ β → Prop} : (∀ x, p x) ↔ (∀ a, p (inl a)) ∧ ∀ b, p (inr b)
protected theorem «forall» {p : α ⊕ β → Prop} :
(∀ x, p x) ↔ (∀ a, p (inl a)) ∧ ∀ b, p (inr b) :=
⟨fun h => ⟨fun _ => h _, fun _ => h _⟩, fun ⟨h₁, h₂⟩ => Sum.rec h₁ h₂⟩
Sum.exists
theorem
{p : α ⊕ β → Prop} : (∃ x, p x) ↔ (∃ a, p (inl a)) ∨ ∃ b, p (inr b)
protected theorem «exists» {p : α ⊕ β → Prop} :
(∃ x, p x) ↔ (∃ a, p (inl a)) ∨ ∃ b, p (inr b) :=
⟨ fun
| ⟨inl a, h⟩ => Or.inl ⟨a, h⟩
| ⟨inr b, h⟩ => Or.inr ⟨b, h⟩,
fun
| Or.inl ⟨a, h⟩ => ⟨inl a, h⟩
| Or.inr ⟨b, h⟩ => ⟨inr b, h⟩⟩
Sum.forall_sum
theorem
{γ : α ⊕ β → Sort _} {p : (∀ ab, γ ab) → Prop} : (∀ fab, p fab) ↔ (∀ fa fb, p (Sum.rec fa fb))
theorem forall_sum {γ : α ⊕ β → Sort _} {p : (∀ ab, γ ab) → Prop} :
(∀ fab, p fab) ↔ (∀ fa fb, p (Sum.rec fa fb)) := by
refine ⟨fun h fa fb => h _, fun h fab => ?_⟩
have h1 : fab = Sum.rec (fun a => fab (Sum.inl a)) (fun b => fab (Sum.inr b)) := by
apply funext
rintro (_ | _) <;> rfl
rw [h1]; exact h _ _
Sum.inl_getLeft
theorem
: ∀ (x : α ⊕ β) (h : x.isLeft), inl (x.getLeft h) = x
Sum.inr_getRight
theorem
: ∀ (x : α ⊕ β) (h : x.isRight), inr (x.getRight h) = x
Sum.getLeft?_eq_none_iff
theorem
{x : α ⊕ β} : x.getLeft? = none ↔ x.isRight
@[simp] theorem getLeft?_eq_none_iff {x : α ⊕ β} : x.getLeft? = none ↔ x.isRight := by
cases x <;> simp only [getLeft?, isRight, eq_self_iff_true, reduceCtorEq]
Sum.getRight?_eq_none_iff
theorem
{x : α ⊕ β} : x.getRight? = none ↔ x.isLeft
@[simp] theorem getRight?_eq_none_iff {x : α ⊕ β} : x.getRight? = none ↔ x.isLeft := by
cases x <;> simp only [getRight?, isLeft, eq_self_iff_true, reduceCtorEq]
Sum.getLeft_eq_iff
theorem
(h : x.isLeft) : x.getLeft h = a ↔ x = inl a
@[simp] theorem getLeft_eq_iff (h : x.isLeft) : x.getLeft h = a ↔ x = inl a := by
cases x <;> simp at h ⊢
Sum.getRight_eq_iff
theorem
(h : x.isRight) : x.getRight h = b ↔ x = inr b
@[simp] theorem getRight_eq_iff (h : x.isRight) : x.getRight h = b ↔ x = inr b := by
cases x <;> simp at h ⊢
Sum.getLeft?_eq_some_iff
theorem
: x.getLeft? = some a ↔ x = inl a
@[simp] theorem getLeft?_eq_some_iff : x.getLeft? = some a ↔ x = inl a := by
cases x <;> simp only [getLeft?, Option.some.injEq, inl.injEq, reduceCtorEq]
Sum.getRight?_eq_some_iff
theorem
: x.getRight? = some b ↔ x = inr b
@[simp] theorem getRight?_eq_some_iff : x.getRight? = some b ↔ x = inr b := by
cases x <;> simp only [getRight?, Option.some.injEq, inr.injEq, reduceCtorEq]
Sum.bnot_isLeft
theorem
(x : α ⊕ β) : !x.isLeft = x.isRight
@[simp] theorem bnot_isLeft (x : α ⊕ β) : !x.isLeft = x.isRight := by cases x <;> rfl
Sum.isLeft_eq_false
theorem
{x : α ⊕ β} : x.isLeft = false ↔ x.isRight
@[simp] theorem isLeft_eq_false {x : α ⊕ β} : x.isLeft = false ↔ x.isRight := by cases x <;> simp
Sum.not_isLeft
theorem
{x : α ⊕ β} : ¬x.isLeft ↔ x.isRight
theorem not_isLeft {x : α ⊕ β} : ¬x.isLeft¬x.isLeft ↔ x.isRight := by simp
Sum.bnot_isRight
theorem
(x : α ⊕ β) : !x.isRight = x.isLeft
@[simp] theorem bnot_isRight (x : α ⊕ β) : !x.isRight = x.isLeft := by cases x <;> rfl
Sum.isRight_eq_false
theorem
{x : α ⊕ β} : x.isRight = false ↔ x.isLeft
@[simp] theorem isRight_eq_false {x : α ⊕ β} : x.isRight = false ↔ x.isLeft := by cases x <;> simp
Sum.not_isRight
theorem
{x : α ⊕ β} : ¬x.isRight ↔ x.isLeft
theorem not_isRight {x : α ⊕ β} : ¬x.isRight¬x.isRight ↔ x.isLeft := by simp
Sum.isLeft_iff
theorem
: x.isLeft ↔ ∃ y, x = Sum.inl y
theorem isLeft_iff : x.isLeft ↔ ∃ y, x = Sum.inl y := by cases x <;> simp
Sum.isRight_iff
theorem
: x.isRight ↔ ∃ y, x = Sum.inr y
theorem isRight_iff : x.isRight ↔ ∃ y, x = Sum.inr y := by cases x <;> simp
Sum.inl.inj_iff
theorem
: (inl a : α ⊕ β) = inl b ↔ a = b
theorem inl.inj_iff : (inl a : α ⊕ β) = inl b ↔ a = b := ⟨inl.inj, congrArg _⟩
Sum.inr.inj_iff
theorem
: (inr a : α ⊕ β) = inr b ↔ a = b
theorem inr.inj_iff : (inr a : α ⊕ β) = inr b ↔ a = b := ⟨inr.inj, congrArg _⟩
Sum.inl_ne_inr
theorem
: inl a ≠ inr b
theorem inl_ne_inr : inlinl a ≠ inr b := nofun
Sum.inr_ne_inl
theorem
: inr b ≠ inl a
theorem inr_ne_inl : inrinr b ≠ inl a := nofun
Sum.elim_comp_inl
theorem
(f : α → γ) (g : β → γ) : Sum.elim f g ∘ inl = f
@[simp] theorem elim_comp_inl (f : α → γ) (g : β → γ) : Sum.elimSum.elim f g ∘ inl = f :=
rfl
Sum.elim_comp_inr
theorem
(f : α → γ) (g : β → γ) : Sum.elim f g ∘ inr = g
@[simp] theorem elim_comp_inr (f : α → γ) (g : β → γ) : Sum.elimSum.elim f g ∘ inr = g :=
rfl
Sum.elim_inl_inr
theorem
: @Sum.elim α β _ inl inr = id
@[simp] theorem elim_inl_inr : @Sum.elim α β _ inl inr = id :=
funext fun x => Sum.casesOn x (fun _ => rfl) fun _ => rfl
Sum.comp_elim
theorem
(f : γ → δ) (g : α → γ) (h : β → γ) : f ∘ Sum.elim g h = Sum.elim (f ∘ g) (f ∘ h)
theorem comp_elim (f : γ → δ) (g : α → γ) (h : β → γ) :
f ∘ Sum.elim g h = Sum.elim (f ∘ g) (f ∘ h) :=
funext fun x => Sum.casesOn x (fun _ => rfl) fun _ => rfl
Sum.elim_comp_inl_inr
theorem
(f : α ⊕ β → γ) : Sum.elim (f ∘ inl) (f ∘ inr) = f
@[simp] theorem elim_comp_inl_inr (f : α ⊕ β → γ) :
Sum.elim (f ∘ inl) (f ∘ inr) = f :=
funext fun x => Sum.casesOn x (fun _ => rfl) fun _ => rfl
Sum.elim_eq_iff
theorem
{u u' : α → γ} {v v' : β → γ} : Sum.elim u v = Sum.elim u' v' ↔ u = u' ∧ v = v'
theorem elim_eq_iff {u u' : α → γ} {v v' : β → γ} :
Sum.elimSum.elim u v = Sum.elim u' v' ↔ u = u' ∧ v = v' := by
simp [funext_iff, Sum.forall]
Sum.map_map
theorem
(f' : α' → α'') (g' : β' → β'') (f : α → α') (g : β → β') :
∀ x : Sum α β, (x.map f g).map f' g' = x.map (f' ∘ f) (g' ∘ g)
Sum.map_comp_map
theorem
(f' : α' → α'') (g' : β' → β'') (f : α → α') (g : β → β') : Sum.map f' g' ∘ Sum.map f g = Sum.map (f' ∘ f) (g' ∘ g)
@[simp] theorem map_comp_map (f' : α' → α'') (g' : β' → β'') (f : α → α') (g : β → β') :
Sum.mapSum.map f' g' ∘ Sum.map f g = Sum.map (f' ∘ f) (g' ∘ g) :=
funext <| map_map f' g' f g
Sum.map_id_id
theorem
: Sum.map (@id α) (@id β) = id
Sum.elim_map
theorem
{f₁ : α → β} {f₂ : β → ε} {g₁ : γ → δ} {g₂ : δ → ε} {x} :
Sum.elim f₂ g₂ (Sum.map f₁ g₁ x) = Sum.elim (f₂ ∘ f₁) (g₂ ∘ g₁) x
Sum.elim_comp_map
theorem
{f₁ : α → β} {f₂ : β → ε} {g₁ : γ → δ} {g₂ : δ → ε} : Sum.elim f₂ g₂ ∘ Sum.map f₁ g₁ = Sum.elim (f₂ ∘ f₁) (g₂ ∘ g₁)
theorem elim_comp_map {f₁ : α → β} {f₂ : β → ε} {g₁ : γ → δ} {g₂ : δ → ε} :
Sum.elimSum.elim f₂ g₂ ∘ Sum.map f₁ g₁ = Sum.elim (f₂ ∘ f₁) (g₂ ∘ g₁) :=
funext fun _ => elim_map
Sum.isLeft_map
theorem
(f : α → β) (g : γ → δ) (x : α ⊕ γ) : isLeft (x.map f g) = isLeft x
@[simp] theorem isLeft_map (f : α → β) (g : γ → δ) (x : α ⊕ γ) :
isLeft (x.map f g) = isLeft x := by
cases x <;> rfl
Sum.isRight_map
theorem
(f : α → β) (g : γ → δ) (x : α ⊕ γ) : isRight (x.map f g) = isRight x
@[simp] theorem isRight_map (f : α → β) (g : γ → δ) (x : α ⊕ γ) :
isRight (x.map f g) = isRight x := by
cases x <;> rfl
Sum.getLeft?_map
theorem
(f : α → β) (g : γ → δ) (x : α ⊕ γ) : (x.map f g).getLeft? = x.getLeft?.map f
Sum.getRight?_map
theorem
(f : α → β) (g : γ → δ) (x : α ⊕ γ) : (x.map f g).getRight? = x.getRight?.map g
Sum.swap_swap
theorem
(x : α ⊕ β) : swap (swap x) = x
Sum.swap_swap_eq
theorem
: swap ∘ swap = @id (α ⊕ β)
@[simp] theorem swap_swap_eq : swapswap ∘ swap = @id (α ⊕ β) := funext <| swap_swap
Sum.isLeft_swap
theorem
(x : α ⊕ β) : x.swap.isLeft = x.isRight
@[simp] theorem isLeft_swap (x : α ⊕ β) : x.swap.isLeft = x.isRight := by cases x <;> rfl
Sum.isRight_swap
theorem
(x : α ⊕ β) : x.swap.isRight = x.isLeft
@[simp] theorem isRight_swap (x : α ⊕ β) : x.swap.isRight = x.isLeft := by cases x <;> rfl
Sum.getLeft?_swap
theorem
(x : α ⊕ β) : x.swap.getLeft? = x.getRight?
@[simp] theorem getLeft?_swap (x : α ⊕ β) : x.swap.getLeft? = x.getRight? := by cases x <;> rfl
Sum.getRight?_swap
theorem
(x : α ⊕ β) : x.swap.getRight? = x.getLeft?
@[simp] theorem getRight?_swap (x : α ⊕ β) : x.swap.getRight? = x.getLeft? := by cases x <;> rfl
Sum.LiftRel.mono
theorem
(hr : ∀ a b, r₁ a b → r₂ a b) (hs : ∀ a b, s₁ a b → s₂ a b) (h : LiftRel r₁ s₁ x y) : LiftRel r₂ s₂ x y
theorem LiftRel.mono (hr : ∀ a b, r₁ a b → r₂ a b) (hs : ∀ a b, s₁ a b → s₂ a b)
(h : LiftRel r₁ s₁ x y) : LiftRel r₂ s₂ x y := by
cases h
· exact LiftRel.inl (hr _ _ ‹_›)
· exact LiftRel.inr (hs _ _ ‹_›)
Sum.LiftRel.mono_left
theorem
(hr : ∀ a b, r₁ a b → r₂ a b) (h : LiftRel r₁ s x y) : LiftRel r₂ s x y
theorem LiftRel.mono_left (hr : ∀ a b, r₁ a b → r₂ a b) (h : LiftRel r₁ s x y) :
LiftRel r₂ s x y :=
(h.mono hr) fun _ _ => id
Sum.LiftRel.mono_right
theorem
(hs : ∀ a b, s₁ a b → s₂ a b) (h : LiftRel r s₁ x y) : LiftRel r s₂ x y
theorem LiftRel.mono_right (hs : ∀ a b, s₁ a b → s₂ a b) (h : LiftRel r s₁ x y) :
LiftRel r s₂ x y :=
h.mono (fun _ _ => id) hs
Sum.LiftRel.swap
theorem
(h : LiftRel r s x y) : LiftRel s r x.swap y.swap
protected theorem LiftRel.swap (h : LiftRel r s x y) : LiftRel s r x.swap y.swap := by
cases h
· exact LiftRel.inr ‹_›
· exact LiftRel.inl ‹_›
Sum.liftRel_swap_iff
theorem
: LiftRel s r x.swap y.swap ↔ LiftRel r s x y
Sum.LiftRel.lex
theorem
{a b : α ⊕ β} (h : LiftRel r s a b) : Lex r s a b
Sum.liftRel_subrelation_lex
theorem
: Subrelation (LiftRel r s) (Lex r s)
theorem liftRel_subrelation_lex : Subrelation (LiftRel r s) (Lex r s) := LiftRel.lex
Sum.Lex.mono
theorem
(hr : ∀ a b, r₁ a b → r₂ a b) (hs : ∀ a b, s₁ a b → s₂ a b) (h : Lex r₁ s₁ x y) : Lex r₂ s₂ x y
Sum.Lex.mono_left
theorem
(hr : ∀ a b, r₁ a b → r₂ a b) (h : Lex r₁ s x y) : Lex r₂ s x y
theorem Lex.mono_left (hr : ∀ a b, r₁ a b → r₂ a b) (h : Lex r₁ s x y) : Lex r₂ s x y :=
(h.mono hr) fun _ _ => id
Sum.Lex.mono_right
theorem
(hs : ∀ a b, s₁ a b → s₂ a b) (h : Lex r s₁ x y) : Lex r s₂ x y
theorem Lex.mono_right (hs : ∀ a b, s₁ a b → s₂ a b) (h : Lex r s₁ x y) : Lex r s₂ x y :=
h.mono (fun _ _ => id) hs
Sum.lex_acc_inl
theorem
(aca : Acc r a) : Acc (Lex r s) (inl a)
Sum.lex_acc_inr
theorem
(aca : ∀ a, Acc (Lex r s) (inl a)) {b} (acb : Acc s b) : Acc (Lex r s) (inr b)
Sum.lex_wf
theorem
(ha : WellFounded r) (hb : WellFounded s) : WellFounded (Lex r s)
theorem lex_wf (ha : WellFounded r) (hb : WellFounded s) : WellFounded (Lex r s) :=
have aca : ∀ a, Acc (Lex r s) (inl a) := fun a => lex_acc_inl (ha.apply a)
⟨fun x => Sum.recOn x aca fun b => lex_acc_inr aca (hb.apply b)⟩
Sum.elim_const_const
theorem
(c : γ) : Sum.elim (const _ c : α → γ) (const _ c : β → γ) = const _ c
Sum.elim_lam_const_lam_const
theorem
(c : γ) : Sum.elim (fun _ : α => c) (fun _ : β => c) = fun _ => c
@[simp] theorem elim_lam_const_lam_const (c : γ) :
Sum.elim (fun _ : α => c) (fun _ : β => c) = fun _ => c :=
Sum.elim_const_const c