Documentation

CslibFrontier.Probability.SaksZhou.Snap

Randomized rounding with a random shift ("snap") #

The Saks–Zhou rounding operator [SZ99], called Snap in [ChattopadhyayLiao2020, Definition A.2] after Hoza and Umans, is snap d x y = max (⌊x 2 ^ d - y 2 ^ (-d)⌋ 2 ^ (-d)) 0 for a shift y ∈ [0, 2 ^ d). It perturbs x downward by y 2 ^ (-2d) ∈ [0, 2 ^ (-d)), rounds down to a multiple of 2 ^ (-d) and clips at 0. For x ≥ 0 the result lies in [x - 2 ^ (1 - d), x], and it is always a nonnegative multiple of 2 ^ (-d). Applied entrywise (snapMatrix), it maps substochastic matrices to substochastic matrices with entries in 2 ^ (-d) ℕ (IsDyadicSubstochastic).

The point of the random shift is Lemma A.3 of [CL20]: two nearby values are rounded differently for few shifts. If |a - b| ≤ ε, at most a 2 ^ d ε + 2 ^ (-d) fraction of the shifts y give snap d a y ≠ snap d b y (dens_snap_ne_le). For matrices, a union bound over the entries gives |ι| |κ| (2 ^ d ε + 2 ^ (-d)) (dens_snapMatrix_ne_le). For a ≤ b, each disagreement contributes at least one to the sum of integer-part differences over the shifts. Hermite's identity Int.sum_floor_add_div evaluates that sum as ⌊2 ^ (2d) b⌋ - ⌊2 ^ (2d) a⌋.

Main definitions #

Main results #

References #

noncomputable def Cslib.Probability.SaksZhou.snap (d : ℕ) (x : ℝ) (y : Fin (2 ^ d)) :

The Saks–Zhou rounding operator Snap_d(x, y) = max (⌊x 2 ^ d - y 2 ^ (-d)⌋ 2 ^ (-d)) 0 [ChattopadhyayLiao2020, Definition A.2], for a shift y ∈ [0, 2 ^ d).

theorem Cslib.Probability.SaksZhou.snap_def (d : ℕ) (x : ℝ) (y : Fin (2 ^ d)) :
snap d x y = max (↑⌊x * 2 ^ d - ↑↑y / 2 ^ d⌋ / 2 ^ d) 0
theorem Cslib.Probability.SaksZhou.snap_nonneg (d : ℕ) (x : ℝ) (y : Fin (2 ^ d)) :
0 ≤ snap d x y
theorem Cslib.Probability.SaksZhou.snap_le_max (d : ℕ) (x : ℝ) (y : Fin (2 ^ d)) :
snap d x y ≤ max x 0

Snapping never exceeds the positive part.

theorem Cslib.Probability.SaksZhou.snap_le (d : ℕ) {x : ℝ} (hx : 0 ≤ x) (y : Fin (2 ^ d)) :
snap d x y ≤ x

Snapping rounds a nonnegative value down.

theorem Cslib.Probability.SaksZhou.sub_le_snap (d : ℕ) (x : ℝ) (y : Fin (2 ^ d)) :
x - 2 / 2 ^ d ≤ snap d x y

Snapping loses less than 2 ^ (-d) to the shift and less than 2 ^ (-d) to rounding.

theorem Cslib.Probability.SaksZhou.abs_snap_sub_le (d : ℕ) {x : ℝ} (hx : 0 ≤ x) (y : Fin (2 ^ d)) :
|snap d x y - x| ≤ 2 / 2 ^ d

For x ≥ 0, |snap d x y - x| ≤ 2 ^ (1 - d).

theorem Cslib.Probability.SaksZhou.snap_eq_natFloor (d : ℕ) (x : ℝ) (y : Fin (2 ^ d)) :
snap d x y = ↑⌊x * 2 ^ d - ↑↑y / 2 ^ d⌋₊ / 2 ^ d

Snapping uses the natural floor, which incorporates the lower cutoff at zero.

theorem Cslib.Probability.SaksZhou.exists_snap_eq (d : ℕ) (x : ℝ) (y : Fin (2 ^ d)) :
∃ (k : ℕ), snap d x y = ↑k / 2 ^ d

Snapped values are multiples of 2 ^ (-d).

def Cslib.Probability.SaksZhou.snapCount (scale hits total shift : ℕ) :

Numerator after shifted rounding of a frequency hits / total to the grid of denominator scale. Natural subtraction clips negative values before the division.

theorem Cslib.Probability.SaksZhou.snap_frequency (d hits total : ℕ) (ht : 0 < total) (y : Fin (2 ^ d)) :
snap d (↑hits / ↑total) y = ↑(snapCount (2 ^ d) hits total ↑y) / 2 ^ d

Exact binary arithmetic for rounding a frequency at precision d.

theorem Cslib.Probability.SaksZhou.card_snap_ne_le (d : ℕ) {a b ε : ℝ} (hab : |a - b| ≤ ε) :
↑{y : Fin (2 ^ d) | snap d a y ≠ snap d b y}.card ≤ 4 ^ d * ε + 1

Lemma A.3 of [CL20], counting form. If |a - b| ≤ ε, at most 4 ^ d ε + 1 of the 2 ^ d shifts round a and b differently.

theorem Cslib.Probability.SaksZhou.dens_snap_ne_le (d : ℕ) {a b ε : ℝ} (hab : |a - b| ≤ ε) :
↑{y : Fin (2 ^ d) | snap d a y ≠ snap d b y}.dens ≤ 2 ^ d * ε + (2 ^ d)⁻¹

Lemma A.3 of [CL20] for one entry: if |a - b| ≤ ε, a uniform shift rounds a and b differently with probability at most 2 ^ d ε + 2 ^ (-d).

noncomputable def Cslib.Probability.SaksZhou.snapMatrix {ι : Type u_1} {κ : Type u_2} (d : ℕ) (A : Matrix ι κ ℝ) (y : Fin (2 ^ d)) :
Matrix ι κ ℝ

Entrywise snapping of a matrix.

theorem Cslib.Probability.SaksZhou.snapMatrix_apply {ι : Type u_1} {κ : Type u_2} (d : ℕ) (A : Matrix ι κ ℝ) (y : Fin (2 ^ d)) (i : ι) (j : κ) :
snapMatrix d A y i j = snap d (A i j) y
theorem Cslib.Probability.SaksZhou.card_snapMatrix_ne_le {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] (d : ℕ) {A B : Matrix ι κ ℝ} {ε : ℝ} (hAB : ∀ (i : ι) (j : κ), |A i j - B i j| ≤ ε) :
↑{y : Fin (2 ^ d) | snapMatrix d A y ≠ snapMatrix d B y}.card ≤ ↑(Fintype.card ι) * ↑(Fintype.card κ) * (4 ^ d * ε + 1)

Lemma A.3 of [CL20], counting form for matrices: if two matrices are entrywise within ε, at most |ι| |κ| (4 ^ d ε + 1) shifts snap them differently.

theorem Cslib.Probability.SaksZhou.dens_snapMatrix_ne_le {ι : Type u_1} {κ : Type u_2} [Fintype ι] [Fintype κ] (d : ℕ) {A B : Matrix ι κ ℝ} {ε : ℝ} (hAB : ∀ (i : ι) (j : κ), |A i j - B i j| ≤ ε) :
↑{y : Fin (2 ^ d) | snapMatrix d A y ≠ snapMatrix d B y}.dens ≤ ↑(Fintype.card ι) * ↑(Fintype.card κ) * (2 ^ d * ε + (2 ^ d)⁻¹)

Lemma A.3 of [CL20] for matrices: if two ι × κ matrices are entrywise within ε, a uniform shift snaps them differently with probability at most |ι| |κ| (2 ^ d ε + 2 ^ (-d)).

structure Cslib.Probability.SaksZhou.IsDyadicSubstochastic {ι : Type u_1} [Fintype ι] (d : ℕ) (A : Matrix ι ι ℝ) :

A square matrix is dyadic substochastic at precision d if its entries are nonnegative multiples of 2 ^ (-d) and its rows sum to at most 1. These are the matrices that a read-once branching program reading d bits per step can realize, as in [Hoza2021, proof of Theorem A.3].

  • nonneg (i j : ι) : 0 ≤ A i j

    The entries are nonnegative.

  • sum_le_one (i : ι) : ∑ j : ι, A i j ≤ 1

    Every row sums to at most 1.

  • dyadic (i j : ι) : ∃ (k : ℕ), A i j = ↑k / 2 ^ d

    The entries are multiples of 2 ^ (-d).

theorem Cslib.Probability.SaksZhou.isDyadicSubstochastic_snapMatrix {ι : Type u_1} [Fintype ι] (d : ℕ) {A : Matrix ι ι ℝ} (h0 : ∀ (i j : ι), 0 ≤ A i j) (h1 : ∀ (i : ι), ∑ j : ι, A i j ≤ 1) (y : Fin (2 ^ d)) :

Snapping a substochastic matrix gives a dyadic substochastic matrix.