O(n)
. Partial map. If f : Π a, P a → β
is a partial function defined on
a : α
satisfying P
, then pmap f l h
is essentially the same as map f l
but is defined only when all members of l
satisfy P
, using the proof
to apply f
.
We replace this at runtime with a more efficient version via the csimp
lemma pmap_eq_pmapImpl
.
Equations
- Array.pmap f l H = (List.pmap f l.toList ⋯).toArray
Instances For
O(1)
. "Attach" a proof P x
that holds for all the elements of xs
to produce a new array
with the same elements but in the type {x // P x}
.
Equations
- xs.attachWith P H = { toList := xs.toList.attachWith P ⋯ }
Instances For
O(1)
. "Attach" the proof that the elements of xs
are in xs
to produce a new array
with the same elements but in the type {x // x ∈ xs}
.
Equations
- xs.attach = xs.attachWith (Membership.mem xs) ⋯
Instances For
If we fold over l.attach
with a function that ignores the membership predicate,
we get the same results as folding over l
directly.
This is useful when we need to use attach
to show termination.
Unfortunately this can't be applied by simp
because of the higher order unification problem,
and even when rewriting we need to specify the function explicitly.
See however foldl_subtype
below.
If we fold over l.attach
with a function that ignores the membership predicate,
we get the same results as folding over l
directly.
This is useful when we need to use attach
to show termination.
Unfortunately this can't be applied by simp
because of the higher order unification problem,
and even when rewriting we need to specify the function explicitly.
See however foldr_subtype
below.
See also pmap_eq_map_attach
for writing pmap
in terms of map
and attach
.
unattach #
Array.unattach
is the (one-sided) inverse of Array.attach
. It is a synonym for Array.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 : Array { 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.
A synonym for l.map (·.val)
. Mostly this should not be needed by users.
It is introduced as in intermediate step by lemmas such as map_subtype
,
and is ideally subsequently simplified away by unattach_attach
.
If not, usually the right approach is simp [Array.unattach, -Array.map_subtype]
to unfold.
Instances For
Recognizing higher order functions using a function that only depends on the value. #
This lemma identifies folds over arrays of subtypes, where the function only depends on the value, not the proposition, and simplifies these to the function directly taking the value.
Variant of foldl_subtype
with side condition to check stop = l.size
.
This lemma identifies folds over arrays of subtypes, where the function only depends on the value, not the proposition, and simplifies these to the function directly taking the value.
Variant of foldr_subtype
with side condition to check stop = l.size
.
This lemma identifies maps over arrays of subtypes, where the function only depends on the value, not the proposition, and simplifies these to the function directly taking the value.