The getEnv routine #
With the unary index S(ofNat i) under the head of C and the environment envRepr env on
E with its head at the end, getEnv writes S(env.get i) at the head of X: it walks
left over i separators (phases p1–p3), then to the start of the element (p4), copies
it (p5) and returns the head of E to the end (p8); past the start of the environment
the index is out of range, the rest of it is consumed (p6, p7) and nil is written
(p9). The proof is by induction on the index, over the suffix of the environment not yet
passed.
The unary index S(ofNat i): (1 0)^i 0.
A tape holding the environment from 0, blank before.
- before : BlankBefore τ 0
- beyond : BlankBeyond τ ↑(envRepr env).length
Instances For
The scans #
Phase p3: over the bits l held on p₀ … p₀ + |l| - 1, from the last, to p₀ - 1.
Phase p4: over the bits l, from the last, to p₀ - 1, then one right to p₀ at p5.
Phase p5: copy the bits l under the head of E to X, to the # after them.
Phases p8/p9: the head of E right to the first blank.
Phases p6/p7: consume the index S(ofNat j) on C, then write nil on X and move
E one right, at p9.
The walk #
Cells of a suffix of the environment: for env' = v :: rest a prefix of env, S v sits
at |envRepr rest|, followed by #, and preceded by # or the blank before the tape.
The walk from phase p1: at the separator of the last element of the suffix env' of
env (or before the tape if env' is empty), with the index S(ofNat j) on C.
getEnv: with S(ofNat i) under the head of C and the environment on E with
its head at the end, write S(env.get i) at the head of X.