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 #
Cslib.Circuits.Program.dag: the computation DAG of a program.Cslib.Circuits.Program.RegisterStep,Cslib.Circuits.Program.registerLTS: register evaluation, as a cslibLTSwith ans-register budget.Cslib.Circuits.Program.EvaluatesInRegisters: some evaluation withsregisters occupies the register ofw.
Main results #
Cslib.Circuits.Program.wellFounded_dag: the computation DAG is acyclic.Cslib.Circuits.Program.ncard_dag_adj_le: with fan-in at mostr, every wire has at mostrpredecessors.Cslib.Circuits.Program.registerLTS_mTr_trace_eq: correctness; every occupied register holds the valuep.trace I xof its wire.Cslib.Circuits.Program.evaluatesInRegisters_iff_blackPebblable:pevaluateswwithsregisters exactly whenwis black-pebblable withspebbles inp.dag.Cslib.Circuits.Program.sInf_evaluatesInRegisters: the least number of registers is the black pebbling price.
References #
- J. E. Savage, Models of Computation, Section 10.1.
The computation DAG of a program is acyclic: every wire is accessible, by induction along the program order.
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.
- load {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {C : Finset (Wire n g)} {r : Wire n g → U} (i : Fin n) : p.RegisterStep I x (C, r) (Pebbling.Move.place (Wire.input i))
(insert (Wire.input i) C, Function.update r (Wire.input i) (x i))
Load an input into its register.
- compute {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {C : Finset (Wire n g)} {r : Wire n g → U} (j : Fin g) (h : ∀ (k : Fin (σ.Arity (p.lines j).op)), (p.lines j).wires k ∈ C) : p.RegisterStep I x (C, r) (Pebbling.Move.place (Wire.gate j))
(insert (Wire.gate j) C, Function.update r (Wire.gate j) (I (p.lines j).op (r ∘ (p.lines j).wires)))
Compute a gate from the held registers of its argument wires, into the gate's own fresh register.
- free {σ : Signature} {n g : ℕ} {U : Type u_1} {p : Program σ n g} {I : Interpretation σ U} {x : Fin n → U} {C : Finset (Wire n g)} {r : Wire n g → U} (w : Wire n g) : p.RegisterStep I x (C, r) (Pebbling.Move.remove w) (C.erase w, r)
Free a register.
Correctness. A step keeps every occupied register equal to the value of its wire.
Forgetting register contents turns a register evaluation into a black pebbling of the computation DAG.
Every black pebbling of the computation DAG is a register evaluation, from any initial register contents.
A register evaluation that reaches w holds the correct value of w.
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.
The least number of registers that evaluates w is the black pebbling price of w in the
computation DAG.
Every wire can be evaluated with one register per wire.