Exploratory analysis of Busy Beaver's machines using Basin
Contents:
This is going to be long. Welcome to part 1. This is the setup!
A while ago I wrote a post on Bacon and I said I’d follow up with the hybrid I created (which is called Basin) and the Busy Beaver explorations. This is the BB exploration part as the name suggests. I found a BUNCH of cool things and I don’t know how much of this was already known or what, but it is nevertheless very very interesting.
For results on growth classes and constants, see the next blog.
# Introduction
# Background on Turing Machines
A turing machine is an imaginary state machine which has infinite memory (represented by a physical tape) and a finite set of instructions. I would implore you to read the wikipedia page OR the book Emperor's New Mind by Roger Penrose which is where I learnt about Turing Machines.
In a turing machine, every operation on a single cell in the infinite tape concludes in three possible ways:
- Do (something or nothing) and (go right)
- Do (something or nothing) and (go left)
- Do (something or nothing) and Halt
Based on this, we can come up with machine strings formally called as the Tree Normal Form. A typical machine string looks like this: 1RB1LB_1LA1RZ (This btw, is the BB(2) champion! Say hello). This is for a two state machine, and the _ separates the states. So, a 4 state machine will have 3 _’s and so on.
Each state has 3 characters. In our case, the first state is described by 1RB1LB which has a pair of 3 characters 1RB and 1LB. The former (1RB) describes what to do when you see a 0 on the tape, and the latter (1LB) when you see a 1.
According to these rules, the state 1RB1LB_1LA1RZ means:
State A: on 0 write 1, move R, go to B (1RB). On 1 write 1, move L, go to B (1LB). State B: on 0 write 1, move L, go to A (1LA). On 1 write 1, move R, go to Z (1RZ). Z means halt.
These rules are applied to the tape containing all 0s to start with. Then the machine starts processing this tape of all 0s and halts or not depending on its configuration! And when it does halt, the answer that it was computing, is present in the same tape and can be read off of it.
Busy Beaver (specifically the BB(n) function from Wolfram's definition which is slightly different from the original one) asks a very straightforward question.
Imagine the space of all possible n state Turing Machines with 2 symbols (binary). Some halt and some don’t and there is no algorithm that will tell us whether a machine will halt or not (see the halting problem). But of the ones that do halt, BB(n) is the maximum value of the number of steps taken for the same.
So, for example BB(1) asks for the maximum number of steps a single state turing machine would take before it halts. There are not many single state turing machines that halt. In fact, there is only one, where you directly jump to the halt state! So, BB(1) = 1.
Note that the Halt state is considered seperate from the working states. n is the number of working states. Total states including halt is $n+1$
What about BB(2)? That’s slighlty more complex that the BB(1) case ofcourse. You can see the discourse here. But you’d notice that its not very hard so to speak.
But then you go to BB(3), that’s 3 working states with a separate halt state. And there are 16,777,216 machines. The answer to BB(3) was proved in 1965 by Shen Lin and Tibor Radó, and its 21. Another guy from the BB community, tried to analyze this here.
Nick Drozd has written a lot about Busy Beavers, he’ll obviously do a better job at explaining things about its history and current events! I am not even gonna try to do that, but I’ll finish off the intro in a few more lines.
The BB(4) has to find its champion in a pool of 25.6 Billion possible machines, and to solve BB(5) you have to find the champion within $>21^10$ possible machines. The answer to BB(5) is 47,176,870 and it was found in 2024. The search space grows extremely fast and is already extremely large. This with the halting problem means that each new value of BB(n) has to be tackled independently.
We have a champion for BB(5) and BB(6) has contenders but no proofs as of the time of writing.
# The goal
Well, simply put I had no intention of doing anything “Busy Beaver”. I just wanted to run my tool Basin on different kinds of numerical data. I know that curve fitting on the growth of turing machines is hopeless because the behaviour is very very erratic. However, I thought it’ll be a fun thing to do and I was curious as to what might happen!
The plan was simple, I’d pick many machines that never halt (how do I if a machine halts or not? I’ll talk about it in the Datasets section). Then I’d run each from a blank tape and measure its span (i.e. how much tape it has touched) at many times t which are iterations, or the number of MOVES the machine makes.
Then I’d fit an equation using Basin and see what kinds of relations emerge. So for example, a formula can look like $span = 1.414 \cdot \sqrt{t} − 2.87$, and I can also measure how well that formula fits.
The BB Challenge wiki has a LOT of data. They have also catalogues on the different machines (represented by their machine strings) atleast upto BB(5).
Through the machine strings, we know what the machine does. So, we can simulate it in C++ and get our data.
There are many curiosities you see, do the champions have more complex equations? Is there a clear division between different machines based on this approach? Are there constants of these machines that can be recovered? And, a hopeless romantic that I am, do halting machines and non-halting machines have a possible seperation based on this heuristic. (I know, I know, chide me all you like).
The community refers to champions as those machines that solve a BB(n) problem. So, BB(5) champion is the machine which has the largest number of steps before halting.
We want to look at:
- What kind of formula (linear, $\sqrt{t}$, $\log{t}$, …)? This is the growth class.
- What constant is in the formula (
1/3,√2, …)? (This turned out to be a revelation if I so shall speak for myself) - How badly does the formula fit? This is the
roughness. It turned out that badly fitting machines are the interesting ones!
# The span
This is the dependent variable that we’re trying to fit the time with. span(t) = (rightmost cell the head has ever stood on) − (leftmost cell the head has ever stood on) + 1, measured after step t.
So, its essentially how much tape has been mapped by the machine. It can never decrease as t increases.
For the BB(2) champion, let’s record the span as it progresses:
| step t | state before | reads | rule used | head moves to | cells visited so far | span |
|---|---|---|---|---|---|---|
| 0 | A | – | – | 0 | {0} | 1 |
| 1 | A | 0 at cell 0 | write 1, R, go B | 1 | 0..1 | 2 |
| 2 | B | 0 at cell 1 | write 1, L, go A | 0 | 0..1 | 2 |
| 3 | A | 1 at cell 0 | write 1, L, go B | −1 | −1..1 | 3 |
| 4 | B | 0 at cell −1 | write 1, L, go A | −2 | −2..1 | 4 |
| 5 | A | 0 at cell −2 | write 1, R, go B | −1 | −2..1 | 4 |
| 6 | B | 1 at cell −1 | write 1, R, halt | 0 | −2..1 | 4 |
So the span goes 1, 2, 2, 3, 4, 4, 4. It halts after 6 steps with four 1s on the tape, which are the known BB(2) values.
But this machine halts, and in my study, I used machines that never halt. Let me give you a couple of interesting examples on those:
- A
bounded span, for example with this machine1RB1RB_1LA1LA. StateAon any symbol says write 1, go right, go to B. StateBon any symbol says write 1, go left, go to A. So the head goes0 → 1 → 0 → 1 → ...forever and hence the span stays as 2.
Such machines are called cyclers, that is, it repeats the same configuration over and over, and its span is bounded (it stops growing).
- A
lineargrowth span, for example with this1RB1RA_0LA---machine. StateAon any symbol says write 1, go right, goto B if 0, goto A if 1. StateBon any symbol says write 0, go left, goto A if 0.
Notice how state B on a 1 is undefined. If you feed an empty tape (initialized to all 0s) and trace what this machine does, it’s easy to see that it will never reach a 1 in state B.
Let’s trace this guy.
span = 0
initial_state = A
at t = 1:
- sees a 0 at state = A
- writes 1
- goes right // (span++)
- initial_state = B // since it had seen a 0
at t = 2:
- sees a 0 at state = B
- writes 0
- goes left // (span stays the same)
- changes state to A // since it had seen a 0
at t = 3:
- sees a 1 at state = A
- writes 1
- goes left // span++
- keeps state A // since it had seen a 1
And this keeps happening. In fact the span for this machine can be written exactly as $\text{span}(t) = 2 + \lfloor\frac{t − 1}{3}\rfloor$. So, it’s growth class is roughly $\frac{t}{3}$.
This machine is what’s called a translated cycler. Here the same 3-step pattern repeats, but it shifts one cell right each time. Clearly, it’s span grows linearly and there is no way it can halt! There is no halt state.
The speed of this machine is $\frac{1}{3}$. It’s just a nomenclature I came up with. Just so future ideas make sense.
# The runs
So, I pulled the machines from BB’s wiki. Then we have to simulate it. Not a very tough job with LLMs. I ran each machine for $2^22$ iterations, and recorded its span at 49 different checkpoints. Its not particularly useful to have the span at EVERY checkpoint because Basin will doesn’t need that much data, it’ll just slow it down. The second reason is that, spans don’t change very frequently!
In particular, at every $t_k$ iteration, we recorded the span:
$$ t_k = \text{round}(2^(10 + \frac{k}{4})), k = 0, 1, 2, …, 48. $$
And, the first few spans (from $2^10$ up to just under $2^12$) which amounts of 8 of these 49 ones, are discarded. If you think about it, the machine is just starting out, so these don’t really capture the growth class we’re looking for.
The final dataset is then a table of span values for 41 different times for each machine.
# The datasets
Right, so I am using 2 symbol machines as is custom. Note that the BB wiki does have more than 2 symbol machines too, but I didn’t go there (yet).
Remember the TNF (Tree Normal Form)? That was important because it removes duplication within machines. For example, theoretically there are 16,777,216 possible 3 state 2 symbol turing machines. But after TNF, the number comes down to 4057.
Now to figure out which of these halt or not, its simple! We know the BB(3) value! Since the number of machines to enumerate is so small, we can run each of them UPTO BB(3) and if it doesn’t halt by then, then we know it will never halt. For BB(3) every run I did, used all the 2678 non-halting machines.
Similarly, for BB(4), the TNF search space is enumerable and the BB(4) value also is small enough. Here, I used a random sample of 20k machines for all the runs.
But we cannot do this for BB(5), its way too big and too many steps needed. But we don’t have to because every database record is now proven non-halting. So, that makes thing life easy. There are like 88M+ such machines though, of course I am not going to use all of them. I’ll mention exactly what type of non-halting machines from BB(5) I used in that case. There are some special types like the 43 skelets, the 20 top halting contenders before victory was announced etc.
Same goes for BB(6). You can probably imagine that this is big as big get.
An important thing to note here is the distincting between
space-limitandtime-limit.
These are two stopping rules that bbchallenge (the organisation behind the whole BB wiki effort) used when it built the BB(5) database. The database was built BEFORE the champion was PROVED (but people belived in it) so, things were designed aroung it. For BB(5) the time limit is understandably 47,176,870 (the champion’s halting steps). Machines that ran for more than this, would either never halt (which we know is true now) or would beat the champion, so these machines were undecided. The space-limit (which we call the span) was reached when the machine head touched more than 12,289 cells. This is the span of BB(5)’s champion too.
The space-limit really proves nothing about a machine (unlike the time-limit) so it was a problem, people still kept it tho.
So, while pulling the data from BBchallenge, I used both of these categories of machines separately to see if my equations also are able to distinguish between them in any sense!
Okay that’s about it for this one. I will talk about the growth classes, rate, results on growth classes and the constants in the next blog.