# Is the halting problem also undecideable for turing machines always writing a $1$ on the tape?

It is well known that the halting problem is generally undecideable.

Is this still the case, if we only allow Turing machines that always write a $1$ on the tape.

The conditions are as in the usual busy beaver game. I am unsure whether the decision problem whether such a machine halts is as hard as in the general case, since the tape has exactly one block of ones without gaps at any time (except at the beginning). This could make it easier to analyze the behaviour of such machines.

Yes, the problem is decidable. With a few tricks, it may even be possible to find an algorithm polynomial in $Q$, the number of states in the machine, though in the rest of this answer I'll just prove that the problem is decidable.

Let me rephrase your question like this:

A blackout machine is a Turing machine whose every transition rule prints a $\mathtt{1}$ on the tape. Is it decidable whether a given blackout machine halts on a blank tape?

Terminology. First, let's define terminology. The tape of a blackout machine always consists of a contiguous finite string of ones, surrounded by zeroes. The string of ones is called the interior. The two blank cells adjacent to the string of ones are called the left and right frontier, respectively. The frontier cells are part of the infinite regions of zeroes called the exterior.

How we prove that halting is decidable. The plan is to prove that the behavior of a blackout machine is completely determined by a few details of its configuration: its current state, which side of the frontier it's currently on, and the size of the interior modulo an integer $N(Q)$. (Here $N$ is some number dependent on $Q$—for decidability, it's enough to prove this statement for $N=Q!$ as I do in this proof, though a smaller number would produce a more efficient algorithm.) Because a blackout machine effectively has a finite number of configurations, it's enough to simulate the machine until it either halts or must revisit one of its finitely many configurations in which case it loops forever.

Simple looping behavior. The key insight for this proof is that all Turing machines exhibit looping behavior when run on a sufficiently long region of ones. Imagine starting with an infinite tape that has infinitely many zeroes to the left of the starting cell and infinitely many ones to the right of the starting cell. $$\mathtt{\ldots000000000000\,11111111111\ldots}$$

You start a $Q$-state read-only(!) Turing machine on the leftmost 1 cell. Then, as it runs, the tape head may travel within the region of ones or it may exit into the region of zeroes. Observe that if the tape head has not exited the region of ones after $Q$ steps, its deterministic control has entered a cycle. Indeed, for $Q$ consecutive steps, it has read a 1 on the tape and transitioned into a new state. After the $Q$th such transition (if not earlier), it will read 1 on the tape and transition into a state it has been in earlier, then read 1 on the tape, and so on.

The behavior of the cycle dictates what happens next: throughout one iteration of the cycle, the tape head may overall move left, move right, or stay in the same place. If the tape head overall moves left, it must eventually exit the region of ones. If the tape head overall moves right, it will continue moving rightward forever. If the tape head overall stays put, the machine will retread the same tape cells indefinitely—looping forever.

Moreover, we can efficiently predict what state the machine will be in each time it visits a new tape cell (e.g. what state it will be in when it exits the region of ones, or what state it will be in when it reaches the 102547th tape cell containing a one). Imagine we modify our Turing machine so that it annotates each new tape cell it visits with a note indicating its current state. (If it revisits a cell, the annotation is not changed, and the annotation doesn't affect the transition rule.) With this modification, note that the machine will mark no more than $Q$ cells before entering a cycle which also has length at most $Q$. Thus the machine will produce a pattern of annotations on the tape that in cartoon form looks like this:

$$q_v q_w q_x q_y q_z \;q_A q_B q_C \; q_A q_B q_C \; q_A q_B q_C \;\cdots$$

To decide the behavior of the machine after some number of steps, we simulate it for $Q$ steps. At that point, it has either exited the region of ones in a particular state, or it has entered a cycle. Elementary modular arithmetic will tell us what state the machine will be in when it enters a tape cell for the first time. (Take the position of the desired tape cell. Subtract the length of the prefix pattern $q_vq_wq_xq_yq_z$. Find the remainder modulo the length of the repeating pattern $q_Aq_Bq_C$. The result tells you what state the machine will be in when it reaches that cell— one of $q_A$, $q_B$, $q_C$.)

Extended looping behavior. Now suppose we have a region with some finite region of ones, as we'd make with a blackout machine.

$$\ldots00000\ldots 0000011111\ldots 1111100000 \ldots 00000\ldots$$

Suppose we start a $Q$-state read-only Turing machine on the leftmost one. Based on our previous observations, we now know that after simulating $Q$ steps, one of the following outcomes must occur: (1) the tape head exits on the left frontier, (2) the tape head exits on the right frontier, (3) the tape head enters an inescapable loop in the interior, (4) the tape head enters a cycle that will eventually move it to the left or right frontier. Moreover, after $Q$ steps, we can efficiently discover whether the tape head will exit the interior, which side of the frontier it will exit on, and also which state it will be in when it exits. The calculation depends mainly on the number of ones in the interior modulo the length of the newly-visited state cycle (what I called $q_Aq_Bq_C$ above). That cycle has length at most $Q$.

Finitely many configurations. At first glance, the behavior of a blackout machine depends on the number of ones in the interior, the current position of the tape head, and the state of the finite control. The halting problem seems potentially undecidable because the number of ones can become arbitrarily large which seems like it could lead to arbitrarily unpredicable behavior in the long run. However, cycles cut down on the possibilities. Through the modular arithmetic considerations above, we know that machines must enter a loop if the number of ones is larger than the number of states. Hence the behavior of the machine is effectively finite. We can "fast forward" the progress of the machine. We can start it at one frontier, run it for at most $Q$ steps, then skip ahead to the point where it exits on another frontier. We are able to skip ahead because we can predict whether the machine will eventually exit on the left or right frontier, and what state it will be in when it does. As such, we actually no longer need to keep track of the size of the interior in order to simulate the blackout machine(!). We just need to know the number of ones, modulo various cycle lengths.

Bounding the number of configurations.

Let's do some calculations to get loose bounds on the number of possible configurations. Given a blackout machine, we can easily (in polynomial time) create a lookup table to decide what the machine will do when it starts on the left/right frontier, in a particular state, when the interior has at most $Q$ ones in it. The table will tell you, given a state and frontier, what state and frontier the machine will go to next. That's a lookup table with $2 \times Q \times Q$ entries (two frontiers and $Q$ possible starting states and up to $Q$ ones on the tape)— it's quadratic in $Q$.

If the tape has more than $Q$ ones on it, the machine must necessarily cycle, so modular arithmetic makes prediction easy. Indeed, if we know what state the machine enters the interior in, and we simulate it for $Q$ steps, we get enough information to "fast forward" to the point where it exits the interior. Because cycles have length at most $Q$, we don't need to know the exact number $n$ of ones in the interior in order to fast-forward. It's enough to know $n\pmod{Q}, n\pmod{Q-1},\ldots, n\pmod{2}$. That's certainly enough to cover all possible cycle lengths. It's $Q!$ possible configurations—huge overkill for us— but that's still finite for every $Q$.

Halting algorithm

Given a blackout machine,

1. For every possible starting state, for every string of ones of length at most $Q+1$, and for both frontiers as a starting position, simulate the blackout machine for $Q+1$ steps. This takes polynomial time in $Q$ and provides the length of all cycles.

2. Construct a "configuration transition graph". Each node represents a configuration, and each arrow denotes a deterministic connection between two configurations: If the size of the interior is $k\pmod{Q!}$ and the machine is on the left/right frontier in state $q$, the next time it's on the frontier it will be on the left/right frontier in state $q^\prime$ and there will be $(k+1)\pmod{Q!}$ ones in the interior. (Of course, we add nodes for halting and looping forever in the interior).

3. The configuration transition graph lets us simulate the blackout machine in fast-forward. We start in a particular node of this graph. We follow the unique transitions for $Q!$ steps until we either halt, loop forever in the interior, or revisit a configuration in which case we loop forever in the exterior.

Hence we can decide the halting problem for blackout machines in around $Q!$ steps, where $Q$ is the number of states of the blackout machine.