Documentation

CslibFrontier.Computability.Circuit.Frontier.TensorNetwork

Tensor networks and their contraction #

A tensor network over a commutative semiring R and an alphabet U is a multigraph whose edges carry values in U, with a tensor at each vertex v: a value N.tensor v x ∈ R for each assignment x : E → U of values to the edges, which depends only on the values on the edges at v. Its contraction sums, over all assignments, the product of the tensors:

Z(N) = ∑ x : E → U, ∏ v, N.tensor v x.

A Boolean tensor network has U = Bool, one bit per edge. The usual presentation gives the tensor at v as a function F_v of the bits on the ordered list δ(v) of edges at v, with Z = ∑ x ∏ v F_v (x|δ(v)). Here the tensor is a function of the whole assignment, constrained to read only the edges at v (TensorNetwork.tensor_congr); the ordered presentation, with explicit tables, is Cslib.Circuits.Frontier.ExplicitTensorNetwork, and Cslib.Circuits.Frontier.TensorNetwork.contraction_toExplicit shows that the two contractions agree. Parallel edges are distinct elements of E and so give distinct ports.

A tensor network is the weighted form of a constraint network (Cslib.Circuits.Frontier.Network) on a fixed input: the two share the multigraph and the locality condition, and a constraint becomes its 0–1 indicator tensor, whose contraction counts the satisfying assignments (Cslib.Circuits.Frontier.Network.contraction_toTensorNetwork).

Subdivision (TensorNetwork.subdivide). Splitting every edge e into two edges joined at a new vertex that carries the equality tensor [y₁ = y₂] preserves the contraction (TensorNetwork.contraction_subdivide): each assignment of the old network extends in exactly one way to an assignment of the new one with nonzero weight. The subdivided network is bipartite (TensorNetwork.isBipartite_subdivide), with the old vertices on one side and the new ones on the other, and it keeps the degree bound of a loopless network (TensorNetwork.maxDegreeLE_subdivide). It has twice as many edges and one new vertex per old edge.

Main definitions #

Main results #

References #

Bipartite multigraphs #

A multigraph is bipartite when its vertices split into two sides, side v = true and side v = false, and every edge joins the two sides. A bipartite multigraph has no loops (Multigraph.IsBipartite.loopless).

A bipartite multigraph has no loops.

A multigraph is bipartite exactly when it has no loops and its underlying simple graph is bipartite in the sense of Mathlib (SimpleGraph.IsBipartite, a 2-colouring).

Tensor networks #

structure Cslib.Circuits.Frontier.TensorNetwork (R : Type u_1) (U : Type u_2) (V : Type u_3) (E : Type u_4) extends Cslib.Circuits.Frontier.Multigraph V E :
Type (max (max (max u_1 u_2) u_3) u_4)

A tensor network over the commutative semiring R with alphabet U: a multigraph on the vertices V and edges E, whose edges carry values in U, and at each vertex a tensor, a value in R for each assignment of values to the edges, that sees only the values on the edges at that vertex. A Boolean tensor network has U = Bool.

  • src : E → V
  • tgt : E → V
  • tensor : V → (E → U) → R

    The tensor at a vertex: its value on an assignment of values to the edges.

  • tensor_congr (v : V) (x y : E → U) : (∀ (e : E), self.src e = v ∨ self.tgt e = v → x e = y e) → self.tensor v x = self.tensor v y

    Tensors are local: the tensor at v sees only the values on the edges incident to v.

def Cslib.Circuits.Frontier.TensorNetwork.contraction {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [CommSemiring R] [Fintype U] [Fintype V] [Fintype E] [DecidableEq E] (N : TensorNetwork R U V E) :
R

The contraction of a tensor network: the sum over all assignments of values to the edges of the product of the tensors at all vertices.

Subdivision by equality tensors #

def Cslib.Circuits.Frontier.TensorNetwork.subdivide {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) :
TensorNetwork R U (V ⊕ E) (E ⊕ E)

The subdivision of a tensor network by equality tensors. Each edge e becomes a new vertex Sum.inr e and two edges: Sum.inl e, from the source of e, and Sum.inr e, from its target, both ending at Sum.inr e. The new vertex carries the equality tensor, one when its two edges carry the same value and zero otherwise. An old vertex reads the value of e on the half of e at its end.

@[simp]
theorem Cslib.Circuits.Frontier.TensorNetwork.subdivide_src_inl {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) (e : E) :
@[simp]
theorem Cslib.Circuits.Frontier.TensorNetwork.subdivide_src_inr {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) (e : E) :
@[simp]
theorem Cslib.Circuits.Frontier.TensorNetwork.subdivide_tgt_inl {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) (e : E) :
@[simp]
theorem Cslib.Circuits.Frontier.TensorNetwork.subdivide_tgt_inr {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) (e : E) :
theorem Cslib.Circuits.Frontier.TensorNetwork.subdivide_tensor_inl {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) (v : V) (y : E ⊕ E → U) :
N.subdivide.tensor (Sum.inl v) y = N.tensor v fun (e : E) => if N.src e = v then y (Sum.inl e) else y (Sum.inr e)

The tensor at an old vertex of the subdivision.

theorem Cslib.Circuits.Frontier.TensorNetwork.subdivide_tensor_inr {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) (e : E) (y : E ⊕ E → U) :
N.subdivide.tensor (Sum.inr e) y = if y (Sum.inl e) = y (Sum.inr e) then 1 else 0

The equality tensor at a new vertex of the subdivision.

theorem Cslib.Circuits.Frontier.TensorNetwork.isBipartite_subdivide {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) :

Subdivision is bipartite. Every edge of the subdivision joins an old vertex to a new one.

Subdivision preserves the contraction. An assignment of the subdivision has nonzero weight only when the two halves of every edge carry the same value, and such assignments are exactly the assignments of the original network.

theorem Cslib.Circuits.Frontier.TensorNetwork.incidenceSet_subdivide_inl {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) (v : V) :
N.subdivide.incidenceSet (Sum.inl v) = Sum.inl '' {e : E | N.src e = v} ∪ Sum.inr '' {e : E | N.tgt e = v}

The edges at an old vertex of the subdivision are the halves of its old edges at it.

theorem Cslib.Circuits.Frontier.TensorNetwork.incidenceSet_subdivide_inr {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) (e : E) :

The edges at a new vertex of the subdivision are the two halves of its edge.

theorem Cslib.Circuits.Frontier.TensorNetwork.maxDegreeLE_subdivide {R : Type u_1} {U : Type u_2} {V : Type u_3} {E : Type u_4} [DecidableEq U] [DecidableEq V] [Zero R] [One R] (N : TensorNetwork R U V E) [Finite E] {d : ℕ} (hloop : N.Loopless) (hd : N.MaxDegreeLE d) (h2 : 2 ≤ d) :

Subdivision keeps the degree bound. In a loopless network, the edges at a vertex are those with it as source and those with it as target, and they are the halves at its old vertex in the subdivision; a new vertex has degree two.