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 PartENat
, is used to move decidability of the order to
decidability of PartENat.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.ofOption
: Converts anOption α
to aPart α
by sendingnone
tonone
andsome a
tosome a
.Part.toOption
: Converts aPart α
with a decidable domain to anOption α
.Part.equivOption
: 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.
- Dom : Prop
The domain of a partial value
- get : self.Dom → α
Extract a value from a partial value given a proof of
Dom
Instances For
- Part.instAdd
- Part.instAppend
- Part.instCoeOption
- Part.instDiv
- Part.instInhabited
- Part.instInter
- Part.instInv
- Part.instLawfulMonad
- Part.instMembership
- Part.instMod
- Part.instMonad
- Part.instMul
- Part.instNeg
- Part.instOne
- Part.instOrderBot
- Part.instPartialOrder
- Part.instSDiff
- Part.instSub
- Part.instUnion
- Part.instZero
- Part.omegaCompletePartialOrder
Equations
- Part.instMembership = { mem := Part.Mem }
Equations
- Part.instInhabited = { default := Part.none }
Alias of Part.notMem_none
.
Equations
Equations
Equations
- Part.instCoeOption = { coe := Part.ofOption }
Part α
is (classically) equivalent to Option α
.
Equations
- Part.equivOption = { toFun := fun (o : Part α) => o.toOption, invFun := Part.ofOption, left_inv := ⋯, right_inv := ⋯ }
Equations
- Part.instOrderBot = { bot := Part.none, bot_le := ⋯ }
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
- One or more equations did not get rendered due to their size.
We define several instances for constants and operations on Part α
inherited from α
.
This section could be moved to a separate file to avoid the import of
Mathlib/Algebra/Notation/Defs.lean
.