Ranking and unranking combinations #
The weight-k indicators of length m, ordered lexicographically with false first, are
numbered 0, …, C(m, k) - 1. Cslib.BitString.unrankCombination m k r is the indicator of rank
r: its first bit is false exactly when r is below the C(m - 1, k) indicators that start
with false. Conversely, Cslib.BitString.rankCombination bs recovers the lexicographic rank of
bs, and Cslib.BitString.subsetEquiv m k packages this ranking/unranking pair with
Cslib.BitString.supportOfList into a computable bijection between k-element subsets of Fin m
and Fin (m.choose k).
Main definitions #
Cslib.BitString.unrankCombination: the weight-kindicator of lengthmof a given rank.Cslib.BitString.rankCombination: the lexicographic rank of a Boolean indicator list.Cslib.BitString.subsetEquiv: computable bijection{ S : Finset (Fin m) // S.card = k } ≃ Fin (m.choose k).
Main results #
Cslib.BitString.length_unrankCombination: the indicator has lengthm.Cslib.BitString.count_true_unrankCombination: a rank belowC(m, k)gives weightk.Cslib.BitString.unrankCombination_injective: distinct ranks belowC(m, k)give distinct indicators.Cslib.BitString.rankCombination_lt_choose,Cslib.BitString.unrankCombination_rankCombination,Cslib.BitString.rankCombination_unrankCombination: range and round-trip identities forrankCombinationandunrankCombination.
The combination of rank r among the weight-k indicators of length m, in the
lexicographic order with false first. A rank r < C(m, k) gives an indicator of weight k
(count_true_unrankCombination), and distinct ranks give distinct indicators
(unrankCombination_injective).
A rank below C(m, k) unranks to an indicator of weight k.
Distinct ranks below C(m, k) unrank to distinct indicators.
The lexicographic rank of a Boolean indicator bs among all indicators of length
bs.length and weight bs.count true (false before true), inverting unrankCombination.
The rank of bs is strictly below C(bs.length, bs.count true).
Unranking the rank of bs at (bs.length, bs.count true) recovers bs.
Ranking unrankCombination m k r for r < C(m, k) recovers r.