doc-next-gen

Init.Data.Option.Lemmas

Module docstring

{"### beq ","### ite ","### pbind ","### pmap ","### pelim ","### LT and LE ","### min and max "}

Option.mem_iff theorem
{a : α} {b : Option α} : a ∈ b ↔ b = some a
Full source
theorem mem_iff {a : α} {b : Option α} : a ∈ ba ∈ b ↔ b = some a := .rfl
Membership in Optional Value iff Equal to Some
Informal description
For any element $a$ of type $\alpha$ and any optional value $b$ of type $\alpha$, the membership relation $a \in b$ holds if and only if $b$ is equal to `some a`.
Option.mem_some theorem
{a b : α} : a ∈ some b ↔ b = a
Full source
theorem mem_some {a b : α} : a ∈ some ba ∈ some b ↔ b = a := by simp
Membership in Some Value iff Equal to That Value
Informal description
For any elements $a$ and $b$ of type $\alpha$, the membership relation $a \in \text{some }b$ holds if and only if $b = a$.
Option.mem_some_self theorem
(a : α) : a ∈ some a
Full source
theorem mem_some_self (a : α) : a ∈ some a := mem_some.2 rfl
Reflexivity of Membership in Some Value: $a \in \text{some }a$
Informal description
For any element $a$ of type $\alpha$, the membership relation $a \in \text{some }a$ holds.
Option.some_ne_none theorem
(x : α) : some x ≠ none
Full source
theorem some_ne_none (x : α) : somesome x ≠ none := nofun
Some is Not None: $\text{some }x \neq \text{none}$
Informal description
For any element $x$ of type $\alpha$, the optional value $\text{some }x$ is not equal to $\text{none}$.
Option.forall theorem
{p : Option α → Prop} : (∀ x, p x) ↔ p none ∧ ∀ x, p (some x)
Full source
protected theorem «forall» {p : Option α → Prop} : (∀ x, p x) ↔ p none ∧ ∀ x, p (some x) :=
  ⟨fun h => ⟨h _, fun _ => h _⟩, fun h x => Option.casesOn x h.1 h.2⟩
Universal Quantification over Option Type: $\forall x, p(x) \leftrightarrow p(\text{none}) \land \forall x, p(\text{some }x)$
Informal description
For any predicate $p$ on optional values of type $\alpha$, the statement $p(x)$ holds for all optional values $x$ if and only if $p(\text{none})$ holds and $p(\text{some }x)$ holds for all $x : \alpha$. In symbols: $$(\forall x, p(x)) \leftrightarrow p(\text{none}) \land (\forall x, p(\text{some }x))$$
Option.exists theorem
{p : Option α → Prop} : (∃ x, p x) ↔ p none ∨ ∃ x, p (some x)
Full source
protected theorem «exists» {p : Option α → Prop} :
    (∃ x, p x) ↔ p none ∨ ∃ x, p (some x) :=
  ⟨fun | ⟨none, hx⟩ => .inl hx | ⟨some x, hx⟩ => .inr ⟨x, hx⟩,
   fun | .inl h => ⟨_, h⟩ | .inr ⟨_, hx⟩ => ⟨_, hx⟩⟩
Existence in Option Type: $\exists x, p(x) \leftrightarrow p(\text{none}) \lor \exists x, p(\text{some }x)$
Informal description
For any predicate $p$ on optional values of type $\alpha$, there exists an optional value satisfying $p$ if and only if either $p(\text{none})$ holds or there exists some $x : \alpha$ such that $p(\text{some }x)$ holds. In symbols: $$(\exists x, p(x)) \leftrightarrow p(\text{none}) \lor (\exists x, p(\text{some }x))$$
Option.get_mem theorem
: ∀ {o : Option α} (h : isSome o), o.get h ∈ o
Full source
theorem get_mem : ∀ {o : Option α} (h : isSome o), o.get h ∈ o
  | some _, _ => rfl
Extracted Value Belongs to Non-Empty Option
Informal description
For any optional value $o$ of type $\alpha$ and a proof $h$ that $o$ is non-empty (i.e., $\text{isSome } o$ holds), the extracted value $o.\text{get } h$ is a member of $o$.
Option.get_of_mem theorem
: ∀ {o : Option α} (h : isSome o), a ∈ o → o.get h = a
Full source
theorem get_of_mem : ∀ {o : Option α} (h : isSome o), a ∈ o → o.get h = a
  | _, _, rfl => rfl
Extracted Value Equals Element in Non-Empty Option
Informal description
For any optional value `o : Option α` with a proof `h` that `o` is of the form `some x`, if `a` is an element of `o` (i.e., `a ∈ o`), then the value extracted from `o` using `h` is equal to `a`. In other words, if `o` is non-empty and contains `a`, then extracting the value from `o` yields `a`.
Option.not_mem_none theorem
(a : α) : a ∉ (none : Option α)
Full source
@[simp] theorem not_mem_none (a : α) : a ∉ (none : Option α) := nofun
No Element in None Option
Informal description
For any element $a$ of type $\alpha$, $a$ is not a member of the `none` option, i.e., $a \notin \text{none}$.
Option.getD_of_ne_none theorem
{x : Option α} (hx : x ≠ none) (y : α) : some (x.getD y) = x
Full source
theorem getD_of_ne_none {x : Option α} (hx : x ≠ none) (y : α) : some (x.getD y) = x := by
  cases x; {contradiction}; rw [getD_some]
Equality of `some(getD x y)` and `x` for Non-`none` Option $x$
Informal description
For any optional value $x : \text{Option } \alpha$ such that $x \neq \text{none}$ and any element $y : \alpha$, the result of applying $\text{getD}$ to $x$ and $y$ wrapped in $\text{some}$ is equal to $x$, i.e., $\text{some}(x.\text{getD } y) = x$.
Option.getD_eq_iff theorem
{o : Option α} {a b} : o.getD a = b ↔ (o = some b ∨ o = none ∧ a = b)
Full source
theorem getD_eq_iff {o : Option α} {a b} : o.getD a = b ↔ (o = some b ∨ o = none ∧ a = b) := by
  cases o <;> simp
Characterization of Option.getD Equality: $o.\text{getD } a = b \leftrightarrow (o = \text{some } b \lor (o = \text{none} \land a = b))$
Informal description
For any optional value $o : \text{Option } \alpha$ and elements $a, b : \alpha$, the equality $o.\text{getD } a = b$ holds if and only if either $o$ is $\text{some } b$, or $o$ is $\text{none}$ and $a = b$.
Option.get!_none theorem
[Inhabited α] : (none : Option α).get! = default
Full source
@[simp] theorem get!_none [Inhabited α] : (none : Option α).get! = default := rfl
Default Value of `get!` on `none` Option
Informal description
For any inhabited type $\alpha$, the function `get!` applied to the `none` option returns the default value of $\alpha$, i.e., $\text{none.get!} = \text{default}$.
Option.get!_some theorem
[Inhabited α] {a : α} : (some a).get! = a
Full source
@[simp] theorem get!_some [Inhabited α] {a : α} : (some a).get! = a := rfl
Extraction from `some` via `get!` returns the value
Informal description
For any type $\alpha$ with a default element (given by `[Inhabited α]`), and for any element $a \in \alpha$, extracting the value from `some a` using `get!` returns $a$, i.e., `(some a).get! = a`.
Option.get_eq_get! theorem
[Inhabited α] : (o : Option α) → {h : o.isSome} → o.get h = o.get!
Full source
theorem get_eq_get! [Inhabited α] : (o : Option α) → {h : o.isSome} → o.get h = o.get!
  | some _, _ => rfl
Equality of `get` and `get!` for Non-Empty Optional Values
Informal description
For any optional value $o : \text{Option } \alpha$ with a default inhabitant (i.e., $[\text{Inhabited } \alpha]$), if $o$ is non-empty (i.e., $\text{isSome } o$ holds), then extracting the value via $\text{get}$ (with proof $h$) is equal to extracting it via $\text{get!}$, i.e., $o.\text{get } h = o.\text{get!}$.
Option.get_eq_getD theorem
{fallback : α} : (o : Option α) → {h : o.isSome} → o.get h = o.getD fallback
Full source
theorem get_eq_getD {fallback : α} : (o : Option α) → {h : o.isSome} → o.get h = o.getD fallback
  | some _, _ => rfl
Equality of `get` and `getD` for Non-Empty Optional Values
Informal description
For any optional value $o : \text{Option } \alpha$ and any fallback value $\text{fallback} : \alpha$, if $o$ is non-empty (i.e., $\text{isSome } o$ holds), then extracting the value from $o$ via $\text{get}$ is equal to extracting it via $\text{getD}$ with the fallback value, i.e., $o.\text{get} h = o.\text{getD fallback}$.
Option.some_get! theorem
[Inhabited α] : (o : Option α) → o.isSome → some (o.get!) = o
Full source
theorem some_get! [Inhabited α] : (o : Option α) → o.isSomesome (o.get!) = o
  | some _, _ => rfl
Reconstruction of Non-Empty Optional Value via `get!`
Informal description
For any optional value $o : \text{Option } \alpha$ with $\alpha$ being an inhabited type, if $o$ is non-empty (i.e., $\text{isSome } o$ holds), then applying $\text{some}$ to the result of $o.\text{get!}$ yields back $o$ itself, i.e., $\text{some}(o.\text{get!}) = o$.
Option.get!_eq_getD theorem
[Inhabited α] (o : Option α) : o.get! = o.getD default
Full source
theorem get!_eq_getD [Inhabited α] (o : Option α) : o.get! = o.getD default := rfl
Equality of `get!` and `getD` with Default Fallback
Informal description
For any type $\alpha$ with a default element (given by `Inhabited α`), and for any optional value $o : \text{Option } \alpha$, the value obtained by `get!` on $o$ is equal to the value obtained by `getD` on $o$ with the default value of $\alpha$ as the fallback, i.e., $o.\text{get!} = o.\text{getD default}$.
Option.get!_eq_getD_default abbrev
Full source
@[deprecated get!_eq_getD (since := "2024-11-18")] abbrev get!_eq_getD_default := @get!_eq_getD
Equality of `get!` and `getD` with Default Fallback
Informal description
For any type $\alpha$ with a default element (given by `Inhabited α`), and for any optional value $o : \text{Option } \alpha$, the value obtained by `get!` on $o$ is equal to the value obtained by `getD` on $o$ with the default value of $\alpha$ as the fallback, i.e., $o.\text{get!} = o.\text{getD default}$.
Option.mem_unique theorem
{o : Option α} {a b : α} (ha : a ∈ o) (hb : b ∈ o) : a = b
Full source
theorem mem_unique {o : Option α} {a b : α} (ha : a ∈ o) (hb : b ∈ o) : a = b :=
  some.inj <| ha ▸ hb
Uniqueness of Elements in an Optional Value
Informal description
For any optional value $o : \text{Option } \alpha$ and any elements $a, b \in \alpha$, if both $a$ and $b$ are members of $o$, then $a = b$.
Option.ext theorem
: ∀ {o₁ o₂ : Option α}, (∀ a, a ∈ o₁ ↔ a ∈ o₂) → o₁ = o₂
Full source
@[ext] theorem ext : ∀ {o₁ o₂ : Option α}, (∀ a, a ∈ o₁a ∈ o₁ ↔ a ∈ o₂) → o₁ = o₂
  | none, none, _ => rfl
  | some _, _, H => ((H _).1 rfl).symm
  | _, some _, H => (H _).2 rfl
Extensionality of Optional Values: Membership Determines Equality
Informal description
For any two optional values $o_1$ and $o_2$ of type $\alpha$, if for every element $a \in \alpha$ we have $a \in o_1$ if and only if $a \in o_2$, then $o_1 = o_2$.
Option.isSome_iff_exists theorem
: isSome x ↔ ∃ a, x = some a
Full source
theorem isSome_iff_exists : isSomeisSome x ↔ ∃ a, x = some a := by cases x <;> simp [isSome]
Existence of Element in Optional Value iff `isSome` is True
Informal description
For any optional value $x$ of type `Option α`, the Boolean check `isSome x` is true if and only if there exists an element $a \in α$ such that $x = \text{some } a$.
Option.isSome_eq_isSome theorem
: (isSome x = isSome y) ↔ (x = none ↔ y = none)
Full source
theorem isSome_eq_isSome : (isSome x = isSome y) ↔ (x = none ↔ y = none) := by
  cases x <;> cases y <;> simp
Equivalence of `isSome` Equality and `none` Equivalence for Optional Values
Informal description
For any optional values $x$ and $y$ of type $\text{Option }\alpha$, the equality $\text{isSome }x = \text{isSome }y$ holds if and only if $x = \text{none}$ is equivalent to $y = \text{none}$.
Option.not_isSome theorem
: isSome a = false ↔ a.isNone = true
Full source
@[simp] theorem not_isSome : isSomeisSome a = false ↔ a.isNone = true := by
  cases a <;> simp
Equivalence of `isSome` and `isNone` for Optional Values
Informal description
For any optional value `a` of type `Option α`, the predicate `isSome a` evaluates to `false` if and only if `a` is `none`.
Option.isSome_iff_ne_none theorem
: o.isSome ↔ o ≠ none
Full source
theorem isSome_iff_ne_none : o.isSome ↔ o ≠ none := by
  cases o <;> simp
Equivalence between `isSome` and Non-Null Option: $o.\text{isSome} \leftrightarrow o \neq \text{none}$
Informal description
For any optional value $o$ of type `Option α`, the boolean value `o.isSome` is true if and only if $o$ is not equal to `none`.
Option.not_isSome_iff_eq_none theorem
: ¬o.isSome ↔ o = none
Full source
theorem not_isSome_iff_eq_none : ¬o.isSome¬o.isSome ↔ o = none := by
  cases o <;> simp
Negation of `isSome` is Equivalent to Equality with `none`
Informal description
For any optional value $o$ of type $\text{Option}\,\alpha$, the negation of $\text{isSome}\,o$ is equivalent to $o$ being equal to $\text{none}$, i.e., $\neg (\text{isSome}\,o) \leftrightarrow o = \text{none}$.
Option.ne_none_iff_isSome theorem
: o ≠ none ↔ o.isSome
Full source
theorem ne_none_iff_isSome : o ≠ noneo ≠ none ↔ o.isSome := by cases o <;> simp
Equivalence of Non-None Optional Value and isSome Check
Informal description
For an optional value $o$ of type $\text{Option } \alpha$, the statement $o \neq \text{none}$ is equivalent to $o.\text{isSome}$ being true.
Option.ne_none_iff_exists theorem
: o ≠ none ↔ ∃ x, some x = o
Full source
theorem ne_none_iff_exists : o ≠ noneo ≠ none ↔ ∃ x, some x = o := by cases o <;> simp
Characterization of Non-None Option Values: $o \neq \text{none} \leftrightarrow \exists x, o = \text{some }x$
Informal description
For an optional value $o$ of type `Option α`, $o$ is not equal to `none` if and only if there exists an element $x$ of type $\alpha$ such that $o = \text{some }x$.
Option.ne_none_iff_exists' theorem
: o ≠ none ↔ ∃ x, o = some x
Full source
theorem ne_none_iff_exists' : o ≠ noneo ≠ none ↔ ∃ x, o = some x :=
  ne_none_iff_exists.trans <| exists_congr fun _ => eq_comm
Characterization of Non-None Option Values: $o \neq \text{none} \leftrightarrow \exists x, o = \text{some }x$
Informal description
For an optional value $o$ of type $\text{Option } \alpha$, $o$ is not equal to $\text{none}$ if and only if there exists an element $x$ of type $\alpha$ such that $o = \text{some }x$.
Option.bex_ne_none theorem
{p : Option α → Prop} : (∃ x, ∃ (_ : x ≠ none), p x) ↔ ∃ x, p (some x)
Full source
theorem bex_ne_none {p : Option α → Prop} : (∃ x, ∃ (_ : x ≠ none), p x) ↔ ∃ x, p (some x) :=
  ⟨fun ⟨x, hx, hp⟩ => ⟨x.get <| ne_none_iff_isSome.1 hx, by rwa [some_get]⟩,
    fun ⟨x, hx⟩ => ⟨some x, some_ne_none x, hx⟩⟩
Existence of Non-None Option Satisfying Predicate is Equivalent to Existence of Some Element Satisfying Predicate
Informal description
For any predicate $p$ on optional values of type $\text{Option } \alpha$, the statement that there exists an optional value $x \neq \text{none}$ satisfying $p(x)$ is equivalent to the statement that there exists an element $x$ of type $\alpha$ such that $p(\text{some }x)$ holds.
Option.ball_ne_none theorem
{p : Option α → Prop} : (∀ x (_ : x ≠ none), p x) ↔ ∀ x, p (some x)
Full source
theorem ball_ne_none {p : Option α → Prop} : (∀ x (_ : x ≠ none), p x) ↔ ∀ x, p (some x) :=
  ⟨fun h x => h (some x) (some_ne_none x),
    fun h x hx => by
      have := h <| x.get <| ne_none_iff_isSome.1 hx
      simp [some_get] at this ⊢
      exact this⟩
Universal Quantification over Non-None Options is Equivalent to Universal Quantification over Some Values
Informal description
For any predicate $p$ on optional values of type $\text{Option } \alpha$, the following equivalence holds: $(\forall x \neq \text{none}, p(x)) \leftrightarrow (\forall x, p(\text{some }x))$.
Option.pure_def theorem
: pure = @some α
Full source
@[simp] theorem pure_def : pure = @some α := rfl
`pure` as `some` in Option Type
Informal description
The function `pure` is equal to the constructor `some` for the type `Option α`.
Option.bind_eq_bind theorem
: bind = @Option.bind α β
Full source
@[simp] theorem bind_eq_bind : bind = @Option.bind α β := rfl
Equality of `bind` and `Option.bind` Operations
Informal description
The function `bind` is equal to the `Option.bind` operation for types `α` and `β`.
Option.bind_some theorem
(x : Option α) : x.bind some = x
Full source
@[simp] theorem bind_some (x : Option α) : x.bind some = x := by cases x <;> rfl
Binding with `some` is the Identity Operation on Optional Values
Informal description
For any optional value $x$ of type $\alpha$, binding $x$ with the `some` function returns $x$ itself, i.e., $x.\text{bind}(\text{some}) = x$.
Option.bind_none theorem
(x : Option α) : x.bind (fun _ => none (α := β)) = none
Full source
@[simp] theorem bind_none (x : Option α) : x.bind (fun _ => none (α := β)) = none := by
  cases x <;> rfl
Binding with Constant None Function Yields None
Informal description
For any optional value $x$ of type $\alpha$, binding $x$ with the constant function that returns `none` (of type $\beta$) results in `none`, i.e., $x.\text{bind}(\lambda \_. \text{none}) = \text{none}$.
Option.bind_eq_some theorem
: x.bind f = some b ↔ ∃ a, x = some a ∧ f a = some b
Full source
theorem bind_eq_some : x.bind f = some b ↔ ∃ a, x = some a ∧ f a = some b := by
  cases x <;> simp
Characterization of Bind Resulting in Some: $x.\text{bind} f = \text{some }b \leftrightarrow \exists a, x = \text{some }a \land f(a) = \text{some }b$
Informal description
For any optional value $x$ of type $\alpha$ and any function $f \colon \alpha \to \text{Option }\beta$, the sequential composition $x.\text{bind} f$ results in $\text{some }b$ if and only if there exists an element $a \in \alpha$ such that $x = \text{some }a$ and $f(a) = \text{some }b$.
Option.bind_eq_none theorem
{o : Option α} {f : α → Option β} : o.bind f = none ↔ ∀ a, o = some a → f a = none
Full source
@[simp] theorem bind_eq_none {o : Option α} {f : α → Option β} :
    o.bind f = none ↔ ∀ a, o = some a → f a = none := by cases o <;> simp
Characterization of Bind Resulting in None: $o.\text{bind} f = \text{none} \leftrightarrow \forall a, o = \text{some }a \to f(a) = \text{none}$
Informal description
For an optional value $o$ of type $\text{Option }\alpha$ and a function $f \colon \alpha \to \text{Option }\beta$, the sequential composition $o.\text{bind} f$ results in `none` if and only if for every element $a \in \alpha$ such that $o = \text{some }a$, the application $f(a)$ results in `none$.
Option.bind_eq_none' theorem
{o : Option α} {f : α → Option β} : o.bind f = none ↔ ∀ b a, a ∈ o → b ∉ f a
Full source
theorem bind_eq_none' {o : Option α} {f : α → Option β} :
    o.bind f = none ↔ ∀ b a, a ∈ o → b ∉ f a := by
  simp only [eq_none_iff_forall_not_mem, not_exists, not_and, mem_def, bind_eq_some]
Characterization of Bind Resulting in None for Optional Values
Informal description
For any optional value $o$ of type $\text{Option }\alpha$ and any function $f \colon \alpha \to \text{Option }\beta$, the sequential composition $o.\text{bind} f$ results in `none` if and only if for every element $a \in \alpha$ such that $a$ is in $o$ (i.e., $o = \text{some }a$), and for every element $b \in \beta$, $b$ is not in $f(a)$ (i.e., $f(a) \neq \text{some }b$).
Option.mem_bind_iff theorem
{o : Option α} {f : α → Option β} : b ∈ o.bind f ↔ ∃ a, a ∈ o ∧ b ∈ f a
Full source
theorem mem_bind_iff {o : Option α} {f : α → Option β} :
    b ∈ o.bind fb ∈ o.bind f ↔ ∃ a, a ∈ o ∧ b ∈ f a := by
  cases o <;> simp
Characterization of Membership in Bind for Optional Values: $b \in o.\text{bind} f \leftrightarrow \exists a \in o, b \in f(a)$
Informal description
For any optional value $o$ of type $\text{Option }\alpha$, any function $f \colon \alpha \to \text{Option }\beta$, and any element $b \in \beta$, the element $b$ is in the result of the sequential composition $o.\text{bind} f$ if and only if there exists an element $a \in \alpha$ such that $a$ is in $o$ and $b$ is in $f(a)$. In other words, $b \in o.\text{bind} f \leftrightarrow \exists a \in \alpha, (a \in o) \land (b \in f(a))$.
Option.bind_comm theorem
{f : α → β → Option γ} (a : Option α) (b : Option β) : (a.bind fun x => b.bind (f x)) = b.bind fun y => a.bind fun x => f x y
Full source
theorem bind_comm {f : α → β → Option γ} (a : Option α) (b : Option β) :
    (a.bind fun x => b.bind (f x)) = b.bind fun y => a.bind fun x => f x y := by
  cases a <;> cases b <;> rfl
Commutativity of Bind for Optional Values
Informal description
For any function $f \colon \alpha \to \beta \to \text{Option } \gamma$ and any optional values $a \colon \text{Option } \alpha$ and $b \colon \text{Option } \beta$, the following equality holds: \[ a.\text{bind} \left( \lambda x, \, b.\text{bind} (f x) \right) = b.\text{bind} \left( \lambda y, \, a.\text{bind} \left( \lambda x, \, f x y \right) \right). \] This expresses the commutativity of the bind operation for optional values.
Option.bind_assoc theorem
(x : Option α) (f : α → Option β) (g : β → Option γ) : (x.bind f).bind g = x.bind fun y => (f y).bind g
Full source
theorem bind_assoc (x : Option α) (f : α → Option β) (g : β → Option γ) :
    (x.bind f).bind g = x.bind fun y => (f y).bind g := by cases x <;> rfl
Associativity of Bind for Optional Values
Informal description
For any optional value $x : \text{Option } \alpha$ and functions $f : \alpha \to \text{Option } \beta$ and $g : \beta \to \text{Option } \gamma$, the following associativity property holds: \[ (x.\text{bind} \, f).\text{bind} \, g = x.\text{bind} \left( \lambda y, \, (f \, y).\text{bind} \, g \right). \]
Option.bind_congr theorem
{α β} {o : Option α} {f g : α → Option β} : (h : ∀ a, o = some a → f a = g a) → o.bind f = o.bind g
Full source
theorem bind_congr {α β} {o : Option α} {f g : α → Option β} :
    (h : ∀ a, o = some a → f a = g a) → o.bind f = o.bind g := by
  cases o <;> simp
Congruence of Bind Operation for Optional Values
Informal description
For any types $\alpha$ and $\beta$, an optional value $o : \text{Option } \alpha$, and functions $f, g : \alpha \to \text{Option } \beta$, if for every $a \in \alpha$ the condition $o = \text{some } a$ implies $f(a) = g(a)$, then the bind operations $o.\text{bind} f$ and $o.\text{bind} g$ are equal.
Option.join_eq_some theorem
: x.join = some a ↔ x = some (some a)
Full source
theorem join_eq_some : x.join = some a ↔ x = some (some a) := by
  simp [bind_eq_some]
Flattening Equivalence for Optional Values: $x.\text{join} = \text{some } a \leftrightarrow x = \text{some}(\text{some } a)$
Informal description
For an optional value $x$ of type $\text{Option}(\text{Option} \alpha)$ and an element $a$ of type $\alpha$, the flattened optional value $x.\text{join}$ equals $\text{some } a$ if and only if $x$ equals $\text{some}(\text{some } a)$.
Option.join_ne_none theorem
: x.join ≠ none ↔ ∃ z, x = some (some z)
Full source
theorem join_ne_none : x.join ≠ nonex.join ≠ none ↔ ∃ z, x = some (some z) := by
  simp only [ne_none_iff_exists', join_eq_some, iff_self]
Non-None Flattening Condition for Nested Optional Values: $x.\text{join} \neq \text{none} \leftrightarrow \exists z, x = \text{some}(\text{some } z)$
Informal description
For an optional value $x$ of type $\text{Option}(\text{Option} \alpha)$, the flattened optional value $x.\text{join}$ is not equal to $\text{none}$ if and only if there exists an element $z$ of type $\alpha$ such that $x = \text{some}(\text{some } z)$.
Option.join_ne_none' theorem
: ¬x.join = none ↔ ∃ z, x = some (some z)
Full source
theorem join_ne_none' : ¬x.join = none¬x.join = none ↔ ∃ z, x = some (some z) :=
  join_ne_none
Non-None Flattening Condition for Nested Optional Values: $\neg x.\text{join} = \text{none} \leftrightarrow \exists z, x = \text{some}(\text{some}\ z)$
Informal description
For a nested optional value $x$ of type $\text{Option}(\text{Option}\ \alpha)$, the flattened value $x.\text{join}$ is not equal to $\text{none}$ if and only if there exists an element $z$ of type $\alpha$ such that $x = \text{some}(\text{some}\ z)$.
Option.join_eq_none theorem
: o.join = none ↔ o = none ∨ o = some none
Full source
theorem join_eq_none : o.join = none ↔ o = none ∨ o = some none :=
  match o with | none | some none | some (some _) => by simp
Flattened Optional Value is None if and only if Input is None or Some None
Informal description
For an optional value $o$ of type $\text{Option}(\text{Option}\ \alpha)$, the flattened value $o.\text{join}$ equals $\text{none}$ if and only if $o$ is either $\text{none}$ or $\text{some}\ \text{none}$.
Option.bind_id_eq_join theorem
{x : Option (Option α)} : x.bind id = x.join
Full source
theorem bind_id_eq_join {x : Option (Option α)} : x.bind id = x.join := rfl
Flattening via Identity Binding in Optional Values
Informal description
For any nested optional value $x$ of type $\text{Option}(\text{Option}\ \alpha)$, the sequential composition of $x$ with the identity function is equal to flattening $x$, i.e., $x.\text{bind}\ \text{id} = x.\text{join}$.
Option.map_eq_map theorem
: Functor.map f = Option.map f
Full source
@[simp] theorem map_eq_map : Functor.map f = Option.map f := rfl
Equality of Functorial Map and Option Map
Informal description
For any function $f : \alpha \to \beta$, the functorial map operation `Functor.map f` on optional values is equal to the `Option.map f` operation.
Option.map_none theorem
: f <$> none = none
Full source
theorem map_none : f <$> none = none := rfl
Functorial Map Preserves None Values
Informal description
For any function $f : \alpha \to \beta$, applying the functorial map of $f$ to the optional value $\text{none}$ results in $\text{none}$, i.e., $f <\$> \text{none} = \text{none}$.
Option.map_some theorem
: f <$> some a = some (f a)
Full source
theorem map_some : f <$> some a = some (f a) := rfl
Functorial Map Preserves Some Values
Informal description
For any function $f : \alpha \to \beta$ and any element $a \in \alpha$, applying the functorial map of $f$ to the optional value $\text{some } a$ results in $\text{some } (f a)$, i.e., $f <\$> \text{some } a = \text{some } (f a)$.
Option.map_eq_some' theorem
: x.map f = some b ↔ ∃ a, x = some a ∧ f a = b
Full source
@[simp] theorem map_eq_some' : x.map f = some b ↔ ∃ a, x = some a ∧ f a = b := by cases x <;> simp
Characterization of Mapped Optional Values: $\text{map } f x = \text{some } b \leftrightarrow \exists a, x = \text{some } a \land f(a) = b$
Informal description
For any optional value $x : \text{Option } \alpha$, function $f : \alpha \to \beta$, and element $b \in \beta$, the mapped value $\text{Option.map } f x$ equals $\text{some } b$ if and only if there exists an element $a \in \alpha$ such that $x = \text{some } a$ and $f(a) = b$. In other words, $x.\text{map } f = \text{some } b \leftrightarrow \exists a, x = \text{some } a \land f(a) = b$.
Option.map_eq_some theorem
: f <$> x = some b ↔ ∃ a, x = some a ∧ f a = b
Full source
theorem map_eq_some : f <$> xf <$> x = some b ↔ ∃ a, x = some a ∧ f a = b := map_eq_some'
Characterization of Mapped Optional Values: $f <\$> x = \text{some } b \leftrightarrow \exists a, x = \text{some } a \land f(a) = b$
Informal description
For any optional value $x : \text{Option } \alpha$, function $f : \alpha \to \beta$, and element $b \in \beta$, the mapped value $f <\$> x$ equals $\text{some } b$ if and only if there exists an element $a \in \alpha$ such that $x = \text{some } a$ and $f(a) = b$. In other words, $f <\$> x = \text{some } b \leftrightarrow \exists a, x = \text{some } a \land f(a) = b$.
Option.map_eq_none' theorem
: x.map f = none ↔ x = none
Full source
@[simp] theorem map_eq_none' : x.map f = none ↔ x = none := by
  cases x <;> simp [map_none', map_some', eq_self_iff_true]
Mapping Preserves `none` in Optional Values
Informal description
For any optional value $x : \text{Option } \alpha$ and function $f : \alpha \to \beta$, the mapped value $\text{Option.map } f x$ is `none` if and only if $x$ itself is `none`. In other words, $x.\text{map } f = \text{none} \leftrightarrow x = \text{none}$.
Option.isSome_map theorem
{x : Option α} : (f <$> x).isSome = x.isSome
Full source
theorem isSome_map {x : Option α} : (f <$> x).isSome = x.isSome := by
  cases x <;> simp
Preservation of `isSome` under Mapping of Optional Values
Informal description
For any optional value $x : \text{Option } \alpha$ and function $f : \alpha \to \beta$, the boolean check whether the mapped value $\text{Option.map } f x$ is `some` is equal to the boolean check whether $x$ itself is `some$. In other words, $(f <$> x).\text{isSome} = x.\text{isSome}$.
Option.isSome_map' theorem
{x : Option α} : (x.map f).isSome = x.isSome
Full source
@[simp] theorem isSome_map' {x : Option α} : (x.map f).isSome = x.isSome := by
  cases x <;> simp
Preservation of `isSome` under Mapping of Optional Values
Informal description
For any optional value $x : \text{Option } \alpha$ and function $f : \alpha \to \beta$, the boolean check whether the mapped value $\text{Option.map } f x$ is `some` is equal to the boolean check whether $x$ itself is `some`. In other words, $(f <$> x).\text{isSome} = x.\text{isSome}$.
Option.isNone_map' theorem
{x : Option α} : (x.map f).isNone = x.isNone
Full source
@[simp] theorem isNone_map' {x : Option α} : (x.map f).isNone = x.isNone := by
  cases x <;> simp
Preservation of `isNone` under Mapping of Optional Values
Informal description
For any optional value $x : \text{Option } \alpha$ and function $f : \alpha \to \beta$, the boolean check whether the mapped value $\text{Option.map } f x$ is `none` is equal to the boolean check whether $x$ itself is `none`. In other words, $(x.\text{map } f).\text{isNone} = x.\text{isNone}$.
Option.map_eq_none theorem
: f <$> x = none ↔ x = none
Full source
theorem map_eq_none : f <$> xf <$> x = none ↔ x = none := map_eq_none'
Mapping Preserves `none` in Optional Values
Informal description
For any optional value $x : \text{Option } \alpha$ and function $f : \alpha \to \beta$, the mapped value $f <$> $x$ is `none` if and only if $x$ itself is `none$.
Option.map_eq_bind theorem
{x : Option α} : x.map f = x.bind (some ∘ f)
Full source
theorem map_eq_bind {x : Option α} : x.map f = x.bind (somesome ∘ f) := by
  cases x <;> simp [Option.bind]
Equivalence of Mapping and Binding with Some Composition
Informal description
For any optional value $x : \text{Option } \alpha$ and function $f : \alpha \to \beta$, the mapping of $f$ over $x$ is equal to binding $x$ with the composition of $\text{some}$ and $f$. In other words, $x.\text{map } f = x.\text{bind } (\text{some} \circ f)$.
Option.map_congr theorem
{x : Option α} (h : ∀ a, a ∈ x → f a = g a) : x.map f = x.map g
Full source
theorem map_congr {x : Option α} (h : ∀ a, a ∈ x → f a = g a) : x.map f = x.map g := by
  cases x <;> simp only [map_none', map_some', h, mem_def]
Congruence of Mapping over Optional Values: $f(a) = g(a)$ for $a \in x$ implies $x.map f = x.map g$
Informal description
For any optional value $x : \text{Option } \alpha$ and functions $f, g : \alpha \to \beta$, if for every $a \in \alpha$ such that $a \in x$ we have $f(a) = g(a)$, then mapping $f$ over $x$ yields the same result as mapping $g$ over $x$, i.e., $x.map f = x.map g$.
Option.map_id_fun theorem
{α : Type u} : Option.map (id : α → α) = id
Full source
@[simp] theorem map_id_fun {α : Type u} : Option.map (id : α → α) = id := by
  funext; simp [map_id]
Identity Mapping Law for Optional Values: $\text{Option.map id} = \text{id}$
Informal description
For any type $\alpha$, the function $\text{Option.map}$ applied to the identity function $\text{id} : \alpha \to \alpha$ is equal to the identity function on $\text{Option } \alpha$. That is, $\text{Option.map id} = \text{id}$ as functions from $\text{Option } \alpha$ to itself.
Option.map_id' theorem
{x : Option α} : (x.map fun a => a) = x
Full source
theorem map_id' {x : Option α} : (x.map fun a => a) = x := congrFun map_id x
Identity Mapping Law for Optional Values: $x.\text{map}(\text{id}) = x$
Informal description
For any optional value $x : \text{Option } \alpha$, mapping the identity function over $x$ yields $x$ itself, i.e., $x.\text{map}(\text{id}) = x$.
Option.map_id_fun' theorem
{α : Type u} : Option.map (fun (a : α) => a) = id
Full source
@[simp] theorem map_id_fun' {α : Type u} : Option.map (fun (a : α) => a) = id := by
  funext; simp [map_id']
Identity Mapping Law for Optional Values: $\text{Option.map}(\text{id}) = \text{id}$
Informal description
For any type $\alpha$, the function $\text{Option.map}$ applied to the identity function $\lambda (a : \alpha), a$ is equal to the identity function on $\text{Option } \alpha$. That is, $\text{Option.map}(\text{id}) = \text{id}$ as functions from $\text{Option } \alpha$ to itself.
Option.get_map theorem
{f : α → β} {o : Option α} {h : (o.map f).isSome} : (o.map f).get h = f (o.get (by simpa using h))
Full source
theorem get_map {f : α → β} {o : Option α} {h : (o.map f).isSome} :
    (o.map f).get h = f (o.get (by simpa using h)) := by
  cases o with
  | none => simp at h
  | some a => simp
Value Extraction Commutes with Mapping for Optional Values: $\text{get}(f <$> $o) = f(\text{get } o)$
Informal description
For any function $f : \alpha \to \beta$ and optional value $o : \text{Option } \alpha$, if the mapped value $o.\text{map } f$ is non-empty (i.e., $\text{isSome } (o.\text{map } f)$ holds), then extracting the value from $o.\text{map } f$ via $\text{get}$ is equal to applying $f$ to the value extracted from $o$ via $\text{get}$ (where the proof that $o$ is non-empty is derived from the proof that $o.\text{map } f$ is non-empty). In other words, $(o.\text{map } f).\text{get } h = f(o.\text{get } h')$, where $h'$ is a proof that $o$ is non-empty constructed from $h$.
Option.map_map theorem
(h : β → γ) (g : α → β) (x : Option α) : (x.map g).map h = x.map (h ∘ g)
Full source
@[simp] theorem map_map (h : β → γ) (g : α → β) (x : Option α) :
    (x.map g).map h = x.map (h ∘ g) := by
  cases x <;> simp only [map_none', map_some', ·∘·]
Composition Law for Option Mapping: $(x.\text{map } g).\text{map } h = x.\text{map } (h \circ g)$
Informal description
For any functions $g : \alpha \to \beta$ and $h : \beta \to \gamma$, and any optional value $x : \text{Option } \alpha$, the composition of mapping $g$ followed by $h$ over $x$ is equal to mapping the composition $h \circ g$ over $x$. In other words, $(x.\text{map } g).\text{map } h = x.\text{map } (h \circ g)$.
Option.comp_map theorem
(h : β → γ) (g : α → β) (x : Option α) : x.map (h ∘ g) = (x.map g).map h
Full source
theorem comp_map (h : β → γ) (g : α → β) (x : Option α) : x.map (h ∘ g) = (x.map g).map h :=
  (map_map ..).symm
Composition Law for Option Mapping: $x.\text{map } (h \circ g) = (x.\text{map } g).\text{map } h$
Informal description
For any functions $g : \alpha \to \beta$ and $h : \beta \to \gamma$, and any optional value $x : \text{Option } \alpha$, the mapping of the composition $h \circ g$ over $x$ is equal to the composition of mapping $g$ followed by $h$ over $x$. In other words, $x.\text{map } (h \circ g) = (x.\text{map } g).\text{map } h$.
Option.map_comp_map theorem
(f : α → β) (g : β → γ) : Option.map g ∘ Option.map f = Option.map (g ∘ f)
Full source
@[simp] theorem map_comp_map (f : α → β) (g : β → γ) :
    Option.mapOption.map g ∘ Option.map f = Option.map (g ∘ f) := by funext x; simp
Composition of Option Maps: $(g \circ f)_{\text{Option}} = g_{\text{Option}} \circ f_{\text{Option}}$
Informal description
For any functions $f : \alpha \to \beta$ and $g : \beta \to \gamma$, the composition of the option maps satisfies $(g \circ f)_{\text{Option}} = g_{\text{Option}} \circ f_{\text{Option}}$, where $h_{\text{Option}}$ denotes the lifting of a function $h$ to operate on optional values via `Option.map`.
Option.mem_map_of_mem theorem
(g : α → β) (h : a ∈ x) : g a ∈ Option.map g x
Full source
theorem mem_map_of_mem (g : α → β) (h : a ∈ x) : g a ∈ Option.map g x := h.symmmap_some' ..
Mapping Preserves Membership in Optional Values
Informal description
For any function $g : \alpha \to \beta$ and any optional value $x : \text{Option } \alpha$, if $a \in x$ (i.e., $x = \text{some } a$), then $g(a) \in \text{Option.map } g \ x$ (i.e., $\text{Option.map } g \ x = \text{some } (g a)$).
Option.map_inj_right theorem
{f : α → β} {o o' : Option α} (w : ∀ x y, f x = f y → x = y) : o.map f = o'.map f ↔ o = o'
Full source
theorem map_inj_right {f : α → β} {o o' : Option α} (w : ∀ x y, f x = f y → x = y) :
    o.map f = o'.map f ↔ o = o' := by
  cases o with
  | none => cases o' <;> simp
  | some a =>
    cases o' with
    | none => simp
    | some a' => simpa using ⟨fun h => w _ _ h, fun h => congrArg f h⟩
Injectivity of Option Mapping under Injective Functions: $\text{map } f \ o = \text{map } f \ o' \leftrightarrow o = o'$
Informal description
For any function $f : \alpha \to \beta$ and optional values $o, o' : \text{Option } \alpha$, if $f$ is injective (i.e., for all $x, y \in \alpha$, $f(x) = f(y)$ implies $x = y$), then the equality $\text{Option.map } f \ o = \text{Option.map } f \ o'$ holds if and only if $o = o'$.
Option.map_if theorem
{f : α → β} [Decidable c] : (if c then some a else none).map f = if c then some (f a) else none
Full source
@[simp] theorem map_if {f : α → β} [Decidable c] :
     (if c then some a else none).map f = if c then some (f a) else none := by
  split <;> rfl
Mapping Preserves Conditional Optional Value: $\text{map}\ f\ (\text{ite}\ c\ (\text{some}\ a)\ \text{none}) = \text{ite}\ c\ (\text{some}\ (f\ a))\ \text{none}$
Informal description
For any function $f : \alpha \to \beta$ and decidable proposition $c$, the mapping of a conditional optional value satisfies: $$\text{map}\ f\ (\text{if } c \text{ then some } a \text{ else none}) = \text{if } c \text{ then some } (f\ a) \text{ else none}$$
Option.map_dif theorem
{f : α → β} [Decidable c] {a : c → α} : (if h : c then some (a h) else none).map f = if h : c then some (f (a h)) else none
Full source
@[simp] theorem map_dif {f : α → β} [Decidable c] {a : c → α} :
     (if h : c then some (a h) else none).map f = if h : c then some (f (a h)) else none := by
  split <;> rfl
Mapping over Dependent If-Then-Else Option: $\text{map } f \circ \text{dite} = \text{dite} \circ (f \circ)$
Informal description
For any function $f : \alpha \to \beta$ and decidable proposition $c$, and for any dependent function $a : c \to \alpha$, the following equality holds: \[ \text{map } f \left( \text{if } h : c \text{ then some } (a h) \text{ else none} \right) = \text{if } h : c \text{ then some } (f (a h)) \text{ else none} \]
Option.filter_none theorem
(p : α → Bool) : none.filter p = none
Full source
@[simp] theorem filter_none (p : α → Bool) : none.filter p = none := rfl
Filtering `none` Returns `none`
Informal description
For any predicate $p : \alpha \to \text{Bool}$, filtering the `none` value of type `Option α` with $p$ returns `none`. That is, $\text{filter}\ p\ \text{none} = \text{none}$.
Option.filter_some theorem
: Option.filter p (some a) = if p a then some a else none
Full source
theorem filter_some : Option.filter p (some a) = if p a then some a else none := rfl
Filtering a Some Value: $\text{Option.filter } p (\text{some } a) = \text{ite } (p a) (\text{some } a) \text{none}$
Informal description
For any predicate $p : \alpha \to \text{Bool}$ and any element $a : \alpha$, the filtered optional value $\text{Option.filter } p (\text{some } a)$ equals $\text{some } a$ if $p(a) = \text{true}$ and equals $\text{none}$ otherwise.
Option.isSome_of_isSome_filter theorem
(p : α → Bool) (o : Option α) (h : (o.filter p).isSome) : o.isSome
Full source
theorem isSome_of_isSome_filter (p : α → Bool) (o : Option α) (h : (o.filter p).isSome) :
    o.isSome := by
  cases o <;> simp at h ⊢
Filtered Optional is Some Implies Original is Some
Informal description
For any predicate $p : \alpha \to \text{Bool}$ and optional value $o : \text{Option } \alpha$, if the filtered optional value $(o.\text{filter } p).\text{isSome}$ is true (i.e., the filtered result is `some a`), then $o.\text{isSome}$ must also be true (i.e., the original optional value must be `some a`).
Option.isSome_filter_of_isSome abbrev
Full source
@[deprecated isSome_of_isSome_filter (since := "2025-03-18")]
abbrev isSome_filter_of_isSome := @isSome_of_isSome_filter
Existence of Filtered Some Value from Original Some Value
Informal description
For any predicate $p : \alpha \to \text{Bool}$ and optional value $o : \text{Option } \alpha$, if $o.\text{isSome}$ is true (i.e., $o$ is of the form $\text{some } a$), then there exists an element $a \in o$ such that $p(a) = \text{true}$ implies $(o.\text{filter } p).\text{isSome}$ is true.
Option.filter_eq_none theorem
{p : α → Bool} : o.filter p = none ↔ o = none ∨ ∀ a, a ∈ o → ¬p a
Full source
@[simp] theorem filter_eq_none {p : α → Bool} :
    o.filter p = none ↔ o = none ∨ ∀ a, a ∈ o → ¬ p a := by
  cases o <;> simp [filter_some]
Characterization of Filtered Optional Value Being None: $o.\text{filter } p = \text{none} \leftrightarrow o = \text{none} \lor \forall a \in o, \neg p(a)$
Informal description
For any predicate $p : \alpha \to \text{Bool}$ and optional value $o : \text{Option } \alpha$, the filtered optional value $o.\text{filter } p$ equals `none` if and only if either $o$ itself is `none`, or for every element $a$ contained in $o$, the predicate $p(a)$ evaluates to `false`.
Option.filter_eq_some theorem
{o : Option α} {p : α → Bool} : o.filter p = some a ↔ a ∈ o ∧ p a
Full source
@[simp] theorem filter_eq_some {o : Option α} {p : α → Bool} :
    o.filter p = some a ↔ a ∈ o ∧ p a := by
  cases o with
  | none => simp
  | some a =>
    simp [filter_some]
    split <;> rename_i h
    · simp only [some.injEq, iff_self_and]
      rintro rfl
      exact h
    · simp only [reduceCtorEq, false_iff, not_and, Bool.not_eq_true]
      rintro rfl
      simpa using h
Characterization of Filtered Optional Value Being Some: $o.\text{filter } p = \text{some } a \leftrightarrow a \in o \land p(a)$
Informal description
For any optional value $o$ of type $\alpha$ and any predicate $p : \alpha \to \text{Bool}$, the filtered optional value $o.\text{filter } p$ equals $\text{some } a$ if and only if $a$ is an element of $o$ and $p(a)$ holds.
Option.mem_filter_iff theorem
{p : α → Bool} {a : α} {o : Option α} : a ∈ o.filter p ↔ a ∈ o ∧ p a
Full source
theorem mem_filter_iff {p : α → Bool} {a : α} {o : Option α} :
    a ∈ o.filter pa ∈ o.filter p ↔ a ∈ o ∧ p a := by
  simp
Membership in Filtered Optional Value: $a \in o.\text{filter } p \leftrightarrow a \in o \land p(a)$
Informal description
For any predicate $p : \alpha \to \text{Bool}$, element $a \in \alpha$, and optional value $o : \text{Option } \alpha$, the element $a$ is in the filtered optional value $o.\text{filter } p$ if and only if $a$ is in $o$ and $p(a)$ holds.
Option.all_guard theorem
(p : α → Prop) [DecidablePred p] (a : α) : Option.all q (guard p a) = (!p a || q a)
Full source
@[simp] theorem all_guard (p : α → Prop) [DecidablePred p] (a : α) :
    Option.all q (guard p a) = (!p a!p a || q a) := by
  simp only [guard]
  split <;> simp_all
Universal Quantification over Guarded Optional Value: $\text{Option.all}\ q\ (\text{guard}\ p\ a) = \neg p(a) \lor q(a)$
Informal description
For any predicate $p : \alpha \to \text{Prop}$ with a decidable instance, any element $a \in \alpha$, and any predicate $q : \alpha \to \text{Bool}$, the following equality holds: $$\text{Option.all}\ q\ (\text{guard}\ p\ a) = (\neg p(a) \lor q(a))$$ where $\text{guard}\ p\ a$ returns $\text{some}\ a$ if $p(a)$ holds and $\text{none}$ otherwise, and $\text{Option.all}\ q\ o$ returns $\text{true}$ if $o$ is $\text{none}$ or $q(a)$ holds for the value $a$ in $o$.
Option.any_guard theorem
(p : α → Prop) [DecidablePred p] (a : α) : Option.any q (guard p a) = (p a && q a)
Full source
@[simp] theorem any_guard (p : α → Prop) [DecidablePred p] (a : α) :
    Option.any q (guard p a) = (p a && q a) := by
  simp only [guard]
  split <;> simp_all
Guard and Any Interaction: $\text{Option.any}\ q\ (\text{guard}\ p\ a) = p(a) \land q(a)$
Informal description
For any predicate $p : \alpha \to \text{Prop}$ with a decidable instance, any element $a \in \alpha$, and any predicate $q : \alpha \to \text{Bool}$, the following equality holds: $$\text{Option.any}\ q\ (\text{guard}\ p\ a) = (p(a) \land q(a))$$ where $\text{guard}\ p\ a$ returns $\text{some}\ a$ if $p(a)$ holds and $\text{none}$ otherwise, and $\text{Option.any}\ q$ checks if $q$ holds for the value inside an $\text{Option}$.
Option.bind_map_comm theorem
{α β} {x : Option (Option α)} {f : α → β} : x.bind (Option.map f) = (x.map (Option.map f)).bind id
Full source
theorem bind_map_comm {α β} {x : Option (Option α)} {f : α → β} :
    x.bind (Option.map f) = (x.map (Option.map f)).bind id := by cases x <;> simp
Commutativity of Bind and Map for Nested Optional Values
Informal description
For any types $\alpha$ and $\beta$, given an optional value $x$ of type $\text{Option}(\text{Option}\ \alpha)$ and a function $f : \alpha \to \beta$, the following equality holds: $$x.\text{bind}(\text{Option.map}\ f) = (x.\text{map}(\text{Option.map}\ f)).\text{bind}(\text{id})$$
Option.bind_map theorem
{f : α → β} {g : β → Option γ} {x : Option α} : (x.map f).bind g = x.bind (g ∘ f)
Full source
theorem bind_map {f : α → β} {g : β → Option γ} {x : Option α} :
    (x.map f).bind g = x.bind (g ∘ f) := by cases x <;> simp
Bind-Map Commutation for Optional Values: $\text{bind}\ (\text{map}\ f\ x)\ g = \text{bind}\ x\ (g \circ f)$
Informal description
For any function $f : \alpha \to \beta$, any function $g : \beta \to \text{Option}\ \gamma$, and any optional value $x : \text{Option}\ \alpha$, the following equality holds: $$ \text{bind}\ (\text{map}\ f\ x)\ g = \text{bind}\ x\ (g \circ f) $$ where $\text{map}\ f$ applies $f$ to the value inside $x$ if it exists, and $\text{bind}$ sequences optional computations.
Option.map_bind theorem
{f : α → Option β} {g : β → γ} {x : Option α} : (x.bind f).map g = x.bind (Option.map g ∘ f)
Full source
@[simp] theorem map_bind {f : α → Option β} {g : β → γ} {x : Option α} :
    (x.bind f).map g = x.bind (Option.mapOption.map g ∘ f) := by cases x <;> simp
Map-Bind Commutation for Optional Values: $\text{map}\ g \circ \text{bind}\ f = \text{bind}\ (\text{map}\ g \circ f)$
Informal description
For any function $f : \alpha \to \text{Option}\ \beta$, any function $g : \beta \to \gamma$, and any optional value $x : \text{Option}\ \alpha$, the following equality holds: $$ \text{map}\ g\ (\text{bind}\ x\ f) = \text{bind}\ x\ (\text{map}\ g \circ f) $$ where $\text{bind}$ sequences optional computations and $\text{map}$ applies a function to the value inside an optional value if it exists.
Option.join_map_eq_map_join theorem
{f : α → β} {x : Option (Option α)} : (x.map (Option.map f)).join = x.join.map f
Full source
theorem join_map_eq_map_join {f : α → β} {x : Option (Option α)} :
    (x.map (Option.map f)).join = x.join.map f := by cases x <;> simp
Join-Map Commutation for Nested Optional Values: $\text{join} \circ \text{map}\ (\text{map}\ f) = \text{map}\ f \circ \text{join}$
Informal description
For any function $f : \alpha \to \beta$ and any nested optional value $x : \text{Option}(\text{Option}\ \alpha)$, the following equality holds: $$ \text{join}(\text{map}\ (\text{map}\ f)\ x) = \text{map}\ f\ (\text{join}\ x) $$ where $\text{join}$ flattens a nested optional value and $\text{map}$ applies a function to the value inside an optional value if it exists.
Option.join_join theorem
{x : Option (Option (Option α))} : x.join.join = (x.map join).join
Full source
theorem join_join {x : Option (Option (Option α))} : x.join.join = (x.map join).join := by
  cases x <;> simp
Associativity of Join for Nested Optional Values: $\text{join} \circ \text{join} = \text{join} \circ \text{map}\ \text{join}$
Informal description
For any triply nested optional value $x : \text{Option}(\text{Option}(\text{Option}\ \alpha))$, flattening twice is equivalent to first mapping the flattening operation and then flattening the result, i.e., $$ \text{join}(\text{join}(x)) = \text{join}(\text{map}\ \text{join}\ x). $$
Option.mem_of_mem_join theorem
{a : α} {x : Option (Option α)} (h : a ∈ x.join) : some a ∈ x
Full source
theorem mem_of_mem_join {a : α} {x : Option (Option α)} (h : a ∈ x.join) : somesome a ∈ x :=
  h.symmjoin_eq_some.1 h
Membership Preservation under Join: $a \in x.\text{join} \implies \text{some } a \in x$
Informal description
For any element $a$ of type $\alpha$ and any nested optional value $x$ of type $\text{Option}(\text{Option}\ \alpha)$, if $a$ is a member of the flattened optional value $x.\text{join}$, then $\text{some } a$ is a member of $x$.
Option.some_orElse theorem
(a : α) (x : Option α) : (some a <|> x) = some a
Full source
@[simp] theorem some_orElse (a : α) (x : Option α) : (some a <|> x) = some a := rfl
Left Identity of "Or Else" Operation for Non-Empty Option
Informal description
For any element $a$ of type $\alpha$ and any optional value $x : \text{Option}\ \alpha$, the "or else" operation applied to $\text{some}\ a$ and $x$ returns $\text{some}\ a$, i.e., $$ (\text{some}\ a <|> x) = \text{some}\ a. $$
Option.none_orElse theorem
(x : Option α) : (none <|> x) = x
Full source
@[simp] theorem none_orElse (x : Option α) : (none <|> x) = x := rfl
Left Identity of "Or Else" Operation with None
Informal description
For any optional value $x$ of type $\text{Option}\,\alpha$, the operation $\text{none} <|> x$ evaluates to $x$.
Option.orElse_none theorem
(x : Option α) : (x <|> none) = x
Full source
@[simp] theorem orElse_none (x : Option α) : (x <|> none) = x := by cases x <;> rfl
Right Identity of "Or Else" with None: $x \text{ or else } \text{none} = x$
Informal description
For any optional value $x$ of type $\text{Option } \alpha$, the operation $x \text{ or else } \text{none}$ is equal to $x$.
Option.map_orElse theorem
{x y : Option α} : (x <|> y).map f = (x.map f <|> y.map f)
Full source
theorem map_orElse {x y : Option α} : (x <|> y).map f = (x.map f <|> y.map f) := by
  cases x <;> simp
Distributivity of Mapping over OrElse for Optional Values
Informal description
For any function $f : \alpha \to \beta$ and optional values $x, y : \text{Option } \alpha$, the mapping of $f$ over the "or else" combination of $x$ and $y$ is equal to the "or else" combination of the mappings of $f$ over $x$ and $y$ respectively. In symbols: $$ \text{map } f (x <|> y) = (\text{map } f x) <|> (\text{map } f y) $$
Option.guard_eq_some theorem
[DecidablePred p] : guard p a = some b ↔ a = b ∧ p a
Full source
@[simp] theorem guard_eq_some [DecidablePred p] : guardguard p a = some b ↔ a = b ∧ p a :=
  if h : p a then by simp [Option.guard, h] else by simp [Option.guard, h]
Guard Function Yields Some if and only if Condition Holds and Values Are Equal: $\text{guard}(p, a) = \text{some }b \leftrightarrow a = b \land p(a)$
Informal description
For a decidable predicate $p$ on a type $\alpha$ and elements $a, b \in \alpha$, the guard function returns $\text{some }b$ if and only if $a = b$ and $p(a)$ holds.
Option.isSome_guard theorem
[DecidablePred p] : (Option.guard p a).isSome ↔ p a
Full source
@[simp] theorem isSome_guard [DecidablePred p] : (Option.guard p a).isSome ↔ p a :=
  if h : p a then by simp [Option.guard, h] else by simp [Option.guard, h]
$\text{isSome }(\text{guard } p a) \leftrightarrow p(a)$
Informal description
For any decidable predicate $p$ on a type $\alpha$ and any element $a \in \alpha$, the optional value $\text{guard } p a$ is of the form $\text{some }x$ (i.e., $\text{isSome }(\text{guard } p a)$ holds) if and only if $p(a)$ holds.
Option.guard_isSome abbrev
Full source
@[deprecated isSome_guard (since := "2025-03-18")]
abbrev guard_isSome := @isSome_guard
Guard Yields Some if and only if Predicate Holds: $\text{isSome }(\text{guard } p a) \leftrightarrow p(a)$
Informal description
For any decidable predicate $p$ on a type $\alpha$ and any element $a \in \alpha$, the optional value $\text{guard } p a$ is of the form $\text{some }x$ (i.e., $\text{isSome }(\text{guard } p a)$ holds) if and only if $p(a)$ holds.
Option.guard_eq_none theorem
[DecidablePred p] : Option.guard p a = none ↔ ¬p a
Full source
@[simp] theorem guard_eq_none [DecidablePred p] : Option.guardOption.guard p a = none ↔ ¬ p a :=
  if h : p a then by simp [Option.guard, h] else by simp [Option.guard, h]
Guard Returns None if and only if Predicate Fails: $\text{guard } p a = \text{none} \leftrightarrow \neg p(a)$
Informal description
For any predicate $p$ on a type $\alpha$ with a decidable instance, and any element $a \in \alpha$, the `Option.guard` function returns `none` if and only if the predicate $p(a)$ does not hold. In other words, $\text{guard } p a = \text{none} \leftrightarrow \neg p(a)$.
Option.guard_pos theorem
[DecidablePred p] (h : p a) : Option.guard p a = some a
Full source
@[simp] theorem guard_pos [DecidablePred p] (h : p a) : Option.guard p a = some a := by
  simp [Option.guard, h]
`Option.guard` Yields `some a` When Predicate Holds
Informal description
For any predicate $p$ on a type $\alpha$ with a decidable instance, and any element $a \in \alpha$, if $p(a)$ holds, then the `Option.guard` function applied to $p$ and $a$ returns $\text{some }a$.
Option.guard_congr theorem
{f g : α → Prop} [DecidablePred f] [DecidablePred g] (h : ∀ a, f a ↔ g a) : guard f = guard g
Full source
@[congr] theorem guard_congr {f g : α → Prop} [DecidablePred f] [DecidablePred g]
    (h : ∀ a, f a ↔ g a):
    guard f = guard g := by
  funext a
  simp [guard, h]
Congruence of Guard Functions under Equivalent Predicates: $\text{guard }f = \text{guard }g$ when $f \leftrightarrow g$
Informal description
For any type $\alpha$ and decidable predicates $f, g : \alpha \to \text{Prop}$, if $f(a) \leftrightarrow g(a)$ holds for all $a \in \alpha$, then the `guard` functions for $f$ and $g$ are equal, i.e., $\text{guard }f = \text{guard }g$.
Option.guard_false theorem
{α} : guard (fun (_ : α) => False) = fun _ => none
Full source
@[simp] theorem guard_false {α} :
    guard (fun (_ : α) => False) = fun _ => none := by
  funext a
  simp [guard]
Guard with False Predicate Always Returns None
Informal description
For any type $\alpha$, the function `guard` applied to the constant false predicate `(fun (_ : α) => False)` is equal to the constant function that always returns `none`. In other words, $\text{guard}(\lambda x. \text{False}) = \lambda x. \text{none}$.
Option.guard_true theorem
{α} : guard (fun (_ : α) => True) = some
Full source
@[simp] theorem guard_true {α} :
    guard (fun (_ : α) => True) = some := by
  funext a
  simp [guard]
Guard with True Predicate Yields Some Constructor
Informal description
For any type $\alpha$, the function `guard` applied to the constant true predicate `fun (_ : α) => True` is equal to the `some` constructor of the `Option` type. That is, $\text{guard}(\lambda x. \text{True}) = \text{some}$.
Option.guard_comp theorem
{p : α → Prop} [DecidablePred p] {f : β → α} : guard p ∘ f = Option.map f ∘ guard (p ∘ f)
Full source
theorem guard_comp {p : α → Prop} [DecidablePred p] {f : β → α} :
    guardguard p ∘ f = Option.mapOption.map f ∘ guard (p ∘ f) := by
  ext1 b
  simp [guard]
Commutativity of Guard and Map: $\text{guard } p \circ f = \text{map } f \circ \text{guard } (p \circ f)$
Informal description
For any decidable predicate $p$ on a type $\alpha$ and any function $f : \beta \to \alpha$, the composition of the guard function for $p$ with $f$ is equal to the composition of the mapping of $f$ over optional values with the guard function for the predicate $p \circ f$. In other words: $$ \text{guard } p \circ f = \text{Option.map } f \circ \text{guard } (p \circ f) $$
Option.liftOrGet_eq_or_eq theorem
{f : α → α → α} (h : ∀ a b, f a b = a ∨ f a b = b) : ∀ o₁ o₂, liftOrGet f o₁ o₂ = o₁ ∨ liftOrGet f o₁ o₂ = o₂
Full source
theorem liftOrGet_eq_or_eq {f : α → α → α} (h : ∀ a b, f a b = a ∨ f a b = b) :
    ∀ o₁ o₂, liftOrGetliftOrGet f o₁ o₂ = o₁ ∨ liftOrGet f o₁ o₂ = o₂
  | none, none => .inl rfl
  | some _, none => .inl rfl
  | none, some _ => .inr rfl
  | some a, some b => by have := h a b; simp [liftOrGet] at this ⊢; exact this
Lifted Operation Preserves Option Equality: $\text{liftOrGet}\, f\, o_1\, o_2 = o_1 \lor \text{liftOrGet}\, f\, o_1\, o_2 = o_2$
Informal description
For any binary function $f : \alpha \to \alpha \to \alpha$ satisfying the property that for all $a, b \in \alpha$, either $f(a, b) = a$ or $f(a, b) = b$, and for any optional values $o_1, o_2 \in \text{Option } \alpha$, the lifted operation satisfies $\text{liftOrGet}\, f\, o_1\, o_2 = o_1$ or $\text{liftOrGet}\, f\, o_1\, o_2 = o_2$.
Option.liftOrGet_none_left theorem
{f} {b : Option α} : liftOrGet f none b = b
Full source
@[simp] theorem liftOrGet_none_left {f} {b : Option α} : liftOrGet f none b = b := by
  cases b <;> rfl
Left Identity Property of Lifted Operation with None
Informal description
For any binary function $f : \alpha \to \alpha \to \alpha$ and optional value $b : \text{Option } \alpha$, the lifted operation satisfies $\text{liftOrGet}\, f\, \text{none}\, b = b$.
Option.liftOrGet_none_right theorem
{f} {a : Option α} : liftOrGet f a none = a
Full source
@[simp] theorem liftOrGet_none_right {f} {a : Option α} : liftOrGet f a none = a := by
  cases a <;> rfl
Right Identity Property of Lifted Operation with None
Informal description
For any binary function $f : \alpha \to \alpha \to \alpha$ and optional value $a : \text{Option } \alpha$, the lifted operation satisfies $\text{liftOrGet}\, f\, a\, \text{none} = a$.
Option.liftOrGet_some_some theorem
{f} {a b : α} : liftOrGet f (some a) (some b) = f a b
Full source
@[simp] theorem liftOrGet_some_some {f} {a b : α} :
  liftOrGet f (some a) (some b) = f a b := rfl
Lifted Operation on Some Values: $\text{liftOrGet}\, f\, (\text{some}\, a)\, (\text{some}\, b) = \text{some}\, (f\, a\, b)$
Informal description
For any binary function $f : \alpha \to \alpha \to \alpha$ and elements $a, b \in \alpha$, applying the lifted operation `liftOrGet` to `some a` and `some b` yields `some (f a b)`, i.e., $\text{liftOrGet}\, f\, (\text{some}\, a)\, (\text{some}\, b) = \text{some}\, (f\, a\, b)$.
Option.elim_none theorem
(x : β) (f : α → β) : none.elim x f = x
Full source
@[simp] theorem elim_none (x : β) (f : α → β) : none.elim x f = x := rfl
Elimination Principle for None Case: $\text{none.elim}\,x\,f = x$
Informal description
For any default value $x \in \beta$ and function $f : \alpha \to \beta$, applying the elimination principle to `none` with default $x$ and function $f$ yields $x$, i.e., $\text{none.elim}\,x\,f = x$.
Option.elim_some theorem
(x : β) (f : α → β) (a : α) : (some a).elim x f = f a
Full source
@[simp] theorem elim_some (x : β) (f : α → β) (a : α) : (some a).elim x f = f a := rfl
Elimination Principle for Some Case: $\text{some}(a).\text{elim}\,x\,f = f(a)$
Informal description
For any default value $x \in \beta$, function $f : \alpha \to \beta$, and element $a \in \alpha$, applying the elimination principle to `some a` with default $x$ and function $f$ yields $f(a)$, i.e., $\text{some}(a).\text{elim}\,x\,f = f(a)$.
Option.getD_map theorem
(f : α → β) (x : α) (o : Option α) : (o.map f).getD (f x) = f (getD o x)
Full source
@[simp] theorem getD_map (f : α → β) (x : α) (o : Option α) :
  (o.map f).getD (f x) = f (getD o x) := by cases o <;> rfl
Commutativity of Mapping and Default Value for Optional Values: $(o.\text{map } f).\text{getD } (f x) = f (o.\text{getD } x)$
Informal description
For any function $f : \alpha \to \beta$, element $x \in \alpha$, and optional value $o \in \text{Option } \alpha$, the following equality holds: $$(o.\text{map } f).\text{getD } (f x) = f (o.\text{getD } x)$$
Option.choice definition
(α : Type _) : Option α
Full source
/--
An optional arbitrary element of a given type.

If `α` is non-empty, then there exists some `v : α` and this arbitrary element is `some v`.
Otherwise, it is `none`.
-/
noncomputable def choice (α : Type _) : Option α :=
  if h : Nonempty α then some (Classical.choice h) else none
Arbitrary element of a type (as an optional value)
Informal description
Given a type $\alpha$, the function `Option.choice` returns an arbitrary element of $\alpha$ wrapped in `some` if $\alpha$ is nonempty (i.e., if there exists at least one element in $\alpha$), and `none` otherwise. The element is chosen nonconstructively using the axiom of choice when $\alpha$ is nonempty.
Option.choice_eq theorem
{α : Type _} [Subsingleton α] (a : α) : choice α = some a
Full source
theorem choice_eq {α : Type _} [Subsingleton α] (a : α) : choice α = some a := by
  simp [choice]
  rw [dif_pos (⟨a⟩ : Nonempty α)]
  simp; apply Subsingleton.elim
Choice Function Yields Unique Element in Subsingleton Types: $\text{choice }\alpha = \text{some }a$
Informal description
For any subsingleton type $\alpha$ (a type with at most one element) and any element $a \in \alpha$, the function `choice` applied to $\alpha$ returns `some a`.
Option.isSome_choice_iff_nonempty theorem
{α : Type _} : (choice α).isSome ↔ Nonempty α
Full source
theorem isSome_choice_iff_nonempty {α : Type _} : (choice α).isSome ↔ Nonempty α :=
  ⟨fun h => ⟨(choice α).get h⟩, fun h => by simp only [choice, dif_pos h, isSome_some]⟩
Nonemptiness of $\alpha$ is Equivalent to `choice α` Being `some x`
Informal description
For any type $\alpha$, the optional value `choice α` is of the form `some x` (i.e., `(choice α).isSome` is true) if and only if $\alpha$ is nonempty (i.e., there exists at least one element in $\alpha$).
Option.choice_isSome_iff_nonempty abbrev
Full source
@[deprecated isSome_choice_iff_nonempty (since := "2025-03-18")]
abbrev choice_isSome_iff_nonempty := @isSome_choice_iff_nonempty
Nonemptiness of $\alpha$ is Equivalent to `choice α` Being `some x`
Informal description
For any type $\alpha$, the optional value `choice α` is of the form `some x` (i.e., `(choice α).isSome` is true) if and only if $\alpha$ is nonempty (i.e., there exists at least one element in $\alpha$).
Option.toList_some theorem
(a : α) : (a : Option α).toList = [a]
Full source
@[simp] theorem toList_some (a : α) : (a : Option α).toList = [a] := rfl
Conversion of `some a` to List Yields Singleton $[a]$
Informal description
For any element $a$ of type $\alpha$, the conversion of the optional value `some a` to a list results in the singleton list $[a]$.
Option.toList_none theorem
(α : Type _) : (none : Option α).toList = []
Full source
@[simp] theorem toList_none (α : Type _) : (none : Option α).toList = [] := rfl
Conversion of `none` to Empty List
Informal description
For any type $\alpha$, converting the `none` value of type `Option α` to a list results in the empty list $[]$.
Option.some_or theorem
: (some a).or o = some a
Full source
@[simp] theorem some_or : (some a).or o = some a := rfl
Right Identity of `or` Operation on `Option` Type: `(some a).or o = some a`
Informal description
For any optional value $o$ of type $\alpha$ and any element $a \in \alpha$, the operation `(some a).or o` equals `some a`.
Option.none_or theorem
: none.or o = o
Full source
@[simp] theorem none_or : none.or o = o := rfl
Left Identity of `or` Operation on `Option` Type: `none.or o = o`
Informal description
For any optional value $o$ of type $\alpha$, the operation `none.or o` equals $o$.
Option.or_eq_right_of_none theorem
{o o' : Option α} (h : o = none) : o.or o' = o'
Full source
theorem or_eq_right_of_none {o o' : Option α} (h : o = none) : o.or o' = o' := by
  cases h; simp
Right Identity of `or` Operation When Left Operand is `none`
Informal description
For any optional values $o$ and $o'$ of type $\alpha$, if $o$ is equal to `none`, then the operation `o.or o'` equals $o'$.
Option.or_some theorem
: (some a).or o = some a
Full source
@[deprecated some_or (since := "2024-11-03")] theorem or_some : (some a).or o = some a := rfl
Right Identity of `or` Operation on `Option` Type: `(some a).or o = some a`
Informal description
For any optional value $o$ of type $\alpha$ and any element $a \in \alpha$, the operation `(some a).or o` equals `some a`.
Option.or_some' theorem
{o : Option α} : o.or (some a) = o.getD a
Full source
/-- This will be renamed to `or_some` once the existing deprecated lemma is removed. -/
@[simp] theorem or_some' {o : Option α} : o.or (some a) = o.getD a := by
  cases o <;> rfl
Option `or` with `some` equals default value: $o \text{ or } \text{some } a = o.\text{getD } a$
Informal description
For any optional value $o$ of type $\alpha$ and any element $a \in \alpha$, the operation $o \text{ or } \text{some } a$ is equal to the default value of $o$ with fallback $a$, i.e., $o.\text{getD } a$.
Option.or_eq_bif theorem
: or o o' = bif o.isSome then o else o'
Full source
theorem or_eq_bif : or o o' = bif o.isSome then o else o' := by
  cases o <;> rfl
Option `or` Operation Equals Boolean Conditional
Informal description
For any optional values $o$ and $o'$ of type $\alpha$, the operation `or o o'` is equal to the Boolean conditional expression `if o.isSome then o else o'`.
Option.isSome_or theorem
: (or o o').isSome = (o.isSome || o'.isSome)
Full source
@[simp] theorem isSome_or : (or o o').isSome = (o.isSome || o'.isSome) := by
  cases o <;> rfl
Preservation of `isSome` under Option `or` Operation
Informal description
For any optional values $o$ and $o'$ of type $\alpha$, the boolean check whether the result of `or o o'` is `some` is equal to the logical disjunction of the checks whether $o$ is `some` and whether $o'$ is `some`. In other words, $(o \text{ or } o').\text{isSome} = o.\text{isSome} \lor o'.\text{isSome}$.
Option.isNone_or theorem
: (or o o').isNone = (o.isNone && o'.isNone)
Full source
@[simp] theorem isNone_or : (or o o').isNone = (o.isNone && o'.isNone) := by
  cases o <;> rfl
Option `or` Operation Yields `none` if and only if Both Operands are `none`
Informal description
For any optional values $o$ and $o'$ of type $\alpha$, the result of `or o o'` is `none` if and only if both $o$ and $o'$ are `none$. In other words, $(o \text{ or } o').\text{isNone} = o.\text{isNone} \land o'.\text{isNone}$.
Option.or_eq_none theorem
: or o o' = none ↔ o = none ∧ o' = none
Full source
@[simp] theorem or_eq_none : oror o o' = none ↔ o = none ∧ o' = none := by
  cases o <;> simp
Option `or` Yields `none` if and only if Both Operands are `none`
Informal description
For any optional values $o$ and $o'$ of type $\text{Option } \alpha$, the result of $o \text{ or } o'$ is `none` if and only if both $o$ and $o'$ are `none`. In other words, $o \text{ or } o' = \text{none} \leftrightarrow o = \text{none} \land o' = \text{none}$.
Option.or_eq_some theorem
: or o o' = some a ↔ o = some a ∨ (o = none ∧ o' = some a)
Full source
@[simp] theorem or_eq_some : oror o o' = some a ↔ o = some a ∨ (o = none ∧ o' = some a) := by
  cases o <;> simp
Characterization of Option.or Result as Some Value: $o \text{ or } o' = \text{some } a \leftrightarrow o = \text{some } a \lor (o = \text{none} \land o' = \text{some } a)$
Informal description
For any optional values $o$ and $o'$ of type $\text{Option } \alpha$ and any element $a \in \alpha$, the result of $o \text{ or } o'$ is equal to $\text{some } a$ if and only if either $o = \text{some } a$, or $o = \text{none}$ and $o' = \text{some } a$.
Option.or_assoc theorem
: or (or o₁ o₂) o₃ = or o₁ (or o₂ o₃)
Full source
theorem or_assoc : or (or o₁ o₂) o₃ = or o₁ (or o₂ o₃) := by
  cases o₁ <;> cases o₂ <;> rfl
Associativity of Option.or: $(o_1 \text{ or } o_2) \text{ or } o_3 = o_1 \text{ or } (o_2 \text{ or } o_3)$
Informal description
For any optional values $o_1, o_2, o_3$ of type $\text{Option } \alpha$, the operation $\text{or}$ is associative, i.e., $(o_1 \text{ or } o_2) \text{ or } o_3 = o_1 \text{ or } (o_2 \text{ or } o_3)$.
Option.instAssociativeOr instance
: Std.Associative (or (α := α))
Full source
instance : Std.Associative (or (α := α)) := ⟨@or_assoc _⟩
Associativity of Option.or Operation
Informal description
The operation `or` on optional values of type `Option α` is associative.
Option.or_none theorem
: or o none = o
Full source
@[simp]
theorem or_none : or o none = o := by
  cases o <;> rfl
Right Identity of Option.or with None: $o \text{ or } \text{none} = o$
Informal description
For any optional value $o$ of type $\text{Option } \alpha$, the operation $\text{or}$ between $o$ and $\text{none}$ yields $o$, i.e., $o \text{ or } \text{none} = o$.
Option.or_eq_left_of_none theorem
{o o' : Option α} (h : o' = none) : o.or o' = o
Full source
theorem or_eq_left_of_none {o o' : Option α} (h : o' = none) : o.or o' = o := by
  cases h; simp
Left Identity of Option.or with None: $\text{or}(o, \text{none}) = o$
Informal description
For any optional values $o, o'$ of type $\text{Option } \alpha$, if $o' = \text{none}$, then the non-short-circuiting choice operation $\text{or}(o, o')$ equals $o$.
Option.instLawfulIdentityOrNone instance
: Std.LawfulIdentity (or (α := α)) none
Full source
instance : Std.LawfulIdentity (or (α := α)) none where
  left_id := @none_or _
  right_id := @or_none _
`none` is the Identity for Optional `or` Operation
Informal description
The operation `or` on optional values of type `Option α` has `none` as a lawful identity element. That is, for any optional value `o`, both `or none o = o` and `or o none = o` hold.
Option.or_self theorem
: or o o = o
Full source
@[simp]
theorem or_self : or o o = o := by
  cases o <;> rfl
Idempotence of Non-short-circuiting Choice for Optional Values
Informal description
For any optional value $o$ of type $\alpha$, the non-short-circuiting choice operation applied to $o$ and itself is equal to $o$, i.e., $\text{or}(o, o) = o$.
Option.instIdempotentOpOr instance
: Std.IdempotentOp (or (α := α))
Full source
instance : Std.IdempotentOp (or (α := α)) := ⟨@or_self _⟩
Idempotence of the `or` Operation on Optional Values
Informal description
The binary operation `or` on optional values of type `α` is idempotent, meaning that for any optional value `o`, `or o o = o`.
Option.or_eq_orElse theorem
: or o o' = o.orElse (fun _ => o')
Full source
theorem or_eq_orElse : or o o' = o.orElse (fun _ => o') := by
  cases o <;> rfl
Equivalence of Non-short-circuiting and Short-circuiting Choice for Optional Values
Informal description
For any optional values $o$ and $o'$ of type $\alpha$, the non-short-circuiting choice operation `or` is equivalent to applying the short-circuiting `orElse` operation with a constant function returning $o'$. That is, $\text{or}(o, o') = \text{orElse}(o, \lambda \_. o')$.
Option.map_or theorem
: f <$> or o o' = (f <$> o).or (f <$> o')
Full source
theorem map_or : f <$> or o o' = (f <$> o).or (f <$> o') := by
  cases o <;> rfl
Mapping Distributes Over Non-short-circuiting Choice for Optional Values
Informal description
For any optional values $o$ and $o'$ of type $\text{Option}\,\alpha$ and any function $f : \alpha \to \beta$, the mapping of $f$ over the non-short-circuiting choice between $o$ and $o'$ is equal to the non-short-circuiting choice between mapping $f$ over $o$ and mapping $f$ over $o'$. That is, $f <\$> (o \text{ or } o') = (f <\$> o) \text{ or } (f <\$> o')$.
Option.map_or' theorem
: (or o o').map f = (o.map f).or (o'.map f)
Full source
theorem map_or' : (or o o').map f = (o.map f).or (o'.map f) := by
  cases o <;> rfl
Mapping Distributes Over Choice for Optional Values
Informal description
For any optional values $o$ and $o'$ of type $\text{Option}\,\alpha$ and any function $f : \alpha \to \beta$, the mapping of $f$ over the choice between $o$ and $o'$ is equal to the choice between mapping $f$ over $o$ and mapping $f$ over $o'$. That is, $(o \text{ or } o').\text{map } f = (o.\text{map } f) \text{ or } (o'.\text{map } f)$.
Option.or_of_isSome theorem
{o o' : Option α} (h : o.isSome) : o.or o' = o
Full source
theorem or_of_isSome {o o' : Option α} (h : o.isSome) : o.or o' = o := by
  match o, h with
  | some _, _ => simp
Behavior of Option.or When First Argument is Some
Informal description
For any optional values $o$ and $o'$ of type $\text{Option}\,\alpha$, if $o$ is of the form $\text{some}\,x$ (i.e., $o.\text{isSome}$ holds), then the result of $o.\text{or}\,o'$ is equal to $o$.
Option.or_of_isNone theorem
{o o' : Option α} (h : o.isNone) : o.or o' = o'
Full source
theorem or_of_isNone {o o' : Option α} (h : o.isNone) : o.or o' = o' := by
  match o, h with
  | none, _ => simp
Behavior of Option.or When First Argument is None
Informal description
For any optional values $o$ and $o'$ of type $\text{Option}\,\alpha$, if $o$ is `none`, then the result of $o.\text{or}\,o'$ is equal to $o'$.
Option.none_beq_none theorem
: ((none : Option α) == none) = true
Full source
@[simp] theorem none_beq_none : ((none : Option α) == none) = true := rfl
Boolean Equality of `none` with `none` is True
Informal description
For any type $\alpha$, the boolean equality comparison between two `none` values of type `Option α` evaluates to `true`.
Option.none_beq_some theorem
(a : α) : ((none : Option α) == some a) = false
Full source
@[simp] theorem none_beq_some (a : α) : ((none : Option α) == some a) = false := rfl
Boolean Inequality of `none` and `some a` in Optional Values
Informal description
For any element $a$ of type $\alpha$, the boolean equality comparison between `none` and `some a` (both of type `Option α`) evaluates to `false$.
Option.some_beq_none theorem
(a : α) : ((some a : Option α) == none) = false
Full source
@[simp] theorem some_beq_none (a : α) : ((some a : Option α) == none) = false := rfl
Boolean Inequality: $\text{some}(a) \neq \text{none}$
Informal description
For any element $a$ of type $\alpha$, the boolean equality comparison between `some a` and `none` (both of type `Option \alpha$) evaluates to `false`.
Option.some_beq_some theorem
{a b : α} : (some a == some b) = (a == b)
Full source
@[simp] theorem some_beq_some {a b : α} : (some a == some b) = (a == b) := rfl
Boolean Equality of `some` Constructors in Optional Values
Informal description
For any elements $a$ and $b$ of type $\alpha$, the boolean equality comparison of the optional values `some a` and `some b` (of type `Option α`) is equal to the boolean equality comparison of $a$ and $b$ themselves. That is, `(some a == some b) = (a == b)`.
Option.reflBEq_iff theorem
: ReflBEq (Option α) ↔ ReflBEq α
Full source
@[simp] theorem reflBEq_iff : ReflBEqReflBEq (Option α) ↔ ReflBEq α := by
  constructor
  · intro h
    constructor
    intro a
    suffices (some a == some a) = true by
      simpa only [some_beq_some]
    simp
  · intro h
    constructor
    · rintro (_ | a) <;> simp
Reflexivity of Boolean Equality for Optional Values: `ReflBEq (Option α) ↔ ReflBEq α`
Informal description
For any type $\alpha$, the boolean equality relation on `Option α` is reflexive if and only if the boolean equality relation on $\alpha$ is reflexive. In other words, `ReflBEq (Option α)` holds precisely when `ReflBEq α` holds.
Option.lawfulBEq_iff theorem
: LawfulBEq (Option α) ↔ LawfulBEq α
Full source
@[simp] theorem lawfulBEq_iff : LawfulBEqLawfulBEq (Option α) ↔ LawfulBEq α := by
  constructor
  · intro h
    constructor
    · intro a b h
      apply Option.some.inj
      apply eq_of_beq
      simpa
    · intro a
      suffices (some a == some a) = true by
        simpa only [some_beq_some]
      simp
  · intro h
    constructor
    · intro a b h
      simpa using h
    · intro a
      simp
Lawful Boolean Equality for Optional Values: $\text{LawfulBEq}(\text{Option}\ \alpha) \leftrightarrow \text{LawfulBEq}(\alpha)$
Informal description
For any type $\alpha$, the boolean equality relation on `Option α` is lawful (i.e., agrees with propositional equality) if and only if the boolean equality relation on $\alpha$ is lawful. In other words, `LawfulBEq (Option α)` holds precisely when `LawfulBEq α` holds.
Option.dite_none_left_eq_some theorem
{p : Prop} [Decidable p] {b : ¬p → Option β} : (if h : p then none else b h) = some a ↔ ∃ h, b h = some a
Full source
@[simp] theorem dite_none_left_eq_some {p : Prop} [Decidable p] {b : ¬pOption β} :
    (if h : p then none else b h) = some a ↔ ∃ h, b h = some a := by
  split <;> simp_all
Equivalence of Dependent If-Then-Else with `none` Left Branch and `some a` to Existence of Proof Making Right Branch `some a`
Informal description
For any decidable proposition $p$ and function $b : \neg p \to \text{Option}\ \beta$, the dependent if-then-else expression `if h : p then none else b h` equals `some a` if and only if there exists a proof $h$ of $\neg p$ such that $b h = \text{some}\ a$.
Option.dite_none_right_eq_some theorem
{p : Prop} [Decidable p] {b : p → Option α} : (if h : p then b h else none) = some a ↔ ∃ h, b h = some a
Full source
@[simp] theorem dite_none_right_eq_some {p : Prop} [Decidable p] {b : p → Option α} :
    (if h : p then b h else none) = some a ↔ ∃ h, b h = some a := by
  split <;> simp_all
Equivalence between dependent if-then-else with `none` in else branch and existence of satisfying input
Informal description
For any decidable proposition $p$ and function $b : p \to \text{Option}\ \alpha$, the dependent if-then-else expression `(if h : p then b h else none)` equals `some a` if and only if there exists a proof $h$ of $p$ such that $b h = \text{some}\ a$.
Option.some_eq_dite_none_left theorem
{p : Prop} [Decidable p] {b : ¬p → Option β} : some a = (if h : p then none else b h) ↔ ∃ h, some a = b h
Full source
@[simp] theorem some_eq_dite_none_left {p : Prop} [Decidable p] {b : ¬pOption β} :
    somesome a = (if h : p then none else b h) ↔ ∃ h, some a = b h := by
  split <;> simp_all
Equivalence of Some with Conditional None Left Branch
Informal description
For any decidable proposition $p$ and function $b : \neg p \to \text{Option}\ \beta$, the equality $\text{some}\ a = (\text{if}\ h : p\ \text{then none else}\ b\ h)$ holds if and only if there exists a proof $h$ of $\neg p$ such that $\text{some}\ a = b\ h$.
Option.some_eq_dite_none_right theorem
{p : Prop} [Decidable p] {b : p → Option α} : some a = (if h : p then b h else none) ↔ ∃ h, some a = b h
Full source
@[simp] theorem some_eq_dite_none_right {p : Prop} [Decidable p] {b : p → Option α} :
    somesome a = (if h : p then b h else none) ↔ ∃ h, some a = b h := by
  split <;> simp_all
Equivalence between Some Equality and Dependent If-Then-Else with None in Right Branch
Informal description
For any decidable proposition $p$ and function $b : p \to \text{Option}\ \alpha$, the equality $\text{some}\ a = \text{dite}\ p\ b\ (\lambda \_, \text{none})$ holds if and only if there exists a proof $h$ of $p$ such that $\text{some}\ a = b\ h$.
Option.ite_none_left_eq_some theorem
{p : Prop} [Decidable p] {b : Option β} : (if p then none else b) = some a ↔ ¬p ∧ b = some a
Full source
@[simp] theorem ite_none_left_eq_some {p : Prop} [Decidable p] {b : Option β} :
    (if p then none else b) = some a ↔ ¬ p ∧ b = some a := by
  split <;> simp_all
Equivalence of Conditional None with Some: $\text{if } p \text{ then none else } b = \text{some } a \leftrightarrow \neg p \land b = \text{some } a$
Informal description
For any proposition $p$ with a decidable instance and any optional value $b : \text{Option} \beta$, the equality `(if p then none else b) = some a` holds if and only if $\neg p$ holds and $b = \text{some } a$.
Option.ite_none_right_eq_some theorem
{p : Prop} [Decidable p] {b : Option α} : (if p then b else none) = some a ↔ p ∧ b = some a
Full source
@[simp] theorem ite_none_right_eq_some {p : Prop} [Decidable p] {b : Option α} :
    (if p then b else none) = some a ↔ p ∧ b = some a := by
  split <;> simp_all
Conditional None in Option Type: $\text{if } p \text{ then } b \text{ else none} = \text{some } a \leftrightarrow p \land b = \text{some } a$
Informal description
For any proposition $p$ with a decidable instance and any optional value $b : \text{Option}\ \alpha$, the equality $\text{if } p \text{ then } b \text{ else none} = \text{some } a$ holds if and only if $p$ is true and $b = \text{some } a$.
Option.some_eq_ite_none_left theorem
{p : Prop} [Decidable p] {b : Option β} : some a = (if p then none else b) ↔ ¬p ∧ some a = b
Full source
@[simp] theorem some_eq_ite_none_left {p : Prop} [Decidable p] {b : Option β} :
    somesome a = (if p then none else b) ↔ ¬ p ∧ some a = b := by
  split <;> simp_all
Equality of Some with Conditional None Left Branch: $\text{some } a = (\text{if } p \text{ then none else } b) \leftrightarrow \neg p \land \text{some } a = b$
Informal description
For any decidable proposition $p$ and any optional value $b : \text{Option } \beta$, the equality $\text{some } a = (\text{if } p \text{ then none else } b)$ holds if and only if $\neg p$ holds and $\text{some } a = b$.
Option.some_eq_ite_none_right theorem
{p : Prop} [Decidable p] {b : Option α} : some a = (if p then b else none) ↔ p ∧ some a = b
Full source
@[simp] theorem some_eq_ite_none_right {p : Prop} [Decidable p] {b : Option α} :
    somesome a = (if p then b else none) ↔ p ∧ some a = b := by
  split <;> simp_all
Equality of Some with Conditional None: $\text{some } a = (\text{if } p \text{ then } b \text{ else none}) \leftrightarrow p \land \text{some } a = b$
Informal description
For any proposition $p$ with a decidable instance and any optional value $b : \text{Option } \alpha$, the equality $\text{some } a = (\text{if } p \text{ then } b \text{ else none})$ holds if and only if $p$ is true and $\text{some } a = b$.
Option.mem_dite_none_left theorem
{x : α} [Decidable p] {l : ¬p → Option α} : (x ∈ if h : p then none else l h) ↔ ∃ h : ¬p, x ∈ l h
Full source
theorem mem_dite_none_left {x : α} [Decidable p] {l : ¬ pOption α} :
    (x ∈ if h : p then none else l h) ↔ ∃ h : ¬ p, x ∈ l h := by
  simp
Membership in Dependent If-Then-Else with None Left Branch
Informal description
For any element $x$ of type $\alpha$ and a decidable proposition $p$, given a function $l : \neg p \to \text{Option } \alpha$, the statement that $x$ belongs to the dependent if-then-else expression `if h : p then none else l h` is equivalent to the existence of a proof $h$ of $\neg p$ such that $x$ belongs to $l(h)$. In symbols: $$x \in (\text{if } h : p \text{ then none else } l(h)) \leftrightarrow \exists h : \neg p, x \in l(h).$$
Option.mem_dite_none_right theorem
{x : α} [Decidable p] {l : p → Option α} : (x ∈ if h : p then l h else none) ↔ ∃ h : p, x ∈ l h
Full source
theorem mem_dite_none_right {x : α} [Decidable p] {l : p → Option α} :
    (x ∈ if h : p then l h else none) ↔ ∃ h : p, x ∈ l h := by
  simp
Membership in Dependent If-Then-Else with None Right Branch: $x \in (\text{if } h : p \text{ then } l(h) \text{ else none}) \leftrightarrow \exists h : p, x \in l(h)$
Informal description
For any element $x$ of type $\alpha$ and a decidable proposition $p$, the statement that $x$ is in the dependent if-then-else expression `if h : p then l h else none` is equivalent to the existence of a proof $h$ of $p$ such that $x$ is in $l(h)$. In symbols: $x \in (\text{if } h : p \text{ then } l(h) \text{ else none}) \leftrightarrow \exists h : p, x \in l(h)$.
Option.mem_ite_none_left theorem
{x : α} [Decidable p] {l : Option α} : (x ∈ if p then none else l) ↔ ¬p ∧ x ∈ l
Full source
theorem mem_ite_none_left {x : α} [Decidable p] {l : Option α} :
    (x ∈ if p then none else l) ↔ ¬ p ∧ x ∈ l := by
  simp
Membership in Conditional Optional Value: $x \in (\text{if } p \text{ then none else } l) \leftrightarrow \neg p \land x \in l$
Informal description
For any element $x$ of type $\alpha$ and a decidable proposition $p$, the statement that $x$ is in the optional value `if p then none else l` is equivalent to the conjunction of $\neg p$ and $x \in l$.
Option.mem_ite_none_right theorem
{x : α} [Decidable p] {l : Option α} : (x ∈ if p then l else none) ↔ p ∧ x ∈ l
Full source
theorem mem_ite_none_right {x : α} [Decidable p] {l : Option α} :
    (x ∈ if p then l else none) ↔ p ∧ x ∈ l := by
  simp
Membership in Conditional Optional Value: $x \in (\text{if } p \text{ then } l \text{ else none}) \leftrightarrow p \land x \in l$
Informal description
For any element $x$ of type $\alpha$ and any proposition $p$ with a decidable instance, the statement that $x$ is in the optional value `if p then l else none` is equivalent to $p$ being true and $x$ being in the optional value $l$.
Option.isSome_dite theorem
{p : Prop} [Decidable p] {b : p → β} : (if h : p then some (b h) else none).isSome = true ↔ p
Full source
@[simp] theorem isSome_dite {p : Prop} [Decidable p] {b : p → β} :
    (if h : p then some (b h) else none).isSome = true ↔ p := by
  split <;> simpa
Dependent If-Then-Else Optional Value is Some if and only if Condition Holds
Informal description
For any decidable proposition $p$ and function $b : p \to \beta$, the boolean value `(if h : p then some (b h) else none).isSome` is `true` if and only if $p$ holds.
Option.isSome_ite theorem
{p : Prop} [Decidable p] : (if p then some b else none).isSome = true ↔ p
Full source
@[simp] theorem isSome_ite {p : Prop} [Decidable p] :
    (if p then some b else none).isSome = true ↔ p := by
  split <;> simpa
Optional Value is `some` if and only if Condition Holds
Informal description
For any proposition $p$ with a decidable instance, the boolean value indicating whether the optional value `if p then some b else none` is `some` is true if and only if $p$ holds.
Option.isSome_dite' theorem
{p : Prop} [Decidable p] {b : ¬p → β} : (if h : p then none else some (b h)).isSome = true ↔ ¬p
Full source
@[simp] theorem isSome_dite' {p : Prop} [Decidable p] {b : ¬ p → β} :
    (if h : p then none else some (b h)).isSome = true ↔ ¬ p := by
  split <;> simpa
Dependent If-Then-Else is `some` if and only if Condition is False
Informal description
For any decidable proposition $p$ and any type $\beta$, the dependent if-then-else expression `if h : p then none else some (b h)` (where $b : \neg p \to \beta$) satisfies that checking whether the result is `some` is equivalent to $\neg p$. In other words, the expression `(if h : p then none else some (b h)).isSome = true` holds if and only if $\neg p$ holds.
Option.isSome_ite' theorem
{p : Prop} [Decidable p] : (if p then none else some b).isSome = true ↔ ¬p
Full source
@[simp] theorem isSome_ite' {p : Prop} [Decidable p] :
    (if p then none else some b).isSome = true ↔ ¬ p := by
  split <;> simpa
Optional Value is `some` if and only if Condition is False
Informal description
For any decidable proposition $p$, the boolean value indicating whether the optional value `if p then none else some b` is `some` is true if and only if $\neg p$ holds. In other words, $(if\ p\ then\ none\ else\ some\ b).isSome = true \leftrightarrow \neg p$.
Option.get_dite theorem
{p : Prop} [Decidable p] (b : p → β) (w) : (if h : p then some (b h) else none).get w = b (by simpa using w)
Full source
@[simp] theorem get_dite {p : Prop} [Decidable p] (b : p → β) (w) :
    (if h : p then some (b h) else none).get w = b (by simpa using w) := by
  split
  · simp
  · exfalso
    simp at w
    contradiction
Extraction from Dependent If-Then-Else with `some` Branch
Informal description
For any decidable proposition $p$ and any type $\beta$, given a function $b : p \to \beta$ and a proof $w$ that the dependent if-then-else expression `if h : p then some (b h) else none` is of the form `some x`, the extracted value is equal to $b$ applied to the proof obtained from $w$. That is, the value extracted from the expression is $b(\text{by simpa using } w)$.
Option.get_ite theorem
{p : Prop} [Decidable p] (h) : (if p then some b else none).get h = b
Full source
@[simp] theorem get_ite {p : Prop} [Decidable p] (h) :
    (if p then some b else none).get h = b := by
  simpa using get_dite (p := p) (fun _ => b) (by simpa using h)
Extraction from If-Then-Else Optional Value
Informal description
For any decidable proposition $p$ and any element $b$ of type $\beta$, if the optional value `if p then some b else none` is of the form `some x`, then the extracted value is equal to $b$.
Option.get_dite' theorem
{p : Prop} [Decidable p] (b : ¬p → β) (w) : (if h : p then none else some (b h)).get w = b (by simpa using w)
Full source
@[simp] theorem get_dite' {p : Prop} [Decidable p] (b : ¬ p → β) (w) :
    (if h : p then none else some (b h)).get w = b (by simpa using w) := by
  split
  · exfalso
    simp at w
    contradiction
  · simp
Extraction from Negated Condition in Optional Value
Informal description
For any decidable proposition $p$ and type $\beta$, given a function $b : \neg p \to \beta$ and a proof $w$ that the condition `if h : p then none else some (b h)` is `some`, the value extracted from this condition equals $b$ applied to the proof derived from $w$ (which simplifies to $\neg p$).
Option.get_ite' theorem
{p : Prop} [Decidable p] (h) : (if p then none else some b).get h = b
Full source
@[simp] theorem get_ite' {p : Prop} [Decidable p] (h) :
    (if p then none else some b).get h = b := by
  simpa using get_dite' (p := p) (fun _ => b) (by simpa using h)
Value Extraction from Negated Conditional Optional
Informal description
For any decidable proposition $p$ and element $b$ of type $\beta$, if $p$ is false (as witnessed by the proof $h$), then extracting the value from the optional value `if p then none else some b` yields $b$.
Option.pbind_none theorem
: pbind none f = none
Full source
@[simp] theorem pbind_none : pbind none f = none := rfl
Partial Bind of None Yields None
Informal description
For any partial function $f$, the partial bind operation applied to `none` returns `none`, i.e., $\text{pbind}(\text{none}, f) = \text{none}$.
Option.pbind_some theorem
: pbind (some a) f = f a (mem_some_self a)
Full source
@[simp] theorem pbind_some : pbind (some a) f = f a (mem_some_self a) := rfl
Partial Bind of Some Value Equals Function Application
Informal description
For any element $a$ of type $\alpha$ and any partial function $f : (a : \alpha) \to a \in \text{some }a \to \text{Option }\beta$, the partial bind operation satisfies $\text{pbind}(\text{some }a, f) = f(a, \text{mem\_some\_self }a)$.
Option.map_pbind theorem
{o : Option α} {f : (a : α) → a ∈ o → Option β} {g : β → γ} : (o.pbind f).map g = o.pbind (fun a h => (f a h).map g)
Full source
@[simp] theorem map_pbind {o : Option α} {f : (a : α) → a ∈ oOption β} {g : β → γ} :
    (o.pbind f).map g = o.pbind (fun a h => (f a h).map g) := by
  cases o <;> simp
Commutativity of Map and Partial Bind for Optional Values: $(o.\text{pbind} f).\text{map} g = o.\text{pbind} (\lambda a h, (f a h).\text{map} g)$
Informal description
For any optional value $o : \text{Option } \alpha$, any partial function $f : (a : \alpha) \to a \in o \to \text{Option } \beta$, and any function $g : \beta \to \gamma$, the following equality holds: $$(o.\text{pbind} f).\text{map} g = o.\text{pbind} \left( \lambda a h, (f a h).\text{map} g \right).$$
Option.pbind_congr theorem
{o o' : Option α} (ho : o = o') {f : (a : α) → a ∈ o → Option β} {g : (a : α) → a ∈ o' → Option β} (hf : ∀ a h, f a (ho ▸ h) = g a h) : o.pbind f = o'.pbind g
Full source
@[congr] theorem pbind_congr {o o' : Option α} (ho : o = o')
    {f : (a : α) → a ∈ oOption β} {g : (a : α) → a ∈ o'Option β}
    (hf : ∀ a h, f a (ho ▸ h) = g a h) : o.pbind f = o'.pbind g := by
  subst ho
  exact (funext fun a => funext fun h => hf a h) ▸ Eq.refl (o.pbind f)
Congruence Property of Partial Bind for Optional Values
Informal description
Let $o$ and $o'$ be optional values of type $\alpha$ such that $o = o'$. For any functions $f : (a : \alpha) \to a \in o \to \text{Option} \beta$ and $g : (a : \alpha) \to a \in o' \to \text{Option} \beta$, if for all $a \in \alpha$ and $h : a \in o$, we have $f(a, h) = g(a, \text{ho} \cdot h)$, then the partial bind operations satisfy $o.\text{pbind} f = o'.\text{pbind} g$.
Option.pbind_eq_none_iff theorem
{o : Option α} {f : (a : α) → a ∈ o → Option β} : o.pbind f = none ↔ o = none ∨ ∃ a h, f a h = none
Full source
theorem pbind_eq_none_iff {o : Option α} {f : (a : α) → a ∈ oOption β} :
    o.pbind f = none ↔ o = none ∨ ∃ a h, f a h = none := by
  cases o with
  | none => simp
  | some a =>
    simp only [pbind_some, reduceCtorEq, mem_def, some.injEq, false_or]
    constructor
    · intro h
      exact ⟨a, rfl, h⟩
    · rintro ⟨a, rfl, h⟩
      exact h
Partial Bind Yields None if and only if Input is None or Function Returns None
Informal description
For an optional value $o : \text{Option } \alpha$ and a partial function $f : (a : \alpha) \to a \in o \to \text{Option } \beta$, the partial bind operation $o.\text{pbind} f$ results in $\text{none}$ if and only if either $o$ is $\text{none}$, or there exists some $a \in \alpha$ and a proof $h$ that $a \in o$ such that $f(a, h) = \text{none}$. In symbols: $$o.\text{pbind} f = \text{none} \leftrightarrow (o = \text{none}) \lor (\exists a\ h, f(a, h) = \text{none})$$
Option.pbind_isSome theorem
{o : Option α} {f : (a : α) → a ∈ o → Option β} : (o.pbind f).isSome = ∃ a h, (f a h).isSome
Full source
theorem pbind_isSome {o : Option α} {f : (a : α) → a ∈ oOption β} :
    (o.pbind f).isSome = ∃ a h, (f a h).isSome := by
  cases o with
  | none => simp
  | some a =>
    simp only [pbind_some, mem_def, some.injEq, eq_iff_iff]
    constructor
    · intro h
      exact ⟨a, rfl, h⟩
    · rintro ⟨a, rfl, h⟩
      exact h
Partial Bind is Some if and only if Function Application is Some
Informal description
For an optional value $o : \text{Option}\,\alpha$ and a partial function $f : (a : \alpha) \to a \in o \to \text{Option}\,\beta$, the predicate $\text{isSome}$ on the partial bind $o.\text{pbind}\,f$ holds if and only if there exists an element $a \in \alpha$ and a proof $h : a \in o$ such that $\text{isSome}\,(f\,a\,h)$ holds.
Option.pbind_eq_some_iff theorem
{o : Option α} {f : (a : α) → a ∈ o → Option β} {b : β} : o.pbind f = some b ↔ ∃ a h, f a h = some b
Full source
theorem pbind_eq_some_iff {o : Option α} {f : (a : α) → a ∈ oOption β} {b : β} :
    o.pbind f = some b ↔ ∃ a h, f a h = some b := by
  cases o with
  | none => simp
  | some a =>
    simp only [pbind_some, mem_def, some.injEq]
    constructor
    · intro h
      exact ⟨a, rfl, h⟩
    · rintro ⟨a, rfl, h⟩
      exact h
Partial Bind Yields Some if and only if Function Does
Informal description
For an optional value `o : Option α`, a partial function `f : (a : α) → a ∈ o → Option β`, and an element `b : β`, the partial bind operation `pbind` applied to `o` and `f` results in `some b` if and only if there exists an element `a : α` and a proof `h : a ∈ o` such that `f a h = some b`. In symbols: \[ \text{pbind}\,o\,f = \text{some}\,b \leftrightarrow \exists a\,h, f\,a\,h = \text{some}\,b \]
Option.pmap_none theorem
{p : α → Prop} {f : ∀ (a : α), p a → β} {h} : pmap f none h = none
Full source
@[simp] theorem pmap_none {p : α → Prop} {f : ∀ (a : α), p a → β} {h} :
    pmap f none h = none := rfl
Partial Map of None is None
Informal description
For any predicate $p$ on elements of type $\alpha$, any function $f$ mapping elements of $\alpha$ satisfying $p$ to elements of type $\beta$, and any proof $h$ that all elements in `none` satisfy $p$, the partial map of $f$ over `none` is `none`. In other words, $\text{pmap}\,f\,\text{none}\,h = \text{none}$.
Option.pmap_some theorem
{p : α → Prop} {f : ∀ (a : α), p a → β} {h} : pmap f (some a) h = f a (h a (mem_some_self a))
Full source
@[simp] theorem pmap_some {p : α → Prop} {f : ∀ (a : α), p a → β} {h}:
    pmap f (some a) h = f a (h a (mem_some_self a)) := rfl
Partial Map of Some Value
Informal description
For any predicate $p$ on elements of type $\alpha$, any function $f$ mapping elements of $\alpha$ satisfying $p$ to elements of type $\beta$, and any proof $h$ that all elements in $\text{some }a$ satisfy $p$, the partial map of $f$ over $\text{some }a$ equals $f$ applied to $a$ with the proof that $a$ satisfies $p$. In other words, $\text{pmap}\,f\,(\text{some }a)\,h = f\,a\,(h\,a\,(\text{mem\_some\_self }a))$.
Option.pmap_eq_none_iff theorem
{p : α → Prop} {f : ∀ (a : α), p a → β} {h} : pmap f o h = none ↔ o = none
Full source
@[simp] theorem pmap_eq_none_iff {p : α → Prop} {f : ∀ (a : α), p a → β} {h} :
    pmappmap f o h = none ↔ o = none := by
  cases o <;> simp
Partial Map Yields None if and only if Input is None
Informal description
For any predicate $p$ on elements of type $\alpha$, any function $f$ mapping elements of $\alpha$ satisfying $p$ to elements of type $\beta$, and any optional value $o : \text{Option } \alpha$ with a proof that all elements in $o$ satisfy $p$, the partial map $\text{pmap}\,f\,o\,h$ equals $\text{none}$ if and only if $o$ equals $\text{none}$.
Option.pmap_isSome theorem
{p : α → Prop} {f : ∀ (a : α), p a → β} {o : Option α} {h} : (pmap f o h).isSome = o.isSome
Full source
@[simp] theorem pmap_isSome {p : α → Prop} {f : ∀ (a : α), p a → β} {o : Option α} {h} :
    (pmap f o h).isSome = o.isSome := by
  cases o <;> simp
Preservation of `isSome` under Partial Mapping of Optional Values
Informal description
For any predicate $p$ on elements of type $\alpha$, a function $f$ mapping elements of $\alpha$ satisfying $p$ to elements of type $\beta$, and an optional value $o : \text{Option } \alpha$ with a proof that all elements in $o$ satisfy $p$, the boolean value indicating whether the partial map $\text{pmap } f \ o \ h$ is `some` is equal to the boolean value indicating whether $o$ is `some`. In other words, $\text{isSome}(\text{pmap } f \ o \ h) = \text{isSome}(o)$.
Option.pmap_eq_some_iff theorem
{p : α → Prop} {f : ∀ (a : α), p a → β} {o : Option α} {h} : pmap f o h = some b ↔ ∃ (a : α) (h : p a), o = some a ∧ b = f a h
Full source
@[simp] theorem pmap_eq_some_iff {p : α → Prop} {f : ∀ (a : α), p a → β} {o : Option α} {h} :
    pmappmap f o h = some b ↔ ∃ (a : α) (h : p a), o = some a ∧ b = f a h := by
  cases o with
  | none => simp
  | some a =>
    simp only [pmap, eq_comm, some.injEq, exists_and_left, exists_eq_left']
    constructor
    · exact fun w => ⟨h a rfl, w⟩
    · rintro ⟨h, rfl⟩
      rfl
Partial Map Yields Some if and only if Input is Some and Predicate Holds
Informal description
For any predicate $p$ on elements of type $\alpha$, a function $f$ mapping elements of $\alpha$ satisfying $p$ to elements of type $\beta$, and an optional value $o : \text{Option } \alpha$ with a proof that all elements in $o$ satisfy $p$, the partial map $\text{pmap } f \ o \ h$ equals $\text{some } b$ if and only if there exists an element $a \in \alpha$ and a proof $h : p(a)$ such that $o = \text{some } a$ and $b = f(a, h)$.
Option.pmap_eq_map theorem
(p : α → Prop) (f : α → β) (o : Option α) (H) : @pmap _ _ p (fun a _ => f a) o H = Option.map f o
Full source
@[simp]
theorem pmap_eq_map (p : α → Prop) (f : α → β) (o : Option α) (H) :
    @pmap _ _ p (fun a _ => f a) o H = Option.map f o := by
  cases o <;> simp
Equality of Partial Map and Standard Map on Optional Values
Informal description
For any predicate $p$ on elements of type $\alpha$, any function $f : \alpha \to \beta$, any optional value $o : \text{Option } \alpha$, and any proof $H$ that all elements in $o$ satisfy $p$, the partial map $\text{pmap}$ with $f$ (ignoring the predicate) applied to $o$ is equal to the standard map $\text{map } f$ applied to $o$.
Option.map_pmap theorem
{p : α → Prop} (g : β → γ) (f : ∀ a, p a → β) (o H) : Option.map g (pmap f o H) = pmap (fun a h => g (f a h)) o H
Full source
theorem map_pmap {p : α → Prop} (g : β → γ) (f : ∀ a, p a → β) (o H) :
    Option.map g (pmap f o H) = pmap (fun a h => g (f a h)) o H := by
  cases o <;> simp
Commutativity of Map and Partial Map on Optional Values
Informal description
For any predicate $p$ on elements of type $\alpha$, any function $g : \beta \to \gamma$, any function $f : (a : \alpha) \to p(a) \to \beta$, any optional value $o : \text{Option } \alpha$, and any proof $H$ that all elements in $o$ satisfy $p$, the following equality holds: \[ \text{map } g (\text{pmap } f \ o \ H) = \text{pmap } (\lambda a \ h, g (f a h)) \ o \ H \]
Option.pmap_map theorem
(o : Option α) (f : α → β) {p : β → Prop} (g : ∀ b, p b → γ) (H) : pmap g (o.map f) H = pmap (fun a h => g (f a) h) o (fun a m => H (f a) (mem_map_of_mem f m))
Full source
theorem pmap_map (o : Option α) (f : α → β) {p : β → Prop} (g : ∀ b, p b → γ) (H) :
    pmap g (o.map f) H =
      pmap (fun a h => g (f a) h) o (fun a m => H (f a) (mem_map_of_mem f m)) := by
  cases o <;> simp
Commutativity of Partial Map and Standard Map on Optional Values
Informal description
For any optional value $o : \text{Option } \alpha$, any function $f : \alpha \to \beta$, any predicate $p$ on $\beta$, and any function $g : (b : \beta) \to p(b) \to \gamma$, the following equality holds: \[ \text{pmap } g \ (o.\text{map } f) \ H = \text{pmap } (\lambda a \ h, g (f a) h) \ o \ (\lambda a \ m, H (f a) (\text{mem\_map\_of\_mem } f \ m)) \] where $H$ is a proof that all elements in $o.\text{map } f$ satisfy $p$.
Option.pelim_none theorem
: pelim none b f = b
Full source
@[simp] theorem pelim_none : pelim none b f = b := rfl
Partial Elimination of `none` Returns Fallback Value
Informal description
For any fallback value $b$ of type $\beta$ and any partial function $f : (a : \alpha) \to a \in o \to \beta$, the partial elimination of the `none` optional value returns $b$, i.e., $\text{pelim}(\text{none}, b, f) = b$.
Option.pelim_some theorem
: pelim (some a) b f = f a rfl
Full source
@[simp] theorem pelim_some : pelim (some a) b f = f a rfl := rfl
Partial Elimination of Some Option
Informal description
For any element $a$ of type $\alpha$, fallback value $b$ of type $\beta$, and partial function $f : (a : \alpha) \to (a \in \text{some } a) \to \beta$, the partial elimination of the optional value $\text{some } a$ satisfies $\text{pelim } (\text{some } a) \, b \, f = f \, a \, \text{rfl}$.
Option.pelim_eq_elim theorem
: pelim o b (fun a _ => f a) = o.elim b f
Full source
@[simp] theorem pelim_eq_elim : pelim o b (fun a _ => f a) = o.elim b f := by
  cases o <;> simp
Equivalence of Partial and Full Elimination for Optional Values
Informal description
For any optional value $o : \text{Option}\ \alpha$, a default value $b : \beta$, and a function $f : \alpha \to \beta$, the partial elimination `pelim` of $o$ with $b$ and the function $\lambda a \_. f(a)$ is equal to the full elimination `elim` of $o$ with $b$ and $f$.
Option.elim_pmap theorem
{p : α → Prop} (f : (a : α) → p a → β) (o : Option α) (H : ∀ (a : α), a ∈ o → p a) (g : γ) (g' : β → γ) : (o.pmap f H).elim g g' = o.pelim g (fun a h => g' (f a (H a h)))
Full source
@[simp] theorem elim_pmap {p : α → Prop} (f : (a : α) → p a → β) (o : Option α)
    (H : ∀ (a : α), a ∈ o → p a) (g : γ) (g' : β → γ) :
    (o.pmap f H).elim g g' =
       o.pelim g (fun a h => g' (f a (H a h))) := by
  cases o <;> simp
Equality of Elimination for Partial Map and Partial Elimination on Optional Values
Informal description
Given a predicate $p$ on elements of type $\alpha$, a function $f \colon (a \colon \alpha) \to p(a) \to \beta$, an optional value $o \colon \text{Option}\ \alpha$, and a proof $H \colon \forall (a \colon \alpha), a \in o \to p(a)$, for any default value $g \colon \gamma$ and function $g' \colon \beta \to \gamma$, the elimination of the partial map $\text{pmap}\ f\ o\ H$ with $g$ and $g'$ is equal to the partial elimination of $o$ with $g$ and the function $\lambda a\ h, g'(f\ a\ (H\ a\ h))$.
Option.not_lt_none theorem
[LT α] {a : Option α} : ¬a < none
Full source
@[simp] theorem not_lt_none [LT α] {a : Option α} : ¬ a < none := by cases a <;> simp [LT.lt, Option.lt]
No Optional Value is Less Than None
Informal description
For any type $\alpha$ with a "less than" relation $<$ and for any optional value $a : \text{Option}\ \alpha$, it is not the case that $a$ is less than $\text{none}$.
Option.none_lt_some theorem
[LT α] {a : α} : none < some a
Full source
@[simp] theorem none_lt_some [LT α] {a : α} : none < some a := by simp [LT.lt, Option.lt]
None is Less Than Some in Optional Type
Informal description
For any type $\alpha$ equipped with a "less than" relation $<$, and for any element $a \in \alpha$, the optional value $\text{none}$ is less than $\text{some }a$.
Option.some_lt_some theorem
[LT α] {a b : α} : some a < some b ↔ a < b
Full source
@[simp] theorem some_lt_some [LT α] {a b : α} : somesome a < some b ↔ a < b := by simp [LT.lt, Option.lt]
Comparison of Some Elements in Optional Type: $\text{some }a < \text{some }b \leftrightarrow a < b$
Informal description
For any type $\alpha$ equipped with a "less than" relation $<$, and for any elements $a, b \in \alpha$, the optional value $\text{some }a$ is less than $\text{some }b$ if and only if $a < b$ in $\alpha$.
Option.none_le theorem
[LE α] {a : Option α} : none ≤ a
Full source
@[simp] theorem none_le [LE α] {a : Option α} : none ≤ a := by cases a <;> simp [LE.le, Option.le]
None is the Least Element in Option Type
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$, and for any optional value $a : \text{Option } \alpha$, the value $\text{none}$ is less than or equal to $a$.
Option.not_some_le_none theorem
[LE α] {a : α} : ¬some a ≤ none
Full source
@[simp] theorem not_some_le_none [LE α] {a : α} : ¬ some a ≤ none := by simp [LE.le, Option.le]
Some Element Not Less Than or Equal to None
Informal description
For any type $\alpha$ with a "less than or equal to" relation $\leq$, and for any element $a \in \alpha$, the optional value $\text{some }a$ is not less than or equal to $\text{none}$.
Option.some_le_some theorem
[LE α] {a b : α} : some a ≤ some b ↔ a ≤ b
Full source
@[simp] theorem some_le_some [LE α] {a b : α} : somesome a ≤ some b ↔ a ≤ b := by simp [LE.le, Option.le]
Order Preservation in Option Type: $\text{some }a \leq \text{some }b \leftrightarrow a \leq b$
Informal description
For any type $\alpha$ with a "less than or equal to" relation $\leq$, and for any elements $a, b \in \alpha$, the optional value `some a` is less than or equal to `some b` if and only if $a \leq b$ in $\alpha$.
Option.min_eq_left theorem
[LE α] [Min α] (min_eq_left : ∀ x y : α, x ≤ y → min x y = x) {a b : Option α} (h : a ≤ b) : min a b = a
Full source
theorem min_eq_left [LE α] [Min α] (min_eq_left : ∀ x y : α, x ≤ y → min x y = x)
    {a b : Option α} (h : a ≤ b) : min a b = a := by
  cases a <;> cases b <;> simp_all
Minimum of Optional Values When Left is Less Than or Equal to Right
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a minimum operation $\min$, if for all $x, y \in \alpha$ we have $x \leq y \implies \min(x, y) = x$, then for any optional values $a, b \in \text{Option}\ \alpha$ with $a \leq b$, it follows that $\min(a, b) = a$.
Option.min_eq_right theorem
[LE α] [Min α] (min_eq_right : ∀ x y : α, y ≤ x → min x y = y) {a b : Option α} (h : b ≤ a) : min a b = b
Full source
theorem min_eq_right [LE α] [Min α] (min_eq_right : ∀ x y : α, y ≤ x → min x y = y)
    {a b : Option α} (h : b ≤ a) : min a b = b := by
  cases a <;> cases b <;> simp_all
Minimum of Optional Values When Right is Less Than or Equal to Left
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a minimum operation $\min$, if for all $x, y \in \alpha$ we have $y \leq x \implies \min(x, y) = y$, then for any optional values $a, b \in \text{Option}\ \alpha$ with $b \leq a$, it follows that $\min(a, b) = b$.
Option.min_eq_left_of_lt theorem
[LT α] [Min α] (min_eq_left : ∀ x y : α, x < y → min x y = x) {a b : Option α} (h : a < b) : min a b = a
Full source
theorem min_eq_left_of_lt [LT α] [Min α] (min_eq_left : ∀ x y : α, x < y → min x y = x)
    {a b : Option α} (h : a < b) : min a b = a := by
  cases a <;> cases b <;> simp_all
Minimum of Optional Values When Left is Less Than Right
Informal description
Let $\alpha$ be a type equipped with a "less than" relation $<$ and a minimum operation $\min$. Suppose that for any $x, y \in \alpha$, if $x < y$ then $\min(x, y) = x$. Then for any optional values $a, b \in \text{Option}\ \alpha$, if $a < b$, it follows that $\min(a, b) = a$.
Option.min_eq_right_of_lt theorem
[LT α] [Min α] (min_eq_right : ∀ x y : α, y < x → min x y = y) {a b : Option α} (h : b < a) : min a b = b
Full source
theorem min_eq_right_of_lt [LT α] [Min α] (min_eq_right : ∀ x y : α, y < x → min x y = y)
    {a b : Option α} (h : b < a) : min a b = b := by
  cases a <;> cases b <;> simp_all
Minimum of Optional Values When Right is Less Than Left
Informal description
Let $\alpha$ be a type equipped with a "less than" relation $<$ and a minimum operation $\min$. Suppose that for any $x, y \in \alpha$, if $y < x$ then $\min(x, y) = y$. Then for any optional values $a, b \in \text{Option}\ \alpha$, if $b < a$, it follows that $\min(a, b) = b$.
Option.min_eq_or theorem
[LE α] [Min α] (min_eq_or : ∀ x y : α, min x y = x ∨ min x y = y) {a b : Option α} : min a b = a ∨ min a b = b
Full source
theorem min_eq_or [LE α] [Min α] (min_eq_or : ∀ x y : α, minmin x y = x ∨ min x y = y)
    {a b : Option α} : minmin a b = a ∨ min a b = b := by
  cases a <;> cases b <;> simp_all
Minimum of Optional Values is Either Left or Right
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a minimum operation $\min$, if for all $x, y \in \alpha$ the minimum $\min(x, y)$ equals either $x$ or $y$, then for any optional values $a, b \in \text{Option } \alpha$, the minimum $\min(a, b)$ equals either $a$ or $b$.
Option.min_le_left theorem
[LE α] [Min α] (min_le_left : ∀ x y : α, min x y ≤ x) {a b : Option α} : min a b ≤ a
Full source
theorem min_le_left [LE α] [Min α] (min_le_left : ∀ x y : α, min x y ≤ x)
    {a b : Option α} : min a b ≤ a := by
  cases a <;> cases b <;> simp_all
Left Inequality for Minimum of Optional Values: $\min(a, b) \leq a$
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a minimum operation $\min$, and for any optional values $a, b : \text{Option } \alpha$, the minimum of $a$ and $b$ is less than or equal to $a$.
Option.min_le_right theorem
[LE α] [Min α] (min_le_right : ∀ x y : α, min x y ≤ y) {a b : Option α} : min a b ≤ b
Full source
theorem min_le_right [LE α] [Min α] (min_le_right : ∀ x y : α, min x y ≤ y)
    {a b : Option α} : min a b ≤ b := by
  cases a <;> cases b <;> simp_all
Right Inequality for Minimum of Optional Values: $\min(a, b) \leq b$
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a minimum operation $\min$, and for any optional values $a, b : \text{Option } \alpha$, the minimum of $a$ and $b$ is less than or equal to $b$.
Option.le_min theorem
[LE α] [Min α] (le_min : ∀ x y z : α, x ≤ min y z ↔ x ≤ y ∧ x ≤ z) {a b c : Option α} : a ≤ min b c ↔ a ≤ b ∧ a ≤ c
Full source
theorem le_min [LE α] [Min α] (le_min : ∀ x y z : α, x ≤ min y z ↔ x ≤ y ∧ x ≤ z)
    {a b c : Option α} : a ≤ min b c ↔ a ≤ b ∧ a ≤ c := by
  cases a <;> cases b <;> cases c <;> simp_all
Characterization of Inequality with Minimum in Optional Values: $a \leq \min(b, c) \leftrightarrow a \leq b \land a \leq c$
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a minimum operation $\min$, and for any optional values $a, b, c : \text{Option } \alpha$, the inequality $a \leq \min(b, c)$ holds if and only if both $a \leq b$ and $a \leq c$ hold.
Option.max_eq_left theorem
[LE α] [Max α] (max_eq_left : ∀ x y : α, x ≤ y → max x y = y) {a b : Option α} (h : a ≤ b) : max a b = b
Full source
theorem max_eq_left [LE α] [Max α] (max_eq_left : ∀ x y : α, x ≤ y → max x y = y)
    {a b : Option α} (h : a ≤ b) : max a b = b := by
  cases a <;> cases b <;> simp_all
Maximum of Optional Values When Left is Less Than or Equal to Right: $\max(a, b) = b$ if $a \leq b$
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a maximum operation $\max$, and for any optional values $a, b : \text{Option } \alpha$, if $a \leq b$, then $\max(a, b) = b$.
Option.max_eq_right theorem
[LE α] [Max α] (max_eq_right : ∀ x y : α, y ≤ x → max x y = x) {a b : Option α} (h : b ≤ a) : max a b = a
Full source
theorem max_eq_right [LE α] [Max α] (max_eq_right : ∀ x y : α, y ≤ x → max x y = x)
    {a b : Option α} (h : b ≤ a) : max a b = a := by
  cases a <;> cases b <;> simp_all
Maximum of Optional Values When Right is Less Than or Equal to Left: $\max(a, b) = a$ if $b \leq a$
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a maximum operation $\max$, and for any optional values $a, b : \text{Option } \alpha$, if $b \leq a$, then $\max(a, b) = a$.
Option.max_eq_left_of_lt theorem
[LT α] [Max α] (max_eq_left : ∀ x y : α, x < y → max x y = y) {a b : Option α} (h : a < b) : max a b = b
Full source
theorem max_eq_left_of_lt [LT α] [Max α] (max_eq_left : ∀ x y : α, x < y → max x y = y)
    {a b : Option α} (h : a < b) : max a b = b := by
  cases a <;> cases b <;> simp_all
Maximum of Optional Values When Left is Less Than Right: $\max(a, b) = b$ if $a < b$
Informal description
For any type $\alpha$ equipped with a "less than" relation $<$ and a maximum operation $\max$, if for all $x, y \in \alpha$ we have $x < y \implies \max(x, y) = y$, then for any optional values $a, b : \text{Option}\ \alpha$ with $a < b$, it follows that $\max(a, b) = b$.
Option.max_eq_right_of_lt theorem
[LT α] [Max α] (max_eq_right : ∀ x y : α, y < x → max x y = x) {a b : Option α} (h : b < a) : max a b = a
Full source
theorem max_eq_right_of_lt [LT α] [Max α] (max_eq_right : ∀ x y : α, y < x → max x y = x)
    {a b : Option α} (h : b < a) : max a b = a := by
  cases a <;> cases b <;> simp_all
Maximum of Optional Values When Right is Less Than Left: $\max(a, b) = a$ if $b < a$
Informal description
For any type $\alpha$ equipped with a "less than" relation $<$ and a maximum operation $\max$, if for all $x, y \in \alpha$ we have $y < x \implies \max(x, y) = x$, then for any optional values $a, b : \text{Option}\ \alpha$ with $b < a$, it follows that $\max(a, b) = a$.
Option.max_eq_or theorem
[LE α] [Max α] (max_eq_or : ∀ x y : α, max x y = x ∨ max x y = y) {a b : Option α} : max a b = a ∨ max a b = b
Full source
theorem max_eq_or [LE α] [Max α] (max_eq_or : ∀ x y : α, maxmax x y = x ∨ max x y = y)
    {a b : Option α} : maxmax a b = a ∨ max a b = b := by
  cases a <;> cases b <;> simp_all
Maximum of Optional Values is Either Left or Right
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a maximum operation $\max$, if for all $x, y \in \alpha$ the maximum $\max(x, y)$ is equal to either $x$ or $y$, then for any optional values $a, b \in \text{Option }\alpha$, the maximum $\max(a, b)$ is equal to either $a$ or $b$.
Option.left_le_max theorem
[LE α] [Max α] (le_refl : ∀ x : α, x ≤ x) (left_le_max : ∀ x y : α, x ≤ max x y) {a b : Option α} : a ≤ max a b
Full source
theorem left_le_max [LE α] [Max α] (le_refl : ∀ x : α, x ≤ x) (left_le_max : ∀ x y : α, x ≤ max x y)
    {a b : Option α} : a ≤ max a b := by
  cases a <;> cases b <;> simp_all
Left Element is Less Than or Equal to Maximum in Optional Values
Informal description
For any type $\alpha$ equipped with a reflexive "less than or equal to" relation $\leq$ and a maximum operation $\max$, if for all $x, y \in \alpha$ we have $x \leq \max(x, y)$, then for any optional values $a, b \in \text{Option }\alpha$, it follows that $a \leq \max(a, b)$.
Option.right_le_max theorem
[LE α] [Max α] (le_refl : ∀ x : α, x ≤ x) (right_le_max : ∀ x y : α, y ≤ max x y) {a b : Option α} : b ≤ max a b
Full source
theorem right_le_max [LE α] [Max α] (le_refl : ∀ x : α, x ≤ x) (right_le_max : ∀ x y : α, y ≤ max x y)
    {a b : Option α} : b ≤ max a b := by
  cases a <;> cases b <;> simp_all
Right Element is Less Than or Equal to Maximum in Optional Values
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a maximum operation $\max$, if: 1. $\leq$ is reflexive (i.e., $\forall x \in \alpha, x \leq x$), and 2. For any $x, y \in \alpha$, $y \leq \max(x, y)$, then for any optional values $a, b \in \text{Option }\alpha$, we have $b \leq \max(a, b)$.
Option.max_le theorem
[LE α] [Max α] (max_le : ∀ x y z : α, max x y ≤ z ↔ x ≤ z ∧ y ≤ z) {a b c : Option α} : max a b ≤ c ↔ a ≤ c ∧ b ≤ c
Full source
theorem max_le [LE α] [Max α] (max_le : ∀ x y z : α, maxmax x y ≤ z ↔ x ≤ z ∧ y ≤ z)
    {a b c : Option α} : maxmax a b ≤ c ↔ a ≤ c ∧ b ≤ c := by
  cases a <;> cases b <;> cases c <;> simp_all
Maximum of Optional Values is Less Than or Equal to Another if and Only if Both Are
Informal description
For any type $\alpha$ equipped with a "less than or equal to" relation $\leq$ and a maximum operation $\max$, if for all $x, y, z \in \alpha$ we have $\max(x, y) \leq z \leftrightarrow x \leq z \land y \leq z$, then for any optional values $a, b, c \in \text{Option }\alpha$, it follows that $\max(a, b) \leq c \leftrightarrow a \leq c \land b \leq c$.