Partial values of a type #
This file defines part α
, the partial values of a type.
o : part α
carries a proposition o.dom
, its domain, along with a function get : o.dom → α
, its
value. The rule is then that every partial value has a value but, to access it, you need to provide
a proof of the domain.
part α
behaves the same as option α
except that o : option α
is decidably none
or some a
for some a : α
, while the domain of o : part α
doesn't have to be decidable. That means you can
translate back and forth between a partial value with a decidable domain and an option, and
option α
and part α
are classically equivalent. In general, part α
is bigger than option α
.
In current mathlib, part ℕ
, aka enat
, is used to move decidability of the order to decidability
of enat.find
(which is the smallest natural satisfying a predicate, or ∞
if there's none).
Main declarations #
option
-like declarations:
part.none
: The partial value whose domain isfalse
.part.some a
: The partial value whose domain istrue
and whose value isa
.part.of_option
: Converts anoption α
to apart α
by sendingnone
tonone
andsome a
tosome a
.part.to_option
: Converts apart α
with a decidable domain to anoption α
.part.equiv_option
: Classical equivalence betweenpart α
andoption α
.
Monadic structure:
part.bind
:o.bind f
has value(f (o.get _)).get _
(f o
morally) and is defined wheno
andf (o.get _)
are defined.part.map
: Maps the value and keeps the same domain.
Other:
part.restrict
:part.restrict p o
replaces the domain ofo : part α
byp : Prop
so long asp → o.dom
.part.assert
:assert p f
appendsp
to the domains of the values of a partial function.part.unwrap
: Gets the value of a partial value regardless of its domain. Unsound.
Notation #
For a : α
, o : part α
, a ∈ o
means that o
is defined and equal to a
. Formally, it means
o.dom
and o.get _ = a
.
Equations
- part.has_mem = {mem := part.mem α}
Equations
- part.inhabited = {default := part.none α}
Equations
Equations
Equations
- part.has_coe = {coe := part.of_option α}
We give part α
the order where everything is greater than none
.
Equations
- part.partial_order = {le := λ (x y : part α), ∀ (i : α), i ∈ x → i ∈ y, lt := preorder.lt._default (λ (x y : part α), ∀ (i : α), i ∈ x → i ∈ y), le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _}
assert p f
is a bind-like operation which appends an additional condition
p
to the domain and uses f
to produce the value.