Documentation

CslibFrontier.Algorithms.Lean.TrimmedYates

Trimmed Yates passes and selected entries of the subset convolution #

Selected entries of the ranked subset convolution by the trimmed fast zeta transform, following the proof of [CIMY26], Theorem 2.2 (Section 2.1), after [BHKK07] and the trimmed transform of [BHKK10] cited there.

Fix a duplicate-free list l of coordinates and a threshold s. Stage k of Yates's algorithm on F is yatesTransform c (l.take k) F; its value at X reads stage k - 1 only at X and at X minus one coordinate.

The query returns the covering product coveringProduct f g C (query_preprocess), which for ranked inputs and #C = t₁ + t₂ is the subset convolution (query_preprocess_eq_subsetConvolution). solve answers a list of queries after one preprocessing (solve_eq_subsetConvolution).

This module defines the pure mathematical algorithm and proves its correctness over any commutative ring. The Word-RAM implementation and running-time bound of [CIMY26], Theorem 2.2 are in CslibFrontier.Algorithms.WordRAM.TrimmedYates.

Main definitions #

Main results #

References #

Tables #

def Cslib.Algorithms.Lean.TrimmedYates.tabulate {κ : Type u_1} {M : Type u_2} [DecidableEq κ] [Zero M] (dom : List κ) (cell : κ → M) :
κ → M

The lookup table of cell on the keys dom: a finite association-list map from each key of dom to its value, read as 0 off dom.

theorem Cslib.Algorithms.Lean.TrimmedYates.tabulate_apply {κ : Type u_1} {M : Type u_2} [DecidableEq κ] [Zero M] {dom : List κ} (cell : κ → M) {X : κ} (hX : X ∈ dom) :
tabulate dom cell X = cell X

The table of cell reads cell X at every key X of dom.

Layers of subsets #

def Cslib.Algorithms.Lean.TrimmedYates.layers {ι : Type u_1} [DecidableEq ι] (L : List ι) (lo hi : ℕ) :

The subsets of the elements of L with at least lo and at most hi elements, layer by layer, each as the set of a sublist of L.

theorem Cslib.Algorithms.Lean.TrimmedYates.mem_layers {ι : Type u_1} [DecidableEq ι] {L : List ι} (hL : L.Nodup) {lo hi : ℕ} {X : Finset ι} :
X ∈ layers L lo hi ↔ X ⊆ L.toFinset ∧ lo ≤ X.card ∧ X.card ≤ hi
theorem Cslib.Algorithms.Lean.TrimmedYates.length_layers {ι : Type u_1} [DecidableEq ι] (L : List ι) (lo hi : ℕ) :
(layers L lo hi).length = ∑ j ∈ Finset.Icc lo hi, L.length.choose j

There are ∑_{lo ≤ j ≤ hi} (L.length choose j) layered subsets.

Trimmed passes #

def Cslib.Algorithms.Lean.TrimmedYates.stages {ι : Type u_1} {M : Type u_2} {R : Type u_3} [DecidableEq ι] [AddCommMonoid M] [Monoid R] [DistribMulAction R M] (c : R) (s : ℕ) (dom : List (Finset ι)) :
List ι → List (Finset ι → M) → (Finset ι → M) → List (Finset ι → M)

Yates's passes with coefficient c in the coordinates l, on the cells dom, returning every stage: stage 0 is t, and stage k + 1 is the pass in coordinate k of l applied to stage k. A cell reads stage k at sets with at least s elements and the k-th table of fb at smaller sets.

theorem Cslib.Algorithms.Lean.TrimmedYates.getD_stages {ι : Type u_1} {M : Type u_2} {R : Type u_3} [DecidableEq ι] [AddCommMonoid M] [Monoid R] [DistribMulAction R M] (c : R) {s : ℕ} {dom : List (Finset ι)} (P : Finset ι → Prop) (hs : ∀ X ∈ dom, s ≤ X.card) (hdom : ∀ X ∈ dom, ∀ i ∈ X, (s ≤ (X.erase i).card → X.erase i ∈ dom) ∧ ((X.erase i).card < s → P (X.erase i))) (l : List ι) (fb : List (Finset ι → M)) (t G : Finset ι → M) :
(∀ X ∈ dom, t X = G X) → (∀ k < l.length, ∀ (Y : Finset ι), Y.card < s → P Y → fb.getD k 0 Y = BitString.yatesTransform c (List.take k l) G Y) → ∀ k ≤ l.length, ∀ X ∈ dom, (stages c s dom l fb t).getD k 0 X = BitString.yatesTransform c (List.take k l) G X

Correctness of the trimmed passes. Suppose that every cell of dom has at least s elements, that t agrees with G on dom, and that removing a coordinate of l from a cell gives a cell or a set satisfying P with fewer than s elements. If the k-th table of fb agrees with stage k of G on the sets satisfying P with fewer than s elements, then every returned stage k ≤ l.length agrees with stage k of G on dom.

Selected entries of the covering product #

structure Cslib.Algorithms.Lean.TrimmedYates.Tables (ι : Type u_1) (M : Type u_2) :
Type (max u_1 u_2)

The tables kept by the preprocessing phase: every stage of the trimmed transforms on the sets with at most s elements.

  • zetaLeft : List (Finset ι → M)

    Stage k of the zeta transform of the left input.

  • zetaRight : List (Finset ι → M)

    Stage k of the zeta transform of the right input.

  • cover : List (Finset ι → M)

    Stage k of the Möbius transform of the pointwise product of the two zeta transforms.

def Cslib.Algorithms.Lean.TrimmedYates.preprocess {ι : Type u_1} {R : Type u_2} [DecidableEq ι] [CommRing R] (l : List ι) (s : ℕ) (f g : Finset ι → R) :
Tables ι R

The preprocessing phase: every stage of the zeta transforms of f and g, and of the Möbius transform of their pointwise product, on the subsets of l with at most s elements.

def Cslib.Algorithms.Lean.TrimmedYates.query {ι : Type u_1} {R : Type u_2} [DecidableEq ι] [CommRing R] (l : List ι) (s : ℕ) (T : Tables ι R) (f g : Finset ι → R) (C : Finset ι) :
R

The query phase for C: the same stages on the subsets of C with at least s elements, reading the preprocessed stages T at smaller sets. Returns the last stage at C.

def Cslib.Algorithms.Lean.TrimmedYates.solve {ι : Type u_1} {R : Type u_2} [DecidableEq ι] [CommRing R] (l : List ι) (s : ℕ) (f g : Finset ι → R) (Cs : List (Finset ι)) :

Selected entries of the covering product: preprocess once, then answer each query.

Correctness #

theorem Cslib.Algorithms.Lean.TrimmedYates.query_preprocess {ι : Type u_1} {R : Type u_2} [DecidableEq ι] [CommRing R] {l : List ι} (hl : l.Nodup) {s : ℕ} (f g : Finset ι → R) {C : Finset ι} (hC : C ⊆ l.toFinset) (hsC : s ≤ C.card) :
query l s (preprocess l s f g) f g C = BitString.coveringProduct f g C

Correctness of a query: if C is a set of coordinates of l with at least s elements, the query after preprocessing returns the covering product coveringProduct f g C.

theorem Cslib.Algorithms.Lean.TrimmedYates.query_preprocess_eq_subsetConvolution {ι : Type u_1} {R : Type u_2} [DecidableEq ι] [CommRing R] {l : List ι} (hl : l.Nodup) {s t₁ t₂ : ℕ} {f g : Finset ι → R} (hf : ∀ (A : Finset ι), f A ≠ 0 → A.card = t₁) (hg : ∀ (B : Finset ι), g B ≠ 0 → B.card = t₂) {C : Finset ι} (hC : C ⊆ l.toFinset) (hCcard : C.card = t₁ + t₂) (hs : s ≤ t₁ + t₂) :
query l s (preprocess l s f g) f g C = BitString.subsetConvolution f g C

Ranked queries ([CIMY26], Problem 2.1): if f is supported on sets with t₁ elements and g on sets with t₂ elements, a query at a set C of t₁ + t₂ coordinates of l returns the subset convolution ∑_{A ⊆ C} f A * g (C \ A), for every threshold s ≤ t₁ + t₂.

theorem Cslib.Algorithms.Lean.TrimmedYates.solve_eq_subsetConvolution {ι : Type u_1} {R : Type u_2} [DecidableEq ι] [CommRing R] {l : List ι} (hl : l.Nodup) {s t₁ t₂ : ℕ} {f g : Finset ι → R} (hf : ∀ (A : Finset ι), f A ≠ 0 → A.card = t₁) (hg : ∀ (B : Finset ι), g B ≠ 0 → B.card = t₂) {Cs : List (Finset ι)} (hCs : ∀ C ∈ Cs, C ⊆ l.toFinset ∧ C.card = t₁ + t₂) (hs : s ≤ t₁ + t₂) :

Correctness of solve: for queries at sets of t₁ + t₂ coordinates of l, the answers are the selected entries of the subset convolution of ranked inputs.