Documentation

CslibFrontier.Computability.Circuit.Frontier.TensorNetwork.DirectContraction

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 #

Main results #

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 #

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.

One step of direct summation, as a BooleanFold body: add the weight of the current word to the accumulator modulo 2 ^ P, retaining the precision P and the network.

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 #

@[reducible, inline]

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).

@[reducible, inline]

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 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.

@[reducible, inline]

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.

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.