Documentation

CslibFrontier.Computability.Circuit.Frontier.Ledger.Sweep

Sweeping a program with a ledger #

Let the special gates of a program p have a ledger in M, and let p accept the inputs whose value at a wire o lies in a set Acc. Erase the special gates. A wire is live (Frontier.Live) if it is an input or an ordinary gate of positive arity; the others are constants of the erased program, among them the constants replacing the special gates. The live circuit (Frontier.liveCircuit) is the erased program with every live wire as an output. For a guess m ∈ M, the constraint network of the live circuit accepting every value (Frontier.Ledger.network) is satisfied exactly by the run with guess m. Its graph and its sites do not depend on m: they make up the live network (Frontier.liveNetwork), which has no constraints and serves for the frontiers, components and inputs read of every guess.

The ledger sweep (Frontier.Ledger.sweep) is the sweep along a layout of the live network (Frontier.Network.frontierSweep) whose extra message has two parts: the readout L.readout m of the consistent guess m = L.total (p.trace I x) on the special gates, and the product of the contributions of the wires whose vertices come first (the ledger so far). Two inputs with the same message can be spliced (Frontier.Ledger.mem_of_splice): matching readouts give the exact same erased constraint network; the two parts of the ledger multiply back to the second input's consistent guess; and a consistent guess yields the true run.

Tightened transitions (|U|^k · |M|, bounded also by |M|^2). Because the readout stays constant across step t → t + 1 and the contribution of a newly processed signal vertex w is determined by its outgoing head edge in frontier π t ∪ frontier π (t + 1) (or touching W), the extra message L.extra π (t + 1) x is already determined by L.extra π t x and the edge values of the step (Frontier.Ledger.extra_succ_eq). Thus each step multiplies the transition count only by min (|U| ^ k) |M| * |M|, where k = |{g // special g}| (Frontier.Ledger.ncard_extra_le), replacing the naive |M| ^ 3 bound (Frontier.Ledger.exists_ncard_le).

Main definitions #

Main results #

The live circuit #

def Cslib.Circuits.Frontier.Live {σ : Signature} {n s : ℕ} (p : Program σ n s) (special : Fin s → Prop) :
Wire n s → Prop

A wire is live, once the special gates of p are erased, when it is an input or an ordinary gate of positive arity. The other wires are constants of the erased program: the constants replacing the special gates and the gates of arity zero.

noncomputable def Cslib.Circuits.Frontier.liveCircuit {σ : Signature} {n s : ℕ} (p : Program σ n s) (special : Fin s → Prop) [DecidablePred special] :
Circuit (σ.withConstants { g : Fin s // special g }) n (Nat.card { w : Wire n s // Live p special w })

The live circuit: the program p with its special gates erased, and with every live wire as an output.

noncomputable def Cslib.Circuits.Frontier.liveNetwork {σ : Signature} {n s : ℕ} (p : Program σ n s) (special : Fin s → Prop) [DecidablePred special] (U : Type u_2) :

The live network: the graph of the live circuit and the sites of its inputs, without constraints. It does not depend on a ledger or a guess; its frontiers, components and inputs read are those of the network of the live circuit on every guess (Frontier.Ledger.network).

theorem Cslib.Circuits.Frontier.reach_input {σ : Signature} {n s : ℕ} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] (i : Fin n) :

The inputs are signals of the live circuit.

theorem Cslib.Circuits.Frontier.innerSize_liveCircuit {σ : Signature} {n s : ℕ} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] :
(liveCircuit p special).innerSize = {g ∈ p.innerGates | ¬special g}.card

The inner gates of the live circuit are the ordinary inner gates.

theorem Cslib.Circuits.Frontier.card_live_le {σ : Signature} {n s : ℕ} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] :
Nat.card { w : Wire n s // Live p special w } ≤ n + (liveCircuit p special).innerSize

There are at most n + s' live wires, where s' counts the ordinary inner gates.

theorem Cslib.Circuits.Frontier.read_liveNetwork {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] :
(liveNetwork p special U).read = Set.univ

The live network reads every input.

theorem Cslib.Circuits.Frontier.card_vertex_liveCircuit_pos {σ : Signature} {n s : ℕ} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] (hn : 0 < n) :

When there are inputs, the graph of the live circuit has a vertex.

def Cslib.Circuits.Frontier.wiresIn {σ : Signature} {n s : ℕ} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] (P : Set (Compiler.Vertex (liveCircuit p special))) :
Set (Wire n s)

The wires whose vertices lie in P.

@[reducible, inline]
noncomputable abbrev Cslib.Circuits.Frontier.Ledger.network {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) (m : M) :

The constraint network of the live circuit on the guess m, accepting every value. Its satisfying assignments are the runs with guess m. Its graph and its sites are those of the live network, whatever the guess.

Splicing #

theorem Cslib.Circuits.Frontier.Ledger.trace_of_splice {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) {P : Set (Compiler.Vertex (liveCircuit p special))} {x y z : Fin n → U} (hread : L.readout (L.total (p.trace I x)) = L.readout (L.total (p.trace I y))) (hpart : L.totalOn (wiresIn P) (p.trace I x) = L.totalOn (wiresIn P) (p.trace I y)) (hcut : Set.EqOn (fun (e : Compiler.Edge (liveCircuit p special)) => p.trace I x ↑e.signal) (fun (e : Compiler.Edge (liveCircuit p special)) => p.trace I y ↑e.signal) ((liveNetwork p special U).edgeCut P)) (hzx : Set.EqOn z x ((liveNetwork p special U).readIn P)) (hzy : Set.EqOn z y ((liveNetwork p special U).readIn P)ᶜ) (w : Wire n s) :
(w ∈ wiresIn P → p.trace I z w = p.trace I x w) ∧ (w ∉ wiresIn P → p.trace I z w = p.trace I y w)

Splicing traces wire by wire. If the runs of x and y have the same readout on the special gates, the same ledger on the wires of a set of vertices P, and the same values on the edge cut of P, then every input z that reads like x at P and like y elsewhere has p.trace I z equal to p.trace I x on wiresIn P and equal to p.trace I y outside wiresIn P.

theorem Cslib.Circuits.Frontier.Ledger.mem_of_splice {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) {o : Wire n s} {Acc : Set U} {P : Set (Compiler.Vertex (liveCircuit p special))} {x y z : Fin n → U} (hx : p.trace I x o ∈ Acc) (hy : p.trace I y o ∈ Acc) (hread : L.readout (L.total (p.trace I x)) = L.readout (L.total (p.trace I y))) (hpart : L.totalOn (wiresIn P) (p.trace I x) = L.totalOn (wiresIn P) (p.trace I y)) (hcut : Set.EqOn (fun (e : Compiler.Edge (liveCircuit p special)) => p.trace I x ↑e.signal) (fun (e : Compiler.Edge (liveCircuit p special)) => p.trace I y ↑e.signal) ((liveNetwork p special U).edgeCut P)) (hzx : Set.EqOn z x ((liveNetwork p special U).readIn P)) (hzy : Set.EqOn z y ((liveNetwork p special U).readIn P)ᶜ) :
p.trace I z o ∈ Acc

Splicing two inputs with the same message. Let x and y be inputs whose value at the wire o lies in Acc. If their runs have the same readout on the special gates, the same ledger on the wires of a set of vertices P, and the same values on the edge cut of P, then every input z that reads like x at P and like y elsewhere has its value at o in Acc as well.

theorem Cslib.Circuits.Frontier.Ledger.run_eq_of_eqOn_readIn {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) (m : M) {W : Set (Compiler.Vertex (liveCircuit p special))} (hW : (liveNetwork p special U).edgeCut W = ∅) {x x' : Fin n → U} (hxx' : Set.EqOn x x' ((liveNetwork p special U).readIn W)) {e : Compiler.Edge (liveCircuit p special)} (he : e ∈ (liveNetwork p special U).touching W) :
L.run m x ↑e.signal = L.run m x' ↑e.signal

Locality inside a closed set. For a fixed guess, the values of the run on the edges at a closed set of vertices W depend only on the inputs read in W.

The sweep #

noncomputable def Cslib.Circuits.Frontier.Ledger.extra {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) (π : Layout (Compiler.Vertex (liveCircuit p special))) (t : ℕ) (x : Fin n → U) :
({ g : Fin s // special g } → U) × M

The extra message at time t: the readout of the consistent guess on the special gates and the ledger of the first t vertices. After the last vertex it is constant.

noncomputable def Cslib.Circuits.Frontier.Ledger.sweep {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) (o : Wire n s) (Acc : Set U) (π : Layout (Compiler.Vertex (liveCircuit p special))) :
Sweep {x : Fin n → U | p.trace I x o ∈ Acc} ((({ g : Fin s // special g } → U) × M) × (Compiler.Edge (liveCircuit p special) → Option U))

The sweep of a program with a ledger, along a layout of its live network: the frontier sweep of the values of the run, whose extra message is the readout on the special gates and the ledger so far.

theorem Cslib.Circuits.Frontier.Ledger.extra_succ_eq {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) (π : Layout (Compiler.Vertex (liveCircuit p special))) {t : ℕ} (ht : t < Nat.card (Compiler.Vertex (liveCircuit p special))) {x y : Fin n → U} (h₀ : L.extra π t x = L.extra π t y) (hw : ∀ (w₀ : Compiler.Signal (liveCircuit p special)), (Equiv.symm π) ⟨t, ht⟩ = Compiler.Vertex.signal w₀ → p.trace I x ↑w₀ = p.trace I y ↑w₀) :
L.extra π (t + 1) x = L.extra π (t + 1) y

When step t processes vertex v, L.extra π (t + 1) is determined by L.extra π t and, if v = .signal w₀, the value of the run at w₀.

theorem Cslib.Circuits.Frontier.Ledger.ncard_extra_le {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) {o : Wire n s} {Acc : Set U} (π : Layout (Compiler.Vertex (liveCircuit p special))) [Finite U] [Finite M] (t : ℕ) :
(L.extra π t '' {x : Fin n → U | p.trace I x o ∈ Acc}).ncard ≤ min (Nat.card U ^ Nat.card { g : Fin s // special g }) (Nat.card M) * Nat.card M

The extra message at time t takes at most min (|U| ^ k) |M| * |M| values, where k is the number of special gates: the readout lies in {g // special g} → U as well as in the image of M, and the partial ledger lies in M.

theorem Cslib.Circuits.Frontier.Ledger.ncard_transition_le_width {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) {o : Wire n s} {Acc : Set U} (π : Layout (Compiler.Vertex (liveCircuit p special))) [Finite U] [Finite M] {t : ℕ} (ht : t < Nat.card (Compiler.Vertex (liveCircuit p special))) :
((L.sweep o Acc π).transition t '' {x : Fin n → U | p.trace I x o ∈ Acc}).ncard ≤ min (Nat.card U ^ Nat.card { g : Fin s // special g }) (Nat.card M) * Nat.card M * Nat.card U ^ (((liveNetwork p special U).frontier π t ∪ (liveNetwork p special U).frontier π (t + 1)).ncard + ((liveNetwork p special U).readAt ((Equiv.symm π) ⟨t, ht⟩)).ncard)

Transitions by width. A transition at step t is determined by the extra message at time t, the values on the two frontiers, and the input read at the vertex processed.

theorem Cslib.Circuits.Frontier.Ledger.ncard_transition_le_readIn {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) {o : Wire n s} {Acc : Set U} (π : Layout (Compiler.Vertex (liveCircuit p special))) [Finite U] [Finite M] {t : ℕ} (ht : t < Nat.card (Compiler.Vertex (liveCircuit p special))) {W : Set (Compiler.Vertex (liveCircuit p special))} (hW : (liveNetwork p special U).edgeCut W = ∅) (hv : (Equiv.symm π) ⟨t, ht⟩ ∈ W) (hC : (liveNetwork p special U).frontier π t ∪ (liveNetwork p special U).frontier π (t + 1) ⊆ (liveNetwork p special U).touching W) :
((L.sweep o Acc π).transition t '' {x : Fin n → U | p.trace I x o ∈ Acc}).ncard ≤ min (Nat.card U ^ Nat.card { g : Fin s // special g }) (Nat.card M) * Nat.card M * Nat.card U ^ ((liveNetwork p special U).readIn W).ncard

Transitions inside a closed set. If the vertex processed at step t lies in a closed set W whose edges contain both frontiers of the step, a transition is determined by the extra message at time t and the inputs read in W.

theorem Cslib.Circuits.Frontier.Ledger.exists_ncard_le {σ : Signature} {n s : ℕ} {U : Type u_1} {p : Program σ n s} {special : Fin s → Prop} [DecidablePred special] {I : Interpretation σ U} {M : Type u_2} [CommMonoid M] (L : Ledger special p I M) {o : Wire n s} {Acc : Set U} (π : Layout (Compiler.Vertex (liveCircuit p special))) [Finite U] [Nonempty U] [Finite M] {K : ℕ} (hfree : RectangleFree {x : Fin n → U | p.trace I x o ∈ Acc} K) (hK : K ≤ {x : Fin n → U | p.trace I x o ∈ Acc}.ncard) (hV : 0 < Nat.card (Compiler.Vertex (liveCircuit p special))) (hC : ∀ (t : ℕ) (ht : t < Nat.card (Compiler.Vertex (liveCircuit p special))), (liveNetwork p special U).frontier π t ∪ (liveNetwork p special U).frontier π (t + 1) ⊆ (liveNetwork p special U).touching ((liveNetwork p special U).component ((Equiv.symm π) ⟨t, ht⟩))) :
∃ (t : ℕ) (ht : t < Nat.card (Compiler.Vertex (liveCircuit p special))), {x : Fin n → U | p.trace I x o ∈ Acc}.ncard ≤ (K - 1) ^ 2 * (Nat.card (Compiler.Vertex (liveCircuit p special)) + 1) * (min (Nat.card U ^ Nat.card { g : Fin s // special g }) (Nat.card M) * Nat.card M) * Nat.card U ^ min (((liveNetwork p special U).frontier π t ∪ (liveNetwork p special U).frontier π (t + 1)).ncard + ((liveNetwork p special U).readAt ((Equiv.symm π) ⟨t, ht⟩)).ncard) ((liveNetwork p special U).readIn ((liveNetwork p special U).component ((Equiv.symm π) ⟨t, ht⟩))).ncard

Counting along a layout of the components. Suppose that, at each step of a layout, the frontiers lie among the edges of the component of the vertex processed. Then some step t bounds the set accepted by p by (K - 1) ^ 2 (|V| + 1) (min (|U| ^ k) |M| * |M|) q ^ e, where q = |U|, k counts the special gates, and e is the smaller of the width of the step and the number of inputs read in the component of the vertex processed.