Contracting an explicit tensor network by direct summation #
The leaf and small-size case of the contraction theorem, Theorem D.1 of [OAI26k]
(Appendix D.4.7, p. 64), where a leaf sums directly over all Boolean edge assignments, and the
fallback for small sizes (Appendix D.4.2, p. 58). On input (P, r, d), with d an explicit network
whose row vertices are the first r (the bipartition the fast algorithm uses), direct summation
computes the contraction of d modulo 2 ^ P. It ignores r.
directContraction streams over the 2 ^ m assignments of bits to the m edges with
Cslib.GenericRAM.BooleanFold, in their binary order, keeping only the current index, the input
and an accumulator below 2 ^ P. For each assignment it multiplies the table entries at the bits
on the ports, reducing modulo 2 ^ P after each factor (weightMod), and adds the product to the
accumulator modulo 2 ^ P (sumStep). directContraction_eq proves that the result is
d.contraction % 2 ^ P.
Input encoding (encContractionInput). The triple (P, r, d) is encoded as a pair: P in
unary, then the pair of r in binary and d. The network d (encExplicitNetwork) is the pair
of its number of edges, in unary, and its list of vertices. Each vertex is the pair of its list
of ports and its table, both lists of binary numbers. The unary fields keep the arithmetic
modulo 2 ^ P and the streamed assignments polynomial in the input length.
Precision in binary (directContractionBinaryCertificate). The same triple with P in binary
(encBinaryInput: encPair encNat (encPair encNat encExplicitNetwork)) is handled by capping
first: the contraction is below 2 ^ |d| for |d| the encoded length of d, so P can be
replaced by the unary min |d| P (capPrecision) without changing the residue. The bounds carry
over.
Main definitions #
Cslib.Circuits.Frontier.ExplicitTensorNetwork.weightMod: the weight of an assignment modulo2 ^ P.Cslib.Circuits.Frontier.ExplicitTensorNetwork.sumStep: one step of direct summation.Cslib.Circuits.Frontier.ExplicitTensorNetwork.directContraction: direct summation on(P, r, d).Cslib.Circuits.Frontier.ExplicitTensorNetwork.encExplicitNetwork,Cslib.Circuits.Frontier.ExplicitTensorNetwork.encContractionInput,Cslib.Circuits.Frontier.ExplicitTensorNetwork.encWeightInput,Cslib.Circuits.Frontier.ExplicitTensorNetwork.encSumState,Cslib.Circuits.Frontier.ExplicitTensorNetwork.encBinaryInput: the input and state encodings.Cslib.Circuits.Frontier.ExplicitTensorNetwork.directContractionCertificate: one native machine for direct summation, streaming withBooleanFold.Cslib.Circuits.Frontier.ExplicitTensorNetwork.capPrecision,Cslib.Circuits.Frontier.ExplicitTensorNetwork.directContractionBinaryCertificate: capping a binary precision, and direct summation with the precision in binary.
Main results #
Cslib.Circuits.Frontier.ExplicitTensorNetwork.weightMod_ofFn: the weight of an assignment.Cslib.Circuits.Frontier.ExplicitTensorNetwork.directContraction_eq: direct summation computes the contraction modulo2 ^ P.Cslib.Circuits.Frontier.ExplicitTensorNetwork.runPrefix_sumStep: every prefix of the loop retains the input and keeps its accumulator below2 ^ P.Cslib.Circuits.Frontier.ExplicitTensorNetwork.weightMod_polyTime,Cslib.Circuits.Frontier.ExplicitTensorNetwork.sumStep_polyTime,Cslib.Circuits.Frontier.ExplicitTensorNetwork.numEdges_polyTime,Cslib.Circuits.Frontier.ExplicitTensorNetwork.initial_polyTime: the weight, one step, the width and the initial state in polynomial time.Cslib.Circuits.Frontier.ExplicitTensorNetwork.directContractionCertificate_bounds: on every input, polynomial workspace and time2 ^ m + 1times a polynomial in the input length, wheremis the number of edges.Cslib.Circuits.Frontier.ExplicitTensorNetwork.exists_directContractionCertificate_le: the same with one constant, timeK (n + 1) ^ K 2 ^ mand workspaceK (n + 1) ^ Kfor input lengthn.Cslib.Circuits.Frontier.ExplicitTensorNetwork.exists_computableInO_contraction_mod: the contraction modulo2 ^ Pis computable within time(n + 1) ^ K 2 ^ mand space(n + 1) ^ K, up to constants, on every input.Cslib.Circuits.Frontier.ExplicitTensorNetwork.contraction_lt_two_pow_length,Cslib.Circuits.Frontier.ExplicitTensorNetwork.contraction_mod_two_pow_min,Cslib.Circuits.Frontier.ExplicitTensorNetwork.capPrecision_polyTime: the contraction is below2 ^ |d|, so capping the precision at|d|keeps the residue, in polynomial time.Cslib.Circuits.Frontier.ExplicitTensorNetwork.directContractionBinaryCertificate_bounds,Cslib.Circuits.Frontier.ExplicitTensorNetwork.exists_directContractionBinaryCertificate_le: the same bounds with the precision in binary.
These bounds hold on every input because the live state keeps only the binary index, the input
and an accumulator below 2 ^ P, and P is unary (runPrefix_sumStep, with
Cslib.GenericRAM.BooleanFold.certificate_bounds) or capped at the input length.
References #
- [OAI26k], Theorem D.1 (Appendix D.1, p. 53) and its proof (Appendix D.4.7, p. 64).
The weight modulo 2 ^ P of an assignment of bits to the edges, given as a word: port i
reads bit i of the word, and false past its end. It is the product of the table entries at
the bits on the ports, reduced modulo 2 ^ P after each factor.
Direct summation on the input (P, r, d): stream over the 2 ^ m assignments to the m
edges of d, accumulating their weights modulo 2 ^ P. The number r of row vertices is not
used.
Input encoding #
The encoding of an explicit network: its number of edges in unary, then its list of vertices, each the pair of its list of ports and its table, as lists of binary numbers.
The encoding of a contraction input (P, r, d): the precision P in unary, then the
number r of row vertices in binary and the network (encExplicitNetwork).
Correctness #
The weight of an assignment. On the word of an assignment x to the edges, weightMod is
the product of the table entries at the bits on the ports, modulo 2 ^ P.
Direct summation computes the contraction modulo 2 ^ P, on every input.
One step in polynomial time #
The encoding of ((P, d), word) for weightMod: the precision P in unary (framed) paired
with the network d (encExplicitNetwork), that pair framed, followed by the current assignment
bit word word unframed (encBits).
The weight of the current word modulo 2 ^ P is computable in polynomial time.
The encoding of the live state ((P, d), acc) of direct summation: the precision P in unary
(framed) paired with the network d (encExplicitNetwork), that pair framed, followed by the
accumulator acc in binary (encNat, unframed).
One step of direct summation is computable in polynomial time, in the encoding of the
BooleanFold callback input: the width and the current word, and the live state.
The streaming loop #
The live state of every prefix of the loop: the precision and the network are retained,
and the accumulator is the sum of the weights of the visited words modulo 2 ^ P, so it stays
below 2 ^ P.
The width of the loop: the number of edges, in unary.
The initial live state: the precision, the network and a zero accumulator.
A native certificate for direct summation: one finite machine streams the 2 ^ m
assignments with BooleanFold, running the polynomial-time step sumStep on each. Its explicit
bounds are directContractionCertificate_bounds and exists_directContractionCertificate_le.
Explicit bounds #
The bounds of direct summation, on every input (P, r, d): polynomial workspace in the
input length, and time 2 ^ m + 1 times a polynomial in the input length, where m is the number
of edges of d.
The bounds of direct summation in one constant: there is K such that on every input
x = (P, r, d) the time is at most K (n + 1) ^ K 2 ^ m and the workspace at most
K (n + 1) ^ K, where n is the input length and m the number of edges of d. Since
2 ^ m ≤ 2 ^ (K m), this gives the unconditional K (n + 1) ^ K 2 ^ (K m) form of the
contraction contract.
Direct summation is computable within time (n + 1) ^ K 2 ^ m and space (n + 1) ^ K,
up to constants, on every input x = (P, r, d), where n is the input length and m the number
of edges of d. The output is the contraction of d modulo 2 ^ P, in binary.
The precision in binary #
A precision given in binary can be exponentially larger than the input. It can be capped: the
contraction is below 2 ^ |d|, for |d| the encoded length of the network, so reducing modulo
2 ^ min |d| P gives the same residue. The capped precision is unary and at most |d|, so direct
summation keeps its bounds.
The encoding of a contraction input (P, r, d) with binary precision: the precision P in
binary (encNat), framed, then the number r of row vertices in binary (encNat), framed, and
the network d (encExplicitNetwork), unframed.
The contraction is below 2 ^ |d|, for |d| the encoded length of the network: each
table entry is at most the sum of its table, and there are 2 ^ m assignments.
Capping the precision at the encoded length of the network does not change the residue.
Cap the precision at the encoded length of the network.
Capping is computable in polynomial time, from the precision in binary to the capped precision in unary.
Direct summation with the precision in binary: cap the precision, then sum directly. The
input (P, r, d) is encoded as P in binary, then r in binary and the network, and the output is
d.contraction % 2 ^ P in binary.
The bounds of direct summation with the precision in binary, on every input (P, r, d):
polynomial workspace in the input length, and time 2 ^ m + 1 times a polynomial in the input
length, where m is the number of edges of d.
The bounds of direct summation with the precision in binary, in one constant: there is K
such that on every input the time is at most K (n + 1) ^ K 2 ^ m and the workspace at most
K (n + 1) ^ K, where n is the input length and m the number of edges.