Disjoint union of types #
This file proves basic results about the sum type α ⊕ β
.
α ⊕ β
is the type made of a copy of α
and a copy of β
. It is also called disjoint union.
Main declarations #
sum.get_left
: Retrieves the left content ofx : α ⊕ β
or returnsnone
if it's coming from the right.sum.get_right
: Retrieves the right content ofx : α ⊕ β
or returnsnone
if it's coming from the left.sum.is_left
: Returns whetherx : α ⊕ β
comes from the left component or not.sum.is_right
: Returns whetherx : α ⊕ β
comes from the right component or not.sum.map
: Mapsα ⊕ β
toγ ⊕ δ
component-wise.sum.elim
: Nondependent eliminator/induction principle forα ⊕ β
.sum.swap
: Mapsα ⊕ β
toβ ⊕ α
by swapping components.sum.lex
: Lexicographic order onα ⊕ β
induced by a relation onα
and a relation onβ
.
Notes #
The definition of sum
takes values in Type*
. This effectively forbids Prop
- valued sum types.
To this effect, we have psum
, which takes value in Sort*
and carries a more complicated
universe signature in consequence. The Prop
version is or
.
@[protected, instance]
def
sum.decidable_eq
(α : Type u)
[a : decidable_eq α]
(β : Type v)
[a_1 : decidable_eq β] :
decidable_eq (α ⊕ β)
@[simp]
@[simp]
@[simp]
theorem
sum.update_elim_inl
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq α]
[decidable_eq (α ⊕ β)]
{f : α → γ}
{g : β → γ}
{i : α}
{x : γ} :
function.update (sum.elim f g) (sum.inl i) x = sum.elim (function.update f i x) g
@[simp]
theorem
sum.update_elim_inr
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq β]
[decidable_eq (α ⊕ β)]
{f : α → γ}
{g : β → γ}
{i : β}
{x : γ} :
function.update (sum.elim f g) (sum.inr i) x = sum.elim f (function.update g i x)
@[simp]
theorem
sum.update_inl_comp_inl
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq α]
[decidable_eq (α ⊕ β)]
{f : α ⊕ β → γ}
{i : α}
{x : γ} :
function.update f (sum.inl i) x ∘ sum.inl = function.update (f ∘ sum.inl) i x
@[simp]
theorem
sum.update_inl_apply_inl
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq α]
[decidable_eq (α ⊕ β)]
{f : α ⊕ β → γ}
{i j : α}
{x : γ} :
function.update f (sum.inl i) x (sum.inl j) = function.update (f ∘ sum.inl) i x j
@[simp]
theorem
sum.update_inl_comp_inr
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq (α ⊕ β)]
{f : α ⊕ β → γ}
{i : α}
{x : γ} :
@[simp]
theorem
sum.update_inl_apply_inr
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq (α ⊕ β)]
{f : α ⊕ β → γ}
{i : α}
{j : β}
{x : γ} :
function.update f (sum.inl i) x (sum.inr j) = f (sum.inr j)
@[simp]
theorem
sum.update_inr_comp_inl
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq (α ⊕ β)]
{f : α ⊕ β → γ}
{i : β}
{x : γ} :
@[simp]
theorem
sum.update_inr_apply_inl
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq (α ⊕ β)]
{f : α ⊕ β → γ}
{i : α}
{j : β}
{x : γ} :
function.update f (sum.inr j) x (sum.inl i) = f (sum.inl i)
@[simp]
theorem
sum.update_inr_comp_inr
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq β]
[decidable_eq (α ⊕ β)]
{f : α ⊕ β → γ}
{i : β}
{x : γ} :
function.update f (sum.inr i) x ∘ sum.inr = function.update (f ∘ sum.inr) i x
@[simp]
theorem
sum.update_inr_apply_inr
{α : Type u}
{β : Type v}
{γ : Type u_1}
[decidable_eq β]
[decidable_eq (α ⊕ β)]
{f : α ⊕ β → γ}
{i j : β}
{x : γ} :
function.update f (sum.inr i) x (sum.inr j) = function.update (f ∘ sum.inr) i x j
@[simp]
@[simp]
inductive
sum.lift_rel
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
(r : α → γ → Prop)
(s : β → δ → Prop) :
- inl : ∀ {α : Type u} {β : Type v} {γ : Type u_1} {δ : Type u_2} {r : α → γ → Prop} {s : β → δ → Prop} {a : α} {c : γ}, r a c → sum.lift_rel r s (sum.inl a) (sum.inl c)
- inr : ∀ {α : Type u} {β : Type v} {γ : Type u_1} {δ : Type u_2} {r : α → γ → Prop} {s : β → δ → Prop} {b : β} {d : δ}, s b d → sum.lift_rel r s (sum.inr b) (sum.inr d)
Lifts pointwise two relations between α
and γ
and between β
and δ
to a relation between
α ⊕ β
and γ ⊕ δ
.
@[simp]
theorem
sum.lift_rel_inl_inl
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r : α → γ → Prop}
{s : β → δ → Prop}
{a : α}
{c : γ} :
sum.lift_rel r s (sum.inl a) (sum.inl c) ↔ r a c
@[simp]
theorem
sum.not_lift_rel_inl_inr
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r : α → γ → Prop}
{s : β → δ → Prop}
{a : α}
{d : δ} :
¬sum.lift_rel r s (sum.inl a) (sum.inr d)
@[simp]
theorem
sum.not_lift_rel_inr_inl
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r : α → γ → Prop}
{s : β → δ → Prop}
{b : β}
{c : γ} :
¬sum.lift_rel r s (sum.inr b) (sum.inl c)
@[simp]
theorem
sum.lift_rel_inr_inr
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r : α → γ → Prop}
{s : β → δ → Prop}
{b : β}
{d : δ} :
sum.lift_rel r s (sum.inr b) (sum.inr d) ↔ s b d
@[protected, instance]
def
sum.lift_rel.decidable
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r : α → γ → Prop}
{s : β → δ → Prop}
[Π (a : α) (c : γ), decidable (r a c)]
[Π (b : β) (d : δ), decidable (s b d)]
(ab : α ⊕ β)
(cd : γ ⊕ δ) :
decidable (sum.lift_rel r s ab cd)
Equations
- sum.lift_rel.decidable (sum.inr b) (sum.inr d) = decidable_of_iff' (s b d) sum.lift_rel_inr_inr
- sum.lift_rel.decidable (sum.inr b) (sum.inl c) = is_false sum.not_lift_rel_inr_inl
- sum.lift_rel.decidable (sum.inl a) (sum.inr d) = is_false sum.not_lift_rel_inl_inr
- sum.lift_rel.decidable (sum.inl a) (sum.inl c) = decidable_of_iff' (r a c) sum.lift_rel_inl_inl
theorem
sum.lift_rel.mono
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r₁ r₂ : α → γ → Prop}
{s₁ s₂ : β → δ → Prop}
{x : α ⊕ β}
{y : γ ⊕ δ}
(hr : ∀ (a : α) (b : γ), r₁ a b → r₂ a b)
(hs : ∀ (a : β) (b : δ), s₁ a b → s₂ a b)
(h : sum.lift_rel r₁ s₁ x y) :
sum.lift_rel r₂ s₂ x y
theorem
sum.lift_rel.mono_left
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r₁ r₂ : α → γ → Prop}
{s : β → δ → Prop}
{x : α ⊕ β}
{y : γ ⊕ δ}
(hr : ∀ (a : α) (b : γ), r₁ a b → r₂ a b)
(h : sum.lift_rel r₁ s x y) :
sum.lift_rel r₂ s x y
theorem
sum.lift_rel.mono_right
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r : α → γ → Prop}
{s₁ s₂ : β → δ → Prop}
{x : α ⊕ β}
{y : γ ⊕ δ}
(hs : ∀ (a : β) (b : δ), s₁ a b → s₂ a b)
(h : sum.lift_rel r s₁ x y) :
sum.lift_rel r s₂ x y
@[protected]
theorem
sum.lift_rel.swap
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r : α → γ → Prop}
{s : β → δ → Prop}
{x : α ⊕ β}
{y : γ ⊕ δ}
(h : sum.lift_rel r s x y) :
sum.lift_rel s r x.swap y.swap
@[simp]
theorem
sum.lift_rel_swap_iff
{α : Type u}
{β : Type v}
{γ : Type u_1}
{δ : Type u_2}
{r : α → γ → Prop}
{s : β → δ → Prop}
{x : α ⊕ β}
{y : γ ⊕ δ} :
sum.lift_rel s r x.swap y.swap ↔ sum.lift_rel r s x y
- inl : ∀ {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} {a₁ a₂ : α}, r a₁ a₂ → sum.lex r s (sum.inl a₁) (sum.inl a₂)
- inr : ∀ {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} {b₁ b₂ : β}, s b₁ b₂ → sum.lex r s (sum.inr b₁) (sum.inr b₂)
- sep : ∀ {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} (a : α) (b : β), sum.lex r s (sum.inl a) (sum.inr b)
Lexicographic order for sum. Sort all the inl a
before the inr b
, otherwise use the
respective order on α
or β
.
@[protected, instance]
def
sum.lex.decidable_rel
{α : Type u}
{β : Type v}
{r : α → α → Prop}
{s : β → β → Prop}
[decidable_rel r]
[decidable_rel s] :
decidable_rel (sum.lex r s)
Equations
- sum.lex.decidable_rel (sum.inr b) (sum.inr d) = decidable_of_iff' (s b d) sum.lex_inr_inr
- sum.lex.decidable_rel (sum.inr b) (sum.inl c) = is_false sum.lex_inr_inl
- sum.lex.decidable_rel (sum.inl a) (sum.inr d) = is_true _
- sum.lex.decidable_rel (sum.inl a) (sum.inl c) = decidable_of_iff' (r a c) sum.lex_inl_inl
@[protected]
theorem
sum.lift_rel.lex
{α : Type u}
{β : Type v}
{r : α → α → Prop}
{s : β → β → Prop}
{a b : α ⊕ β}
(h : sum.lift_rel r s a b) :
sum.lex r s a b
theorem
sum.lex.mono
{α : Type u}
{β : Type v}
{r₁ r₂ : α → α → Prop}
{s₁ s₂ : β → β → Prop}
{x y : α ⊕ β}
(hr : ∀ (a b : α), r₁ a b → r₂ a b)
(hs : ∀ (a b : β), s₁ a b → s₂ a b)
(h : sum.lex r₁ s₁ x y) :
sum.lex r₂ s₂ x y
theorem
sum.lex.mono_left
{α : Type u}
{β : Type v}
{r₁ r₂ : α → α → Prop}
{s : β → β → Prop}
{x y : α ⊕ β}
(hr : ∀ (a b : α), r₁ a b → r₂ a b)
(h : sum.lex r₁ s x y) :
sum.lex r₂ s x y
theorem
sum.lex.mono_right
{α : Type u}
{β : Type v}
{r : α → α → Prop}
{s₁ s₂ : β → β → Prop}
{x y : α ⊕ β}
(hs : ∀ (a b : β), s₁ a b → s₂ a b)
(h : sum.lex r s₁ x y) :
sum.lex r s₂ x y
theorem
sum.lex_wf
{α : Type u}
{β : Type v}
{r : α → α → Prop}
{s : β → β → Prop}
(ha : well_founded r)
(hb : well_founded s) :
well_founded (sum.lex r s)
theorem
function.injective.sum_elim
{α : Type u}
{β : Type v}
{γ : Type u_1}
{f : α → γ}
{g : β → γ}
(hf : function.injective f)
(hg : function.injective g)
(hfg : ∀ (a : α) (b : β), f a ≠ g b) :
function.injective (sum.elim f g)
theorem
function.injective.sum_map
{α : Type u}
{α' : Type w}
{β : Type v}
{β' : Type x}
{f : α → β}
{g : α' → β'}
(hf : function.injective f)
(hg : function.injective g) :
function.injective (sum.map f g)
theorem
function.surjective.sum_map
{α : Type u}
{α' : Type w}
{β : Type v}
{β' : Type x}
{f : α → β}
{g : α' → β'}
(hf : function.surjective f)
(hg : function.surjective g) :
function.surjective (sum.map f g)