Streaming folds #
A streaming fold reads its input once, from left to right, one token at a time. It keeps a state on a work tape; for each token it appends the token's content to the state, computes the next state from the result and emits a word to the output. The input is never copied, so a round costs time and space in the size of the state and the token only.
Main definitions #
Turing.MultiTapeTM.frozenRound: the part of a round that does not use the input.Turing.MultiTapeTM.streamTM: initialization, the loop of rounds, finalization and cleanup.
Main results #
Turing.MultiTapeTM.transformsTapes_frozenRound: the specification offrozenRound.Turing.MultiTapeTM.transformsTapesAt_streamLoop_after: the loop of rounds, started just past an input prefix;transformsTapesAt_streamLoopis its empty-prefix case.Turing.MultiTapeTM.computesTidily_streamTM_after: the tidy assembly ofstreamTMfrom an initializer that may move the input head past a prefix;computesTidily_streamTMis the case of an initializer that leaves the input head at the start.
Specifications on selected tapes #
The part of a round that does not use the input #
Emit with E from the word on tape V, write the next state to tape N with Nm, and move
it to tape V, using tape F to flag the left end of the word.
Instances For
frozenRound takes the word w on tape V and every other tape blank to next on tape V
and every other tape blank, emitting emit, if E emits emit from w and Nm writes next
to tape N.
Rounds and the whole machine #
One round: append the content of the next token to the state on tape V, then run
frozenRound with the input head frozen.
Instances For
The streaming fold: write the initial state to tape V with I, run rounds while there is
input left, emit from the final state with Fm, clear tape V and rewind the input.
Instances For
One round at the input position p₀ of x, on the state v: if E emits emit from the
state with the token's content appended and Nm computes next from it, the round leaves next
on tape V, emits emit and moves the input head over the token.
The streaming loop after an input prefix. The input is a prefix pre followed by the
concatenation of the non-empty tokens toks, from each of which the reader r reads the content
cont j. If for every token j the machine E emits es j and Nm computes the next state
vs (j + 1) from the state vs j followed by cont j, then the loop of rounds, started on the
state vs 0 just past the prefix, leaves the final state on tape V, emits the words es j and
stops at the end of the input. The prefix is neither read nor copied.
The streaming loop. The input x is the concatenation of the non-empty tokens toks, from
each of which the reader r reads the content cont j. If for every token j the machine E
emits es j and Nm computes the next state vs (j + 1) from the state vs j followed by
cont j, then the loop of rounds, started on the state vs 0 at the start of the input, leaves
the final state on tape V, emits the words es j and stops at the end of the input.
Initialize with a phase I that may move the input head past a prefix pre, run a streaming
phase from there, emit from its final state and clean up. The phase specifications own the token
reader, round callbacks and their resource accounting.
Initialize, run a streaming phase, emit from its final state and clean up. The phase
specification owns the token reader, round callbacks and their resource accounting. This is
computesTidily_streamTM_after with an initializer that leaves the input head at the start.