Documentation

CslibFrontier.Computability.Circuit.Frontier.TensorNetwork.CoeffScheme

Coefficient extraction as a stack recursion #

An entry of a packet tensor of the contraction algorithm of [OAI26k] expands a product of at most L affine row factors and keeps the coefficient of a mode monomial. The source evaluates it in time exp(O(L log s)) and polynomial space (§D.4.6, p. 63). This file gives that evaluation as an instance of Cslib.Algorithms.StackRecursion.Scheme, on the coefficient lists of A_p = (ℤ / 2 ^ p)[U] / (f).

The data (CoeffScheme.Terms) are, at a context x : C, the precision (p, fl), the list of the (dense indices of the) modes, and the terms of the row factors: term x r none is the local term of the row r, and term x r (some k) the coefficient of the mode k. A node of the recursion is a context, the rows still to expand and the exponents still needed, as a dense list. A node with rows r :: rs has m + 1 children for m modes: the local term (c = 0), and the mode modes[c - 1] with its exponent lowered (c ≥ 1); it adds the products of their values with the terms of r, skipping the modes with exponent zero. A node without rows is a leaf: one when every exponent is zero, else zero.

So the run has exp(O(L log m)) steps on a stack of at most L + 1 frames of polynomial size: the time and space of §D.4.6. With polynomial-time data (CoeffScheme.Terms.PolyTime: the precision with p in unary, the modes and the terms), every component of the scheme is polynomial-time (CoeffScheme.Terms.scheme_polyTime), and one native machine computes value on every node (CoeffScheme.Terms.valueCertificate), within time K (m + 2) ^ L Z ^ K and space K Z ^ K for Z = n + m + Rv + 2, where n is the length of the node and Rv bounds the reduced coefficient lists (CoeffScheme.Terms.valueCertificate_le).

Main definitions #

Main results #

References #

The data of coefficient extraction: at a context x : C, the precision (p, fl) of the coefficient lists, the list of the modes, and the terms of the row factors (term x r none the local term of the row r, term x r (some k) the coefficient of the mode k).

@[reducible, inline]

A node: a context, the rows still to expand, and the exponents still needed, as a dense list.

The number of nodes of the derivation for m modes and L rows.

At most (m + 2) ^ L nodes.

def Cslib.Circuits.Frontier.CoeffScheme.Terms.modeOf {C Rw : Type} (S : Terms C Rw) (x : C) (c : ℕ) :

The mode of child c ≥ 1: modes[c - 1].

def Cslib.Circuits.Frontier.CoeffScheme.Terms.childExps {C Rw : Type} (S : Terms C Rw) (x : C) (γ : List ℕ) (c : ℕ) :

The exponents of child c: unchanged for the local term c = 0, and with the exponent of the mode modeOf c lowered by one for c ≥ 1.

def Cslib.Circuits.Frontier.CoeffScheme.Terms.contrib {C Rw : Type} (S : Terms C Rw) (x : C) (r : Rw) (γ : List ℕ) (c : ℕ) (y : List ℕ) :

The contribution of child c with value y at the row r: the local term times y for c = 0; for c ≥ 1, zero when the mode has exponent zero, else its coefficient times y.

The leaf: one when every mode has exponent zero, else zero.

def Cslib.Circuits.Frontier.CoeffScheme.Terms.value {C Rw : Type} (S : Terms C Rw) (x : C) :
List Rw → List ℕ → List ℕ

The value of coefficient extraction, as the recursion computes it: the sum over the children of their contributions.

Correctness #

theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.length_childExps {C Rw : Type} (S : Terms C Rw) (x : C) (γ : List ℕ) (c : ℕ) :
(S.childExps x γ c).length = γ.length
theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.getD_childExps {C Rw : Type} (S : Terms C Rw) (x : C) (γ : List ℕ) (c j : ℕ) :
(S.childExps x γ c).getD j 0 = if c ≠ 0 ∧ j = S.modeOf x c then γ.getD j 0 - 1 else γ.getD j 0
theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.getD_childExps_succ {C Rw : Type} (S : Terms C Rw) (x : C) (γ : List ℕ) (c : ℕ) :
(fun (j : ℕ) => (S.childExps x γ (c + 1)).getD j 0) = Function.update (fun (j : ℕ) => γ.getD j 0) (S.modeOf x (c + 1)) (γ.getD (S.modeOf x (c + 1)) 0 - 1)

The exponents of child c ≥ 1 are those of the node with the exponent of its mode lowered.

theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.val_value {C Rw : Type} (S : Terms C Rw) (x : C) (hm : (S.modes x).Nodup) (rows : List Rw) (γ : List ℕ) :
GaloisRingArith.val (S.prec x).1 (S.prec x).2 (S.value x rows γ) = TensorNetwork.listCoeff (S.modes x).toFinset (List.map (fun (r : Rw) (o : Option ℕ) => GaloisRingArith.val (S.prec x).1 (S.prec x).2 (S.term x r o)) rows) fun (k : ℕ) => γ.getD k 0

The value is listCoeff: along duplicate-free modes, the value in A_p of value is TensorNetwork.listCoeff at the values of the terms and the exponents of the dense list.

The recursion scheme #

Coefficient extraction as a recursion scheme. A node with rows has m + 1 children, counted by the accumulator, and adds their contributions at its first row; a node without rows is a leaf.

The invariant at the root (x₀, (rows₀, γ₀)): nodes keep the context, have a suffix of the rows and exponents of the same length below those of the root; frames also have a counter at most m + 1 and a reduced value; values are reduced.

The leaf value is reduced.

theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.eval_value {C Rw : Type} (S : Terms C Rw) (x₀ : C) (rows₀ : List Rw) (γ₀ : List ℕ) (rows : List Rw) (γ : List ℕ) :
rows <:+ rows₀ → γ.length = γ₀.length → (∀ (j : ℕ), γ.getD j 0 ≤ γ₀.getD j 0) → ∃ h ≤ rows.length, S.scheme.Eval (S.invariant x₀ rows₀ γ₀) (x₀, rows, γ) (S.value x₀ rows γ) (count (S.modes x₀).length rows.length) h

The derivation of coefficient extraction. From a node whose rows are a suffix of the root's and whose exponents are below the root's, the recursion computes value, with count m L nodes for L rows and at most L open calls.

theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.eval_root {C Rw : Type} (S : Terms C Rw) (x : C) (rows : List Rw) (γ : List ℕ) :
∃ h ≤ rows.length, S.scheme.Eval (S.invariant x rows γ) (x, rows, γ) (S.value x rows γ) (count (S.modes x).length rows.length) h

The root: from (x, (rows, γ)), the recursion computes value x rows γ with at most (m + 2) ^ L nodes for m modes and L rows.

Polynomial-time components #

@[reducible, inline]

The encoding of a node: the context, the rows and the exponents in binary.

@[reducible, inline]

The encoding of an accumulator: the counter and the sum, in binary.

theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.precision_polyTime {C Rw : Type} {S : Terms C Rw} {encC : C ↪ List Bool} {encRw : Rw ↪ List Bool} (hS : S.PolyTime encC encRw) {α : Type} {encIn : α ↪ List Bool} {x : α → C} (hx : Turing.MultiTapeTM.ComputableInPolyTime x encIn encC) :
theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.coeffs_polyTime {C Rw : Type} {S : Terms C Rw} {encC : C ↪ List Bool} {encRw : Rw ↪ List Bool} (hS : S.PolyTime encC encRw) {α : Type} {encIn : α ↪ List Bool} {x : α → C} (hx : Turing.MultiTapeTM.ComputableInPolyTime x encIn encC) :
theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.zero_polyTime {C Rw : Type} {S : Terms C Rw} {encC : C ↪ List Bool} {encRw : Rw ↪ List Bool} (hS : S.PolyTime encC encRw) {α : Type} {encIn : α ↪ List Bool} {x : α → C} (hx : Turing.MultiTapeTM.ComputableInPolyTime x encIn encC) :
theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.modeOf_polyTime {C Rw : Type} {S : Terms C Rw} {encC : C ↪ List Bool} {encRw : Rw ↪ List Bool} (hS : S.PolyTime encC encRw) {α : Type} {encIn : α ↪ List Bool} {x : α → C} (hx : Turing.MultiTapeTM.ComputableInPolyTime x encIn encC) {c : α → ℕ} (hc : Turing.MultiTapeTM.ComputableInPolyTime c encIn Turing.MultiTapeTM.encNat) :

The leaf is polynomial-time.

The components of coefficient extraction are polynomial-time.

The native machine and its resources #

The number of steps: 2 (m + 2) ^ L for m modes and L rows, at least the 2 N - 1 steps of a derivation with N ≤ (m + 2) ^ L nodes.

The leaf certificate.

One native machine for coefficient extraction, from polynomial-time data: the clocked run of the scheme from the node itself.

theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.run_scheme {C Rw : Type} {S : Terms C Rw} (x : Node C Rw) :
S.scheme.run fuel id x = some (S.value x.1 x.2.1 x.2.2)

The machine computes value.

noncomputable def Cslib.Circuits.Frontier.CoeffScheme.Terms.valueCertificate {C Rw : Type} {S : Terms C Rw} {encC : C ↪ List Bool} {encRw : Rw ↪ List Bool} (hS : S.PolyTime encC encRw) :

Coefficient extraction, as a native certificate for value on every node.

@[simp]
theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.valueCertificate_time {C Rw : Type} {S : Terms C Rw} {encC : C ↪ List Bool} {encRw : Rw ↪ List Bool} (hS : S.PolyTime encC encRw) :
@[simp]
theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.valueCertificate_space {C Rw : Type} {S : Terms C Rw} {encC : C ↪ List Bool} {encRw : Rw ↪ List Bool} (hS : S.PolyTime encC encRw) :
theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.length_encNode_le {C Rw : Type} {S : Terms C Rw} {encC : C ↪ List Bool} {encRw : Rw ↪ List Bool} {x₀ : C} {rows₀ : List Rw} {γ₀ : List ℕ} {x : Node C Rw} (hx : (S.invariant x₀ rows₀ γ₀).node x) :
((encNode encC encRw) x).length ≤ ((encNode encC encRw) (x₀, rows₀, γ₀)).length

A node of the derivation from a root is at most as long as the root.

theorem Cslib.Circuits.Frontier.CoeffScheme.Terms.valueCertificate_le {C Rw : Type} {S : Terms C Rw} {encC : C ↪ List Bool} {encRw : Rw ↪ List Bool} (hS : S.PolyTime encC encRw) :
∃ (K : ℕ), ∀ (x : Node C Rw) (Rv : ℕ), (∀ (y : List ℕ), SumOps.galois.Reduced (S.prec x.1) y → ((Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) y).length ≤ Rv) → (valueCertificate hS).time x ≤ K * ((S.modes x.1).length + 2) ^ x.2.1.length * (((encNode encC encRw) x).length + (S.modes x.1).length + Rv + 2) ^ K ∧ (valueCertificate hS).space x ≤ K * (((encNode encC encRw) x).length + (S.modes x.1).length + Rv + 2) ^ K

The resources of coefficient extraction. There is K such that on a node of length n with m modes and L rows, if the reduced values of its precision are at most Rv bits long, then with Z = n + m + Rv + 2 the time is at most K (m + 2) ^ L Z ^ K and the space at most K Z ^ K: time exp(O(L log m)) times a polynomial, in polynomial space.