Maintaining the lowest elements of a growing set #
Finset.lowest k S keeps the k smallest elements of S. This file shows that it can be
maintained online: inserting a new element into the current selection and selecting again gives the
selection of the enlarged set (Finset.lowest_insert_lowest). A one-pass algorithm can therefore
keep only k elements, as the k-minimum-values sketch for distinct elements does
(CslibFrontier.Computability.Streaming.DistinctElements). It also characterizes when all selected
elements satisfy a property closed downwards (Finset.forall_mem_lowest_iff); for the property
· < x, this says that the k-th smallest element is below x exactly when at least k elements
are.
Main results #
Finset.lowest_eq_self: a set of at mostkelements is its own selection.Finset.lowest_eq_lowest_of_subset: the selection fromSis also the selection from any intermediate set.Finset.lowest_insert_lowest: inserting into the selection and selecting again is selecting from the enlarged set.Finset.forall_mem_lowest_iff: the selected elements all satisfy a downward-closed property exactly when at leastkelements do.
A set with at most k elements is its own selection of k lowest elements.
If T ⊆ S contains the k lowest elements of S, then they are also the k lowest elements
of T.
Online selection: inserting x into the k lowest elements of S and selecting the k
lowest again gives the k lowest elements of insert x S.
Order statistics of a downward-closed property: when k ≤ #S, the k lowest elements of
S all satisfy a property P closed downwards exactly when at least k elements of S do.