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.
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 α × β → γ.
Equations
- Option.map₂ f a b = a.bind fun (a : α) => Option.map (f a) b
Instances For
Option.map₂ in terms of monadic operations. Note that this can't be taken as the definition
because of the lack of universe polymorphism.
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.
Symmetric statement to Option.map₂_map_left_comm.
Symmetric statement to Option.map_map₂_right_comm.
Symmetric statement to Option.map_map₂_distrib_left.
Symmetric statement to Option.map_map₂_distrib_right.
Symmetric statement to Option.map₂_map_left_anticomm.
Symmetric statement to Option.map_map₂_right_anticomm.
Symmetric statement to Option.map_map₂_antidistrib_left.
Symmetric statement to Option.map_map₂_antidistrib_right.
If a is a left identity for a binary operation f, then some a is a left identity for
Option.map₂ f.
If b is a right identity for a binary operation f, then some b is a right identity for
Option.map₂ f.