Documentation

CslibFrontier.Computability.Circuit.Frontier.TensorNetwork.DescribedContraction

Contracting a network with described tensors by direct summation #

The leaves of the recursion in the proof of Theorem D.1 of [OAI26k] are summed directly over all Boolean edge assignments (Appendix D.4.7, p. 64), but their tensors are not tables: a packet vertex has up to 2 L ports, so its table would be superpolynomial, and its entries are computed from a description instead (Appendix D.4.6, p. 63). A described network (DescribedNetwork T) has, for each vertex, its ports and a descriptor t : T of its tensor, whose entry at the bits bs on the ports is eval t bs for an evaluator eval. Explicit networks are the case of tables (ExplicitTensorNetwork, DescribedNetwork.contraction_entry).

Values and their operations (SumOps). The entries are values Y combined by ring operations that depend on a precision q : Q: a zero, a one, a sum and a product, whose results are reduced (of bounded size). The two instances are natural numbers modulo 2 ^ P (SumOps.mod) and the coefficient lists of A_p = (ℤ / 2 ^ p)[U] / (f) at the precision (p, fl) (SumOps.galois), the coefficient rings of the recursion (Appendix D.4.1, p. 57). A map of the values into a commutative semiring that takes the operations at q to the semiring operations (SumOps.IsHom) takes the computed sum to the contraction of the mapped entries.

Direct summation as a stack recursion (DescribedNetwork.sumScheme). The sum over the 2 ^ m assignments is a call whose children are the assignments, in binary order, added with the operations; an assignment is a call whose children are the entries of the vertices at its bits, multiplied with the operations; an entry is a leaf, evaluated by the evaluator. The derivation has 2 ^ m (k + 1) + 1 nodes for k vertices and two open calls, and its value is the fold of the operations (DescribedNetwork.sumValue, DescribedNetwork.eval_sumRoot). So a native certificate of the evaluator, with any bounds, gives one native machine for the sum on every input (DescribedNetwork.contractionCertificate), through Cslib.Algorithms.StackRecursion.Scheme.certificate. If the evaluator takes time E, space ES and outputs at most Ev bits on every vertex, and reduced values are at most Rv bits, the machine takes time 2 ^ m (k + 1) + 1 times K (n + Ev + Rv + 1) ^ K + 2 E and space K (n + Ev + Rv + 1) ^ K + ES on inputs of length n (DescribedNetwork.contractionCertificate_le). Under a homomorphism the value is the contraction (DescribedNetwork.SumOps.IsHom.map_sumValue): modulo 2 ^ P for natural numbers (DescribedNetwork.sumValue_mod, DescribedNetwork.modContractionCertificate), and in A_p for coefficient lists (DescribedNetwork.val_sumValue_galois). This is the leaf step of the contraction algorithm, with implicit packet tensors as descriptors.

Main definitions #

Main results #

References #

Values and their operations #

Ring operations on values for direct summation: at each precision q : Q, a zero, a one, a sum and a product on the values Y, and the reduced values at q, among which are the zero, the one and every sum and product.

  • zero : Q → Y

    The zero at a precision.

  • one : Q → Y

    The one at a precision.

  • add : Q → Y → Y → Y

    The sum at a precision.

  • mul : Q → Y → Y → Y

    The product at a precision.

  • Reduced : Q → Y → Prop

    The reduced values at a precision.

  • reduced_zero (q : Q) : self.Reduced q (self.zero q)
  • reduced_one (q : Q) : self.Reduced q (self.one q)
  • reduced_add (q : Q) (a b : Y) : self.Reduced q (self.add q a b)
  • reduced_mul (q : Q) (a b : Y) : self.Reduced q (self.mul q a b)
structure Cslib.Circuits.Frontier.SumOps.IsHom {Q Y : Type} (ops : SumOps Q Y) (q : Q) {R : Type u_1} [CommSemiring R] (φ : Y → R) :

A homomorphism of the operations at q: a map of the values into a commutative semiring taking the zero, the one, sums and products at q to those of the semiring.

  • map_zero : φ (ops.zero q) = 0
  • map_one : φ (ops.one q) = 1
  • map_add (a b : Y) : φ (ops.add q a b) = φ a + φ b
  • map_mul (a b : Y) : φ (ops.mul q a b) = φ a * φ b
structure Cslib.Circuits.Frontier.SumOps.PolyTime {Q Y : Type} (ops : SumOps Q Y) (encQ : Q ↪ List Bool) (encY : Y ↪ List Bool) :

Polynomial-time operations, for encodings of the precisions and the values.

theorem Cslib.Circuits.Frontier.SumOps.reduced_foldl {Q Y : Type} (ops : SumOps Q Y) {α : Type} (q : Q) (op : Y → Y → Y) (hop : ∀ (a b : Y), ops.Reduced q (op a b)) (f : α → Y) (l : List α) {a : Y} (ha : ops.Reduced q a) :
ops.Reduced q (List.foldl (fun (acc : Y) (v : α) => op acc (f v)) a l)

A left fold of the sum or the product from a reduced start is reduced.

theorem Cslib.Circuits.Frontier.SumOps.IsHom.map_foldl_mul {Q Y : Type} {ops : SumOps Q Y} {q : Q} {R : Type u_1} [CommSemiring R] {φ : Y → R} (h : ops.IsHom q φ) {α : Type} (f : α → Y) (l : List α) (a : Y) :
φ (List.foldl (fun (acc : Y) (v : α) => ops.mul q acc (f v)) a l) = φ a * (List.map (fun (v : α) => φ (f v)) l).prod

A homomorphism takes a fold of products to the product of the images.

theorem Cslib.Circuits.Frontier.SumOps.IsHom.map_foldl_add {Q Y : Type} {ops : SumOps Q Y} {q : Q} {R : Type u_1} [CommSemiring R] {φ : Y → R} (h : ops.IsHom q φ) (g : ℕ → Y) (n : ℕ) (a : Y) :
φ (List.foldl (fun (acc : Y) (j : ℕ) => ops.add q acc (g j)) a (List.range n)) = φ a + ∑ j ∈ Finset.range n, φ (g j)

A homomorphism takes a fold of sums over a range to the sum of the images.

Direct summation as a recursion scheme #

@[reducible, inline]

A node of direct summation: its kind (0 the sum, 1 an assignment, 2 an entry), the precision and the network, and the current word and vertex index.

def Cslib.Circuits.Frontier.DescribedNetwork.entryOf {T Q Y : Type} (ops : SumOps Q Y) (eval : T → List Bool → Y) (x : Node Q T) :
Y

The entry of a node: the evaluator at the descriptor of its vertex and the bits of its word on the vertex's ports, or the zero for an index past the vertices.

Direct summation as a recursion scheme. The sum (kind 0) has the 2 ^ m assignments as children, adding their values; an assignment (kind 1) has the entries of the vertices as children, multiplying them; an entry (kind 2) is a leaf. The operations are those at the precision of the node, and the accumulator is a counter and a value.

The root of direct summation on (q, d).

def Cslib.Circuits.Frontier.DescribedNetwork.weight {T Q Y : Type} (ops : SumOps Q Y) (eval : T → List Bool → Y) (q : Q) (d : DescribedNetwork T) (word : List Bool) :
Y

The weight of a word: the product of the entries at its bits, folded with the operations at q.

def Cslib.Circuits.Frontier.DescribedNetwork.sumValue {T Q Y : Type} (ops : SumOps Q Y) (eval : T → List Bool → Y) (q : Q) (d : DescribedNetwork T) :
Y

The value of direct summation: the weights of the 2 ^ m words in binary order, folded with the sum at q.

The shape of a node of direct summation on q: it keeps q, its kind is at most 2, its word has at most m bits and its index is at most the number of vertices.

The invariant of direct summation on q: nodes have the shape of NodeShape, frames also have a counter at most 2 ^ m + k and a reduced value, and every value is reduced or an entry of a vertex at the bits of an m-bit word.

theorem Cslib.Circuits.Frontier.DescribedNetwork.eval_entry {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} (q : Q × DescribedNetwork T) {word : List Bool} {v : ℕ} (hw : word.length = q.2.numEdges) (hv : v < q.2.vertices.length) :
(sumScheme ops eval).Eval (sumInvariant ops eval q) (2, q, word, v) (entryOf ops eval (2, q, word, v)) 1 0

An entry is a leaf.

theorem Cslib.Circuits.Frontier.DescribedNetwork.eval_assign {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} (q : Q) (d : DescribedNetwork T) {word : List Bool} (hw : word.length = d.numEdges) :
∃ h ≤ 1, (sumScheme ops eval).Eval (sumInvariant ops eval (q, d)) (1, (q, d), word, 0) (weight ops eval q d word) (d.vertices.length + 1) h

An assignment evaluates to the weight of its word, with one node per vertex plus one and one open call.

theorem Cslib.Circuits.Frontier.DescribedNetwork.eval_sumRoot {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} (q : Q) (d : DescribedNetwork T) :
∃ h ≤ 2, (sumScheme ops eval).Eval (sumInvariant ops eval (q, d)) (sumRoot (q, d)) (sumValue ops eval q d) (2 ^ d.numEdges * (d.vertices.length + 1) + 1) h

Direct summation computes sumValue, with 2 ^ m (k + 1) + 1 nodes for m edges and k vertices, and at most two open calls.

theorem Cslib.Circuits.Frontier.DescribedNetwork.reduced_sumValue {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} (q : Q) (d : DescribedNetwork T) :
ops.Reduced q (sumValue ops eval q d)

sumValue is reduced.

theorem Cslib.Circuits.Frontier.SumOps.IsHom.map_sumValue {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} {q : Q} {R : Type u_1} [CommSemiring R] {φ : Y → R} (h : ops.IsHom q φ) (d : DescribedNetwork T) :
φ (DescribedNetwork.sumValue ops eval q d) = DescribedNetwork.contraction (fun (t : T) (bs : List Bool) => φ (eval t bs)) d

Under a homomorphism, the value is the contraction of the mapped entries.

Natural numbers modulo a power of two #

Natural numbers modulo 2 ^ P, with the precision P; the reduced values are those below 2 ^ P.

The cast into ZMod (2 ^ P) is a homomorphism of the operations at P.

theorem Cslib.Circuits.Frontier.DescribedNetwork.sumValue_mod {T : Type} (eval : T → List Bool → ℕ) (P : ℕ) (d : DescribedNetwork T) :
sumValue SumOps.mod eval P d = contraction eval d % 2 ^ P

Modulo 2 ^ P, the value is the contraction modulo 2 ^ P.

Coefficient lists of (ℤ / 2 ^ p)[U] / (f) #

Coefficient lists of A_p = (ℤ / 2 ^ p)[U] / (f), with the precision (p, fl) and the operations of GaloisRingArith; the reduced values have e = fl.length coordinates, each at most 2 ^ p.

The value in A_p is a homomorphism of the operations at (p, fl).

theorem Cslib.Circuits.Frontier.DescribedNetwork.val_sumValue_galois {T : Type} (eval : T → List Bool → List ℕ) (q : ℕ × List ℕ) (d : DescribedNetwork T) :
GaloisRingArith.val q.1 q.2 (sumValue SumOps.galois eval q d) = contraction (fun (t : T) (bs : List Bool) => GaloisRingArith.val q.1 q.2 (eval t bs)) d

In A_p, the value is the contraction of the values of the entries.

A reduced coefficient list at (p, fl) is at most e (2 p + 3) long in binary, with e = fl.length.

The native machine #

The encoding of a described network: its number of edges in unary, then its vertices, each the pair of its list of ports in binary and its descriptor.

@[reducible, inline]

The encoding of an input (q, d): the precision and the network.

@[reducible, inline]

The encoding of a node: its kind in unary, its input, its word and its vertex index in unary.

@[reducible, inline]

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

@[reducible, inline]

The encoding of a vertex: its framed list of ports in binary, then its descriptor.

theorem Cslib.Circuits.Frontier.DescribedNetwork.input_polyTime {T Q : Type} {encQ : Q ↪ List Bool} {encT : T ↪ List Bool} :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : Node Q T) => x.2.1) (encNode encQ encT) (encInput encQ encT)

The input (q, d) of a node.

theorem Cslib.Circuits.Frontier.DescribedNetwork.precision_polyTime {T Q : Type} {encQ : Q ↪ List Bool} {encT : T ↪ List Bool} :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : Node Q T) => x.2.1.1) (encNode encQ encT) encQ

The precision of a node.

The network of a node.

The word of a node.

The vertex index of a node.

theorem Cslib.Circuits.Frontier.DescribedNetwork.sumScheme_polyTime {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} (hops : ops.PolyTime encQ encY) :
(sumScheme ops eval).PolyTime (encNode encQ encT) (encAcc encY) encY

The polynomial-time components of direct summation, from polynomial-time operations.

The descriptor of a vertex and the bits of the node's word on its ports.

noncomputable def Cslib.Circuits.Frontier.DescribedNetwork.vertexCertificate {T Q : Type} {encQ : Q ↪ List Bool} {encT : T ↪ List Bool} :
GenericRAM.NativeCertificate (fun (x : Node Q T) => x.2.1.2.vertices[x.2.2.2]?) (encNode encQ encT) (Turing.MultiTapeTM.encOption (encVertex encT))

The vertex of a node, if its index is in range.

The query to the evaluator: the descriptor and the bits on the ports.

noncomputable def Cslib.Circuits.Frontier.DescribedNetwork.zeroCertificate {T Q Y : Type} {ops : SumOps Q Y} {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} (hops : ops.PolyTime encQ encY) :
GenericRAM.NativeCertificate (fun (x : Node Q T) => ops.zero x.2.1.1) (encNode encQ encT) encY

The zero at the precision of a node.

noncomputable def Cslib.Circuits.Frontier.DescribedNetwork.leafCertificate {T Q Y : Type} {ops : SumOps Q Y} (eval : T → List Bool → Y) {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} (hops : ops.PolyTime encQ encY) (ev : GenericRAM.NativeCertificate (fun (q : T × List Bool) => eval q.1 q.2) (Turing.MultiTapeTM.encPair encT Turing.MultiTapeTM.encBits) encY) :

The leaf step: the evaluator at the descriptor of the node's vertex and its bits, from a native certificate of the evaluator with any bounds.

theorem Cslib.Circuits.Frontier.DescribedNetwork.leafCertificate_time {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} (hops : ops.PolyTime encQ encY) (ev : GenericRAM.NativeCertificate (fun (q : T × List Bool) => eval q.1 q.2) (Turing.MultiTapeTM.encPair encT Turing.MultiTapeTM.encBits) encY) (x : Node Q T) :
(leafCertificate eval hops ev).time x = 2 * vertexCertificate.time x + ((encNode encQ encT) x).length + x.2.1.2.vertices[x.2.2.2]?.elim ((zeroCertificate hops).time x) fun (v : List ℕ × T) => queryCertificate.time (x, v) + ev.time (v.2, wordBits x.2.2.1 v.1)

The time of the leaf step: the vertex lookup, and the zero or the query and the evaluator at a vertex.

theorem Cslib.Circuits.Frontier.DescribedNetwork.leafCertificate_space {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} (hops : ops.PolyTime encQ encY) (ev : GenericRAM.NativeCertificate (fun (q : T × List Bool) => eval q.1 q.2) (Turing.MultiTapeTM.encPair encT Turing.MultiTapeTM.encBits) encY) (x : Node Q T) :
(leafCertificate eval hops ev).space x = 2 * vertexCertificate.space x + ((encNode encQ encT) x).length + x.2.1.2.vertices[x.2.2.2]?.elim ((zeroCertificate hops).space x) fun (v : List ℕ × T) => queryCertificate.space (x, v) + ev.space (v.2, wordBits x.2.2.1 v.1)

The space of the leaf step.

The number of steps of direct summation: 2 (2 ^ m (k + 1) + 1) - 1.

The root in polynomial time.

noncomputable def Cslib.Circuits.Frontier.DescribedNetwork.sumCertificate {T Q Y : Type} {ops : SumOps Q Y} (eval : T → List Bool → Y) {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} (hops : ops.PolyTime encQ encY) (ev : GenericRAM.NativeCertificate (fun (q : T × List Bool) => eval q.1 q.2) (Turing.MultiTapeTM.encPair encT Turing.MultiTapeTM.encBits) encY) :

One native machine for direct summation over described networks, from polynomial-time operations and a native certificate of the evaluator. It returns some (sumValue ops eval q d) (run_sumScheme).

theorem Cslib.Circuits.Frontier.DescribedNetwork.run_sumScheme {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} (q : Q × DescribedNetwork T) :
(sumScheme ops eval).run fuel sumRoot q = some (sumValue ops eval q.1 q.2)

The machine computes sumValue.

noncomputable def Cslib.Circuits.Frontier.DescribedNetwork.contractionCertificate {T Q Y : Type} {ops : SumOps Q Y} (eval : T → List Bool → Y) {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} [Inhabited Y] (hops : ops.PolyTime encQ encY) (ev : GenericRAM.NativeCertificate (fun (q : T × List Bool) => eval q.1 q.2) (Turing.MultiTapeTM.encPair encT Turing.MultiTapeTM.encBits) encY) :
GenericRAM.NativeCertificate (fun (q : Q × DescribedNetwork T) => sumValue ops eval q.1 q.2) (encInput encQ encT) encY

Direct summation over described networks, as a native certificate for sumValue on every input (q, d), from polynomial-time operations and a native certificate of the evaluator.

@[simp]
theorem Cslib.Circuits.Frontier.DescribedNetwork.contractionCertificate_time {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} [Inhabited Y] (hops : ops.PolyTime encQ encY) (ev : GenericRAM.NativeCertificate (fun (q : T × List Bool) => eval q.1 q.2) (Turing.MultiTapeTM.encPair encT Turing.MultiTapeTM.encBits) encY) :
(contractionCertificate eval hops ev).time = (sumCertificate eval hops ev).time

The time is that of the stack machine.

@[simp]
theorem Cslib.Circuits.Frontier.DescribedNetwork.contractionCertificate_space {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} [Inhabited Y] (hops : ops.PolyTime encQ encY) (ev : GenericRAM.NativeCertificate (fun (q : T × List Bool) => eval q.1 q.2) (Turing.MultiTapeTM.encPair encT Turing.MultiTapeTM.encBits) encY) :
(contractionCertificate eval hops ev).space = (sumCertificate eval hops ev).space

The space is that of the stack machine.

Resources #

The number of edges and the number of vertices are at most the encoded length.

An encoded vertex is at most the encoded network long.

The encoded argument of the evaluator at a vertex and bits on its ports is at most three times the encoded network length plus a constant.

theorem Cslib.Circuits.Frontier.DescribedNetwork.length_encNode_le {T Q : Type} {encQ : Q ↪ List Bool} {encT : T ↪ List Bool} {q : Q × DescribedNetwork T} {x : Node Q T} (hx : NodeShape q x) :
((encNode encQ encT) x).length ≤ 5 * ((encInput encQ encT) q).length + 7

A node of the right shape is at most 5 n + 7 long, for n the length of the input.

theorem Cslib.Circuits.Frontier.DescribedNetwork.contractionCertificate_le {T Q Y : Type} {ops : SumOps Q Y} {eval : T → List Bool → Y} {encQ : Q ↪ List Bool} {encY : Y ↪ List Bool} {encT : T ↪ List Bool} [Inhabited Y] (hops : ops.PolyTime encQ encY) (ev : GenericRAM.NativeCertificate (fun (q : T × List Bool) => eval q.1 q.2) (Turing.MultiTapeTM.encPair encT Turing.MultiTapeTM.encBits) encY) :
∃ (K : ℕ), ∀ (q : Q × DescribedNetwork T) (E ES Ev Rv : ℕ), (∀ v ∈ q.2.vertices, ∀ (bs : List Bool), bs.length = v.1.length → ev.time (v.2, bs) ≤ E ∧ ev.space (v.2, bs) ≤ ES ∧ (encY (eval v.2 bs)).length ≤ Ev) → (∀ (y : Y), ops.Reduced q.1 y → (encY y).length ≤ Rv) → (contractionCertificate eval hops ev).time q ≤ (2 ^ q.2.numEdges * (q.2.vertices.length + 1) + 1) * (K * (((encInput encQ encT) q).length + Ev + Rv + 1) ^ K + 2 * E) ∧ (contractionCertificate eval hops ev).space q ≤ K * (((encInput encQ encT) q).length + Ev + Rv + 1) ^ K + ES

The resources of direct summation over described networks. There is K such that, for an input (q, d) of length n with m edges and k vertices, if the evaluator takes time at most E and space at most ES and outputs at most Ev bits on every vertex and every list of bits on its ports, and the reduced values at q are at most Rv bits, then the time is at most 2 ^ m (k + 1) + 1 times K (n + Ev + Rv + 1) ^ K + 2 E, and the space at most K (n + Ev + Rv + 1) ^ K + ES.

The two instances #

Natural numbers modulo 2 ^ P are polynomial-time, with P in unary.

Direct summation modulo 2 ^ P: one native machine for d.contraction eval % 2 ^ P on every input (P, d), with P in unary, from a native certificate of a natural-number evaluator.