Documentation

CslibFrontier.Foundations.Combinatorics.BudgetTuples

Enumerating the tuples of bounded weight #

Give the coordinates of a tuple of natural numbers positive weights ws. The tuples of total weight ∑ j, ws[j] * β[j] < p (weight) are the exponent tuples of the modes in the proof of the Boolean tensor contraction theorem of [OAI26k] (§D.4.5, p. 63), where p is the precision. The source enumerates them "with polynomial delay and space by ordering the variables and successively choosing each exponent subject to the remaining budget". This file makes that enumeration explicit:

The list holds exactly the tuples of weight below p (mem_budgetTuples), each once (nodup_budgetTuples). It starts at the zero tuple (head?_budgetTuples), each entry is followed by its successor (isChain_budgetTuples), and the last one has none (budgetNext_getLast?). So iterating budgetNext from zero visits every tuple once. The successor is also a left scan (budgetNextScan_eq), one pass over the coordinates; its polynomial-time certificate is in CslibFrontier/Computability/PolyTime/BudgetTuples.lean.

For tuples indexed by a finite type M, listed by a duplicate-free list of all coordinates, a sum over the tuples of weight below p, the mode budget of the contraction recursion, is the sum along budgetTuples (sum_filter_weight_lt_eq).

Main definitions #

Main results #

References #

The weight ∑ j, ws[j] * β[j] of a tuple β for the weights ws.

theorem Cslib.BudgetTuples.lt_ceilDiv_iff {w p b : ℕ} (hw : 0 < w) :
b < p ⌈/⌉ w ↔ w * b < p

A value of a coordinate of weight w fits the budget p exactly when it is below the ceiling division p ⌈/⌉ w.

The tuples of weight below p, in lexicographic order: the first coordinate takes each value b with w * b < p (lt_ceilDiv_iff) in increasing order, and the rest is a tuple of weight below p - w * b.

The successor of a tuple: advance the tail within its remaining budget if possible, and otherwise increment the first coordinate and reset the tail to zero.

The tuples in the list #

theorem Cslib.BudgetTuples.budgetTuples_cons (w : ℕ) (ws : List ℕ) (p : ℕ) :
budgetTuples (w :: ws) p = List.flatMap (fun (b : ℕ) => List.map (fun (x : List ℕ) => b :: x) (budgetTuples ws (p - w * b))) (List.range (p ⌈/⌉ w))
@[simp]
theorem Cslib.BudgetTuples.weight_cons_cons (w : ℕ) (ws : List ℕ) (b : ℕ) (β : List ℕ) :
weight (w :: ws) (b :: β) = w * b + weight ws β
theorem Cslib.BudgetTuples.mem_budgetTuples {ws : List ℕ} (hw : ∀ w ∈ ws, 0 < w) {p : ℕ} {β : List ℕ} :
β ∈ budgetTuples ws p ↔ β.length = ws.length ∧ weight ws β < p

The list holds exactly the tuples of weight below p, for positive weights.

theorem Cslib.BudgetTuples.le_weight_of_mem {ws β : List ℕ} :
(∀ w ∈ ws, 0 < w) → β.length = ws.length → ∀ b ∈ β, b ≤ weight ws β

Each entry of a tuple is at most its weight, for positive weights.

theorem Cslib.BudgetTuples.lt_of_mem_budgetTuples {ws : List ℕ} (hw : ∀ w ∈ ws, 0 < w) {p : ℕ} {β : List ℕ} (hβ : β ∈ budgetTuples ws p) {b : ℕ} (hb : b ∈ β) :
b < p

Every entry of a tuple of weight below p is below p, for positive weights.

Each tuple appears once.

The successor walks the list #

theorem Cslib.BudgetTuples.head?_budgetTuples {ws : List ℕ} (hw : ∀ w ∈ ws, 0 < w) {p : ℕ} (hp : 0 < p) :

The list starts at the zero tuple, for positive weights and a positive budget.

theorem Cslib.BudgetTuples.budgetNext_getLast? {ws : List ℕ} (hw : ∀ w ∈ ws, 0 < w) {p : ℕ} (x : List ℕ) :

The last tuple has no successor.

theorem Cslib.BudgetTuples.isChain_budgetTuples {ws : List ℕ} (hw : ∀ w ∈ ws, 0 < w) (p : ℕ) :
List.IsChain (fun (x y : List ℕ) => budgetNext ws p x = some y) (budgetTuples ws p)

Each tuple is followed by its successor.

Tuples indexed by a finite type #

def Cslib.BudgetTuples.ofList {M : Type u_1} [DecidableEq M] (ms : List M) (l : List ℕ) (Z : M) :

The tuple listed by l as a function of the coordinates listed by ms: coordinate Z reads the entry of l at the position of Z in ms.

theorem Cslib.BudgetTuples.sum_filter_weight_lt_eq {M : Type u_1} [DecidableEq M] {ms : List M} [Fintype M] (hms : ms.Nodup) (hcover : ∀ (Z : M), Z ∈ ms) {w : M → ℕ} (hw : ∀ (Z : M), 0 < w Z) (p : ℕ) {S : Type u_2} [AddCommMonoid S] (f : (M → ℕ) → S) :
∑ β ∈ Fintype.piFinset fun (x : M) => Finset.range p with ∑ Z : M, w Z * β Z < p, f β = (List.map (fun (l : List ℕ) => f (ofList ms l)) (budgetTuples (List.map w ms) p)).sum

The sum over the tuples of weight below p is the sum along budgetTuples, for positive weights and any duplicate-free list ms of all coordinates. The finite set is the mode budget Cslib.Circuits.Frontier.modeBudget w p of the contraction recursion.

The successor as a left scan #

One step of the left scan behind budgetNext, reading a weight and a coordinate (w, b). The state holds the remaining budget, the number of remaining weights, the coordinates read so far, and the successor obtained by incrementing the deepest position read so far that has room.

The successor by a left scan: the deepest position with room is incremented and the positions after it reset to zero.

theorem Cslib.BudgetTuples.budgetNextScan_eq (ws : List ℕ) (p : ℕ) (β : List ℕ) :
budgetNextScan ws p β = budgetNext ws p β

The left scan computes the successor.