Documentation

CslibFrontier.Computability.Circuit.Frontier.TensorNetwork.ChildCursor

The cursor over the children of an active call #

An active call of the Boolean tensor contraction recursion of [OAI26k] (§D.4.5–§D.4.7, pp. 62–64) evaluates, for each node t of positive multiplicity, each interpolation point k, each exponent tuple β of weight below the node's precision and each group g < r, one child network. This file walks these indices with a cursor: the state is (t, k, β, g), and cursorNext advances the group, then the exponents (Cslib.BudgetTuples.budgetNext), then the point, then the node, resetting the inner indices to their first values. The nodes are numbered 0, …, T - 1; node t has the weights ws t and the budget ps t.

cursorList lists the indices in this order, nested from the node outwards. Under positive counts, weights and budgets, the walk from cursorStart follows it: the list starts at cursorStart (head?_cursorList), each entry is followed by its successor (isChain_cursorList) and the last one has none (cursorNext_getLast?). cursorList_walk states this by index, in the form a loop over counted children consumes. One step reads only the current node's weights and budget and the next node's number of modes (cursorNext_eq_cursorStep), and it is polynomial-time (computableInPolyTime_cursorStep), so the children are enumerated with polynomial delay.

Accumulating. absorbAt folds a child's value into the accumulator of the call: it multiplies it into the product over the groups, adds the product to the sum over the exponent tuples after the last group, and stores the sum after the last tuple. Along cursorList this stores, for each node and point in order, the sum over the tuples of the products over the groups (runAcc_cursorList), seen through any map to a commutative semiring that respects the operations, such as the value of a coefficient list. With the weights listed along the modes, that sum is the sum over the mode budget of the right side of (D.16) (sumAt_eq_sum_filter).

Main definitions #

Main results #

References #

Chains of blocks #

theorem Cslib.Circuits.Frontier.ChildCursor.isChain_flatMap {α : Type u_1} {β : Type u_2} {R : β → β → Prop} (f : α → List β) (l : List α) (hne : ∀ a ∈ l, f a ≠ []) (hblock : ∀ a ∈ l, List.IsChain R (f a)) (hjoin : List.IsChain (fun (a a' : α) => ∀ x ∈ (f a).getLast?, ∀ y ∈ (f a').head?, R x y) l) :

A chain of nonempty blocks. The concatenation of nonempty chains is a chain when the last entry of each block is related to the first entry of the next.

theorem Cslib.Circuits.Frontier.ChildCursor.getLast?_flatMap_concat {α : Type u_1} {β : Type u_2} (f : α → List β) (l : List α) (a : α) (ha : f a ≠ []) :

The last entry of a concatenation of blocks whose last block is nonempty.

The cursor #

@[reducible, inline]

A state of the cursor: the node, the point, the exponents and the group.

The children of one exponent tuple: one per group.

The children of one point: the exponent tuples of weight below ps t, in lexicographic order.

The children of one node: its n points.

The children of an active call, as indices (t, k, β, g): nested from the node outwards, for the nodes t < T, the points k < n, the exponent tuples of weight below ps t and the groups g < r.

The successor of an index: the next group, else the next exponent tuple, else the next point, else the next node, with the inner indices reset to their first values.

theorem Cslib.Circuits.Frontier.ChildCursor.head?_groupBlock {r : ℕ} (hr : 0 < r) (t k : ℕ) (β : List ℕ) :
(groupBlock r t k β).head? = some (t, k, β, 0)
theorem Cslib.Circuits.Frontier.ChildCursor.getLast?_groupBlock {r : ℕ} (hr : 0 < r) (t k : ℕ) (β : List ℕ) :
(groupBlock r t k β).getLast? = some (t, k, β, r - 1)
theorem Cslib.Circuits.Frontier.ChildCursor.head?_pointBlock {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {r : ℕ} (hr : 0 < r) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (t k : ℕ) :
(pointBlock ws ps r t k).head? = some (t, k, List.replicate (ws t).length 0, 0)
theorem Cslib.Circuits.Frontier.ChildCursor.getLast?_pointBlock {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {r : ℕ} (hr : 0 < r) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (t k : ℕ) :
∃ (β : List ℕ), (pointBlock ws ps r t k).getLast? = some (t, k, β, r - 1) ∧ BudgetTuples.budgetNext (ws t) (ps t) β = none
theorem Cslib.Circuits.Frontier.ChildCursor.pointBlock_ne_nil {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {r : ℕ} (hr : 0 < r) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (t k : ℕ) :
pointBlock ws ps r t k ≠ []
theorem Cslib.Circuits.Frontier.ChildCursor.isChain_pointBlock {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {T n r : ℕ} (hr : 0 < r) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (t k : ℕ) :
List.IsChain (fun (x y : State) => cursorNext ws ps T n r x = some y) (pointBlock ws ps r t k)

Within one point, the cursor walks the exponent tuples and the groups.

theorem Cslib.Circuits.Frontier.ChildCursor.head?_nodeBlock {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {n r : ℕ} (hr : 0 < r) (hn : 0 < n) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (t : ℕ) :
(nodeBlock ws ps n r t).head? = some (t, 0, List.replicate (ws t).length 0, 0)
theorem Cslib.Circuits.Frontier.ChildCursor.nodeBlock_ne_nil {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {n r : ℕ} (hr : 0 < r) (hn : 0 < n) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (t : ℕ) :
nodeBlock ws ps n r t ≠ []
theorem Cslib.Circuits.Frontier.ChildCursor.getLast?_nodeBlock {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {n r : ℕ} (hr : 0 < r) (hn : 0 < n) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (t : ℕ) :
∃ (β : List ℕ), (nodeBlock ws ps n r t).getLast? = some (t, n - 1, β, r - 1) ∧ BudgetTuples.budgetNext (ws t) (ps t) β = none
theorem Cslib.Circuits.Frontier.ChildCursor.isChain_nodeBlock {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {T n r : ℕ} (hr : 0 < r) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (t : ℕ) :
List.IsChain (fun (x y : State) => cursorNext ws ps T n r x = some y) (nodeBlock ws ps n r t)

Within one node, the cursor walks the points, the exponent tuples and the groups.

theorem Cslib.Circuits.Frontier.ChildCursor.head?_cursorList {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {T n r : ℕ} (hr : 0 < r) (hn : 0 < n) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (hT : 0 < T) :
(cursorList ws ps T n r).head? = some (cursorStart ws)

The walk starts at cursorStart.

theorem Cslib.Circuits.Frontier.ChildCursor.isChain_cursorList {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {T n r : ℕ} (hr : 0 < r) (hn : 0 < n) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) :
List.IsChain (fun (x y : State) => cursorNext ws ps T n r x = some y) (cursorList ws ps T n r)

Each index is followed by its successor.

theorem Cslib.Circuits.Frontier.ChildCursor.cursorNext_getLast? {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {T n r : ℕ} (hr : 0 < r) (hn : 0 < n) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (x : State) :
x ∈ (cursorList ws ps T n r).getLast? → cursorNext ws ps T n r x = none

The last index has no successor.

theorem Cslib.Circuits.Frontier.ChildCursor.cursorList_walk {ws : ℕ → List ℕ} {ps : ℕ → ℕ} {T n r : ℕ} (hr : 0 < r) (hn : 0 < n) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (hT : 0 < T) :
∃ (h : 0 < (cursorList ws ps T n r).length), (cursorList ws ps T n r)[0] = cursorStart ws ∧ (∀ (c : ℕ) (hc : c + 1 < (cursorList ws ps T n r).length), cursorNext ws ps T n r (cursorList ws ps T n r)[c] = some (cursorList ws ps T n r)[c + 1]) ∧ cursorNext ws ps T n r (cursorList ws ps T n r)[(cursorList ws ps T n r).length - 1] = none

The indexed walk, in the form a counted loop consumes: the first child is cursorStart, child c + 1 is the successor of child c, and the last child has no successor.

Polynomial time #

def Cslib.Circuits.Frontier.ChildCursor.cursorStep (T n r : ℕ) (wt : List ℕ) (pt nextLen : ℕ) (s : State) :

One step of the cursor, from the counts (T, n, r), the current node's weights and budget, and the next node's number of modes: cursorNext with the data of the nodes read off.

theorem Cslib.Circuits.Frontier.ChildCursor.cursorNext_eq_cursorStep (ws : ℕ → List ℕ) (ps : ℕ → ℕ) (T n r : ℕ) (s : State) :
cursorNext ws ps T n r s = cursorStep T n r (ws s.1) (ps s.1) (ws (s.1 + 1)).length s

The cursor is its step at the current node.

@[reducible, inline]

The inputs of cursorStep: the counts in unary, the weights and the budget in binary, the next number of modes in unary, and the state with its exponents in binary.

The cursor step is polynomial-time: the children are enumerated with polynomial delay.

Accumulating the values of the children #

@[reducible, inline]

The accumulator of a call: the product over the groups so far, the sum over the exponent tuples so far, and the stored values, one per node and point.

def Cslib.Circuits.Frontier.ChildCursor.absorbAt (ws : ℕ → List ℕ) (ps : ℕ → ℕ) (r : ℕ) {S : Type u_1} (mul add : S → S → S) (one zero : S) (s : State) (acc : Acc S) (y : S) :
Acc S

Absorb the value y of the child at s: multiply it into the product over the groups; after the last group, add the product to the sum over the exponent tuples; after the last tuple, store the sum.

def Cslib.Circuits.Frontier.ChildCursor.runAcc (ws : ℕ → List ℕ) (ps : ℕ → ℕ) (r : ℕ) {S : Type u_1} (mul add : S → S → S) (one zero : S) (val : State → S) (l : List State) (acc : Acc S) :
Acc S

The accumulator after the children l with the values val.

theorem Cslib.Circuits.Frontier.ChildCursor.runAcc_append (ws : ℕ → List ℕ) (ps : ℕ → ℕ) (r : ℕ) {S : Type u_1} (mul add : S → S → S) (one zero : S) (val : State → S) (l₁ l₂ : List State) (acc : Acc S) :
runAcc ws ps r mul add one zero val (l₁ ++ l₂) acc = runAcc ws ps r mul add one zero val l₂ (runAcc ws ps r mul add one zero val l₁ acc)

Absorbing two lists of children absorbs one, then the other.

def Cslib.Circuits.Frontier.ChildCursor.sumAt (ws : ℕ → List ℕ) (ps : ℕ → ℕ) (r : ℕ) {S : Type u_1} {R : Type u_2} [CommSemiring R] (φ : S → R) (val : State → S) (t k : ℕ) :
R

The values stored for a node and point: the sum over the exponent tuples of the products over the groups.

theorem Cslib.Circuits.Frontier.ChildCursor.runAcc_cursorList (ws : ℕ → List ℕ) (ps : ℕ → ℕ) {T n : ℕ} (r : ℕ) {S : Type u_1} {R : Type u_2} [CommSemiring R] (mul add : S → S → S) (one zero : S) (φ : S → R) (hmul : ∀ (x y : S), φ (mul x y) = φ x * φ y) (hadd : ∀ (x y : S), φ (add x y) = φ x + φ y) (hone : φ one = 1) (hzero : φ zero = 0) (hr : 0 < r) (hps : ∀ (t : ℕ), 0 < ps t) (hws : ∀ (t w : ℕ), w ∈ ws t → 0 < w) (val : State → S) :
∃ (qs : List S), List.map φ qs = List.flatMap (fun (t : ℕ) => List.map (sumAt ws ps r φ val t) (List.range n)) (List.range T) ∧ runAcc ws ps r mul add one zero val (cursorList ws ps T n r) (one, zero, []) = (one, zero, qs)

The values stored by a call: absorbing the values of the children along cursorList stores, for each node and point in order, the sum over the exponent tuples of the products over the groups (sumAt), as seen through φ.

theorem Cslib.Circuits.Frontier.ChildCursor.sumAt_eq_sum_filter (ws : ℕ → List ℕ) (ps : ℕ → ℕ) (r : ℕ) {S : Type u_1} {R : Type u_2} [CommSemiring R] (φ : S → R) {M : Type u_3} [Fintype M] [DecidableEq M] {ms : List M} (hms : ms.Nodup) (hcover : ∀ (Z : M), Z ∈ ms) {w : M → ℕ} (hw : ∀ (Z : M), 0 < w Z) (val : State → S) (t k : ℕ) (hwt : ws t = List.map w ms) (F : (M → ℕ) → R) (hF : ∀ l ∈ BudgetTuples.budgetTuples (ws t) (ps t), (List.map (fun (g : ℕ) => φ (val (t, k, l, g))) (List.range r)).prod = F (BudgetTuples.ofList ms l)) :
sumAt ws ps r φ val t k = ∑ β ∈ Fintype.piFinset fun (x : M) => Finset.range (ps t) with ∑ Z : M, w Z * β Z < ps t, F β

The stored sum is the sum over the mode budget. If the weights of node t list the weights w of the modes along a duplicate-free list ms of all of them, and the product over the groups of the children of each tuple l is F (ofList ms l), then the value stored for t and k is the sum of F over the tuples of weight below ps t, which is Cslib.Circuits.Frontier.modeBudget w (ps t).