RAM row-scan loop of breadth-first search
ProvedWilliamsonShmoys.ram_bfs_row_scanThis is the inner loop of the RAM breadth-first search for Baker's levels: one scan of an adjacency row.
Let a program contain, at position , the 14-instruction loop over (cell 16, bound in cell 13). It reads the edge bits at addresses (row ) and (column , with in cell 20) and the level label at . When an edge bit is and the label is (unvisited), it writes the new label held in cell 14 and sets the flag cell 23 to .
Started at the loop head with iterations remaining, pointers , and the label region disjoint from the edge addresses, the loop reaches within operations. For every ,
The flag becomes exactly when some label was written, and is unchanged otherwise. All other cells, except the loop registers and the scratch cell 22, are unchanged. Reading both row and column implements the symmetrised adjacency of SimpleGraph.fromRel.
Formalization Note. Code placement is CodeAt from Def_WilliamsonShmoys_RAMExec.
import Mathlib import Definitions.Def_WilliamsonShmoys_RAMExec set_option autoImplicit false open WilliamsonShmoys PlanarRAMInstruction
theorem WilliamsonShmoys.ram_bfs_row_scan (p : List PlanarRAMInstruction) (b : ℕ)
(hcode : CodeAt p b
[natBranch 13 16 (b + 14) (b + 1), natLoad 22 17, natBranch 11 22 (b + 5) (b + 3), natLoad 22 18, natBranch 11 22 (b + 5) (b + 9), natLoad 22 21, natBranch 22 12 (b + 7) (b + 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 b]) :
∀ (r w pr pc la : ℕ) (M : ℕ → ℕ) (R : ℕ → ℝ), w + r = M 13 →
M 16 = w → M 17 = pr → M 18 = pc → M 21 = la → M 11 = 1 → M 12 = 0 → M 19 = 2 →
32 ≤ la → 32 ≤ pr → 32 ≤ pc →
(∀ j j', j < r → j' < r → la + 2 * j ≠ pr + 2 * j' ∧ la + 2 * j ≠ pc + j' * M 20) →
∃ τ, τ ≤ 14 * r + 1 ∧
(planarRAMRun p ⟨b, M, R⟩ τ).pc = b + 14 ∧
(∀ j, j < r → (planarRAMRun p ⟨b, M, R⟩ τ).natMem (la + 2 * j) =
if (1 ≤ M (pr + 2 * j) ∨ 1 ≤ M (pc + j * M 20)) ∧ M (la + 2 * j) = 0 then M 14
else M (la + 2 * j)) ∧
(planarRAMRun p ⟨b, M, R⟩ τ).natMem 23 =
(if ∃ j, j < r ∧ (1 ≤ M (pr + 2 * j) ∨ 1 ≤ M (pc + j * M 20)) ∧ M (la + 2 * j) = 0 then 1
else M 23) ∧
(∀ a, a ≠ 16 → a ≠ 17 → a ≠ 18 → a ≠ 21 → a ≠ 22 → a ≠ 23 → (∀ j, j < r → a ≠ la + 2 * j) →
(planarRAMRun p ⟨b, M, R⟩ τ).natMem a = M a) ∧
(planarRAMRun p ⟨b, M, R⟩ τ).realMem = R := by sorry