Following a walk by Savitch's midpoint recursion #
Savitch's midpoint recursion (Cslib.Reachability.reach) decides whether v is reachable from u
within 2 ^ d steps between words of width w. This file turns the recursion into a walk that
visits the vertices of such a path in order, one per step, holding only a stack of pending targets
with their levels.
A state of the walk (Cslib.Reachability.Walk.State) is the current vertex and the stack. A target
at level 0 is one step away: the walk moves to it and pops it. A target t at level i + 1 is
split at the midpoint m of the current vertex and t (Cslib.Reachability.Walk.midpoint): the
walk replaces it by m and t, both at level i. The midpoint is the first word of width w, in
the order of the binary counter, that the current vertex reaches and that reaches t at level i
(Cslib.Reachability.Walk.search); when there is none, it is the word of zeros.
The midpoint is always a word of width w, so the shape of the run does not depend on the edges:
a target at level d is reached in exactly 2 ^ (d + 1) - 1 steps
(Cslib.Reachability.Walk.iterate_step_frame), a whole stack in
Cslib.Reachability.Walk.stackSteps steps (Cslib.Reachability.Walk.iterate_step_stack), every
word on the way has width w (Cslib.Reachability.Walk.width_iterate), and a run from a target at
level d holds at most d + 1 targets, at levels at most d
(Cslib.Reachability.Walk.levelsLE_iterate). When v is reachable from u within 2 ^ d steps,
each step of the run from u to v stays put or follows an edge
(Cslib.Reachability.Walk.eq_or_edge_iterate), because each target remains reachable from the
previous one at its level (Cslib.Reachability.Walk.chain_iterate).
The space of a step on multi-tape machines is in
Cslib.Computability.Machines.Turing.MultiTape.Complexity.Space.SavitchWalk.
Main definitions #
Cslib.Reachability.Walk.searchStep,Cslib.Reachability.Walk.search: search in counter order.Cslib.Reachability.Walk.midpoint: the first midpoint of a call.Cslib.Reachability.Walk.State,Cslib.Reachability.Walk.step: the walk.Cslib.Reachability.Walk.stackSteps: the number of steps that clear a stack.Cslib.Reachability.Walk.Width,Cslib.Reachability.Walk.LevelsLE,Cslib.Reachability.Walk.Chain: the invariants of a run.
Main results #
Cslib.Reachability.Walk.search_eq,Cslib.Reachability.Walk.test_search,Cslib.Reachability.Walk.search_of_forall: the search finds the first word that passes the test, and the word of zeros when there is none;Cslib.Reachability.Walk.search_congr: it depends only on the test at words of widthw.Cslib.Reachability.Walk.reach_midpoint,Cslib.Reachability.Walk.midpoint_of_reach_eq_false: the midpoint splits a call, and is the word of zeros when the call fails.Cslib.Reachability.Walk.iterate_step_frame,Cslib.Reachability.Walk.iterate_step_stack,Cslib.Reachability.Walk.iterate_step_run: the walk reaches its targets in a fixed number of steps.Cslib.Reachability.Walk.width_iterate,Cslib.Reachability.Walk.levelsLE_iterate,Cslib.Reachability.Walk.LevelsLE.length_le,Cslib.Reachability.Walk.LevelsLE.le_of_mem: the shape of the states of a run.Cslib.Reachability.Walk.chain_iterate,Cslib.Reachability.Walk.eq_or_edge_iterate: a run between reachable vertices follows edges.
References #
Search in counter order #
Search in counter order. From the word of w zeros, 2 ^ w rounds of searchStep stop at
the first word of width w, in the order of the binary counter, that passes test; when there is
none, the counter wraps around to the word of zeros.
The search finds the first word that passes test: if the k-th word of width w in
counter order passes it and no earlier word does, the search returns it.
The midpoint of a call #
The midpoint of a call from u to v at level i + 1: the first word of width w, in
counter order, that u reaches and that reaches v at level i (search). It is the word of
zeros when there is no such word, and when u or v does not have width w.
The midpoint splits a call: if v is reachable from u at level i + 1, the midpoint is
reachable from u, and reaches v, at level i.
The walk #
A state of the walk: the current vertex, and the stack of pending targets with their levels,
the next target first. A target at level i is reachable within 2 ^ i steps from the vertex or
target before it.
One step of the walk, with the edge test edge and words of width w.
- An empty stack is a fixed point: the walk has arrived.
- A target at level
0is one step away: move to it and pop it. - A target
tat leveli + 1is replaced by the midpoint of the current vertex andt, followed byt, both at leveli.
A target at level d is reached in 2 ^ (d + 1) - 1 steps, whatever the edges: the walk
then stands on the target, with the rest of the stack untouched.
The shape of the states #
The words of a state have width w: the current vertex and every pending target.
A run between reachable vertices #
Following a walk. If v is reachable from u within 2 ^ d steps between words of width
w, every step of the run from u to the target v at level d stays put or follows an edge.