Selecting a column by its natural weight #
The columns of a row receive consecutive intervals of natural labels, of lengths given by their weights. Subtracting each weight from the remaining label finds the column containing it. A label outside every interval returns the row width. This also handles zero weights and empty rows.
Main definitions #
Cslib.scanWeightedRowselects the column containing a natural label.
Main results #
Cslib.scanWeightedRow_specbounds the returned column and its prefix weight.Cslib.scanWeightedRow_eq_iffcharacterizes each real column by its half-open interval.
theorem Cslib.scanWeightedRow_spec (n : ℕ) (weight : ℕ → ℕ) (label : ℕ) :
have j := scanWeightedRow n weight label;
j ≤ n ∧ ∑ i ∈ Finset.range j, weight i ≤ label ∧ (j < n → label < ∑ i ∈ Finset.range (j + 1), weight i)
The returned column is at most the width. Its prefix weight fits the label, and if this is a real column its interval reaches strictly beyond the label.
theorem Cslib.scanWeightedRow_eq_iff {n j : ℕ} (hj : j < n) (weight : ℕ → ℕ) (label : ℕ) :
scanWeightedRow n weight label = j ↔ ∑ i ∈ Finset.range j, weight i ≤ label ∧ label < ∑ i ∈ Finset.range j, weight i + weight j
A label selects column j < n exactly on the half-open interval starting at the prefix
weight of the first j columns.