Module docstring
{"### beq ","### ite ","### pbind ","### pmap ","### pelim ","### LT and LE ","### min and max "}
{"### beq ","### ite ","### pbind ","### pmap ","### pelim ","### LT and LE ","### min and max "}
Option.mem_iff
theorem
{a : α} {b : Option α} : a ∈ b ↔ b = some a
theorem mem_iff {a : α} {b : Option α} : a ∈ ba ∈ b ↔ b = some a := .rfl
Option.mem_some
theorem
{a b : α} : a ∈ some b ↔ b = a
theorem mem_some {a b : α} : a ∈ some ba ∈ some b ↔ b = a := by simp
Option.mem_some_self
theorem
(a : α) : a ∈ some a
theorem mem_some_self (a : α) : a ∈ some a := mem_some.2 rfl
Option.some_ne_none
theorem
(x : α) : some x ≠ none
theorem some_ne_none (x : α) : somesome x ≠ none := nofun
Option.forall
theorem
{p : Option α → Prop} : (∀ x, p x) ↔ p none ∧ ∀ x, p (some x)
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⟩
Option.exists
theorem
{p : Option α → Prop} : (∃ x, p x) ↔ p none ∨ ∃ x, p (some x)
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⟩⟩
Option.get_mem
theorem
: ∀ {o : Option α} (h : isSome o), o.get h ∈ o
theorem get_mem : ∀ {o : Option α} (h : isSome o), o.get h ∈ o
| some _, _ => rfl
Option.get_of_mem
theorem
: ∀ {o : Option α} (h : isSome o), a ∈ o → o.get h = a
Option.not_mem_none
theorem
(a : α) : a ∉ (none : Option α)
@[simp] theorem not_mem_none (a : α) : a ∉ (none : Option α) := nofun
Option.getD_of_ne_none
theorem
{x : Option α} (hx : x ≠ none) (y : α) : some (x.getD y) = x
Option.getD_eq_iff
theorem
{o : Option α} {a b} : o.getD a = b ↔ (o = some b ∨ o = none ∧ a = b)
theorem getD_eq_iff {o : Option α} {a b} : o.getD a = b ↔ (o = some b ∨ o = none ∧ a = b) := by
cases o <;> simp
Option.get!_none
theorem
[Inhabited α] : (none : Option α).get! = default
Option.get!_some
theorem
[Inhabited α] {a : α} : (some a).get! = a
Option.get_eq_get!
theorem
[Inhabited α] : (o : Option α) → {h : o.isSome} → o.get h = o.get!
Option.get_eq_getD
theorem
{fallback : α} : (o : Option α) → {h : o.isSome} → o.get h = o.getD fallback
Option.some_get!
theorem
[Inhabited α] : (o : Option α) → o.isSome → some (o.get!) = o
Option.get!_eq_getD
theorem
[Inhabited α] (o : Option α) : o.get! = o.getD default
Option.get!_eq_getD_default
abbrev
@[deprecated get!_eq_getD (since := "2024-11-18")] abbrev get!_eq_getD_default := @get!_eq_getD
Option.mem_unique
theorem
{o : Option α} {a b : α} (ha : a ∈ o) (hb : b ∈ o) : a = b
theorem mem_unique {o : Option α} {a b : α} (ha : a ∈ o) (hb : b ∈ o) : a = b :=
some.inj <| ha ▸ hb
Option.ext
theorem
: ∀ {o₁ o₂ : Option α}, (∀ a, a ∈ o₁ ↔ a ∈ o₂) → o₁ = o₂
Option.isSome_iff_exists
theorem
: isSome x ↔ ∃ a, x = some a
theorem isSome_iff_exists : isSomeisSome x ↔ ∃ a, x = some a := by cases x <;> simp [isSome]
Option.isSome_eq_isSome
theorem
: (isSome x = isSome y) ↔ (x = none ↔ y = none)
theorem isSome_eq_isSome : (isSome x = isSome y) ↔ (x = none ↔ y = none) := by
cases x <;> cases y <;> simp
Option.not_isSome
theorem
: isSome a = false ↔ a.isNone = true
@[simp] theorem not_isSome : isSomeisSome a = false ↔ a.isNone = true := by
cases a <;> simp
Option.isSome_iff_ne_none
theorem
: o.isSome ↔ o ≠ none
theorem isSome_iff_ne_none : o.isSome ↔ o ≠ none := by
cases o <;> simp
Option.not_isSome_iff_eq_none
theorem
: ¬o.isSome ↔ o = none
theorem not_isSome_iff_eq_none : ¬o.isSome¬o.isSome ↔ o = none := by
cases o <;> simp
Option.ne_none_iff_isSome
theorem
: o ≠ none ↔ o.isSome
theorem ne_none_iff_isSome : o ≠ noneo ≠ none ↔ o.isSome := by cases o <;> simp
Option.ne_none_iff_exists
theorem
: o ≠ none ↔ ∃ x, some x = o
theorem ne_none_iff_exists : o ≠ noneo ≠ none ↔ ∃ x, some x = o := by cases o <;> simp
Option.ne_none_iff_exists'
theorem
: o ≠ none ↔ ∃ x, o = some x
theorem ne_none_iff_exists' : o ≠ noneo ≠ none ↔ ∃ x, o = some x :=
ne_none_iff_exists.trans <| exists_congr fun _ => eq_comm
Option.bex_ne_none
theorem
{p : Option α → Prop} : (∃ x, ∃ (_ : x ≠ none), p x) ↔ ∃ x, p (some x)
Option.ball_ne_none
theorem
{p : Option α → Prop} : (∀ x (_ : x ≠ none), p x) ↔ ∀ x, p (some x)
Option.pure_def
theorem
: pure = @some α
Option.bind_eq_bind
theorem
: bind = @Option.bind α β
@[simp] theorem bind_eq_bind : bind = @Option.bind α β := rfl
Option.bind_some
theorem
(x : Option α) : x.bind some = x
Option.bind_none
theorem
(x : Option α) : x.bind (fun _ => none (α := β)) = none
Option.bind_eq_some
theorem
: x.bind f = some b ↔ ∃ a, x = some a ∧ f a = some b
theorem bind_eq_some : x.bind f = some b ↔ ∃ a, x = some a ∧ f a = some b := by
cases x <;> simp
Option.bind_eq_none
theorem
{o : Option α} {f : α → Option β} : o.bind f = none ↔ ∀ a, o = some a → f a = none
@[simp] theorem bind_eq_none {o : Option α} {f : α → Option β} :
o.bind f = none ↔ ∀ a, o = some a → f a = none := by cases o <;> simp
Option.bind_eq_none'
theorem
{o : Option α} {f : α → Option β} : o.bind f = none ↔ ∀ b a, a ∈ o → b ∉ f a
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]
Option.mem_bind_iff
theorem
{o : Option α} {f : α → Option β} : b ∈ o.bind f ↔ ∃ a, a ∈ o ∧ b ∈ f a
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
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
Option.bind_assoc
theorem
(x : Option α) (f : α → Option β) (g : β → Option γ) : (x.bind f).bind g = x.bind fun y => (f y).bind g
Option.bind_congr
theorem
{α β} {o : Option α} {f g : α → Option β} : (h : ∀ a, o = some a → f a = g a) → o.bind f = o.bind g
Option.join_eq_some
theorem
: x.join = some a ↔ x = some (some a)
theorem join_eq_some : x.join = some a ↔ x = some (some a) := by
simp [bind_eq_some]
Option.join_ne_none
theorem
: x.join ≠ none ↔ ∃ z, x = some (some z)
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]
Option.join_ne_none'
theorem
: ¬x.join = none ↔ ∃ z, x = some (some z)
theorem join_ne_none' : ¬x.join = none¬x.join = none ↔ ∃ z, x = some (some z) :=
join_ne_none
Option.join_eq_none
theorem
: o.join = none ↔ o = none ∨ o = some none
theorem join_eq_none : o.join = none ↔ o = none ∨ o = some none :=
match o with | none | some none | some (some _) => by simp
Option.bind_id_eq_join
theorem
{x : Option (Option α)} : x.bind id = x.join
Option.map_eq_map
theorem
: Functor.map f = Option.map f
@[simp] theorem map_eq_map : Functor.map f = Option.map f := rfl
Option.map_none
theorem
: f <$> none = none
theorem map_none : f <$> none = none := rfl
Option.map_some
theorem
: f <$> some a = some (f a)
theorem map_some : f <$> some a = some (f a) := rfl
Option.map_eq_some'
theorem
: x.map f = some b ↔ ∃ a, x = some a ∧ f a = b
@[simp] theorem map_eq_some' : x.map f = some b ↔ ∃ a, x = some a ∧ f a = b := by cases x <;> simp
Option.map_eq_some
theorem
: f <$> x = some b ↔ ∃ a, x = some a ∧ f a = b
theorem map_eq_some : f <$> xf <$> x = some b ↔ ∃ a, x = some a ∧ f a = b := map_eq_some'
Option.map_eq_none'
theorem
: x.map f = none ↔ x = none
@[simp] theorem map_eq_none' : x.map f = none ↔ x = none := by
cases x <;> simp [map_none', map_some', eq_self_iff_true]
Option.isSome_map
theorem
{x : Option α} : (f <$> x).isSome = x.isSome
theorem isSome_map {x : Option α} : (f <$> x).isSome = x.isSome := by
cases x <;> simp
Option.isSome_map'
theorem
{x : Option α} : (x.map f).isSome = x.isSome
@[simp] theorem isSome_map' {x : Option α} : (x.map f).isSome = x.isSome := by
cases x <;> simp
Option.isNone_map'
theorem
{x : Option α} : (x.map f).isNone = x.isNone
@[simp] theorem isNone_map' {x : Option α} : (x.map f).isNone = x.isNone := by
cases x <;> simp
Option.map_eq_none
theorem
: f <$> x = none ↔ x = none
theorem map_eq_none : f <$> xf <$> x = none ↔ x = none := map_eq_none'
Option.map_eq_bind
theorem
{x : Option α} : x.map f = x.bind (some ∘ f)
theorem map_eq_bind {x : Option α} : x.map f = x.bind (somesome ∘ f) := by
cases x <;> simp [Option.bind]
Option.map_congr
theorem
{x : Option α} (h : ∀ a, a ∈ x → f a = g a) : x.map f = x.map g
Option.map_id_fun
theorem
{α : Type u} : Option.map (id : α → α) = id
@[simp] theorem map_id_fun {α : Type u} : Option.map (id : α → α) = id := by
funext; simp [map_id]
Option.map_id'
theorem
{x : Option α} : (x.map fun a => a) = x
Option.map_id_fun'
theorem
{α : Type u} : Option.map (fun (a : α) => a) = id
@[simp] theorem map_id_fun' {α : Type u} : Option.map (fun (a : α) => a) = id := by
funext; simp [map_id']
Option.get_map
theorem
{f : α → β} {o : Option α} {h : (o.map f).isSome} : (o.map f).get h = f (o.get (by simpa using h))
Option.map_map
theorem
(h : β → γ) (g : α → β) (x : Option α) : (x.map g).map h = x.map (h ∘ g)
Option.comp_map
theorem
(h : β → γ) (g : α → β) (x : Option α) : x.map (h ∘ g) = (x.map g).map h
Option.map_comp_map
theorem
(f : α → β) (g : β → γ) : Option.map g ∘ Option.map f = Option.map (g ∘ f)
@[simp] theorem map_comp_map (f : α → β) (g : β → γ) :
Option.mapOption.map g ∘ Option.map f = Option.map (g ∘ f) := by funext x; simp
Option.mem_map_of_mem
theorem
(g : α → β) (h : a ∈ x) : g a ∈ Option.map g x
theorem mem_map_of_mem (g : α → β) (h : a ∈ x) : g a ∈ Option.map g x := h.symm ▸ map_some' ..
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'
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⟩
Option.map_if
theorem
{f : α → β} [Decidable c] : (if c then some a else none).map f = if c then some (f a) else none
@[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
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
@[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
Option.filter_none
theorem
(p : α → Bool) : none.filter p = none
Option.filter_some
theorem
: Option.filter p (some a) = if p a then some a else none
theorem filter_some : Option.filter p (some a) = if p a then some a else none := rfl
Option.isSome_of_isSome_filter
theorem
(p : α → Bool) (o : Option α) (h : (o.filter p).isSome) : o.isSome
Option.isSome_filter_of_isSome
abbrev
@[deprecated isSome_of_isSome_filter (since := "2025-03-18")]
abbrev isSome_filter_of_isSome := @isSome_of_isSome_filter
Option.filter_eq_none
theorem
{p : α → Bool} : o.filter p = none ↔ o = none ∨ ∀ a, a ∈ o → ¬p a
@[simp] theorem filter_eq_none {p : α → Bool} :
o.filter p = none ↔ o = none ∨ ∀ a, a ∈ o → ¬ p a := by
cases o <;> simp [filter_some]
Option.filter_eq_some
theorem
{o : Option α} {p : α → Bool} : o.filter p = some a ↔ a ∈ o ∧ p a
@[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
Option.mem_filter_iff
theorem
{p : α → Bool} {a : α} {o : Option α} : a ∈ o.filter p ↔ a ∈ o ∧ p a
theorem mem_filter_iff {p : α → Bool} {a : α} {o : Option α} :
a ∈ o.filter pa ∈ o.filter p ↔ a ∈ o ∧ p a := by
simp
Option.all_guard
theorem
(p : α → Prop) [DecidablePred p] (a : α) : Option.all q (guard p a) = (!p a || q a)
@[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
Option.any_guard
theorem
(p : α → Prop) [DecidablePred p] (a : α) : Option.any q (guard p a) = (p a && q a)
@[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
Option.bind_map_comm
theorem
{α β} {x : Option (Option α)} {f : α → β} : x.bind (Option.map f) = (x.map (Option.map f)).bind id
theorem bind_map_comm {α β} {x : Option (Option α)} {f : α → β} :
x.bind (Option.map f) = (x.map (Option.map f)).bind id := by cases x <;> simp
Option.bind_map
theorem
{f : α → β} {g : β → Option γ} {x : Option α} : (x.map f).bind g = x.bind (g ∘ f)
Option.map_bind
theorem
{f : α → Option β} {g : β → γ} {x : Option α} : (x.bind f).map g = x.bind (Option.map g ∘ f)
@[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
Option.join_map_eq_map_join
theorem
{f : α → β} {x : Option (Option α)} : (x.map (Option.map f)).join = x.join.map f
theorem join_map_eq_map_join {f : α → β} {x : Option (Option α)} :
(x.map (Option.map f)).join = x.join.map f := by cases x <;> simp
Option.join_join
theorem
{x : Option (Option (Option α))} : x.join.join = (x.map join).join
Option.mem_of_mem_join
theorem
{a : α} {x : Option (Option α)} (h : a ∈ x.join) : some a ∈ x
theorem mem_of_mem_join {a : α} {x : Option (Option α)} (h : a ∈ x.join) : somesome a ∈ x :=
h.symm ▸ join_eq_some.1 h
Option.some_orElse
theorem
(a : α) (x : Option α) : (some a <|> x) = some a
@[simp] theorem some_orElse (a : α) (x : Option α) : (some a <|> x) = some a := rfl
Option.none_orElse
theorem
(x : Option α) : (none <|> x) = x
@[simp] theorem none_orElse (x : Option α) : (none <|> x) = x := rfl
Option.orElse_none
theorem
(x : Option α) : (x <|> none) = x
@[simp] theorem orElse_none (x : Option α) : (x <|> none) = x := by cases x <;> rfl
Option.map_orElse
theorem
{x y : Option α} : (x <|> y).map f = (x.map f <|> y.map f)
theorem map_orElse {x y : Option α} : (x <|> y).map f = (x.map f <|> y.map f) := by
cases x <;> simp
Option.guard_eq_some
theorem
[DecidablePred p] : guard p a = some b ↔ a = b ∧ p a
@[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]
Option.isSome_guard
theorem
[DecidablePred p] : (Option.guard p a).isSome ↔ p a
@[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]
Option.guard_isSome
abbrev
@[deprecated isSome_guard (since := "2025-03-18")]
abbrev guard_isSome := @isSome_guard
Option.guard_eq_none
theorem
[DecidablePred p] : Option.guard p a = none ↔ ¬p a
@[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]
Option.guard_pos
theorem
[DecidablePred p] (h : p a) : Option.guard p a = some a
@[simp] theorem guard_pos [DecidablePred p] (h : p a) : Option.guard p a = some a := by
simp [Option.guard, h]
Option.guard_congr
theorem
{f g : α → Prop} [DecidablePred f] [DecidablePred g] (h : ∀ a, f a ↔ g a) : guard f = guard g
@[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]
Option.guard_false
theorem
{α} : guard (fun (_ : α) => False) = fun _ => none
Option.guard_true
theorem
{α} : guard (fun (_ : α) => True) = some
Option.guard_comp
theorem
{p : α → Prop} [DecidablePred p] {f : β → α} : guard p ∘ f = Option.map f ∘ guard (p ∘ f)
theorem guard_comp {p : α → Prop} [DecidablePred p] {f : β → α} :
guardguard p ∘ f = Option.mapOption.map f ∘ guard (p ∘ f) := by
ext1 b
simp [guard]
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₂
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
Option.liftOrGet_none_left
theorem
{f} {b : Option α} : liftOrGet f none b = b
@[simp] theorem liftOrGet_none_left {f} {b : Option α} : liftOrGet f none b = b := by
cases b <;> rfl
Option.liftOrGet_none_right
theorem
{f} {a : Option α} : liftOrGet f a none = a
@[simp] theorem liftOrGet_none_right {f} {a : Option α} : liftOrGet f a none = a := by
cases a <;> rfl
Option.liftOrGet_some_some
theorem
{f} {a b : α} : liftOrGet f (some a) (some b) = f a b
@[simp] theorem liftOrGet_some_some {f} {a b : α} :
liftOrGet f (some a) (some b) = f a b := rfl
Option.elim_none
theorem
(x : β) (f : α → β) : none.elim x f = x
Option.elim_some
theorem
(x : β) (f : α → β) (a : α) : (some a).elim x f = f a
Option.getD_map
theorem
(f : α → β) (x : α) (o : Option α) : (o.map f).getD (f x) = f (getD o x)
Option.choice
definition
(α : Type _) : Option α
/--
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
Option.choice_eq
theorem
{α : Type _} [Subsingleton α] (a : α) : choice α = some a
theorem choice_eq {α : Type _} [Subsingleton α] (a : α) : choice α = some a := by
simp [choice]
rw [dif_pos (⟨a⟩ : Nonempty α)]
simp; apply Subsingleton.elim
Option.isSome_choice_iff_nonempty
theorem
{α : Type _} : (choice α).isSome ↔ Nonempty α
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]⟩
Option.choice_isSome_iff_nonempty
abbrev
@[deprecated isSome_choice_iff_nonempty (since := "2025-03-18")]
abbrev choice_isSome_iff_nonempty := @isSome_choice_iff_nonempty
Option.toList_some
theorem
(a : α) : (a : Option α).toList = [a]
@[simp] theorem toList_some (a : α) : (a : Option α).toList = [a] := rfl
Option.toList_none
theorem
(α : Type _) : (none : Option α).toList = []
Option.some_or
theorem
: (some a).or o = some a
Option.none_or
theorem
: none.or o = o
Option.or_eq_right_of_none
theorem
{o o' : Option α} (h : o = none) : o.or o' = o'
theorem or_eq_right_of_none {o o' : Option α} (h : o = none) : o.or o' = o' := by
cases h; simp
Option.or_some
theorem
: (some a).or o = some a
Option.or_some'
theorem
{o : Option α} : o.or (some a) = o.getD a
Option.or_eq_bif
theorem
: or o o' = bif o.isSome then o else o'
theorem or_eq_bif : or o o' = bif o.isSome then o else o' := by
cases o <;> rfl
Option.isSome_or
theorem
: (or o o').isSome = (o.isSome || o'.isSome)
@[simp] theorem isSome_or : (or o o').isSome = (o.isSome || o'.isSome) := by
cases o <;> rfl
Option.isNone_or
theorem
: (or o o').isNone = (o.isNone && o'.isNone)
@[simp] theorem isNone_or : (or o o').isNone = (o.isNone && o'.isNone) := by
cases o <;> rfl
Option.or_eq_none
theorem
: or o o' = none ↔ o = none ∧ o' = none
@[simp] theorem or_eq_none : oror o o' = none ↔ o = none ∧ o' = none := by
cases o <;> simp
Option.or_eq_some
theorem
: or o o' = some a ↔ o = some a ∨ (o = none ∧ o' = some a)
@[simp] theorem or_eq_some : oror o o' = some a ↔ o = some a ∨ (o = none ∧ o' = some a) := by
cases o <;> simp
Option.or_assoc
theorem
: or (or o₁ o₂) o₃ = or o₁ (or o₂ o₃)
Option.instAssociativeOr
instance
: Std.Associative (or (α := α))
instance : Std.Associative (or (α := α)) := ⟨@or_assoc _⟩
Option.or_none
theorem
: or o none = o
Option.or_eq_left_of_none
theorem
{o o' : Option α} (h : o' = none) : o.or o' = o
theorem or_eq_left_of_none {o o' : Option α} (h : o' = none) : o.or o' = o := by
cases h; simp
Option.instLawfulIdentityOrNone
instance
: Std.LawfulIdentity (or (α := α)) none
Option.or_self
theorem
: or o o = o
Option.instIdempotentOpOr
instance
: Std.IdempotentOp (or (α := α))
instance : Std.IdempotentOp (or (α := α)) := ⟨@or_self _⟩
Option.or_eq_orElse
theorem
: or o o' = o.orElse (fun _ => o')
theorem or_eq_orElse : or o o' = o.orElse (fun _ => o') := by
cases o <;> rfl
Option.map_or
theorem
: f <$> or o o' = (f <$> o).or (f <$> o')
theorem map_or : f <$> or o o' = (f <$> o).or (f <$> o') := by
cases o <;> rfl
Option.map_or'
theorem
: (or o o').map f = (o.map f).or (o'.map f)
Option.or_of_isSome
theorem
{o o' : Option α} (h : o.isSome) : o.or o' = o
theorem or_of_isSome {o o' : Option α} (h : o.isSome) : o.or o' = o := by
match o, h with
| some _, _ => simp
Option.or_of_isNone
theorem
{o o' : Option α} (h : o.isNone) : o.or o' = o'
theorem or_of_isNone {o o' : Option α} (h : o.isNone) : o.or o' = o' := by
match o, h with
| none, _ => simp
Option.none_beq_none
theorem
: ((none : Option α) == none) = true
Option.none_beq_some
theorem
(a : α) : ((none : Option α) == some a) = false
Option.some_beq_none
theorem
(a : α) : ((some a : Option α) == none) = false
Option.some_beq_some
theorem
{a b : α} : (some a == some b) = (a == b)
@[simp] theorem some_beq_some {a b : α} : (some a == some b) = (a == b) := rfl
Option.reflBEq_iff
theorem
: ReflBEq (Option α) ↔ ReflBEq α
@[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
Option.lawfulBEq_iff
theorem
: LawfulBEq (Option α) ↔ LawfulBEq α
@[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
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
@[simp] theorem dite_none_left_eq_some {p : Prop} [Decidable p] {b : ¬p → Option β} :
(if h : p then none else b h) = some a ↔ ∃ h, b h = some a := by
split <;> simp_all
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
@[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
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
@[simp] theorem some_eq_dite_none_left {p : Prop} [Decidable p] {b : ¬p → Option β} :
somesome a = (if h : p then none else b h) ↔ ∃ h, some a = b h := by
split <;> simp_all
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
@[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
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
@[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
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
@[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
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
@[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
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
@[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
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
theorem mem_dite_none_left {x : α} [Decidable p] {l : ¬ p → Option α} :
(x ∈ if h : p then none else l h) ↔ ∃ h : ¬ p, x ∈ l h := by
simp
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
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
Option.mem_ite_none_left
theorem
{x : α} [Decidable p] {l : Option α} : (x ∈ if p then none else l) ↔ ¬p ∧ x ∈ l
theorem mem_ite_none_left {x : α} [Decidable p] {l : Option α} :
(x ∈ if p then none else l) ↔ ¬ p ∧ x ∈ l := by
simp
Option.mem_ite_none_right
theorem
{x : α} [Decidable p] {l : Option α} : (x ∈ if p then l else none) ↔ p ∧ x ∈ l
theorem mem_ite_none_right {x : α} [Decidable p] {l : Option α} :
(x ∈ if p then l else none) ↔ p ∧ x ∈ l := by
simp
Option.isSome_dite
theorem
{p : Prop} [Decidable p] {b : p → β} : (if h : p then some (b h) else none).isSome = true ↔ p
@[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
Option.isSome_ite
theorem
{p : Prop} [Decidable p] : (if p then some b else none).isSome = true ↔ p
@[simp] theorem isSome_ite {p : Prop} [Decidable p] :
(if p then some b else none).isSome = true ↔ p := by
split <;> simpa
Option.isSome_dite'
theorem
{p : Prop} [Decidable p] {b : ¬p → β} : (if h : p then none else some (b h)).isSome = true ↔ ¬p
@[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
Option.isSome_ite'
theorem
{p : Prop} [Decidable p] : (if p then none else some b).isSome = true ↔ ¬p
@[simp] theorem isSome_ite' {p : Prop} [Decidable p] :
(if p then none else some b).isSome = true ↔ ¬ p := by
split <;> simpa
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)
@[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
Option.get_ite
theorem
{p : Prop} [Decidable p] (h) : (if p then some b else none).get h = b
@[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)
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)
Option.get_ite'
theorem
{p : Prop} [Decidable p] (h) : (if p then none else some b).get h = b
@[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)
Option.pbind_none
theorem
: pbind none f = none
@[simp] theorem pbind_none : pbind none f = none := rfl
Option.pbind_some
theorem
: pbind (some a) f = f a (mem_some_self a)
@[simp] theorem pbind_some : pbind (some a) f = f a (mem_some_self a) := rfl
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)
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
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
theorem pbind_eq_none_iff {o : Option α} {f : (a : α) → a ∈ o → Option β} :
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
Option.pbind_isSome
theorem
{o : Option α} {f : (a : α) → a ∈ o → Option β} : (o.pbind f).isSome = ∃ a h, (f a h).isSome
theorem pbind_isSome {o : Option α} {f : (a : α) → a ∈ o → Option β} :
(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
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
theorem pbind_eq_some_iff {o : Option α} {f : (a : α) → a ∈ o → Option β} {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
Option.pmap_none
theorem
{p : α → Prop} {f : ∀ (a : α), p a → β} {h} : pmap f none h = 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))
@[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
Option.pmap_eq_none_iff
theorem
{p : α → Prop} {f : ∀ (a : α), p a → β} {h} : pmap f o h = none ↔ o = none
@[simp] theorem pmap_eq_none_iff {p : α → Prop} {f : ∀ (a : α), p a → β} {h} :
pmappmap f o h = none ↔ o = none := by
cases o <;> simp
Option.pmap_isSome
theorem
{p : α → Prop} {f : ∀ (a : α), p a → β} {o : Option α} {h} : (pmap f o h).isSome = o.isSome
@[simp] theorem pmap_isSome {p : α → Prop} {f : ∀ (a : α), p a → β} {o : Option α} {h} :
(pmap f o h).isSome = o.isSome := by
cases o <;> simp
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
@[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
Option.pmap_eq_map
theorem
(p : α → Prop) (f : α → β) (o : Option α) (H) : @pmap _ _ p (fun a _ => f a) o H = Option.map f o
@[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
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
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
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))
Option.pelim_none
theorem
: pelim none b f = b
@[simp] theorem pelim_none : pelim none b f = b := rfl
Option.pelim_some
theorem
: pelim (some a) b f = f a rfl
@[simp] theorem pelim_some : pelim (some a) b f = f a rfl := rfl
Option.pelim_eq_elim
theorem
: pelim o b (fun a _ => f a) = o.elim b f
@[simp] theorem pelim_eq_elim : pelim o b (fun a _ => f a) = o.elim b f := by
cases o <;> simp
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)))
Option.not_lt_none
theorem
[LT α] {a : Option α} : ¬a < none
@[simp] theorem not_lt_none [LT α] {a : Option α} : ¬ a < none := by cases a <;> simp [LT.lt, Option.lt]
Option.none_lt_some
theorem
[LT α] {a : α} : none < some a
Option.some_lt_some
theorem
[LT α] {a b : α} : some a < some b ↔ a < b
@[simp] theorem some_lt_some [LT α] {a b : α} : somesome a < some b ↔ a < b := by simp [LT.lt, Option.lt]
Option.none_le
theorem
[LE α] {a : Option α} : none ≤ a
Option.not_some_le_none
theorem
[LE α] {a : α} : ¬some a ≤ none
@[simp] theorem not_some_le_none [LE α] {a : α} : ¬ some a ≤ none := by simp [LE.le, Option.le]
Option.some_le_some
theorem
[LE α] {a b : α} : some a ≤ some b ↔ a ≤ b
@[simp] theorem some_le_some [LE α] {a b : α} : somesome a ≤ some b ↔ a ≤ b := by simp [LE.le, Option.le]
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
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
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
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
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
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
Option.min_le_left
theorem
[LE α] [Min α] (min_le_left : ∀ x y : α, min x y ≤ x) {a b : Option α} : min a b ≤ a
Option.min_le_right
theorem
[LE α] [Min α] (min_le_right : ∀ x y : α, min x y ≤ y) {a b : Option α} : min a b ≤ 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
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
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
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
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
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
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
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
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
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
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
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