Documentation

CslibFrontier.Foundations.Data.Nat.MultiplyHigh

Fibres of multiplication followed by integer division #

The map u ↦ u * d / M sends integers below M into the range below d. Each fibre has between M / d and M / d + 1 elements. This is the integer arithmetic behind multiply-high sampling; it differs from reduction modulo d in the placement of the larger fibres.

Main results #

theorem Nat.mul_div_lt_of_lt {M d u : ℕ} (hM : 0 < M) (hd : 0 < d) (hu : u < M) :
u * d / M < d

Multiplication followed by division maps an input below M into the range below d.

theorem Nat.card_mul_div_fiber {M d : ℕ} (hM : 0 < M) (hd : 0 < d) (k : Fin d) :
Nat.card { u : Fin M // ↑u * d / M = ↑k } = (↑k + 1) * M ⌈/⌉ d - ↑k * M ⌈/⌉ d

The fibre of u ↦ u * d / M over k < d is the interval between consecutive scaled ceiling divisions.

theorem Nat.card_mul_div_fiber_bounds {M d : ℕ} (hM : 0 < M) (hd : 0 < d) (k : Fin d) :
M / d ≤ Nat.card { u : Fin M // ↑u * d / M = ↑k } ∧ Nat.card { u : Fin M // ↑u * d / M = ↑k } ≤ M / d + 1

Every multiply-high fibre has either the floor-size count or at most one more input.