Documentation

CslibFrontier.Computability.Circuit.Frontier.TensorNetwork.Explicit

Explicit Boolean tensor networks #

A Boolean tensor network as an algorithm reads it (DescribedNetwork T) is the number of edges, numbered 0, 1, …, and a list of vertices, each given by its ordered list of ports, the numbers of the edges at the vertex, and a descriptor t : T of its tensor. For an evaluator eval : T → List Bool → R, the entry of the vertex when port i carries the bit bs[i] is eval t bs, and the contraction (DescribedNetwork.contraction) sums, over all assignments of bits to the edges, the product of the entries at the bits on the ports.

An explicit network (ExplicitTensorNetwork R) has tables as descriptors: the value of the tensor of a vertex when port i carries the bit bs[i] is the entry of its table at position BitString.lsbValue bs, the number whose binary digit i is bs[i] (BitString.testBit_lsbValue).

So a vertex with k ports has a table of 2 ^ k entries. The contraction of an explicit network (ExplicitTensorNetwork.contraction) sums, over all assignments of bits to the edges, the product of the table entries at the bits on the ports, which is the contraction of the described network with table lookup as the evaluator (DescribedNetwork.contraction_entry). It needs no well-formedness: a port naming no edge reads false, and a position past the end of a table has entry zero.

Its size measures are the number of edges, the number of vertices, the maximum number of ports of a vertex (ExplicitTensorNetwork.maxDegree) and the total length of the tables (ExplicitTensorNetwork.tableLength). A described network is rows-first bipartite with r rows (DescribedNetwork.IsRowsFirstBipartite) when every port names an edge and every edge is a port of exactly one of its first r vertices and of exactly one of the others.

Writing a network out (TensorNetwork.toExplicit). Given numberings of the vertices and the edges of a Boolean tensor network on finite types, list the edges at each vertex in increasing order and tabulate its tensor on them. The contraction is unchanged (TensorNetwork.contraction_toExplicit). The ports of a vertex are its incident edges, so the degree bound carries over (TensorNetwork.maxDegree_toExplicit_le), and a numbering that puts one end of every edge below r and the other at or above it gives a rows-first bipartite network (TensorNetwork.isRowsFirstBipartite_toExplicit).

Main definitions #

Main results #

References #

A Boolean tensor network with described tensors: the number of edges, numbered from zero, and a list of vertices. A vertex is given by its ordered list of ports, the numbers of its edges, and a descriptor t : T of its tensor.

  • numEdges : ℕ

    The number of edges; the edges are numbered 0, …, numEdges - 1.

  • vertices : List (List ℕ × T)

    The vertices, each given by its ports and the descriptor of its tensor.

A described network is its number of edges and its list of vertices.

The bits that a word, read as an assignment of bits to the edges, puts on a list of ports; a port past the end of the word reads false.

def Cslib.Circuits.Frontier.DescribedNetwork.contraction {T : Type u_1} {R : Type u_2} [CommSemiring R] (eval : T → List Bool → R) (d : DescribedNetwork T) :
R

The contraction: the sum over all assignments of bits to the edges of the product of the entries of the vertices at the bits on their ports, for entries in a commutative semiring.

theorem Cslib.Circuits.Frontier.DescribedNetwork.map_contraction {T : Type u_1} {R : Type u_2} {S : Type u_3} [CommSemiring R] [CommSemiring S] (ψ : R →+* S) (eval : T → List Bool → R) (d : DescribedNetwork T) :
ψ (contraction eval d) = contraction (fun (t : T) (bs : List Bool) => ψ (eval t bs)) d

The contraction commutes with maps of semirings.

Rows-first bipartite: the first r vertices are the rows and the others the columns, every port names an edge, and every edge is a port of the rows exactly once and of the columns exactly once. So every edge joins a row to a column.

Instances For
    @[reducible, inline]

    An explicit Boolean tensor network over R: a network whose descriptors are tables. The entry of the table of a vertex at position BitString.lsbValue bs is the value of its tensor when port i carries the bit bs[i].

    The entry of a table at a list of bits, read little-endian (BitString.lsbValue). A position past the end of the table has entry zero.

    The bits on a list of ports under an assignment of bits to the edges. A port naming no edge reads false.

    The contraction of an explicit network: the sum over all assignments of bits to the edges of the product, over the vertices, of the table entries at the bits on their ports.

    The maximum degree: the largest number of ports of a vertex, or zero without vertices.

    The maximum degree is at most k exactly when every vertex has at most k ports.

    Explicit networks: with table lookup as the evaluator, the contraction of a described network is that of the explicit network.

    Writing a tensor network out #

    def Cslib.Circuits.Frontier.TensorNetwork.explicitPorts {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {m : ℕ} (N : TensorNetwork R Bool V E) (ee : E ≃ Fin m) (v : V) :
    List (Fin m)

    The ports of a vertex when the edges are numbered by ee: the numbers of the edges at the vertex, in increasing order.

    @[simp]
    theorem Cslib.Circuits.Frontier.TensorNetwork.mem_explicitPorts {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {m : ℕ} (N : TensorNetwork R Bool V E) (ee : E ≃ Fin m) {v : V} {j : Fin m} :
    j ∈ N.explicitPorts ee v ↔ N.src (ee.symm j) = v ∨ N.tgt (ee.symm j) = v

    An edge is a port of v exactly when it is incident to v.

    def Cslib.Circuits.Frontier.TensorNetwork.explicitTable {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {m : ℕ} (N : TensorNetwork R Bool V E) (ee : E ≃ Fin m) (v : V) :

    The table of a vertex: its tensor at each list of bits on its ports, by position.

    theorem Cslib.Circuits.Frontier.TensorNetwork.entry_explicitTable {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {m : ℕ} (N : TensorNetwork R Bool V E) (ee : E ≃ Fin m) [Zero R] (v : V) (x : Fin m → Bool) :

    A written-out table evaluates the tensor. At the bits that an assignment puts on the ports of v, the table of v has the value of the tensor at that assignment.

    theorem Cslib.Circuits.Frontier.TensorNetwork.nodup_explicitPorts {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {m : ℕ} (N : TensorNetwork R Bool V E) (ee : E ≃ Fin m) (v : V) :

    An edge is a port of a vertex at most once.

    theorem Cslib.Circuits.Frontier.TensorNetwork.length_explicitPorts {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {m : ℕ} (N : TensorNetwork R Bool V E) (ee : E ≃ Fin m) (v : V) :

    The ports of a vertex are its incident edges: their number is its degree.

    theorem Cslib.Circuits.Frontier.TensorNetwork.count_explicitPorts {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {m : ℕ} (N : TensorNetwork R Bool V E) (ee : E ≃ Fin m) (v : V) (j : Fin m) :
    List.count (↑j) (List.map Fin.val (N.explicitPorts ee v)) = if N.src (ee.symm j) = v ∨ N.tgt (ee.symm j) = v then 1 else 0

    The number of times the edge numbered j is a port of v: once if it is incident to v, and never otherwise.

    theorem Cslib.Circuits.Frontier.TensorNetwork.length_explicitTable {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {m : ℕ} (N : TensorNetwork R Bool V E) (ee : E ≃ Fin m) (v : V) :

    A table lists the values of the tensor at all 2 ^ (number of ports) lists of bits on the ports.

    theorem Cslib.Circuits.Frontier.TensorNetwork.exists_tensor_of_mem_explicitTable {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {m : ℕ} (N : TensorNetwork R Bool V E) (ee : E ≃ Fin m) {v : V} {a : R} (ha : a ∈ N.explicitTable ee v) :
    ∃ (y : E → Bool), a = N.tensor v y

    Every entry of a written-out table is a value of the tensor.

    def Cslib.Circuits.Frontier.TensorNetwork.toExplicit {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {n m : ℕ} (N : TensorNetwork R Bool V E) (ev : V ≃ Fin n) (ee : E ≃ Fin m) :

    A Boolean tensor network on finite types written out as an explicit network, numbering the vertices by ev and the edges by ee: vertex i is ev.symm i, with its ports in increasing order and its table.

    theorem Cslib.Circuits.Frontier.TensorNetwork.mem_vertices_toExplicit {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {n m : ℕ} (N : TensorNetwork R Bool V E) (ev : V ≃ Fin n) (ee : E ≃ Fin m) {p : List ℕ × List R} :
    p ∈ (N.toExplicit ev ee).vertices ↔ ∃ (v : V), p = (List.map Fin.val (N.explicitPorts ee v), N.explicitTable ee v)

    The vertices of the written-out network are the ports and tables of the vertices.

    theorem Cslib.Circuits.Frontier.TensorNetwork.maxDegree_toExplicit_le {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {n m : ℕ} (N : TensorNetwork R Bool V E) (ev : V ≃ Fin n) (ee : E ≃ Fin m) [Finite E] {D : ℕ} (hD : N.MaxDegreeLE D) :

    The degree bound carries over: a vertex of the written-out network has as many ports as the vertex has incident edges.

    theorem Cslib.Circuits.Frontier.TensorNetwork.length_table_toExplicit {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {n m : ℕ} (N : TensorNetwork R Bool V E) (ev : V ≃ Fin n) (ee : E ≃ Fin m) {p : List ℕ × List R} (hp : p ∈ (N.toExplicit ev ee).vertices) :
    p.2.length = 2 ^ p.1.length

    Every table of the written-out network has an entry for every list of bits on its ports.

    theorem Cslib.Circuits.Frontier.TensorNetwork.exists_tensor_of_mem_toExplicit {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {n m : ℕ} (N : TensorNetwork R Bool V E) (ev : V ≃ Fin n) (ee : E ≃ Fin m) {p : List ℕ × List R} (hp : p ∈ (N.toExplicit ev ee).vertices) {a : R} (ha : a ∈ p.2) :
    ∃ (v : V) (y : E → Bool), a = N.tensor v y

    Every table entry of the written-out network is a value of a tensor.

    theorem Cslib.Circuits.Frontier.TensorNetwork.isRowsFirstBipartite_toExplicit {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {n m : ℕ} (N : TensorNetwork R Bool V E) (ev : V ≃ Fin n) (ee : E ≃ Fin m) (r : ℕ) (hside : ∀ (e : E), ↑(ev (N.src e)) < r ↔ ¬↑(ev (N.tgt e)) < r) :

    Rows first. If every edge joins a vertex numbered below r to one numbered at least r, the written-out network is bipartite with the first r vertices as rows.

    theorem Cslib.Circuits.Frontier.TensorNetwork.contraction_toExplicit {R : Type u_1} {V : Type u_2} {E : Type u_3} [DecidableEq V] {n m : ℕ} (N : TensorNetwork R Bool V E) (ev : V ≃ Fin n) (ee : E ≃ Fin m) [CommSemiring R] [Fintype V] [Fintype E] [DecidableEq E] :

    Writing a network out preserves its contraction.