Multi-pass streaming folds #
A multi-pass fold reads its input several times, from left to right, keeping a state on a work tape between the passes. A pass is a streaming loop over the tokens of the input, followed by an end round that computes the state for the next pass, and a flag on a separate tape that says whether another pass follows. Like a streaming fold, it never copies the input.
Main definitions #
Turing.MultiTapeTM.passTM: one pass.Turing.MultiTapeTM.multiPassTM: the passes, between the initial state and the final emission.
Main results #
Turing.MultiTapeTM.transformsTapes_passTM: the specification of a pass.Turing.MultiTapeTM.computesTidily_multiPassTM: the passes compute tidily.
One pass: clear the flag tape C, run the streaming loop with the rounds E, Nm, run the
end round Ee, Ne with the input head frozen, write the flag with Cm and rewind the input.
Instances For
The multi-pass fold: write the initial state to tape V with I, run passes until the flag
tape C is blank, emit from the final state with Fm and clear tape V.
Instances For
Clear the continuation flag, run a streaming phase, then compute the end-of-pass state and flag and rewind the input. The phase owns the token and round specifications.
The multi-pass fold. If I writes the initial state vs 0 to tape V, each pass i
takes the state vs i and the flag cs i to the state vs (i + 1) and the flag cs (i + 1),
emitting es i, where the flag is blank at the start and exactly after the last pass passes, and
Fm emits ef from the final state, then multiPassTM emits the words es i followed by ef,
tidily.