Documentation

CslibFrontier.Computability.Pebbling.Descending

Evaluating a descending computation along a pebbling walk #

A descending computation on the indices 0, …, N - 1 has a source at 0 and, at each positive index i, a gate gates i reading the values at the d strictly smaller indices child i 0, …, child i (d - 1). Its dependency graph (Cslib.Pebbling.Descending.graph) is a DAG of in-degree at most d, and the Boolean test Cslib.Pebbling.Descending.ready decides on indicator words whether all predecessors of an index carry pebbles. So the word moves Cslib.Pebbling.wordStep (ready child) s are the moves of the black pebble game on the dependency graph, and Savitch's recursion decides whether an index is pebblable with s pebbles.

Following a walk of indicator words, an evaluator keeps a table of (index, value) pairs (Cslib.Pebbling.Descending.tableStep). When a step clears a bit, it drops that index; when a step sets a bit, it computes the value of that index from the values of its children in the table. As long as consecutive words are equal or one legal move apart, the table holds exactly the values of the pebbled indices (Cslib.Pebbling.Descending.Holds), so a walk from the zero word to the word of the single pebble v ends with the value of v in the table. The table never holds more than s entries, whatever the walk. This is how the simulation of Hopcroft, Paul and Valiant uses a pebbling: one stored value per pebble.

Main definitions #

Main results #

References #

The dependency graph #

def Cslib.Pebbling.Descending.graph {N d : ℕ} (child : ℕ → Fin d → ℕ) :

The dependency graph of a descending computation on Fin N: the predecessors of a positive index are its children; the source 0 has none.

@[simp]
theorem Cslib.Pebbling.Descending.graph_adj {N d : ℕ} (child : ℕ → Fin d → ℕ) {u v : Fin N} :
(graph child).Adj u v ↔ 0 < ↑v ∧ ∃ (a : Fin d), child (↑v) a = ↑u
theorem Cslib.Pebbling.Descending.wellFounded_graph {N d : ℕ} (child : ℕ → Fin d → ℕ) (hchild : ∀ (i : ℕ), 0 < i → ∀ (a : Fin d), child i a < i) :

With children below their parents, the dependency graph is acyclic.

theorem Cslib.Pebbling.Descending.ncard_graph_adj_le {N d : ℕ} (child : ℕ → Fin d → ℕ) (v : Fin N) :
{u : Fin N | (graph child).Adj u v}.ncard ≤ d

Every index has at most d predecessors.

Readiness on words #

def Cslib.Pebbling.Descending.ready {d : ℕ} (child : ℕ → Fin d → ℕ) (w : List Bool) (i : ℕ) :

Index i is ready in the word w: it is the source, or each of its children carries a pebble.

theorem Cslib.Pebbling.Descending.ready_indicatorList {N d : ℕ} (child : ℕ → Fin d → ℕ) (hchild : ∀ (i : ℕ), 0 < i → i < N → ∀ (a : Fin d), child i a < N) (C : Finset (Fin N)) (i : Fin N) :
ready child (BitString.indicatorList C) ↑i = true ↔ ∀ (u : Fin N), (graph child).Adj u i → u ∈ C

On indicator words, ready tests that all predecessors in the dependency graph carry pebbles.

theorem Cslib.Pebbling.Descending.reach_wordStep_ready_iff_blackPebblable {N d : ℕ} (child : ℕ → Fin d → ℕ) (hchild : ∀ (i : ℕ), 0 < i → i < N → ∀ (a : Fin d), child i a < N) {s : ℕ} {v : Fin N} :

Savitch's recursion decides pebblability of the dependency graph.

Differences between words #

The first position where u and v differ, or u.length when there is none.

theorem Cslib.Pebbling.Descending.diffIndex_set {u : List Bool} {i : ℕ} (hi : i < u.length) {b : Bool} (hb : u.getD i false ≠ b) :
diffIndex u (u.set i b) = i

Flipping bit i makes i the first difference.

The invariant #

structure Cslib.Pebbling.Descending.Holds {N : ℕ} {U : Type u_1} (value : ℕ → U) (C : Finset (Fin N)) (t : List (ℕ × U)) :

The table t holds exactly the values value i of the pebbled indices i ∈ C, each once.

theorem Cslib.Pebbling.Descending.holds_nil {N : ℕ} {U : Type u_1} {value : ℕ → U} :
Holds value ∅ []

The empty table holds the empty configuration.

theorem Cslib.Pebbling.Descending.Holds.length_eq {N : ℕ} {U : Type u_1} {value : ℕ → U} {C : Finset (Fin N)} {t : List (ℕ × U)} (h : Holds value C t) :

The table has one entry per pebble.

theorem Cslib.Pebbling.Descending.Holds.insert {N : ℕ} {U : Type u_1} {value : ℕ → U} {C : Finset (Fin N)} {t : List (ℕ × U)} (h : Holds value C t) {v : Fin N} (hv : v ∉ C) :
Holds value (Insert.insert v C) ((↑v, value ↑v) :: t)

Placing a pebble on v stores its value.

theorem Cslib.Pebbling.Descending.Holds.erase {N : ℕ} {U : Type u_1} {value : ℕ → U} {C : Finset (Fin N)} {t : List (ℕ × U)} (h : Holds value C t) (v : Fin N) :
Holds value (C.erase v) (List.filter (fun (p : ℕ × U) => p.1 != ↑v) t)

Removing the pebble on v drops its entry.

theorem Cslib.Pebbling.Descending.Holds.lookup_eq {N : ℕ} {U : Type u_1} {value : ℕ → U} {C : Finset (Fin N)} {t : List (ℕ × U)} (h : Holds value C t) {v : Fin N} (hv : v ∈ C) :
List.lookup (↑v) t = some (value ↑v)

A pebbled index is stored with its value.

The table #

def Cslib.Pebbling.Descending.entry {d : ℕ} (child : ℕ → Fin d → ℕ) {U : Type u_1} [Inhabited U] (gates : ℕ → (Fin d → U) → U) (source : U) (t : List (ℕ × U)) (i : ℕ) :
U

The value of index i computed from the table: the source at 0, otherwise the gate of i on the stored values of its children (default for a child that is not stored).

def Cslib.Pebbling.Descending.tableStep {d : ℕ} (child : ℕ → Fin d → ℕ) {U : Type u_1} [Inhabited U] (gates : ℕ → (Fin d → U) → U) (source : U) (s : ℕ) (u v : List Bool) (t : List (ℕ × U)) :
List (ℕ × U)

One update of the table along a walk from u to v, with room for s entries: if v clears the first bit where the words differ, drop that index; if it sets it and the table has fewer than s entries, store its value computed from the table. Equal words, and a set bit when the table is full, leave the table unchanged.

theorem Cslib.Pebbling.Descending.length_tableStep_le {d : ℕ} (child : ℕ → Fin d → ℕ) {U : Type u_1} [Inhabited U] (gates : ℕ → (Fin d → U) → U) (source : U) {s : ℕ} {u v : List Bool} {t : List (ℕ × U)} (ht : t.length ≤ s) :
(tableStep child gates source s u v t).length ≤ s

The table never exceeds s entries, along any walk.

theorem Cslib.Pebbling.Descending.holds_tableStep {N d : ℕ} (child : ℕ → Fin d → ℕ) {U : Type u_1} {value : ℕ → U} [Inhabited U] (gates : ℕ → (Fin d → U) → U) (source : U) (hchild : ∀ (i : ℕ), 0 < i → ∀ (a : Fin d), child i a < i) (hzero : value 0 = source) (hsucc : ∀ (i : ℕ), 0 < i → i < N → value i = gates i fun (a : Fin d) => value (child i a)) {s : ℕ} {C D : Finset (Fin N)} {t : List (ℕ × U)} (h : Holds value C t) (hmove : C = D ∨ (blackPebbleGame (graph child) s).UnlabelledTr C D) :
Holds value D (tableStep child gates source s (BitString.indicatorList C) (BitString.indicatorList D) t)

One move preserves the invariant. If the table holds the values of C, and D is C or one legal move with at most s pebbles away, then after one step from the word of C to the word of D the table holds the values of D.

theorem Cslib.Pebbling.Descending.holds_tableStep_of_wordStep {N d : ℕ} (child : ℕ → Fin d → ℕ) {U : Type u_1} {value : ℕ → U} [Inhabited U] (gates : ℕ → (Fin d → U) → U) (source : U) (hchild : ∀ (i : ℕ), 0 < i → ∀ (a : Fin d), child i a < i) (hzero : value 0 = source) (hsucc : ∀ (i : ℕ), 0 < i → i < N → value i = gates i fun (a : Fin d) => value (child i a)) {s : ℕ} {u v : List Bool} (hu : u.length = N) (hv : v.length = N) (huv : u = v ∨ wordStep (ready child) s u v = true) {t : List (ℕ × U)} (h : Holds value (BitString.supportOfList N u) t) :
Holds value (BitString.supportOfList N v) (tableStep child gates source s u v t)

One step of a word walk preserves the invariant. Between words of length N that are equal or one word move apart, a step of the table carries the invariant from the support of u to the support of v.

theorem Cslib.Pebbling.Descending.lookup_eq_of_tableStep {N d : ℕ} (child : ℕ → Fin d → ℕ) {U : Type u_1} {value : ℕ → U} [Inhabited U] (gates : ℕ → (Fin d → U) → U) (source : U) (hchild : ∀ (i : ℕ), 0 < i → ∀ (a : Fin d), child i a < i) (hzero : value 0 = source) (hsucc : ∀ (i : ℕ), 0 < i → i < N → value i = gates i fun (a : Fin d) => value (child i a)) {s : ℕ} (ws : ℕ → List Bool) (ts : ℕ → List (ℕ × U)) (n : ℕ) (hlen : ∀ j ≤ n, (ws j).length = N) (hws0 : ws 0 = List.replicate N false) (hstep : ∀ j < n, ws j = ws (j + 1) ∨ wordStep (ready child) s (ws j) (ws (j + 1)) = true) (hts0 : ts 0 = []) (hts : ∀ j < n, ts (j + 1) = tableStep child gates source s (ws j) (ws (j + 1)) (ts j)) {v : Fin N} (hend : ws n = BitString.indicatorList {v}) :
List.lookup (↑v) (ts n) = some (value ↑v)

The evaluator is correct. Along a walk ws of words of length N from the zero word in which consecutive words are equal or one word move apart, tables built by tableStep from the empty table hold the values of the pebbled indices. When the walk reaches the word of {v}, the table returns the value of v.