The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V01. The language of Mathlib

Mathlib.Data.Option.NAry

33 declarations. Mathlib docs · Source

Binary map of options

This file defines the binary map of Option. This is mostly useful to define pointwise operations on intervals.

Main declarations

  • Option.map₂: Binary map of options.

Notes

This file is very similar to the n-ary section of Mathlib/Data/Set/Basic.lean, to Mathlib/Data/Finset/NAry.lean and to Mathlib/Order/Filter/NAry.lean. Please keep them in sync.

We do not define Option.map₃ as its only purpose so far would be to prove properties of Option.map₂ and casing already fulfills this task.

Algebraic replacement rules

A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations to the associativity, commutativity, distributivity, ... of Option.map₂ of those operations. The proof pattern is map₂_lemma operation_lemma. For example, map₂_comm mul_comm proves that map₂ (*) a b = map₂ (*) g f in a CommSemigroup.

The following symmetric restatement are needed because unification has a hard time figuring all the functions if you symmetrize on the spot. This is also how the other n-ary APIs do it.

def Option.map₂ E3 #

{α : Type u_1} → {β : Type u_2} → {γ : Type u_3} → (α → β → γ) → Option α → Option β → Option γ

The image of a binary function f : α → β → γ as a function Option α → Option β → Option γ. Mathematically this should be thought of as the image of the corresponding function α × β → γ.

theorem Option.map₂_def E0 #

∀ {α β γ : Type u} (f : α → β → γ) (a : Option α) (b : Option β), Option.map₂ f a b = f <$> a <*> b

Option.map₂ in terms of monadic operations. Note that this can't be taken as the definition because of the lack of universe polymorphism.

theorem Option.map₂_some_some E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α → β → γ) (a : α) (b : β),
  Option.map₂ f (some a) (some b) = some (f a b)

theorem Option.map₂_coe_coe E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α → β → γ) (a : α) (b : β),
  Option.map₂ f (some a) (some b) = some (f a b)

theorem Option.map₂_none_left E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α → β → γ) (b : Option β), Option.map₂ f none b = none

theorem Option.map₂_none_right E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α → β → γ) (a : Option α), Option.map₂ f a none = none

theorem Option.map₂_coe_left E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α → β → γ) (a : α) (b : Option β),
  Option.map₂ f (some a) b = Option.map (fun b ↦ f a b) b

theorem Option.map₂_coe_right E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α → β → γ) (a : Option α) (b : β),
  Option.map₂ f a (some b) = Option.map (fun a ↦ f a b) a

theorem Option.mem_map₂_iff E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {f : α → β → γ} {a : Option α} {b : Option β} {c : γ},
  c ∈ Option.map₂ f a b ↔ ∃ a' b', a' ∈ a ∧ b' ∈ b ∧ f a' b' = c

theorem Option.map₂_eq_some_iff E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {f : α → β → γ} {a : Option α} {b : Option β} {c : γ},
  Option.map₂ f a b = some c ↔ ∃ a' b', a' ∈ a ∧ b' ∈ b ∧ f a' b' = c

simp-normal form of mem_map₂_iff.

theorem Option.map₂_eq_none_iff E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {f : α → β → γ} {a : Option α} {b : Option β},
  Option.map₂ f a b = none ↔ a = none ∨ b = none

theorem Option.map₂_swap E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α → β → γ) (a : Option α) (b : Option β),
  Option.map₂ f a b = Option.map₂ (fun a b ↦ f b a) b a

theorem Option.map_map₂ E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} (f : α → β → γ) (g : γ → δ),
  Option.map g (Option.map₂ f a b) = Option.map₂ (fun a b ↦ g (f a b)) a b

theorem Option.map₂_map_left E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} (f : γ → β → δ) (g : α → γ),
  Option.map₂ f (Option.map g a) b = Option.map₂ (fun a b ↦ f (g a) b) a b

theorem Option.map₂_map_right E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} (f : α → γ → δ) (g : β → γ),
  Option.map₂ f a (Option.map g b) = Option.map₂ (fun a b ↦ f a (g b)) a b

theorem Option.map₂_curry E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α × β → γ) (a : Option α) (b : Option β),
  Option.map₂ (Function.curry f) a b = Option.map f (Option.map₂ Prod.mk a b)

theorem Option.map_uncurry E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α → β → γ) (x : Option (α × β)),
  Option.map (Function.uncurry f) x = Option.map₂ f (Option.map Prod.fst x) (Option.map Prod.snd x)

theorem Option.map₂_assoc E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} {c : Option γ}
  {ε : Type u_8} {ε' : Type u_9} {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'},
  (∀ (a : α) (b : β) (c : γ), f (g a b) c = f' a (g' b c)) →
    Option.map₂ f (Option.map₂ g a b) c = Option.map₂ f' a (Option.map₂ g' b c)

theorem Option.map₂_comm E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {f : α → β → γ} {a : Option α} {b : Option β} {g : β → α → γ},
  (∀ (a : α) (b : β), f a b = g b a) → Option.map₂ f a b = Option.map₂ g b a

theorem Option.map₂_left_comm E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} {c : Option γ}
  {δ' : Type u_7} {ε : Type u_8} {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'} {g' : β → δ' → ε},
  (∀ (a : α) (b : β) (c : γ), f a (g b c) = g' b (f' a c)) →
    Option.map₂ f a (Option.map₂ g b c) = Option.map₂ g' b (Option.map₂ f' a c)

theorem Option.map₂_right_comm E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} {c : Option γ}
  {δ' : Type u_7} {ε : Type u_8} {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'} {g' : δ' → β → ε},
  (∀ (a : α) (b : β) (c : γ), f (g a b) c = g' (f' a c) b) →
    Option.map₂ f (Option.map₂ g a b) c = Option.map₂ g' (Option.map₂ f' a c) b

theorem Option.map_map₂_distrib E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {f : α → β → γ} {a : Option α} {b : Option β}
  {α' : Type u_5} {β' : Type u_6} {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'},
  (∀ (a : α) (b : β), g (f a b) = f' (g₁ a) (g₂ b)) →
    Option.map g (Option.map₂ f a b) = Option.map₂ f' (Option.map g₁ a) (Option.map g₂ b)

theorem Option.map_map₂_distrib_left E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {f : α → β → γ} {a : Option α} {b : Option β}
  {α' : Type u_5} {g : γ → δ} {f' : α' → β → δ} {g' : α → α'},
  (∀ (a : α) (b : β), g (f a b) = f' (g' a) b) → Option.map g (Option.map₂ f a b) = Option.map₂ f' (Option.map g' a) b

Symmetric statement to Option.map₂_map_left_comm.

theorem Option.map_map₂_distrib_right E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {f : α → β → γ} {a : Option α} {b : Option β}
  {β' : Type u_6} {g : γ → δ} {f' : α → β' → δ} {g' : β → β'},
  (∀ (a : α) (b : β), g (f a b) = f' a (g' b)) → Option.map g (Option.map₂ f a b) = Option.map₂ f' a (Option.map g' b)

Symmetric statement to Option.map_map₂_right_comm.

theorem Option.map₂_map_left_comm E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} {α' : Type u_5}
  {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ},
  (∀ (a : α) (b : β), f (g a) b = g' (f' a b)) → Option.map₂ f (Option.map g a) b = Option.map g' (Option.map₂ f' a b)

Symmetric statement to Option.map_map₂_distrib_left.

theorem Option.map_map₂_right_comm E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} {β' : Type u_6}
  {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ},
  (∀ (a : α) (b : β), f a (g b) = g' (f' a b)) → Option.map₂ f a (Option.map g b) = Option.map g' (Option.map₂ f' a b)

Symmetric statement to Option.map_map₂_distrib_right.

theorem Option.map_map₂_antidistrib E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {f : α → β → γ} {a : Option α} {b : Option β}
  {α' : Type u_5} {β' : Type u_6} {g : γ → δ} {f' : β' → α' → δ} {g₁ : β → β'} {g₂ : α → α'},
  (∀ (a : α) (b : β), g (f a b) = f' (g₁ b) (g₂ a)) →
    Option.map g (Option.map₂ f a b) = Option.map₂ f' (Option.map g₁ b) (Option.map g₂ a)

theorem Option.map_map₂_antidistrib_left E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {f : α → β → γ} {a : Option α} {b : Option β}
  {β' : Type u_6} {g : γ → δ} {f' : β' → α → δ} {g' : β → β'},
  (∀ (a : α) (b : β), g (f a b) = f' (g' b) a) → Option.map g (Option.map₂ f a b) = Option.map₂ f' (Option.map g' b) a

Symmetric statement to Option.map₂_map_left_anticomm.

theorem Option.map_map₂_antidistrib_right E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {f : α → β → γ} {a : Option α} {b : Option β}
  {α' : Type u_5} {g : γ → δ} {f' : β → α' → δ} {g' : α → α'},
  (∀ (a : α) (b : β), g (f a b) = f' b (g' a)) → Option.map g (Option.map₂ f a b) = Option.map₂ f' b (Option.map g' a)

Symmetric statement to Option.map_map₂_right_anticomm.

theorem Option.map₂_map_left_anticomm E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} {α' : Type u_5}
  {f : α' → β → γ} {g : α → α'} {f' : β → α → δ} {g' : δ → γ},
  (∀ (a : α) (b : β), f (g a) b = g' (f' b a)) → Option.map₂ f (Option.map g a) b = Option.map g' (Option.map₂ f' b a)

Symmetric statement to Option.map_map₂_antidistrib_left.

theorem Option.map_map₂_right_anticomm E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {a : Option α} {b : Option β} {β' : Type u_6}
  {f : α → β' → γ} {g : β → β'} {f' : β → α → δ} {g' : δ → γ},
  (∀ (a : α) (b : β), f a (g b) = g' (f' b a)) → Option.map₂ f a (Option.map g b) = Option.map g' (Option.map₂ f' b a)

Symmetric statement to Option.map_map₂_antidistrib_right.

theorem Option.map₂_left_identity E1 #

∀ {α : Type u_1} {β : Type u_2} {f : α → β → β} {a : α},
  (∀ (b : β), f a b = b) → ∀ (o : Option β), Option.map₂ f (some a) o = o

If a is a left identity for a binary operation f, then some a is a left identity for Option.map₂ f.

theorem Option.map₂_right_identity E1 #

∀ {α : Type u_1} {β : Type u_2} {f : α → β → α} {b : β},
  (∀ (a : α), f a b = a) → ∀ (o : Option α), Option.map₂ f o (some b) = o

If b is a right identity for a binary operation f, then some b is a right identity for Option.map₂ f.