Folds behind a finite-state translator #
A translator reads bits and emits, for each bit, at most one event, with a finite state in between. A fold over the events of a word is a fold over its bits, whose state also holds the state of the translator: each bit steps the translator and, if it emits an event, steps the inner fold. This turns a fold over a convenient encoding into a fold over another one, at the cost of a constant amount of state, so it applies to streaming and multi-pass folds alike.
Main definitions #
Turing.MultiTapeTM.Translator: finite-state translators from bits to events.Turing.MultiTapeTM.Translator.lift: the step of a fold on bits from one on events.
Main results #
Turing.MultiTapeTM.Translator.foldl_lift: the lifted fold folds over the events.Turing.MultiTapeTM.ComputableTidilyInO.lift: the lifted step is tidily computable.
A translator from bits to events: from each state, a bit leads to a state and at most one event.
- q₀ : Q
The initial state.
The next state and the emitted event, if any.
Instances For
The state and the events after reading w from the state q.
Instances For
The events of w.
Instances For
The lifted fold folds over the events, and ends in the state of the translator.
The bit at position k emits the next event, if any.
The lifted fold after k bits: the state of the translator, and the inner fold after the
events of the first k bits.
The passes of the lifted fold, which restart the translator, are those of the inner fold on the events.
A bound on the events holds for the event of every bit, if any: the event of bit k is the
event after those of the first k bits.
The lifted step is tidily computable, within the bounds of the inner step on the emitted event, if any, plus the length of its input.
Bounds #
Multi-pass folds behind a translator. A multi-pass fold over the events that the
translator tr emits on the encoded input is tidily computable on the encoded input itself, from
parts computable within the given bounds. Each pass reads every bit, so its time is the length of
the input times the bounds on a round; the space is that of the fold on the events. 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.