Disjoint union of types #
This file defines basic operations on the the sum type α ⊕ β.
α ⊕ β is the type made of a copy of α and a copy of β. It is also called disjoint union.
Main declarations #
Sum.isLeft: Returns whetherx : α ⊕ βcomes from the left component or not.Sum.isRight: Returns whetherx : α ⊕ βcomes from the right component or not.Sum.getLeft: Retrieves the left content of ax : α ⊕ βthat is known to come from the left.Sum.getRight: Retrieves the right content ofx : α ⊕ βthat is known to come from the right.Sum.getLeft?: Retrieves the left content ofx : α ⊕ βas an option type or returnsnoneif it's coming from the right.Sum.getRight?: Retrieves the right content ofx : α ⊕ βas an option type or returnsnoneif it's coming from the left.Sum.map: Mapsα ⊕ βtoγ ⊕ δcomponent-wise.Sum.elim: Nondependent eliminator/induction principle forα ⊕ β.Sum.swap: Mapsα ⊕ βtoβ ⊕ αby swapping components.Sum.LiftRel: The disjoint union of two relations.Sum.Lex: Lexicographic order onα ⊕ βinduced by a relation onαand a relation onβ.
Further material #
See Batteries.Data.Sum.Lemmas for theorems about these definitions.
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.
instance
Sum.instDecidableEq_batteries :
{α : Type u_1} → {β : Type u_2} → [inst : DecidableEq α] → [inst : DecidableEq β] → DecidableEq (α ⊕ β)
Equations
- Sum.instDecidableEq_batteries = Sum.decEqSum✝
inductive
Sum.LiftRel
{α : Type u_1}
{γ : Type u_2}
{β : Type u_3}
{δ : Type u_4}
(r : α → γ → Prop)
(s : β → δ → Prop)
:
Lifts pointwise two relations between α and γ and between β and δ to a relation between
α ⊕ β and γ ⊕ δ.
- inl: ∀ {α : Type u_1} {γ : Type u_2} {β : Type u_3} {δ : Type u_4} {r : α → γ → Prop} {s : β → δ → Prop} {a : α} {c : γ}, r a c → Sum.LiftRel r s (Sum.inl a) (Sum.inl c)
- inr: ∀ {α : Type u_1} {γ : Type u_2} {β : Type u_3} {δ : Type u_4} {r : α → γ → Prop} {s : β → δ → Prop} {b : β} {d : δ}, s b d → Sum.LiftRel r s (Sum.inr b) (Sum.inr d)
Instances For
instance
Sum.instDecidableLiftRel
{α : Type u_1}
{γ : Type u_2}
{β : Type u_3}
{δ : Type u_4}
{r : α → γ → Prop}
{s : β → δ → Prop}
[(a : α) → (c : γ) → Decidable (r a c)]
[(b : β) → (d : δ) → Decidable (s b d)]
(ab : α ⊕ β)
(cd : γ ⊕ δ)
:
Decidable (Sum.LiftRel r s ab cd)
Equations
- One or more equations did not get rendered due to their size.
Lexicographic order for sum. Sort all the inl a before the inr b, otherwise use the
respective order on α or β.
- inl: ∀ {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} {a₁ a₂ : α}, r a₁ a₂ → Sum.Lex r s (Sum.inl a₁) (Sum.inl a₂)
- inr: ∀ {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} {b₁ b₂ : β}, s b₁ b₂ → Sum.Lex r s (Sum.inr b₁) (Sum.inr b₂)
- sep: ∀ {α : Type u_1} {β : Type u_2} {r : α → α → Prop} {s : β → β → Prop} (a : α) (b : β), Sum.Lex r s (Sum.inl a) (Sum.inr b)
Instances For
instance
Sum.instDecidableRelSumLex :
{α : Type u_1} →
{r : α → α → Prop} →
{α_1 : Type u_2} →
{s : α_1 → α_1 → Prop} → [inst : DecidableRel r] → [inst : DecidableRel s] → DecidableRel (Sum.Lex r s)
Equations
- One or more equations did not get rendered due to their size.