Partial values of a type #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 part_enat
, is used to move decidability of the order to
decidability of part_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
.
part α
is the type of "partial values" of type α
. It
is similar to option α
except the domain condition can be an
arbitrary proposition, not necessarily decidable.
Instances for part
- part.has_sizeof_inst
- part.has_mem
- part.inhabited
- part.has_coe
- part.partial_order
- part.order_bot
- part.monad
- part.is_lawful_monad
- part.monad_fail
- part.has_one
- part.has_zero
- part.has_mul
- part.has_add
- part.has_inv
- part.has_neg
- part.has_div
- part.has_sub
- part.has_mod
- part.has_append
- part.has_inter
- part.has_union
- part.has_sdiff
- part.omega_complete_partial_order
- part.has_fix
- part.lawful_fix
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
.
assert p f
is a bind-like operation which appends an additional condition
p
to the domain and uses f
to produce the value.
Equations
- part.has_zero = {zero := has_pure.pure 0}
Equations
- part.has_one = {one := has_pure.pure 1}
Equations
- part.has_mul = {mul := λ (a b : part α), has_mul.mul <$> a <*> b}
Equations
- part.has_add = {add := λ (a b : part α), has_add.add <$> a <*> b}
Equations
Equations
Equations
- part.has_div = {div := λ (a b : part α), has_div.div <$> a <*> b}
Equations
- part.has_sub = {sub := λ (a b : part α), has_sub.sub <$> a <*> b}
Equations
- part.has_mod = {mod := λ (a b : part α), has_mod.mod <$> a <*> b}
Equations
- part.has_append = {append := λ (a b : part α), has_append.append <$> a <*> b}
Equations
- part.has_inter = {inter := λ (a b : part α), has_inter.inter <$> a <*> b}
Equations
- part.has_union = {union := λ (a b : part α), has_union.union <$> a <*> b}
Equations
- part.has_sdiff = {sdiff := λ (a b : part α), has_sdiff.sdiff <$> a <*> b}