Binary map of options #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 data.set.n_ary
, data.finset.n_ary
and order.filter.n_ary
. 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 (λ (a : α), option.map (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.
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 comm_semigroup
.
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
.