Iterating a function while its result is non-empty #
tm.iterateWhile mark applies tm to its input, then to the result, and so on, until tm
produces the empty word, and then outputs the last word before the empty one. tm is applied at
least once, so if it maps the input itself to the empty word, the output is the input. The
computation need not terminate.
The machine keeps the current word on one work tape and the next one on another. A round copies
the next word to the current tape (Turing.MultiTapeTM.copyWord) and computes the new next word
from it with tm. Rounds are repeated by Turing.MultiTapeTM.repeatUntilBlank until the next word
is empty.
Main definitions #
Turing.MultiTapeTM.iterateWhile: the iterating machine.
Main results #
Turing.MultiTapeTM.computesTidily_iterateWhile: iftmcomputesw (n + 1)fromw ntidily for everyn ≤ r, andw (n + 1)is empty exactly forn = r, thentm.iterateWhile markcomputesw rfromw 0tidily.Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace.iterateWhile: iffis tidily computable, so isa ↦ f^[r a] a, wherer ais the leastnsuch thatf^[n + 1] ahas the empty encoding.Turing.MultiTapeTM.ComputableTidilyInTimeAndSpaceOfLength.iterateWhile: the same, with bounds on the number of rounds and on the lengths of all intermediate values in terms of the length of the input.
The tapes #
The machine #
The states of Turing.MultiTapeTM.iterateWhileRound.
Instances For
tm, applied repeatedly while its result is non-empty, using mark to flag the left end of
words: load the input to the next tape, repeat rounds until the next tape is empty, then output
the current word and clear its tape.
Instances For
The phases #
Iterating a machine #
If tm computes w (n + 1) from w n tidily within t steps and s cells for every
n ≤ r, the words w n for n ≤ r have length at most l, and w (n + 1) is empty exactly for
n = r, then tm.iterateWhile mark computes w r from w 0 tidily.
Iterating a computable function #
If f is tidily computable, so is a ↦ f^[r a] a, where r a is the least n such that
f^[n + 1] a has the empty encoding. Each of the r a + 1 rounds costs at most the largest time
of f on the values f^[n] a for n ≤ r a plus a term linear in their longest encoding; the
space is linear in the largest space of f on these values and their longest encoding.
If f is tidily computable in time t and space s of the length of its input, for monotone
t and s, so is a ↦ f^[r a] a, where r a is the least n such that f^[n + 1] a has the
empty encoding, provided that for inputs of length n, r a ≤ ρ n and the encodings of all
f^[i] a for i ≤ r a have length at most l n.