Savitch's midpoint reachability with an explicit stack #
Savitch's theorem rests on the midpoint recursion: v is reachable from u within 2 ^ (i + 1)
steps exactly when some midpoint is reachable from u and reaches v within 2 ^ i steps each
(Relation.RelatesWithinSteps.two_pow_succ_iff). On the words of a fixed width w,
Cslib.Reachability.reach is this recursion, with the midpoints enumerated by
Cslib.BitString.enumList, and it decides walks of at most 2 ^ i steps along the edges of an
edge test (Cslib.Reachability.reach_iff).
Savitch's algorithm runs the recursion on an explicit stack. A frame records a call in progress:
its level, its endpoints, the midpoint being tried, which doubles as the counter of the midpoints,
and the half being tried. A register holds the pending call or the value just returned. One total
step function (Cslib.Reachability.Savitch.step) handles the five cases: a call at level 0 tests
for an edge, a call at a higher level pushes a frame, a value returned into either half of a frame
moves to the other half, to the next midpoint or out of the frame, and an empty stack holding a
value is a fixed point. The midpoints advance by a binary counter of fixed width
(Cslib.Reachability.Savitch.next), which visits the words in the order of
Cslib.BitString.enumList. A call at level i returns within
Cslib.Reachability.Savitch.callSteps w i steps
(Cslib.Reachability.Savitch.exists_iterate_step_call), so
Cslib.Reachability.Savitch.steps w d = 2 ^ ((w + 2) * (d + 1)) - 1 steps compute the recursion at
level d (Cslib.Reachability.savitch_eq).
The time and space of the algorithm on multi-tape machines are in
Cslib.Computability.Machines.Turing.MultiTape.Complexity.Space.Reachability.
Main definitions #
Cslib.Reachability.reach: the midpoint recursion.Cslib.Reachability.Savitch.next: the binary counter of fixed width.Cslib.Reachability.Savitch.Frame,Cslib.Reachability.Savitch.Reg,Cslib.Reachability.Savitch.State,Cslib.Reachability.Savitch.step: the stack machine.Cslib.Reachability.Savitch.callSteps,Cslib.Reachability.Savitch.steps: the number of steps of a call, and of the algorithm.Cslib.Reachability.savitch: Savitch's algorithm.
Main results #
Cslib.Reachability.reach_iff: the recursion decides walks of at most2 ^ isteps.Cslib.Reachability.Savitch.next_getElem_enumList: the counter visits the words in the order ofCslib.BitString.enumList.Cslib.Reachability.Savitch.exists_iterate_step_call: every call returns its value.Cslib.Reachability.savitch_eq,Cslib.Reachability.savitch_iff: the algorithm computes the recursion, and decides walks of at most2 ^ dsteps.
References #
Reachability by midpoints #
Reachability within 2 ^ i steps, by midpoints. At level 0, v is u or one edge
away; at level i + 1, some word m of width w is reachable from u and reaches v at level
i. This is the recursion of Savitch's theorem Sipser, Theorem 8.5.
Instances For
A walk along edges between words of width w stays among the words of width w.
The binary counter #
The counter visits the words in the order of Cslib.BitString.enumList: it moves from
each word to the next one, and overflows on the last one.
The stack machine #
A frame of the stack: the call at level level + 1 from src to dst, while it tries the
midpoint mid with two calls at level level.
- level : ℕ
The level of the two calls on the halves; the frame answers a call at level
level + 1. The source of the call.
The target of the call.
The midpoint being tried, which is also the counter of the midpoints tried so far.
- phase : Bool
Instances For
The register of the machine: a pending call, or the value of a call that has returned.
Instances For
The answer held by a register: the returned value, or false while a call is pending.
Instances For
One step of Savitch's machine, with the edge test edge and midpoints of width w.
- A call at level
0returns whethervisuor one edge away. - A call at level
i + 1pushes a frame and calls the first half with the first midpoint, the word of all zeros. - An empty stack with a returned value is a fixed point: the value is the answer.
- A value
truereturned into the first half moves the frame to the second half; returned into the second half, the frame returnstrue. - A value
falsereturned into either half advances the midpoint by the binary counter; when the counter overflows, every midpoint has failed and the frame returnsfalse.
Instances For
The number of steps the machine takes for a call at level i, with midpoints of width w:
one step to push the frame, and for each of the 2 ^ w midpoints at most two calls at level i,
each followed by one step to take its value.
Instances For
The number of steps Savitch's algorithm runs the machine for: 2 ^ ((w + 2) * (d + 1)) - 1,
at least callSteps w d, and written in binary as (w + 2) * (d + 1) ones.