Documentation

CslibFrontier.Algorithms.Lean.Yates

Yates's algorithm on tables of size 2 ^ n #

A function on the subsets of Fin n is stored as a table t : Vector M (2 ^ n): cell k holds the value at maskSet n k, the set of positions of the binary digits 1 of k, and maskIndex S is the cell of S. Yates's algorithm (transform c) makes n passes over the table, one per coordinate i. Pass i (pass c i) writes the new value of cell k as t[k] + c • t[k ^^^ 2 ^ i] when bit i of k is set and as t[k] otherwise, following [Wil14], Lemma 4.2, Proof 1, and [BHK09], Section 2.2.

The output at maskSet n k is ∑_{T ⊆ maskSet n k} c ^ #(maskSet n k \ T) • F T whenever the input table represents F (getElem_transform). The fast zeta transform zeta (coefficient 1) computes subsetZeta F and the fast Möbius transform mobius (coefficient -1) computes subsetMobius F. For checked O((n + 1) * 2 ^ n) standard-basis word-RAM running-time bounds on ℕ and ℤ tables, see CslibFrontier.Algorithms.WordRAM.Yates.

Main definitions #

Main results #

References #

Cells and subsets #

The set of positions i < n of the binary digits 1 of k.

The cell of the subset S of Fin n: the number whose binary digit i is 1 exactly when i ∈ S.

@[simp]
theorem Cslib.Algorithms.Lean.Yates.maskSet_xor_two_pow {n k : ℕ} {i : Fin n} (hi : k.testBit ↑i = true) :
maskSet n (k ^^^ 2 ^ ↑i) = (maskSet n k).erase i

Flipping a binary digit 1 of the index erases its position from the set.

theorem Cslib.Algorithms.Lean.Yates.maskSet_eq_filter {n : ℕ} (k : Fin (2 ^ n)) :
maskSet n ↑k = {i : Fin n | (BitString.equivFin n).symm k i = true}

The set of a cell is the set of true coordinates of the corresponding bit string.

The bit string of cell k is the indicator of the set of cell k.

@[simp]
theorem Cslib.Algorithms.Lean.Yates.getElem_eq_maskIndex_maskSet {α : Type u_1} {n : ℕ} (t : Vector α (2 ^ n)) (k : ℕ) (hk : k < 2 ^ n) :
t[k] = t[↑(maskIndex (maskSet n k))]

Every table represents the function reading the cell of each set.

The passes #

def Cslib.Algorithms.Lean.Yates.pass {M : Type u_1} {R : Type u_2} [AddCommMonoid M] [Monoid R] [DistribMulAction R M] {n : ℕ} (c : R) (i : Fin n) (t : Vector M (2 ^ n)) :
Vector M (2 ^ n)

The pass of Yates's algorithm in coordinate i with coefficient c: cell k becomes t[k] + c • t[k ^^^ 2 ^ i] when bit i of k is set, and t[k] otherwise.

def Cslib.Algorithms.Lean.Yates.transform {M : Type u_1} {R : Type u_2} [AddCommMonoid M] [Monoid R] [DistribMulAction R M] {n : ℕ} (c : R) (t : Vector M (2 ^ n)) :
Vector M (2 ^ n)

Yates's algorithm with coefficient c: the passes in coordinates 0, …, n - 1.

def Cslib.Algorithms.Lean.Yates.zeta {M : Type u_1} [AddCommMonoid M] {n : ℕ} (t : Vector M (2 ^ n)) :
Vector M (2 ^ n)

The fast zeta transform: Yates's algorithm with coefficient 1.

theorem Cslib.Algorithms.Lean.Yates.getElem_pass {M : Type u_1} {R : Type u_2} [AddCommMonoid M] [Monoid R] [DistribMulAction R M] {n : ℕ} (c : R) (i : Fin n) (t : Vector M (2 ^ n)) (F : Finset (Fin n) → M) (hF : ∀ (k : ℕ) (hk : k < 2 ^ n), t[k] = F (maskSet n k)) (k : ℕ) (hk : k < 2 ^ n) :
(pass c i t)[k] = BitString.yatesPass c i F (maskSet n k)
theorem Cslib.Algorithms.Lean.Yates.getElem_transform {M : Type u_1} {R : Type u_2} [AddCommMonoid M] [Monoid R] [DistribMulAction R M] {n : ℕ} (c : R) (t : Vector M (2 ^ n)) (F : Finset (Fin n) → M) (hF : ∀ (k : ℕ) (hk : k < 2 ^ n), t[k] = F (maskSet n k)) (k : ℕ) (hk : k < 2 ^ n) :
(transform c t)[k] = ∑ T ∈ (maskSet n k).powerset, c ^ (maskSet n k \ T).card • F T

Correctness of Yates's algorithm. If the table t represents F, the output at maskSet n k is ∑_{T ⊆ maskSet n k} c ^ #(maskSet n k \ T) • F T.

theorem Cslib.Algorithms.Lean.Yates.getElem_zeta {M : Type u_1} [AddCommMonoid M] {n : ℕ} (t : Vector M (2 ^ n)) (F : Finset (Fin n) → M) (hF : ∀ (k : ℕ) (hk : k < 2 ^ n), t[k] = F (maskSet n k)) (k : ℕ) (hk : k < 2 ^ n) :

The fast zeta transform computes the zeta transform: if the table t represents F, the output at maskSet n k is subsetZeta F (maskSet n k).

theorem Cslib.Algorithms.Lean.Yates.getElem_zeta_maskIndex {M : Type u_1} [AddCommMonoid M] {n : ℕ} (t : Vector M (2 ^ n)) (S : Finset (Fin n)) :
(zeta t)[↑(maskIndex S)] = BitString.subsetZeta (fun (T : Finset (Fin n)) => t[↑(maskIndex T)]) S

The fast zeta transform, read at the cell of S, is the zeta transform of the table read at the cells of the subsets of S.

def Cslib.Algorithms.Lean.Yates.mobius {M : Type u_1} [AddCommGroup M] {n : ℕ} (t : Vector M (2 ^ n)) :
Vector M (2 ^ n)

The fast Möbius transform: Yates's algorithm with coefficient -1.

theorem Cslib.Algorithms.Lean.Yates.getElem_mobius {M : Type u_1} [AddCommGroup M] {n : ℕ} (t : Vector M (2 ^ n)) (F : Finset (Fin n) → M) (hF : ∀ (k : ℕ) (hk : k < 2 ^ n), t[k] = F (maskSet n k)) (k : ℕ) (hk : k < 2 ^ n) :

The fast Möbius transform computes the Möbius transform: if the table t represents F, the output at maskSet n k is subsetMobius F (maskSet n k).

theorem Cslib.Algorithms.Lean.Yates.getElem_mobius_maskIndex {M : Type u_1} [AddCommGroup M] {n : ℕ} (t : Vector M (2 ^ n)) (S : Finset (Fin n)) :
(mobius t)[↑(maskIndex S)] = BitString.subsetMobius (fun (T : Finset (Fin n)) => t[↑(maskIndex T)]) S

The fast Möbius transform, read at the cell of S, is the Möbius transform of the table read at the cells of the subsets of S.