Documentation

CslibFrontier.Computability.Circuit.Encoding.Layer

Layers of circuit codes #

A layer is a list of gates that read only the wires computed before it. Evaluating a layer appends the value of each of its gates, computed from the values before the layer (evalCode_layer), and in the depth interpretation its values are at most the largest value before it plus the largest cost of its operations (le_of_mem_evalCode_depth_layer). So a circuit given as a code of layers has a depth with costs bounded by summing the costs of the layers (Circuit.depthWith_le_of_evalCode).

Main results #

These are original implementation lemmas for the existing circuit semantics.

theorem Cslib.Circuits.Program.isCodeFrom_of_forall {σ : Signature} {n k : ℕ} {gates : List (σ.Op × List ℕ)} (h : ∀ g ∈ gates, g.2.length = σ.Arity g.1 ∧ ∀ i ∈ g.2, i < n + k) :
IsCodeFrom σ n k gates

A list of gates, each with as many arguments as its arity and reading only the n inputs and the k gates before the list, is a code from gate k.

theorem Cslib.Circuits.evalCode_layer {σ : Signature} {U : Type u} (I : Interpretation σ U) (d : U) (x : List U) (gates : List (σ.Op × List ℕ)) (h : ∀ g ∈ gates, ∀ i ∈ g.2, i < x.length) :
evalCode I d x gates = x ++ List.map (fun (g : σ.Op × List ℕ) => I g.1 fun (a : Fin (σ.Arity g.1)) => g.2[↑a]?.elim d fun (x_1 : ℕ) => x.getD x_1 d) gates

Evaluating a layer. When every gate of gates reads only wires below the length of x, evaluating gates from x appends the value of each gate on the wires of x.

theorem Cslib.Circuits.le_of_mem_evalCode_depth_layer {σ : Signature} (cost : σ.Op → ℕ) (x : List ℕ) (gates : List (σ.Op × List ℕ)) (h : ∀ g ∈ gates, ∀ i ∈ g.2, i < x.length) {D c : ℕ} (hx : ∀ v ∈ x, v ≤ D) (hc : ∀ g ∈ gates, cost g.1 ≤ c) (v : ℕ) :
v ∈ evalCode (depthInterpretation cost) 0 x gates → v ≤ D + c

Depths after a layer. In the depth interpretation, if the values of x are at most D and every gate of the layer gates has cost at most c, the values after the layer are at most D + c.

theorem Cslib.Circuits.Circuit.isCodeFrom_code {σ : Signature} {n m : ℕ} (c : Circuit σ n m) :

The gate list of a circuit is a code from its inputs.

theorem Cslib.Circuits.Circuit.toNat_outputs_lt {σ : Signature} {n m : ℕ} (c : Circuit σ n m) (j : Fin m) :
(c.outputs j).toNat < n + c.code.1.length

The output wires of a circuit are wires of its code.

theorem Cslib.Circuits.getD_evalCode_depth_le {σ : Signature} {n : ℕ} (cost : σ.Op → ℕ) {gates : List (σ.Op × List ℕ)} (h : Program.IsCodeFrom σ n 0 gates) {j : ℕ} {g : σ.Op × List ℕ} (hg : gates[j]? = some g) {c : ℕ} (hc : c ∈ g.2) :
(evalCode (depthInterpretation cost) 0 (List.replicate n 0) gates).getD c 0 + cost g.1 ≤ (evalCode (depthInterpretation cost) 0 (List.replicate n 0) gates).getD (n + j) 0

In the depth interpretation, a gate is deeper than each of its arguments by its cost.

theorem Cslib.Circuits.cost_le_getD_evalCode_depth {σ : Signature} {n : ℕ} (cost : σ.Op → ℕ) {gates : List (σ.Op × List ℕ)} (h : Program.IsCodeFrom σ n 0 gates) {j : ℕ} {g : σ.Op × List ℕ} (hg : gates[j]? = some g) :
cost g.1 ≤ (evalCode (depthInterpretation cost) 0 (List.replicate n 0) gates).getD (n + j) 0

In the depth interpretation, a gate is at least as deep as its cost.

Depths through the code. The depth with costs of the wire of output j is the value at its number of the code of the circuit evaluated in the depth interpretation from zero inputs.

theorem Cslib.Circuits.Circuit.depthWith_le_of_evalCode {σ : Signature} {n m : ℕ} (cost : σ.Op → ℕ) (c : Circuit σ n m) {D : ℕ} (h : ∀ v ∈ evalCode (depthInterpretation cost) 0 (List.replicate n 0) c.code.1, v ≤ D) :
depthWith cost c ≤ D

Depth from the code. If every value that the code of a circuit computes in the depth interpretation from zero inputs is at most D, the circuit has depth at most D with costs.