Documentation

CslibFrontier.Computability.Circuit.Frontier.TensorNetwork.Truncated

Contraction at truncation order ℓ, by evaluation and interpolation #

Theorem D.1 of [OAI26k] (p. 53) contracts Boolean tensor networks whose entries lie in B_{P,ℓ} = (ℤ / 2 ^ P)[V] / (V ^ ℓ). This file gives that contraction for described networks (DescribedNetwork T) and reduces it to contractions over A_P = (ℤ / 2 ^ P)[U] / (f) of networks with the same ports, by evaluating V at points of A_P and interpolating.

Entries and the contraction. An entry is a list of natural numbers, its coefficients of 1, V, V ^ 2, … (Mathlib's Polynomial.ofCoeffList). The contraction over ℕ[V] of the entries (DescribedNetwork.polyContraction) has, below V ^ ℓ and modulo 2 ^ P, the coefficients of the contraction in B_{P,ℓ} (DescribedNetwork.truncContraction): they depend only on the images of the entries in B_{P,ℓ}, their coefficients below ℓ modulo 2 ^ P (DescribedNetwork.truncContraction_congr). So truncContraction is the B_{P,ℓ} contraction of the canonical lifts of the entries, as in §D.4.1 (p. 58).

Evaluation. Cutting the entries to ℓ coefficients (cutCoeffs, DescribedNetwork.truncContraction_cutCoeffs) bounds the degree of the contraction over ℕ[V] by (ℓ - 1) k for k vertices (DescribedNetwork.natDegree_polyContraction_le). The network specialized at a point ζ of A_P (DescribedNetwork.specNet) has the same ports, and its entry at a vertex is the value at ζ of the first ℓ coefficients of the original entry, by Horner's rule (specEntry). Its contraction in A_P is the contraction over ℕ[V] evaluated at ζ (DescribedNetwork.val_contraction_specNet).

Interpolation. Let f be irreducible modulo 2. At n points of A_P with unit differences, the Lagrange interpolant of the values (GaloisRingArith.interp) is a polynomial of degree below n agreeing with the contraction at the points. When (ℓ - 1) k < n it is the contraction, so the constant coordinates of its first ℓ coefficients, modulo 2 ^ P, are the truncated contraction (interpRecover, DescribedNetwork.interpRecover_eq_truncContraction). The binary digits of 0, …, n - 1 are such points once n ≤ 2 ^ deg f (isUnit_val_sub_digits).

The reduction (DescribedNetwork.interpContract). Given a contraction core over A_P of the specialized networks, contract the network specialized at each of the (ℓ - 1) k + 1 digit points and interpolate. If core is correct at those inputs, this is the truncated contraction (DescribedNetwork.interpContract_eq). This route is not the manuscript's, which embeds the entries into A = O[V] / (V ^ ℓ) and computes there throughout the recursion (§D.4.1, p. 57, and the proof of Theorem D.1, §D.4.7, p. 64); it reduces truncation order ℓ to ℓ = 1 over A_P and leaves the recursion unchanged.

This file proves correctness only. The native machine running the reduction, with the time and space bounds of Theorem D.1, is not formalized here (#1538).

Main definitions #

Main results #

References #

Entries as polynomials in V #

The first ℓ coefficients of a list, padded with zeros to length ℓ.

@[simp]
theorem Cslib.Circuits.Frontier.getD_cutCoeffs (c : List ℕ) {ℓ i : ℕ} (hi : i < ℓ) :
(cutCoeffs ℓ c).getD i 0 = c.getD i 0

Below ℓ, the cut list has the coefficients of the list.

The contraction in B_{P,ℓ} #

The map ℕ[V] → (ℤ / 2 ^ P)[V] / (V ^ ℓ) onto B_{P,ℓ}.

theorem Cslib.Circuits.Frontier.truncHom_eq_iff {P ℓ : ℕ} {p q : Polynomial ℕ} :
(truncHom P ℓ) p = (truncHom P ℓ) q ↔ ∀ j < ℓ, p.coeff j % 2 ^ P = q.coeff j % 2 ^ P

Two polynomials have the same image in B_{P,ℓ} exactly when their coefficients below ℓ agree modulo 2 ^ P.

The contraction over ℕ[V] of a network whose entries are lists of coefficients of 1, V, V ^ 2, ….

noncomputable def Cslib.Circuits.Frontier.DescribedNetwork.truncContraction {T : Type u_1} (entry : T → List Bool → List ℕ) (P ℓ : ℕ) (G : DescribedNetwork T) :

The contraction in B_{P,ℓ} = (ℤ / 2 ^ P)[V] / (V ^ ℓ), as its ℓ coefficients in [0, 2 ^ P): the coefficients below ℓ of the contraction over ℕ[V], modulo 2 ^ P.

theorem Cslib.Circuits.Frontier.DescribedNetwork.truncHom_polyContraction {T : Type u_1} (entry : T → List Bool → List ℕ) (P ℓ : ℕ) (G : DescribedNetwork T) :
(truncHom P ℓ) (polyContraction entry G) = contraction (fun (t : T) (bs : List Bool) => (truncHom P ℓ) (Polynomial.ofCoeffList (entry t bs))) G

The image of the contraction over ℕ[V] in B_{P,ℓ} is the contraction of the images.

theorem Cslib.Circuits.Frontier.DescribedNetwork.truncContraction_congr {T : Type u_1} {entry entry' : T → List Bool → List ℕ} {P ℓ : ℕ} (G : DescribedNetwork T) (h : ∀ (t : T) (bs : List Bool), ∀ i < ℓ, (entry t bs).getD i 0 % 2 ^ P = (entry' t bs).getD i 0 % 2 ^ P) :
truncContraction entry P ℓ G = truncContraction entry' P ℓ G

The contraction depends only on the entries in B_{P,ℓ}: entries whose coefficients below ℓ agree modulo 2 ^ P have the same truncated contraction.

theorem Cslib.Circuits.Frontier.DescribedNetwork.truncContraction_cutCoeffs {T : Type u_1} (entry : T → List Bool → List ℕ) (P ℓ : ℕ) (G : DescribedNetwork T) :
truncContraction (fun (t : T) (bs : List Bool) => cutCoeffs ℓ (entry t bs)) P ℓ G = truncContraction entry P ℓ G

Cutting the entries to their first ℓ coefficients does not change the truncated contraction.

theorem Cslib.Circuits.Frontier.DescribedNetwork.natDegree_polyContraction_le {T : Type u_1} {entry : T → List Bool → List ℕ} {ℓ : ℕ} (G : DescribedNetwork T) (h : ∀ (t : T) (bs : List Bool), (entry t bs).length ≤ ℓ) :

The degree bound: if every entry has at most ℓ coefficients, the contraction over ℕ[V] has degree at most (ℓ - 1) k for k vertices.

Specialization at a point of A_P #

@[reducible, inline]

The descriptor of a vertex of a network specialized at a point: the original descriptor with the precision P, the truncation order ℓ, the coefficients fl of the modulus and the point ζ, a coefficient list of A_P = (ℤ / 2 ^ P)[U] / (f).

The first ℓ coefficients of a list, each as a constant coefficient list of A_P.

def Cslib.Circuits.Frontier.specEntry {T : Type u_1} (entry : T → List Bool → List ℕ) :

The entry of a specialized descriptor (t, P, ℓ, fl, ζ): the value at ζ in A_P, by Horner's rule, of the first ℓ coefficients of the entry of t.

Constant coefficient lists represent the polynomial of the coefficients in A_p.

theorem Cslib.Circuits.Frontier.val_specEntry {T : Type u_1} (entry : T → List Bool → List ℕ) (t : T) (P ℓ : ℕ) (fl ζ : List ℕ) (bs : List Bool) :

A specialized entry is the evaluation at the point of the polynomial of the first ℓ coefficients.

The network specialized at a point ζ: the same ports, with each descriptor t replaced by (t, P, ℓ, fl, ζ).

@[simp]
theorem Cslib.Circuits.Frontier.DescribedNetwork.numEdges_specNet {T : Type u_1} (P ℓ : ℕ) (fl ζ : List ℕ) (G : DescribedNetwork T) :
(specNet P ℓ fl ζ G).numEdges = G.numEdges
@[simp]
theorem Cslib.Circuits.Frontier.DescribedNetwork.vertices_specNet {T : Type u_1} (P ℓ : ℕ) (fl ζ : List ℕ) (G : DescribedNetwork T) :
(specNet P ℓ fl ζ G).vertices = List.map (fun (v : List ℕ × T) => (v.1, v.2, P, ℓ, fl, ζ)) G.vertices
theorem Cslib.Circuits.Frontier.DescribedNetwork.contraction_specNet {T : Type u_1} {R : Type u_2} [CommSemiring R] (eval : SpecDesc T → List Bool → R) (P ℓ : ℕ) (fl ζ : List ℕ) (G : DescribedNetwork T) :
contraction eval (specNet P ℓ fl ζ G) = contraction (fun (t : T) (bs : List Bool) => eval (t, P, ℓ, fl, ζ) bs) G

The contraction of a specialized network, for any evaluator, is that of the original network with the evaluator read at the specialized descriptors.

theorem Cslib.Circuits.Frontier.DescribedNetwork.val_contraction_specNet {T : Type u_1} (entry : T → List Bool → List ℕ) (P ℓ : ℕ) (fl ζ : List ℕ) (G : DescribedNetwork T) :
contraction (fun (d : SpecDesc T) (bs : List Bool) => GaloisRingArith.val P fl (specEntry entry d bs)) (specNet P ℓ fl ζ G) = Polynomial.eval (GaloisRingArith.val P fl ζ) (Polynomial.map (Nat.castRingHom (GaloisRingArith.Ring P fl)) (polyContraction (fun (t : T) (bs : List Bool) => cutCoeffs ℓ (entry t bs)) G))

Specialization is evaluation: the contraction in A_P of the network specialized at ζ is the contraction over ℕ[V] of the entries cut to ℓ coefficients, evaluated at ζ.

Recovery by interpolation #

Reading the truncated contraction off an interpolant: interpolate the values ys at the points pts and take the constant coordinates, modulo 2 ^ P, of the first ℓ coefficients.

An irreducible modulus has positive degree.

theorem Cslib.Circuits.Frontier.interpRecover_eq {P ℓ : ℕ} {fl : List ℕ} (hirr : Irreducible (Polynomial.map (Int.castRingHom (ZMod 2)) (GaloisRingArith.monicOf fl))) {pts ys : List (List ℕ)} (hunit : Pairwise fun (i j : Fin pts.length) => IsUnit (GaloisRingArith.val P fl (pts.getD ↑i []) - GaloisRingArith.val P fl (pts.getD ↑j []))) {Z : Polynomial ℕ} (hdeg : Z.natDegree < pts.length) (hys : ∀ i < pts.length, GaloisRingArith.val P fl (ys.getD i []) = Polynomial.eval (GaloisRingArith.val P fl (pts.getD i [])) (Polynomial.map (Nat.castRingHom (GaloisRingArith.Ring P fl)) Z)) :
interpRecover P ℓ fl pts ys = List.map (fun (j : ℕ) => Z.coeff j % 2 ^ P) (List.range ℓ)

Recovery from values at points with unit differences. Let f be irreducible modulo 2. If Z over ℕ has degree below the number of points, the points have unit differences in A_P, and ys are the values of Z at them, then reading off the interpolant gives the coefficients of Z below ℓ modulo 2 ^ P.

The binary digits are interpolation points of A_P. The binary digits below e = fl.length of 0, …, n - 1, for n ≤ 2 ^ e and f irreducible modulo 2, have unit differences in A_P.

The number (ℓ - 1) k + 1 of interpolation points for truncation order ℓ and k vertices.

theorem Cslib.Circuits.Frontier.DescribedNetwork.interpRecover_eq_truncContraction {T : Type u_1} {entry : T → List Bool → List ℕ} {P ℓ : ℕ} {fl : List ℕ} (hirr : Irreducible (Polynomial.map (Int.castRingHom (ZMod 2)) (GaloisRingArith.monicOf fl))) (G : DescribedNetwork T) {pts ys : List (List ℕ)} (hunit : Pairwise fun (i j : Fin pts.length) => IsUnit (GaloisRingArith.val P fl (pts.getD ↑i []) - GaloisRingArith.val P fl (pts.getD ↑j []))) (hlen : (ℓ - 1) * G.vertices.length < pts.length) (hys : ∀ i < pts.length, GaloisRingArith.val P fl (ys.getD i []) = contraction (fun (d : SpecDesc T) (bs : List Bool) => GaloisRingArith.val P fl (specEntry entry d bs)) (specNet P ℓ fl (pts.getD i []) G)) :
interpRecover P ℓ fl pts ys = truncContraction entry P ℓ G

The truncated contraction from the specialized contractions. Let f be irreducible modulo 2. At points with unit differences in A_P, more than (ℓ - 1) k of them, if ys are the contractions in A_P of the network specialized at the points, reading off the interpolant gives the truncated contraction.

The reduction to ℓ = 1 over A_P: contract, with core, the network specialized at each of the (ℓ - 1) k + 1 binary-digit points of A_P for the modulus fl, and read the truncated contraction off the interpolant. The input of core is the precision, the modulus, the number r of rows and the specialized network.

theorem Cslib.Circuits.Frontier.DescribedNetwork.interpContract_eq {T : Type u_1} {entry : T → List Bool → List ℕ} {core : ℕ × List ℕ × ℕ × DescribedNetwork (SpecDesc T) → List ℕ} {fl : List ℕ} {P ℓ r : ℕ} (hirr : Irreducible (Polynomial.map (Int.castRingHom (ZMod 2)) (GaloisRingArith.monicOf fl))) (G : DescribedNetwork T) (hn : pointCount ℓ G ≤ 2 ^ fl.length) (hcore : ∀ k < pointCount ℓ G, GaloisRingArith.val P fl (core (P, fl, r, specNet P ℓ fl (FastContraction.digits fl.length k) G)) = contraction (fun (d : SpecDesc T) (bs : List Bool) => GaloisRingArith.val P fl (specEntry entry d bs)) (specNet P ℓ fl (FastContraction.digits fl.length k) G)) :
interpContract core fl P ℓ r G = truncContraction entry P ℓ G

The reduction is correct. If f is irreducible modulo 2, A_P has at least (ℓ - 1) k + 1 residues, and core computes the contraction in A_P of the network specialized at each digit point, then interpContract is the truncated contraction.