Filtered list positions and order-preserving index helpers #
Generic list-indexing helpers for positions of elements matching a Boolean predicate pred:
List.nthFilterPos: position inlof then-th element satisfyingpred, with bounds, strict monotonicity, injectivity, and append equations.List.filter_getElem_count_take: the((cs.take k).filter pred).length-th element ofcs.filter prediscs[k]wheneverpred cs[k] = true.List.filter_strictMono_indicesandList.map_eq_of_strictMono_surj: strictly monotone index embeddings for filtered sublists and equality criteria via surjective strictly monotone position maps.
Main definitions #
List.nthFilterPos: index of then-th element of a list satisfying a Boolean predicate.
Main results #
List.nthFilterPos_strictMono,List.nthFilterPos_inj:nthFilterPosis strictly monotone and injective in the filtered rankn.List.filter_getElem_count_take: lookup incs.filter predat the prefix count(cs.take k).filter pred.List.map_eq_of_strictMono_surj: a list whose positions are strictly monotone, bounded, and surjective onto0 ..< dst.lengthmaps ontodst.
Skipping a head element with pred a = false shifts nthFilterPos by 1 for every n.
Matching head element at rank n + 1 shifts the n-th match in rest by 1.
nthFilterPos pred l n is some iff l.filter pred has length strictly greater than n.
If nthFilterPos pred l n = some pos, then pos < l.length, l[pos]? = (l.filter pred)[n]?,
and pred holds at l[pos]?.
nthFilterPos is strictly monotone in the filtered rank m < n.
nthFilterPos is injective in the filtered rank n.
Ranks at or beyond (l₁.filter pred).length shift into l₂ by l₁.length.
Any match of nthFilterPos pred (l₁ ++ l₂) landing strictly before l₁.length comes from
l₁.
If pos : β → ℕ is strictly monotone on src, bounded below dst.length, and surjective
onto 0 ..< dst.length with val b = dst[pos b], then src.map pos = List.range dst.length and
src.map val = dst.
Every filtered sublist l.filter pred embeds into l via a strictly monotone index map.