Documentation

CslibFrontier.Computability.Circuit.Frontier.TensorNetwork.FastContraction

The native contraction recursion as a stack recursion #

The recursion of Theorem D.1 of [OAI26k] (Appendix D.4.7, p. 64), as a depth-first stack recursion (Cslib.Algorithms.StackRecursion.Scheme) over calls. A call (FastContraction.Call T) is a described network (DescribedNetwork (VertexDesc T)) whose first r vertices are its rows, with the schedule's scale s (the number of edges of the root, since the machine sees no other size), its depth d, an edge bound, its precision p and the coefficients fl of the modulus f. The vertices of the input network have descriptors of a type T, read by an entry procedure ev : T → List Bool → List ℕ (VertexDesc.entry ev); only the leaves and the correctness statement read them, so the recursion is the same for every T.

Active calls and leaves. A call with M edges is active (FastContraction.active) when the schedule makes it an active call (ContractionSchedule.callParams, with a = slotBits s d, u = taper s d and h = ⌈3 M / u⌉), its parameters satisfy the hypotheses of Lemma D.5, its degrees are at most degreeBound s, the M (2 L - 1) + 1 interpolation points are distinct residues (n ≤ 2 ^ e for e = deg f), and M is below its edge bound. Every other call is a leaf, evaluated by direct summation over the coefficient lists of A_p (FastContraction.leafValue ev). A child receives its parent's number of edges as its bound, so the recursion terminates, as TensorNetwork.contractRec does; a child that is not smaller is a leaf.

An active call walks the children (t, k, β, g) with the cursor of Cslib.Circuits.Frontier.ChildCursor, over the nodes ts of positive multiplicity (FastContraction.nodes), the points, the mode tuples of weight below p_t and the 64 groups. The child at a cursor state is given by a child builder mk, which computes the child's rows and network (the native child of §D.4.6). The call absorbs the children's values with the operations of A_N at the common precision N = p + Δ' (FastContraction.wide), where Δ' = (a + 1) 2 ^ (a + 1) h u + 8 h 2 ^ a + 8 M (a + 1) bounds both the shift of Lemma D.5 and every node precision p_t - p; it then places the sums at the rows ts[i] of the table of native recovery (FastContraction.table) and recovers its value with Cslib.Circuits.Frontier.NativeRecovery.recover.

Values and derivations. The values of the scheme are tagged with the depth. FastContraction.value is the value of a call by well-founded recursion on the edge bound, and FastContraction.exists_eval derives it in the scheme, so a run returning a value tagged 0 from a root at depth 0 returns value of the root, for every fuel (FastContraction.eq_value_of_run). Correctness (FastContraction.val_value): if the step of an active call is correct (FastContraction.StepCorrect, the correctness of one call from the correctness of its children, through Lemma D.5) and a well-formedness predicate passes to the children, then every well-formed call computes the contraction of its network in A_p.

Main definitions #

Main results #

References #

@[reducible, inline]

The parameters of a call: the scale s, the depth d, the edge bound, the precision p, the coefficients fl of the modulus and the number r of rows.

@[reducible, inline]

A call of the recursion: its parameters and its network over root descriptors T, whose first r vertices are its rows.

@[reducible, inline]

The scale s of the schedule.

@[reducible, inline]

The depth.

@[reducible, inline]

The edge bound: the call is a leaf unless it has fewer edges.

@[reducible, inline]

The precision p.

@[reducible, inline]

The coefficients of the modulus f = monicOf fl.

@[reducible, inline]

The number of rows.

@[reducible, inline]

The network.

@[reducible, inline]

The number M of edges.

The data of a call #

The packets have 2 ^ a slots, a = slotBits s d.

The number u = taper s d of levels of positive multiplicity.

The multiplicity step h = ⌈3 M / u⌉.

The number n = M (2 L - 1) + 1 of interpolation points.

Whether a call is active: the schedule makes it an active call, its parameters satisfy Lemma D.5 (1 ≤ u ≤ M, u ≤ a), its degrees are at most degreeBound s, its interpolation points are distinct residues (n ≤ 2 ^ e), and it has fewer edges than its bound.

An active call has fewer edges than its bound.

The level v₂ (t) of the node of grid index k, t = k - 2 ^ a.

The nodes of positive multiplicity, as increasing grid indices k < 2 ^ (a + 1), k ≠ 2 ^ a; the node of index k is NativeRecovery.node a k = k - 2 ^ a.

The precision p_t = nodePrecision p h a M (v₂ t) of the i-th node.

The number of rows capped at the number of vertices. The packing and the child builder use it in place of the number of rows: it changes nothing for a rows-first network with an edge (FastContraction.rowCap_eq), and it keeps them polynomial-time on every call, since the number of rows is stored in binary and the packing lists one word per row.

The cap on the rows is inactive when there are at most as many rows as vertices.

The packing of Lemma D.3, natively (nativeParentPacking, r = 64), with the rows capped (FastContraction.rowCap).

The packing is the native packing of the rows when there are at most as many rows as vertices.

The weights of the modes of the i-th node, packet-major over (q, y₀, b) with y₀ < 2 ^ (v₂ t + 1) and b < p_t: mode (q, y₀, b) has weight b + 1.

The shift Δ' = (a + 1) 2 ^ (a + 1) h u + 8 h 2 ^ a + 8 M (a + 1), which bounds the shift (a + 1) ∑_t q_t of Lemma D.5 and every p_t - p.

The common precision N = p + Δ' of the accumulator.

The binary digits of k, as a coefficient list of length e: the lift of the k-th residue.

The interpolation points: the lifts of the residues 0, …, n - 1.

The table of native recovery from the stored values, node-major and point-minor: row ts[j] holds the j-th block of n values, and the other rows are empty.

The accumulator after absorbing the values vals of the children in order.

The value of an active call from its final accumulator: native recovery from the table of the stored values.

The value of a leaf: direct summation in A_p.

The scheme #

The child call at a cursor state c = (i, k, β, g): the rows and the network given by the child builder mk, at depth d + 1, with the parent's number of edges as its bound and the node's precision p_i.

@[reducible, inline]

The accumulator of a call: the cursor state of the next child, if any, and the accumulator of the cursor.

The recursion as a stack recursion, with values tagged by the depth.

@[irreducible]

The value of a call, by well-founded recursion on the edge bound: the leaf value, or the recovery from the values of the children.

theorem Cslib.Circuits.Frontier.FastContraction.value_of_active {T : Type} (ev : T → List Bool → List ℕ) (mk : Call T → ChildCursor.State → ℕ × DescribedNetwork (VertexDesc T)) {x : Call T} (h : active x = true) :
value ev mk x = finishValue x (runLoop x fun (c : ChildCursor.State) => value ev mk (child x mk c))

Derivations #

Every node precision is positive at a call with an edge.

theorem Cslib.Circuits.Frontier.FastContraction.weights_pos {T : Type} {x : Call T} (i w : ℕ) :
w ∈ weights x i → 0 < w

Every weight is positive.

An active call has an edge.

An active call has at least 64 ^ a edges, the hypothesis r ^ a ≤ M of the native packing (PacketPacking.nativePacking_eq), which active implies: with λ = ⌊log₂ s⌋, 1 ≤ u forces λ ≥ 1, a ≤ λ / 32768 (ContractionSchedule.slotBits_le), and M > leafSize s = ⌊s / ⌊√λ⌋⌋ ≥ 2 ^ (6 ⌊λ / 32768⌋), since ⌊√λ⌋ ≤ 2 ^ ((λ + 1) / 2).

An active call has a node of positive multiplicity: the index 2 ^ a + 1, of level 0.

The frames of an active call along its children: the cursor at the c-th child, with the values vals of the earlier children absorbed.

theorem Cslib.Circuits.Frontier.FastContraction.walk {T : Type} (ev : T → List Bool → List ℕ) (mk : Call T → ChildCursor.State → ℕ × DescribedNetwork (VertexDesc T)) {x : Call T} (h : active x = true) (vals : ChildCursor.State → List ℕ) :
frameAt x vals 0 = (scheme ev mk).start x ∧ (∀ c < (children x).length, (scheme ev mk).next x (frameAt x vals c) = some (child x mk ((children x).getD c (0, 0, [], 0)))) ∧ (scheme ev mk).next x (frameAt x vals (children x).length) = none ∧ (∀ c < (children x).length, (scheme ev mk).absorb x (frameAt x vals c) (x.depth + 1, vals ((children x).getD c (0, 0, [], 0))) = frameAt x vals (c + 1)) ∧ runLoop x vals = (frameAt x vals (children x).length).2

The loop of an active call walks its children: from start, the c-th frame asks for the child at the c-th cursor state, absorbing it gives the next frame, and the last frame stops.

The invariant of the derivation from a root x₀ at depth 0: the only node at depth 0 is the root, and a value tagged 0 is the root's value.

theorem Cslib.Circuits.Frontier.FastContraction.exists_eval {T : Type} (ev : T → List Bool → List ℕ) (mk : Call T → ChildCursor.State → ℕ × DescribedNetwork (VertexDesc T)) (x₀ x : Call T) (hx : (inv ev mk x₀).node x) :
∃ (n : ℕ) (h : ℕ), (scheme ev mk).Eval (inv ev mk x₀) x (x.depth, value ev mk x) n h

Derivations of the values. Every call satisfying the invariant of a root x₀ has a derivation of its tagged value.

theorem Cslib.Circuits.Frontier.FastContraction.eq_value_of_run {T : Type} (ev : T → List Bool → List ℕ) (mk : Call T → ChildCursor.State → ℕ × DescribedNetwork (VertexDesc T)) {J : Type} {fuel : J → ℕ} {root : J → Call T} {a : J} {y : List ℕ} (hroot : (root a).depth = 0) (hrun : (scheme ev mk).run fuel root a = some (0, y)) :
y = value ev mk (root a)

A tagged value returned by the run is the root's value, for any fuel: if the root is at depth 0 and the run returns (0, y), then y is the value of the root.

The stored values #

theorem Cslib.Circuits.Frontier.FastContraction.getElem_flatMap_range {α : Type u_1} (f : ℕ → ℕ → α) {T n t k : ℕ} (ht : t < T) (hk : k < n) :
(List.flatMap (fun (t : ℕ) => List.map (f t) (List.range n)) (List.range T))[t * n + k] = f t k

An entry of a concatenation of blocks of n values.

Every node precision is at most the common precision N = p + Δ'.

theorem Cslib.Circuits.Frontier.FastContraction.val_table_runLoop {T : Type} {x : Call T} (h : active x = true) (vals : ChildCursor.State → List ℕ) {j : ℕ} (hj : j < (nodes x).length) {i : ℕ} (hi : i < numPoints x) :
GaloisRingArith.val (nodePrec x j) x.fl (((table x (runLoop x vals).2.2).getD (nodes x)[j] []).getD i []) = (List.map (fun (β : List ℕ) => (List.map (fun (g : ℕ) => GaloisRingArith.val (nodePrec x j) x.fl (vals (j, i, β, g))) (List.range 64)).prod) (BudgetTuples.budgetTuples (weights x j) (nodePrec x j))).sum

The values stored by an active call. At the j-th node of positive multiplicity and the i-th point, the table of native recovery holds, at the node's precision p_j, the sum over the mode tuples of weight below p_j of the products over the 64 groups of the children's values: the hypothesis of the one-call correctness of Lemma D.5 at that node.

Correctness #

The correctness of one active call for a well-formedness predicate WF: at a well-formed active call, if the values vals of the children are their contractions in A_{p_i}, then the recovered value is the contraction of the call's network in A_p.

Well-formedness passes to the children of an active call.

theorem Cslib.Circuits.Frontier.FastContraction.val_value {T : Type} (ev : T → List Bool → List ℕ) (mk : Call T → ChildCursor.State → ℕ × DescribedNetwork (VertexDesc T)) {WF : Call T → Prop} (hstep : StepCorrect ev mk WF) (hwf : WFChildren mk WF) (x : Call T) (hx : WF x) :

Correctness of the recursion. If the step of an active call is correct and well-formedness passes to the children, every well-formed call computes the contraction of its network in A_p.