Documentation

CslibFrontier.Foundations.BooleanAnalysis.SubsetZeta

The subset zeta transform and Yates's algorithm #

The subset zeta transform of f : Finset ι → M is subsetZeta f S = ∑_{T ⊆ S} f T. It is inverse to the subset Möbius transform subsetMobius of CslibFrontier.Foundations.BooleanAnalysis.Mobius: subsetZeta_subsetMobius and subsetMobius_subsetZeta.

Yates's algorithm computes both transforms by one pass per coordinate. The pass in coordinate i with coefficient c (yatesPass) replaces f S by f S + c • f (S \ {i}) when i ∈ S and leaves it unchanged otherwise. After the passes in the coordinates of a duplicate-free list l (yatesTransform), the value at S is ∑_{U ⊆ S ∩ l} c ^ #U • f (S \ U) (yatesTransform_apply). With coefficient 1 this is Williams's invariant for the dynamic program in [Wil14], Lemma 4.2, Proof 1, and once every coordinate of S is processed it is the zeta transform (yatesTransform_one_apply); with coefficient -1 it is the Möbius transform (yatesTransform_neg_one_apply). The algorithm goes back to Yates (1937); see [BHK09], Section 2.2. Passes with coefficient -c in reverse order undo passes with coefficient c (yatesTransform_neg_reverse); this gives the second inversion formula subsetMobius_subsetZeta.

The cost of a table implementation on Fin n (n passes over 2 ^ n cells) is in CslibFrontier.Algorithms.Lean.Yates.

Main definitions #

Main results #

References #

def Cslib.BitString.subsetZeta {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] (f : Finset ι → M) (S : Finset ι) :
M

The subset zeta transform: the value at S is ∑_{T ⊆ S} f T.

def Cslib.BitString.yatesPass {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] {R : Type u_3} [Monoid R] [DistribMulAction R M] [DecidableEq ι] (c : R) (i : ι) (f : Finset ι → M) (S : Finset ι) :
M

One pass of Yates's algorithm in coordinate i with coefficient c: the value at S becomes f S + c • f (S \ {i}) when i ∈ S, and stays f S otherwise.

def Cslib.BitString.yatesTransform {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] {R : Type u_3} [Monoid R] [DistribMulAction R M] [DecidableEq ι] (c : R) (l : List ι) (f : Finset ι → M) :
Finset ι → M

The passes of Yates's algorithm with coefficient c in the coordinates of l, in order.

@[simp]
theorem Cslib.BitString.yatesTransform_nil {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] {R : Type u_3} [Monoid R] [DistribMulAction R M] [DecidableEq ι] (c : R) (f : Finset ι → M) :
theorem Cslib.BitString.yatesTransform_cons {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] {R : Type u_3} [Monoid R] [DistribMulAction R M] [DecidableEq ι] (c : R) (i : ι) (l : List ι) (f : Finset ι → M) :
theorem Cslib.BitString.yatesTransform_append {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] {R : Type u_3} [Monoid R] [DistribMulAction R M] [DecidableEq ι] (c : R) (l₁ l₂ : List ι) (f : Finset ι → M) :
yatesTransform c (l₁ ++ l₂) f = yatesTransform c l₂ (yatesTransform c l₁ f)
theorem Cslib.BitString.yatesTransform_apply {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] {R : Type u_3} [Monoid R] [DistribMulAction R M] [DecidableEq ι] (c : R) {l : List ι} (hl : l.Nodup) (f : Finset ι → M) (S : Finset ι) :
yatesTransform c l f S = ∑ U ∈ (S ∩ l.toFinset).powerset, c ^ U.card • f (S \ U)

The passes in closed form. After the passes in the coordinates of a duplicate-free list l, the value at S is ∑_{U ⊆ S ∩ l} c ^ #U • f (S \ U). For c = 1 this is the invariant of [Wil14], Lemma 4.2, Proof 1: the sum of f T over the T ⊆ S that agree with S outside the processed coordinates.

theorem Cslib.BitString.yatesTransform_apply_of_subset {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] {R : Type u_3} [Monoid R] [DistribMulAction R M] [DecidableEq ι] (c : R) {l : List ι} (hl : l.Nodup) (f : Finset ι → M) {S : Finset ι} (hS : S ⊆ l.toFinset) :
yatesTransform c l f S = ∑ T ∈ S.powerset, c ^ (S \ T).card • f T

Once every coordinate of S has been processed, the value at S is ∑_{T ⊆ S} c ^ #(S \ T) • f T.

theorem Cslib.BitString.yatesTransform_one_apply {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] [DecidableEq ι] {l : List ι} (hl : l.Nodup) (f : Finset ι → M) {S : Finset ι} (hS : S ⊆ l.toFinset) :

Yates's algorithm computes the zeta transform: with coefficient 1, once every coordinate of S has been processed, the value at S is subsetZeta f S.

theorem Cslib.BitString.yatesTransform_one_eq_subsetZeta {ι : Type u_1} {M : Type u_2} [AddCommMonoid M] [DecidableEq ι] {l : List ι} (hl : l.Nodup) (hall : ∀ (i : ι), i ∈ l) (f : Finset ι → M) :

The passes in every coordinate, once each, compute the zeta transform.

theorem Cslib.BitString.yatesPass_neg_yatesPass {ι : Type u_1} {M : Type u_2} {R : Type u_3} [AddCommGroup M] [Ring R] [Module R M] [DecidableEq ι] (c : R) (i : ι) (f : Finset ι → M) :
yatesPass (-c) i (yatesPass c i f) = f

The pass with coefficient -c undoes the pass with coefficient c in the same coordinate.

theorem Cslib.BitString.yatesTransform_neg_reverse {ι : Type u_1} {M : Type u_2} {R : Type u_3} [AddCommGroup M] [Ring R] [Module R M] [DecidableEq ι] (c : R) (l : List ι) (f : Finset ι → M) :

The passes with coefficient -c in reverse order undo the passes with coefficient c.

theorem Cslib.BitString.subsetZeta_subsetMobius {ι : Type u_1} {M : Type u_2} [AddCommGroup M] (f : Finset ι → M) :

Möbius inversion: the zeta transform of the Möbius transform is the identity.

theorem Cslib.BitString.subsetMobius_congr {ι : Type u_1} {M : Type u_2} [AddCommGroup M] {f g : Finset ι → M} {S : Finset ι} (h : ∀ T ⊆ S, f T = g T) :

The Möbius transform at S reads only the values at subsets of S.

theorem Cslib.BitString.yatesTransform_neg_one_apply {ι : Type u_1} {M : Type u_2} [AddCommGroup M] [DecidableEq ι] {l : List ι} (hl : l.Nodup) (f : Finset ι → M) {S : Finset ι} (hS : S ⊆ l.toFinset) :

Yates's algorithm computes the Möbius transform: with coefficient -1, once every coordinate of S has been processed, the value at S is subsetMobius f S.

theorem Cslib.BitString.subsetMobius_subsetZeta {ι : Type u_1} {M : Type u_2} [AddCommGroup M] (f : Finset ι → M) :

Möbius inversion, the other direction: the Möbius transform of the zeta transform is the identity. The proof runs Yates's passes forwards with coefficient 1 and backwards with coefficient -1.