Multi-pass folds of tidily computable functions #
A multi-pass fold reads a list, encoded as the concatenation of the tokens of its elements, several
times. Each pass folds next over the elements, emitting emit for each of them, then emits
passEmit of the resulting state and moves on to passEnd of it. The passes stop once cont of
the state is false, and the fold ends by emitting finish of the final state. Workspace is
controlled by initialization, finalization and the peak state, element and callback bounds,
without a separate full-input-copy term.
Main definitions #
Turing.MultiTapeTM.passState: the state at the start of a pass.
Main results #
Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace.multiPassFold: multi-pass folds are tidily computable, charging each pass and bounding workspace by the initialization, finalization and peak state, element and callback bounds.
The flag after a pass: [true] if another pass follows, blank otherwise.
Instances For
Multi-pass 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. Pass i starts from passState … i; the fold makes passes x + 1 passes, which
cont signals after each of them. If all the parts are tidily computable and g x is encoded by
what the passes emit followed by finish of the final state, then g is tidily computable. Its
time is that of a streaming fold for every pass. The bounds tMax, sMax and lMax bound the
time and space of a round and of the end of a pass, and the lengths of the states and elements.
Workspace also accounts for initialization and finalization, without a separate full-input-copy
term. All these bounds may depend on the input.