Documentation

CslibFrontier.Computability.Circuit.Pebbling

Register evaluation of straight-line programs is black pebbling #

A straight-line program p : Program σ n g has a computation DAG p.dag on its wires: the argument wires of a gate are the predecessors of that gate, and the inputs are sources. This file introduces a register machine for p. Each wire has its own register; a configuration is the set of occupied registers together with their contents. A step either loads an input, computes a gate whose argument registers are all occupied, or frees a register. Evaluation with s registers means that at most s registers are ever occupied at once.

Forgetting the contents of the registers turns an evaluation into a black pebbling of p.dag with the same moves, and conversely every black pebbling is an evaluation from any initial register contents. This is the reading of the pebble game in [Sav98], Section 10.1, where a pebble on a vertex means that its value is held in a register, placing a pebble on an input reads it, placing one on a gate computes it, and removing one erases the value. Inputs occupy registers, as in that model. A gate's value always goes into a fresh register, the gate's own: there is no sliding, as in the black pebble game of Cslib.Pebbling.blackPebbleGame. Savage also allows the result to be placed on (or moved to) the register of an argument, and under that rule the register count of every gate that reads at least one wire is one lower.

Main definitions #

Main results #

References #

def Cslib.Circuits.Program.dag {σ : Signature} {n g : ℕ} (p : Program σ n g) :

The computation DAG of a straight-line program: the argument wires of a gate are its predecessors, and the inputs are sources.

theorem Cslib.Circuits.Program.dag_adj {σ : Signature} {n g : ℕ} {p : Program σ n g} {u v : Wire n g} :
p.dag.Adj u v ↔ ∃ (j : Fin g) (k : Fin (σ.Arity (p.lines j).op)), v = Wire.gate j ∧ (p.lines j).wires k = u
@[simp]
theorem Cslib.Circuits.Program.dag_adj_gate {σ : Signature} {n g : ℕ} {p : Program σ n g} {u : Wire n g} {j : Fin g} :
p.dag.Adj u (Wire.gate j) ↔ ∃ (k : Fin (σ.Arity (p.lines j).op)), (p.lines j).wires k = u
@[simp]
theorem Cslib.Circuits.Program.not_dag_adj_input {σ : Signature} {n g : ℕ} (p : Program σ n g) (u : Wire n g) (i : Fin n) :

The computation DAG of a program is acyclic: every wire is accessible, by induction along the program order.

theorem Cslib.Circuits.Program.ncard_dag_adj_le {σ : Signature} {n g : ℕ} {p : Program σ n g} {r : ℕ} (hp : p.FanInAtMost r) (v : Wire n g) :
{u : Wire n g | p.dag.Adj u v}.ncard ≤ r

With fan-in at most r, every wire has at most r predecessors in the computation DAG.

inductive Cslib.Circuits.Program.RegisterStep {σ : Signature} {n g : ℕ} {U : Type u_1} (p : Program σ n g) (I : Interpretation σ U) (x : Fin n → U) :
Finset (Wire n g) × (Wire n g → U) → Pebbling.Move (Wire n g) → Finset (Wire n g) × (Wire n g → U) → Prop

One step of register evaluation of p. A configuration is the set of occupied registers, one per wire, and their contents. Loading an input reads it, computing a gate requires its argument wires to be held, and any register can be freed. A computed gate value goes into a fresh register (no sliding onto an argument's register), so register counts at gates that read at least one wire are one higher than under Savage's sliding rule.

def Cslib.Circuits.Program.registerLTS {σ : Signature} {n g : ℕ} {U : Type u_1} (p : Program σ n g) (I : Interpretation σ U) (x : Fin n → U) (s : ℕ) :
LTS (Finset (Wire n g) × (Wire n g → U)) (Pebbling.Move (Wire n g))

Register evaluation of p with at most s occupied registers.

theorem Cslib.Circuits.Program.registerLTS_tr {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {s : ℕ} {c d : Finset (Wire n g) × (Wire n g → U)} {m : Pebbling.Move (Wire n g)} :
(p.registerLTS I x s).Tr c m d ↔ p.RegisterStep I x c m d ∧ d.1.card ≤ s
theorem Cslib.Circuits.Program.RegisterStep.trace_eq {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {c d : Finset (Wire n g) × (Wire n g → U)} {m : Pebbling.Move (Wire n g)} (h : p.RegisterStep I x c m d) (hc : ∀ w ∈ c.1, c.2 w = p.trace I x w) (w : Wire n g) :
w ∈ d.1 → d.2 w = p.trace I x w

Correctness. A step keeps every occupied register equal to the value of its wire.

theorem Cslib.Circuits.Program.registerLTS_mTr_trace_eq {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {s : ℕ} {c d : Finset (Wire n g) × (Wire n g → U)} {ms : List (Pebbling.Move (Wire n g))} (h : (p.registerLTS I x s).MTr c ms d) (hc : ∀ w ∈ c.1, c.2 w = p.trace I x w) (w : Wire n g) :
w ∈ d.1 → d.2 w = p.trace I x w
theorem Cslib.Circuits.Program.RegisterStep.blackStep {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {c d : Finset (Wire n g) × (Wire n g → U)} {m : Pebbling.Move (Wire n g)} (h : p.RegisterStep I x c m d) :

Forgetting register contents turns a register evaluation into a black pebbling of the computation DAG.

theorem Cslib.Circuits.Program.blackPebbleGame_mTr_of_registerLTS {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {s : ℕ} {c d : Finset (Wire n g) × (Wire n g → U)} {ms : List (Pebbling.Move (Wire n g))} (h : (p.registerLTS I x s).MTr c ms d) :
theorem Cslib.Circuits.Program.exists_registerLTS_mTr {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {s : ℕ} {C D : Finset (Wire n g)} {ms : List (Pebbling.Move (Wire n g))} (h : (Pebbling.blackPebbleGame p.dag s).MTr C ms D) (r : Wire n g → U) :
∃ (r' : Wire n g → U), (p.registerLTS I x s).MTr (C, r) ms (D, r')

Every black pebbling of the computation DAG is a register evaluation, from any initial register contents.

def Cslib.Circuits.Program.EvaluatesInRegisters {σ : Signature} {n g : ℕ} {U : Type u_1} (p : Program σ n g) (I : Interpretation σ U) (x : Fin n → U) (r₀ : Wire n g → U) (s : ℕ) (w : Wire n g) :

p evaluates wire w with at most s registers, from the initial contents r₀.

theorem Cslib.Circuits.Program.EvaluatesInRegisters.exists_eq_trace {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {r₀ : Wire n g → U} {s : ℕ} {w : Wire n g} (h : p.EvaluatesInRegisters I x r₀ s w) :
∃ (ms : List (Pebbling.Move (Wire n g))) (d : Finset (Wire n g) × (Wire n g → U)), (p.registerLTS I x s).MTr (∅, r₀) ms d ∧ w ∈ d.1 ∧ d.2 w = p.trace I x w

A register evaluation that reaches w holds the correct value of w.

theorem Cslib.Circuits.Program.evaluatesInRegisters_iff_blackPebblable {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {r₀ : Wire n g → U} {s : ℕ} {w : Wire n g} :

Registers are pebbles. p evaluates w with s registers exactly when w can be black-pebbled with s pebbles in the computation DAG of p, for every interpretation, input and initial register contents.

theorem Cslib.Circuits.Program.sInf_evaluatesInRegisters {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} (r₀ : Wire n g → U) (w : Wire n g) :

The least number of registers that evaluates w is the black pebbling price of w in the computation DAG.

theorem Cslib.Circuits.Program.evaluatesInRegisters_card {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} (r₀ : Wire n g → U) (w : Wire n g) :
p.EvaluatesInRegisters I x r₀ (n + g) w

Every wire can be evaluated with one register per wire.