RAM vertex-scan loop of breadth-first search
ProvedWilliamsonShmoys.ram_bfs_vertex_scanThis is the middle loop of the RAM breadth-first search used to compute Baker's levels: one BFS layer expansion over all vertices.
Let a program contain, at position , the 27-instruction loop over vertices (cell 24, bound in cell 13). The edge table of the -vertex graph is stored at odd-spaced addresses , and the level labels at , where . A label means unvisited; otherwise it is the BFS distance plus one. For each whose label equals the current layer label (cell 15), the loop runs the row scan (ram_bfs_row_scan). That scan labels every unvisited neighbour of with (cell 14), where adjacency is the symmetrised relation " or ".
Started at the loop head with in cell 24, vertices remaining and the auxiliary pointer registers initialised, the program reaches within operations. For every ,
The flag cell 23 becomes exactly when some vertex was newly labelled, and is unchanged otherwise. All cells above 28 outside the label array, and all cells , are unchanged, as are the constant registers 19, 20 and 28 and the real memory. Because the new label differs from , vertices labelled during the pass are not expanded in the same pass, so the result is exactly one BFS layer step.
Formalization Note. Code placement is CodeAt from Def_WilliamsonShmoys_RAMExec. The if-conditions with existentials use classical decidability (open Classical).
import Mathlib import Definitions.Def_WilliamsonShmoys_RAMExec set_option autoImplicit false open WilliamsonShmoys PlanarRAMInstruction open Classical
theorem WilliamsonShmoys.ram_bfs_vertex_scan (p : List PlanarRAMInstruction) (c : ℕ)
(hcode : CodeAt p c
[natBranch 13 24 (c + 27) (c + 1),
natLoad 22 27,
natBranch 22 15 (c + 3) (c + 22),
natBranch 15 22 (c + 4) (c + 22),
natConst 16 0,
natAdd 17 25 12,
natAdd 18 26 12,
natAdd 21 28 12,
natBranch 13 16 (c + 8 + 14) (c + 8 + 1),
natLoad 22 17,
natBranch 11 22 (c + 8 + 5) (c + 8 + 3),
natLoad 22 18,
natBranch 11 22 (c + 8 + 5) (c + 8 + 9),
natLoad 22 21,
natBranch 22 12 (c + 8 + 7) (c + 8 + 9),
natStore 21 14,
natAdd 23 11 12,
natAdd 16 16 11,
natAdd 17 17 19,
natAdd 18 18 20,
natAdd 21 21 19,
jump (c + 8),
natAdd 24 24 11,
natAdd 25 25 20,
natAdd 26 26 19,
natAdd 27 27 19,
jump c])
(n t LVB : ℕ) (ht : 1 ≤ t) (hLVB : 36 + 2 * n * n ≤ LVB) :
∀ (r u : ℕ) (M : ℕ → ℕ) (R : ℕ → ℝ), u + r = n →
M 13 = n → M 20 = 2 * n → M 24 = u → M 25 = 36 + 2 * u * n → M 26 = 36 + 2 * u →
M 27 = LVB + 2 * u → M 28 = LVB → M 11 = 1 → M 12 = 0 → M 19 = 2 → M 15 = t → M 14 = t + 1 →
∃ τ, τ ≤ r * (14 * n + 14) + 1 ∧
(planarRAMRun p ⟨c, M, R⟩ τ).pc = c + 27 ∧
(∀ j, j < n → (planarRAMRun p ⟨c, M, R⟩ τ).natMem (LVB + 2 * j) =
if M (LVB + 2 * j) = 0 ∧ ∃ v, u ≤ v ∧ v < n ∧ M (LVB + 2 * v) = t ∧
(1 ≤ M (36 + 2 * v * n + 2 * j) ∨ 1 ≤ M (36 + 2 * v + j * (2 * n)))
then t + 1 else M (LVB + 2 * j)) ∧
(planarRAMRun p ⟨c, M, R⟩ τ).natMem 23 =
(if ∃ v, u ≤ v ∧ v < n ∧ M (LVB + 2 * v) = t ∧ ∃ j, j < n ∧
(1 ≤ M (36 + 2 * v * n + 2 * j) ∨ 1 ≤ M (36 + 2 * v + j * (2 * n))) ∧ M (LVB + 2 * j) = 0
then 1 else M 23) ∧
(∀ a, 28 < a → (∀ j, j < n → a ≠ LVB + 2 * j) → (planarRAMRun p ⟨c, M, R⟩ τ).natMem a = M a) ∧
(∀ a, a ≤ 15 → (planarRAMRun p ⟨c, M, R⟩ τ).natMem a = M a) ∧
(planarRAMRun p ⟨c, M, R⟩ τ).natMem 19 = 2 ∧ (planarRAMRun p ⟨c, M, R⟩ τ).natMem 20 = 2 * n ∧
(planarRAMRun p ⟨c, M, R⟩ τ).natMem 28 = LVB ∧
(planarRAMRun p ⟨c, M, R⟩ τ).realMem = R := by sorry