Documentation

CslibFrontier.Foundations.Data.Option

Option lemmas #

Lemmas about Option operations such as Option.elim and Option.getD.

Main results #

theorem Option.elim_eq_if_isSome {α : Type u_1} {β : Type u_2} (d : α) (o : Option α) (no : β) (yes : α → β) :
o.elim no yes = if o.isSome = true then yes (o.getD d) else no

Eliminating an optional value agrees with branching on o.isSome and reading o.getD d.

@[simp]
theorem Option.getD_self_eq_iff {o : Option Bool} {b : Bool} :
o.getD b = b ↔ ∀ (b' : Bool), o = some b' → b = b'

An optional Boolean value o agrees with b on the defined part (that is, b = b' whenever o = some b') if and only if o.getD b = b holds.

theorem Option.getD_beq_self_eq_true_iff {o : Option Bool} {b : Bool} :
(o.getD b == b) = true ↔ ∀ (b' : Bool), o = some b' → b = b'

An optional Boolean value o agrees with b on the defined part (that is, b = b' whenever o = some b') if and only if o.getD b == b holds.

theorem Vector.ofFnM_option_replace {α : Type u_1} {β : Type u_2} {n : ℕ} (f : Fin n → Option α) (v : Fin n → β) :
(ofFnM fun (i : Fin n) => Option.map (fun (x : α) => v i) (f i)) = Option.map (fun (x : Vector α n) => ofFn v) (ofFnM f)

Replacing every accepted entry in an optional vector with a prescribed value retains failure and returns precisely the vector of prescribed values on success.