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 is- False.
- Part.some a: The partial value whose domain is- Trueand whose value is- a.
- Part.ofOption: Converts an- Option αto a- Part αby sending- noneto- noneand- some ato- some a.
- Part.toOption: Converts a- Part αwith a decidable domain to an- Option α.
- Part.equivOption: Classical equivalence between- Part αand- Option α. Monadic structure:
- Part.bind:- o.bind fhas value- (f (o.get _)).get _(- f omorally) and is defined when- oand- f (o.get _)are defined.
- Part.map: Maps the value and keeps the same domain. Other:
- Part.restrict:- Part.restrict p oreplaces the domain of- o : Part αby- p : Propso long as- p → o.Dom.
- Part.assert:- assert p fappends- pto 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.
Convert a Part α with a decidable domain to an option
Equations
- Part.toOption o = if h : o.Dom then some (o.get h) else none
Instances For
Equations
- Part.instMembershipPart = { mem := Part.Mem }
Equations
- Part.noneDecidable = instDecidableFalse
Equations
Retrieves the value of a : Part α if it exists, and return the provided default value
otherwise.
Equations
- Part.getOrElse a d = if ha : a.Dom then a.get ha else d
Instances For
Equations
- Part.ofOptionDecidable x = match x with | none => Part.noneDecidable | some a => Part.someDecidable a
Equations
- Part.instOrderBotPartToLEToPreorderInstPartialOrderPart = OrderBot.mk (_ : ∀ (x : Part α), ∀ i ∈ ⊥, i ∈ x)
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.assert p f = { Dom := ∃ (h : p), (f h).Dom, get := fun (ha : ∃ (h : p), (f h).Dom) => (f (_ : p)).get (_ : (f (_ : p)).Dom) }
Instances For
Equations
restrict p o h replaces the domain of o with p, and is well defined when
p implies o is defined.
Equations
- Part.restrict p o H = { Dom := p, get := fun (h : p) => o.get (_ : o.Dom) }
Instances For
unwrap o gets the value at o, ignoring the condition. This function is unsound.
Equations
- Part.unwrap o = o.get (_ : o.Dom)
Instances For
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.Group.Defs.