Documentation

Complexity.Computability.Machines.Turing.MultiTape.Encodings.StreamFold

Streaming folds of tidily computable functions #

A list encoded as the concatenation of the tokens of its elements, each read by a finite-state input reader, can be folded in one pass over the input. The fold keeps a state, starting with init l; for each element a it moves from the state s to next (s, a) and emits emit (s, a); at the end it emits finish of the final state. Only the state and one element are ever held on the work tapes.

Main definitions #

Main results #

The cumulative theorem generalizes Christian Reitwiessner's original encoding-layer proof. The typed phase shares token decoding, callback adaptation and copying bounds with multi-pass folds. streamFold_sum_after owns the machine and its resource proof once: streamFold_sum computes the initial state from the whole input, streamFold_pair_sum reads it from a framed input prefix, and the uniform-round corollary reuses the complete single-pass construction.

def Turing.MultiTapeTM.streamState {α : Type u_1} {σ : Type u_2} (init : σ) (next : σ × α → σ) (l : List α) (j : ℕ) :
σ

The state of a streaming fold after the first j elements of l.

Instances For
    def Turing.MultiTapeTM.streamEmit {α : Type u_1} {σ : Type u_2} (next : σ × α → σ) (emit : σ × α → List Bool) :
    σ → List α → List Bool

    The words emitted by a streaming fold from the state s on the list l.

    Instances For
      @[simp]
      theorem Turing.MultiTapeTM.streamState_zero {α : Type u_1} {σ : Type u_2} (init : σ) (next : σ × α → σ) (l : List α) :
      streamState init next l 0 = init
      theorem Turing.MultiTapeTM.streamState_succ {α : Type u_1} {σ : Type u_2} (init : σ) (next : σ × α → σ) (l : List α) {j : ℕ} (hj : j < l.length) :
      streamState init next l (j + 1) = next (streamState init next l j, l[j])
      theorem Turing.MultiTapeTM.streamEmit_eq {α : Type u_1} {σ : Type u_2} (next : σ × α → σ) (emit : σ × α → List Bool) (s : σ) (l : List α) :
      streamEmit next emit s l = (List.map (fun (j : ℕ) => (Option.map (fun (a : α) => emit (streamState s next l j, a)) l[j]?).getD []) (List.range l.length)).flatten

      The emitted words, round by round.

      The lengths of the tokens add up to the length of the input.

      @[simp]
      theorem Turing.MultiTapeTM.streamEmit_const_nil {α : Type u_1} {σ : Type u_2} (next : σ × α → σ) (s : σ) (l : List α) :
      streamEmit next (fun (x : σ × α) => []) s l = []

      A streaming fold whose per-element callback emits nothing emits the empty word.

      An input reader that reads one framed word [true, b₁, …, true, bₖ, false] from the input tape while keeping its framing, stopping immediately after the closing false (including on the empty frame [false]).

      Instances For

        rawFrameReader reads frame w from the start of frame w ++ rest in (frame w).length steps, keeping the framing intact.

        theorem Turing.MultiTapeTM.transformsTapesAt_streamLoop_encoded_after {α σ : Type u} {Q : Type u_3} {SE : Type u_4} {SN : Type u_5} {K : ℕ} {encA : α ↪ List Bool} {encS : σ ↪ List Bool} {E : MultiTapeTM K Bool SE} {Nm : MultiTapeTM K Bool SN} {V N F : Fin K} (r : InputReader Bool Q) (tok : α → List Bool) (htok : ∀ (a : α), tok a ≠ []) (hread : ∀ (a : α) (rest : List Bool), r.read r.q₀ (tok a ++ rest) = (encA a, (tok a).length)) (hVN : V ≠ N) (hVF : V ≠ F) (hNF : N ≠ F) (pre : List Bool) (s : σ) (l : List α) (next : σ × α → σ) (emit : σ × α → List Bool) {tE sE tN sN : σ × α → ℕ} (hE : ∀ (p : σ × α), E.TransformsTapes (fun (x : List Bool) (ws : Fin K → List Bool) => ws = Function.update (fun (x : Fin K) => []) V ((encPair encS encA) p)) (fun (x : List Bool) (ws ws' : Fin K → List Bool) (em : List Bool) => ws' = ws ∧ em = emit p) (tE p) (sE p)) (hN : ∀ (p : σ × α), Nm.TransformsTapes (fun (x : List Bool) (ws : Fin K → List Bool) => ws = Function.update (fun (x : Fin K) => []) V ((encPair encS encA) p)) (fun (x : List Bool) (ws ws' : Fin K → List Bool) (em : List Bool) => ws' = Function.update ws N (frame (encS (next p))) ∧ em = []) (tN p) (sN p)) {roundCost : ℕ → ℕ} {sMax lMax : ℕ} (hcost : ∀ (j : ℕ) (hj : j < l.length), tE (streamState s next l j, l[j]) + tN (streamState s next l j, l[j]) + 12 * ((encS (streamState s next l j)).length + (encS (streamState s next l (j + 1))).length + (encA l[j]).length) + 32 ≤ roundCost j) (hspace : ∀ (j : ℕ) (hj : j < l.length), sE (streamState s next l j, l[j]) + sN (streamState s next l j, l[j]) ≤ sMax) (hstate : ∀ j ≤ l.length, (encS (streamState s next l j)).length ≤ lMax) (helem : ∀ (j : ℕ) (hj : j < l.length), (encA l[j]).length ≤ lMax) :
        (streamRound r E Nm V N F hVN hVF hNF).whileInput.TransformsTapesAt (fun (input : List Bool) (p : Fin (input.length + 2)) (ws : Fin K → List Bool) => input = pre ++ List.flatMap tok l ∧ ↑p = 1 + pre.length ∧ ws = Function.update (fun (x : Fin K) => []) V (frame (encS s))) (fun (input : List Bool) (x : Fin (input.length + 2)) (x_1 : Fin K → List Bool) (p' : Fin (input.length + 2)) (ws' : Fin K → List Bool) (em : List Bool) => input = pre ++ List.flatMap tok l ∧ ↑p' = 1 + (pre ++ List.flatMap tok l).length ∧ ws' = Function.update (fun (x : Fin K) => []) V (frame (encS (streamState s next l l.length))) ∧ em = streamEmit next emit s l) ((List.flatMap tok l).length + ∑ j ∈ Finset.range l.length, roundCost j + 1) (2 * K * (sMax + 16 * lMax + 4 * K + 26) + K)

        A typed streaming phase starting after an input prefix pre.

        theorem Turing.MultiTapeTM.transformsTapesAt_streamLoop_encoded {α σ : Type u} {Q : Type u_3} {SE : Type u_4} {SN : Type u_5} {K : ℕ} {encA : α ↪ List Bool} {encS : σ ↪ List Bool} {E : MultiTapeTM K Bool SE} {Nm : MultiTapeTM K Bool SN} {V N F : Fin K} (r : InputReader Bool Q) (tok : α → List Bool) (htok : ∀ (a : α), tok a ≠ []) (hread : ∀ (a : α) (rest : List Bool), r.read r.q₀ (tok a ++ rest) = (encA a, (tok a).length)) (hVN : V ≠ N) (hVF : V ≠ F) (hNF : N ≠ F) (s : σ) (l : List α) (next : σ × α → σ) (emit : σ × α → List Bool) {tE sE tN sN : σ × α → ℕ} (hE : ∀ (p : σ × α), E.TransformsTapes (fun (x : List Bool) (ws : Fin K → List Bool) => ws = Function.update (fun (x : Fin K) => []) V ((encPair encS encA) p)) (fun (x : List Bool) (ws ws' : Fin K → List Bool) (em : List Bool) => ws' = ws ∧ em = emit p) (tE p) (sE p)) (hN : ∀ (p : σ × α), Nm.TransformsTapes (fun (x : List Bool) (ws : Fin K → List Bool) => ws = Function.update (fun (x : Fin K) => []) V ((encPair encS encA) p)) (fun (x : List Bool) (ws ws' : Fin K → List Bool) (em : List Bool) => ws' = Function.update ws N (frame (encS (next p))) ∧ em = []) (tN p) (sN p)) {roundCost : ℕ → ℕ} {sMax lMax : ℕ} (hcost : ∀ (j : ℕ) (hj : j < l.length), tE (streamState s next l j, l[j]) + tN (streamState s next l j, l[j]) + 12 * ((encS (streamState s next l j)).length + (encS (streamState s next l (j + 1))).length + (encA l[j]).length) + 32 ≤ roundCost j) (hspace : ∀ (j : ℕ) (hj : j < l.length), sE (streamState s next l j, l[j]) + sN (streamState s next l j, l[j]) ≤ sMax) (hstate : ∀ j ≤ l.length, (encS (streamState s next l j)).length ≤ lMax) (helem : ∀ (j : ℕ) (hj : j < l.length), (encA l[j]).length ≤ lMax) :
        (streamRound r E Nm V N F hVN hVF hNF).whileInput.TransformsTapesAt (fun (input : List Bool) (p : Fin (input.length + 2)) (ws : Fin K → List Bool) => input = List.flatMap tok l ∧ ↑p = 1 ∧ ws = Function.update (fun (x : Fin K) => []) V (frame (encS s))) (fun (input : List Bool) (x : Fin (input.length + 2)) (x_1 : Fin K → List Bool) (p' : Fin (input.length + 2)) (ws' : Fin K → List Bool) (em : List Bool) => input = List.flatMap tok l ∧ ↑p' = 1 + (List.flatMap tok l).length ∧ ws' = Function.update (fun (x : Fin K) => []) V (frame (encS (streamState s next l l.length))) ∧ em = streamEmit next emit s l) ((List.flatMap tok l).length + ∑ j ∈ Finset.range l.length, roundCost j + 1) (2 * K * (sMax + 16 * lMax + 4 * K + 26) + K)

        A typed streaming phase on selected tapes. The state is framed, each token is decoded once, and the callbacks receive the ordinary pair encoding. roundCost charges callback time and copying of the current state, next state and decoded element. The phase leaves its final state on tape V and the input cursor just past the last token, so another phase can consume them.

        theorem Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace.streamFold_sum_after {α σ : Type u} {γ : Type u_3} {ε : Type u_4} {φ : Type u_5} {ω : Type u_6} {encA : α ↪ List Bool} {encS : σ ↪ List Bool} {encE : ε ↪ List Bool} {encF : φ ↪ List Bool} {encIn : γ ↪ List Bool} {encOut : ω ↪ List Bool} {Q : Type} [Finite Q] (r : InputReader Bool Q) (tok : α → List Bool) (htok : ∀ (a : α), tok a ≠ []) (hread : ∀ (a : α) (rest : List Bool), r.read r.q₀ (tok a ++ rest) = (encA a, (tok a).length)) (pre : γ → List Bool) (elems : γ → List α) (hL : ∀ (x : γ), encIn x = pre x ++ List.flatMap tok (elems x)) {init : γ → σ} {next : σ × α → σ} {emit : σ × α → ε} {finish : σ → φ} {g : γ → ω} {kI : ℕ} {SI : Type} [Finite SI] (I : {K : ℕ} → (Fin (kI + 1) ↪ Fin K) → MultiTapeTM K Bool SI) {tI sI : γ → ℕ} {tN sN tE sE : σ × α → ℕ} {tF sF : σ → ℕ} (hinit : ∀ {K : ℕ} (e : Fin (kI + 1) ↪ Fin K) (x : γ), (I e).TransformsTapesAt (fun (inp : List Bool) (p : Fin (inp.length + 2)) (ws : Fin K → List Bool) => inp = encIn x ∧ ↑p = 1 ∧ ws = fun (x : Fin K) => []) (fun (x_1 : List Bool) (x_2 : Fin (x_1.length + 2)) (x_3 : Fin K → List Bool) (p' : Fin (x_1.length + 2)) (ws' : Fin K → List Bool) (em : List Bool) => ↑p' = 1 + (pre x).length ∧ ws' = Function.update (fun (x : Fin K) => []) (e (Fin.last kI)) (frame (encS (init x))) ∧ em = []) (tI x) (sI x + (K - (kI + 1)))) (hnext : ComputableTidilyInTimeAndSpace next (encPair encS encA) encS tN sN) (hemit : ComputableTidilyInTimeAndSpace emit (encPair encS encA) encE tE sE) (hfinish : ComputableTidilyInTimeAndSpace finish encS encF tF sF) (hg : ∀ (x : γ), encOut (g x) = streamEmit next (fun (p : σ × α) => encE (emit p)) (init x) (elems x) ++ encF (finish (streamState (init x) next (elems x) (elems x).length))) {roundCost : γ → ℕ → ℕ} {sMax lMax : γ → ℕ} (hcost : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), tN (streamState (init x) next (elems x) j, (elems x)[j]) + tE (streamState (init x) next (elems x) j, (elems x)[j]) + (encS (streamState (init x) next (elems x) j)).length + (encS (streamState (init x) next (elems x) (j + 1))).length + (encA (elems x)[j]).length + 1 ≤ roundCost x j) (hsMax : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), sN (streamState (init x) next (elems x) j, (elems x)[j]) + sE (streamState (init x) next (elems x) j, (elems x)[j]) ≤ sMax x) (hS : ∀ (x : γ), ∀ j ≤ (elems x).length, (encS (streamState (init x) next (elems x) j)).length ≤ lMax x) (hA : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), (encA (elems x)[j]).length ≤ lMax x) :
        ∃ (c : ℕ), ComputableTidilyInTimeAndSpace g encIn encOut (fun (x : γ) => c * (tI x + tF (streamState (init x) next (elems x) (elems x).length) + (encIn x).length + ∑ j ∈ Finset.range (elems x).length, roundCost x j + lMax x + 1)) fun (x : γ) => c * (sI x + sF (streamState (init x) next (elems x) (elems x).length) + sMax x + lMax x + 1)

        Streaming folds after an initialization phase. The input encIn x is a prefix pre x followed by the concatenated non-empty tokens tok a of the elements elems x, from each of which the finite-state reader r reads encA a. On any selection e of tapes, the initializer I e starts at the start of the input on blank tapes, writes the framed initial state frame (encS (init x)) to the selected tape e (Fin.last kI), emits nothing and moves the input head just past pre x, in time tI x and space sI x plus one cell for each unselected tape. If next, emit and finish are tidily computable, and g x is encoded by the words emitted by the fold over elems x followed by finish of its final state, then g is tidily computable. The tokens are streamed directly from the input tape, which is never copied. The time bound sums the initialization, the actual round costs roundCost (each round's computation, current and next states, decoded element storage and control), finalization, input scanning and cleanup. Workspace adds the initialization's to the peak callback workspace sMax and the stored-word bound lMax; output is emitted directly and does not count as workspace.

        theorem Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace.streamFold_sum {α σ : Type u} {γ : Type u_3} {ε : Type u_4} {φ : Type u_5} {ω : Type u_6} {encA : α ↪ List Bool} {encS : σ ↪ List Bool} {encE : ε ↪ List Bool} {encF : φ ↪ List Bool} {encIn : γ ↪ List Bool} {encOut : ω ↪ List Bool} {Q : Type} [Finite Q] (r : InputReader Bool Q) (tok : α → List Bool) (htok : ∀ (a : α), tok a ≠ []) (hread : ∀ (a : α) (rest : List Bool), r.read r.q₀ (tok a ++ rest) = (encA a, (tok a).length)) (elems : γ → List α) (hL : ∀ (x : γ), encIn x = List.flatMap tok (elems x)) {init : γ → σ} {next : σ × α → σ} {emit : σ × α → ε} {finish : σ → φ} {g : γ → ω} {tI sI : γ → ℕ} {tN sN tE sE : σ × α → ℕ} {tF sF : σ → ℕ} (hinit : ComputableTidilyInTimeAndSpace init encIn encS tI sI) (hnext : ComputableTidilyInTimeAndSpace next (encPair encS encA) encS tN sN) (hemit : ComputableTidilyInTimeAndSpace emit (encPair encS encA) encE tE sE) (hfinish : ComputableTidilyInTimeAndSpace finish encS encF tF sF) (hg : ∀ (x : γ), encOut (g x) = streamEmit next (fun (p : σ × α) => encE (emit p)) (init x) (elems x) ++ encF (finish (streamState (init x) next (elems x) (elems x).length))) {roundCost : γ → ℕ → ℕ} {sMax lMax : γ → ℕ} (hcost : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), tN (streamState (init x) next (elems x) j, (elems x)[j]) + tE (streamState (init x) next (elems x) j, (elems x)[j]) + (encS (streamState (init x) next (elems x) j)).length + (encS (streamState (init x) next (elems x) (j + 1))).length + (encA (elems x)[j]).length + 1 ≤ roundCost x j) (hsMax : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), sN (streamState (init x) next (elems x) j, (elems x)[j]) + sE (streamState (init x) next (elems x) j, (elems x)[j]) ≤ sMax x) (hS : ∀ (x : γ), ∀ j ≤ (elems x).length, (encS (streamState (init x) next (elems x) j)).length ≤ lMax x) (hA : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), (encA (elems x)[j]).length ≤ lMax x) :
        ∃ (c : ℕ), ComputableTidilyInTimeAndSpace g encIn encOut (fun (x : γ) => c * (tI x + tF (streamState (init x) next (elems x) (elems x).length) + (encIn x).length + ∑ j ∈ Finset.range (elems x).length, roundCost x j + lMax x + 1)) fun (x : γ) => c * (sI x + sF (streamState (init x) next (elems x) (elems x).length) + sMax x + lMax x + 1)

        Streaming folds with cumulative round costs. The input x is encoded by concatenating the non-empty tokens tok a of the elements elems x, from each of which the finite-state reader r reads encA a. If init, next, emit and finish are tidily computable, and g x is encoded by the words emitted by the fold over elems x followed by finish of its final state, then g is tidily computable. The time bound sums roundCost, including each round's computation, current and next states, decoded element storage and control. Initialization, finalization, input scanning and cleanup are charged separately. sMax and lMax bound peak callback workspace and stored words; output is emitted directly and does not count as workspace.

        theorem Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace.streamFold {α σ : Type u} {γ : Type u_3} {ε : Type u_4} {φ : Type u_5} {ω : Type u_6} {encA : α ↪ List Bool} {encS : σ ↪ List Bool} {encE : ε ↪ List Bool} {encF : φ ↪ List Bool} {encIn : γ ↪ List Bool} {encOut : ω ↪ List Bool} {Q : Type} [Finite Q] (r : InputReader Bool Q) (tok : α → List Bool) (htok : ∀ (a : α), tok a ≠ []) (hread : ∀ (a : α) (rest : List Bool), r.read r.q₀ (tok a ++ rest) = (encA a, (tok a).length)) (elems : γ → List α) (hL : ∀ (x : γ), encIn x = List.flatMap tok (elems x)) {init : γ → σ} {next : σ × α → σ} {emit : σ × α → ε} {finish : σ → φ} {g : γ → ω} {tI sI : γ → ℕ} {tN sN tE sE : σ × α → ℕ} {tF sF : σ → ℕ} (hinit : ComputableTidilyInTimeAndSpace init encIn encS tI sI) (hnext : ComputableTidilyInTimeAndSpace next (encPair encS encA) encS tN sN) (hemit : ComputableTidilyInTimeAndSpace emit (encPair encS encA) encE tE sE) (hfinish : ComputableTidilyInTimeAndSpace finish encS encF tF sF) (hg : ∀ (x : γ), encOut (g x) = streamEmit next (fun (p : σ × α) => encE (emit p)) (init x) (elems x) ++ encF (finish (streamState (init x) next (elems x) (elems x).length))) {tMax sMax lMax : γ → ℕ} (htMax : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), tN (streamState (init x) next (elems x) j, (elems x)[j]) + tE (streamState (init x) next (elems x) j, (elems x)[j]) ≤ tMax x) (hsMax : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), sN (streamState (init x) next (elems x) j, (elems x)[j]) + sE (streamState (init x) next (elems x) j, (elems x)[j]) ≤ sMax x) (hS : ∀ (x : γ), ∀ j ≤ (elems x).length, (encS (streamState (init x) next (elems x) j)).length ≤ lMax x) (hA : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), (encA (elems x)[j]).length ≤ lMax x) :
        ∃ (c : ℕ), ComputableTidilyInTimeAndSpace g encIn encOut (fun (x : γ) => c * (tI x + tF (streamState (init x) next (elems x) (elems x).length) + (encIn x).length + (elems x).length * (tMax x + lMax x + 1) + lMax x + 1)) fun (x : γ) => c * (sI x + sF (streamState (init x) next (elems x) (elems x).length) + sMax x + lMax x + 1)

        Streaming folds are tidily computable. The input x is encoded by concatenating the non- empty tokens tok a of the elements elems x, from each of which the finite-state reader r reads encA a. If init, next, emit and finish are tidily computable, and g x is encoded by the words emitted by the fold over elems x followed by finish of its final state, then g is tidily computable. Its time is linear in the input plus the rounds. Workspace uses peak bounds on states, elements and callbacks. The bounds tMax, sMax and lMax bound the time and space of a round and the lengths of the states and elements.

        theorem Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace.streamFold_pair_sum {α σ : Type u} {γ : Type u_3} {ε : Type u_4} {φ : Type u_5} {ω : Type u_6} {encA : α ↪ List Bool} {encS : σ ↪ List Bool} {encE : ε ↪ List Bool} {encF : φ ↪ List Bool} {encIn : γ ↪ List Bool} {encOut : ω ↪ List Bool} {Q : Type} [Finite Q] (r : InputReader Bool Q) (tok : α → List Bool) (htok : ∀ (a : α), tok a ≠ []) (hread : ∀ (a : α) (rest : List Bool), r.read r.q₀ (tok a ++ rest) = (encA a, (tok a).length)) (init : γ → σ) (elems : γ → List α) (hL : ∀ (x : γ), encIn x = frame (encS (init x)) ++ List.flatMap tok (elems x)) {next : σ × α → σ} {emit : σ × α → ε} {finish : σ → φ} {g : γ → ω} {tN sN tE sE : σ × α → ℕ} {tF sF : σ → ℕ} (hnext : ComputableTidilyInTimeAndSpace next (encPair encS encA) encS tN sN) (hemit : ComputableTidilyInTimeAndSpace emit (encPair encS encA) encE tE sE) (hfinish : ComputableTidilyInTimeAndSpace finish encS encF tF sF) (hg : ∀ (x : γ), encOut (g x) = streamEmit next (fun (p : σ × α) => encE (emit p)) (init x) (elems x) ++ encF (finish (streamState (init x) next (elems x) (elems x).length))) {roundCost : γ → ℕ → ℕ} {sMax lMax : γ → ℕ} (hcost : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), tN (streamState (init x) next (elems x) j, (elems x)[j]) + tE (streamState (init x) next (elems x) j, (elems x)[j]) + (encS (streamState (init x) next (elems x) j)).length + (encS (streamState (init x) next (elems x) (j + 1))).length + (encA (elems x)[j]).length + 1 ≤ roundCost x j) (hsMax : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), sN (streamState (init x) next (elems x) j, (elems x)[j]) + sE (streamState (init x) next (elems x) j, (elems x)[j]) ≤ sMax x) (hS : ∀ (x : γ), ∀ j ≤ (elems x).length, (encS (streamState (init x) next (elems x) j)).length ≤ lMax x) (hA : ∀ (x : γ) (j : ℕ) (hj : j < (elems x).length), (encA (elems x)[j]).length ≤ lMax x) :
        ∃ (c : ℕ), ComputableTidilyInTimeAndSpace g encIn encOut (fun (x : γ) => c * (tF (streamState (init x) next (elems x) (elems x).length) + (encIn x).length + ∑ j ∈ Finset.range (elems x).length, roundCost x j + lMax x + 1)) fun (x : γ) => c * (sF (streamState (init x) next (elems x) (elems x).length) + sMax x + lMax x + 1)

        Streaming folds from a framed initial state prefix. When encIn x consists of the framed initial state frame (encS (init x)) followed directly by the concatenated tokens of elems x (for example, on encPair encS encBits or encPair encS encUnary), appendRead rawFrameReader V copies the framed initial state onto tape V and leaves the input cursor at the start of the token stream, so the tokens are streamed directly from the input tape without copying the remainder of the input onto work tapes.