“Attaches” a proof that some predicate holds for an optional value, if present, returning a subtype that expresses this fact.
This function is primarily used to implement Option.attach
, which allows definitions by
well-founded recursion that use iteration operators (such as Option.map
) to prove that an optional
value drawn from a parameter is smaller than the parameter. This allows the well-founded recursion
mechanism to prove that the function terminates.
Equations
- none.attachWith P H_2 = none
- (some x).attachWith P H_2 = some ⟨x, ⋯⟩
“Attaches” a proof that an optional value, if present, is indeed this value, returning a subtype that expresses this fact.
This function is primarily used to allow definitions by well-founded recursion that use iteration
operators (such as Option.map
) to prove that an optional value drawn from a parameter is smaller
than the parameter. This allows the well-founded recursion mechanism to prove that the function
terminates.
Equations
- xs.attach = xs.attachWith (Membership.mem xs) ⋯
Equations
unattach #
Option.unattach
is the (one-sided) inverse of Option.attach
. It is a synonym for Option.map Subtype.val
.
We use it by providing a simp lemma l.attach.unattach = l
, and simp lemmas which recognize higher order
functions applied to l : Option { x // p x }
which only depend on the value, not the predicate, and rewrite these
in terms of a simpler function applied to l.unattach
.
Further, we provide simp lemmas that push unattach
inwards.
Remove an attached proof that the value in an Option
is indeed that value.
This function is usually inserted automatically by Lean, rather than explicitly in code. It is introduced as an intermediate step during the elaboration of definitions by well-founded recursion.
If this function is encountered in a proof state, the right approach is usually the tactic
simp [Option.unattach, -Option.map_subtype]
.
It is a synonym for Option.map Subtype.val
.
Recognizing higher order functions on subtypes using a function that only depends on the value. #
This lemma identifies maps over lists of subtypes, where the function only depends on the value, not the proposition, and simplifies these to the function directly taking the value.