A busy beaver machine (BBM) is a type of Turing machine with a specific objective: to write the maximum number of non-zero symbols on an initially blank tape before it halts. The intrigue of busy beaver machines lies in their simplicity combined with the complexity of their behavior and the impossibility of prediction. These machines are defined by two parameters: the number of states and the number of symbols they can write.
Halting: A key characteristic of a BBM is that it must eventually halt. Machines that run indefinitely are not considered busy beavers.
Non-zero symbols: The objective is to maximize the number of non-zero symbols (usually 1
s) written on the tape.
Blank tape start: The machine starts with a blank tape (usually all 0
s).
Deterministic operation: BBMs operate deterministically, with their state transition tables pre-defined.
The busy beaver function, which gives the maximum number of non-zero symbols written by the most prolific busy beaver for a given number of states, grows faster than any computable function. This makes it a powerful concept in the study of computability and algorithmic information theory.
For even small numbers of states and symbols, predicting the behavior of the most prolific busy beaver can be extraordinarily complex.
When considering a 2-state busy beaver (with states A and B, and symbols 0 and 1), the challenge is to find the 2-state Turing machine that writes the most 1
s on an initially blank tape and halts.
Here is an example configuration of a 2-state BBM:
State A:
If the current symbol is 0, write 1, move right, and go to state B.
If the current symbol is 1, write 1, move left, and go to state B.
State B:
If the current symbol is 0, write 1, move left, and go to state A.
If the current symbol is 1, write 1, move right, and halt.
This simple BBM will exhibit the following behavior:
Starting in state A and on a blank tape (all 0
s), the machine will write 1
s and move back and forth between its two states.
In its first iteration in state A, it encounters a 0, writes a 1, moves right, and transitions to state B.
In its first iteration in state B, it encounters a 0 (since the tape is initially all zeros), writes a 1, moves left, and transitions to state A.
Now back at the original position, it enters the second iteeration in state A, but this time encounters a 1, writes a 1 (unchanged), moves left, and transitions to state B.
In its second iteration in state B, it encounters a 0, writes a 1, moves right, and transitions to the halting state.
At each step, the machine writes a 1. So, by the time it reaches the halting state, it has written a total of four 1
s on the tape. This is the expected behavior for this particular 2-state busy beaver machine and remains true regardless of the initial tape length as long as it's not too short to constrain the machine's movements.
Here is a Python implementation of a 2-state BBM:
def busy_beaver(length=10):tape = [0] * lengthcursor = length // 2state = 'A'while state != 'HALT':if state == 'A':if tape[cursor] == 0:# Write 1, move right, change to state Btape[cursor] = 1cursor += 1state = 'B'else:# Write 1, move left, change to state Btape[cursor] = 1cursor -= 1state = 'B'elif state == 'B':if tape[cursor] == 0:# Write 1, move left, change to state Atape[cursor] = 1cursor -= 1state = 'A'else:# Write 1, move right, HALTtape[cursor] = 1cursor += 1state = 'HALT'# Keep the cursor within the bounds of the tapecursor = max(0, min(cursor, length - 1))return taperesult = busy_beaver()print("Final tape:", result)
Let's look at what the code above is doing:
Lines 1–3: Initialize tape
as a list of zeros to represent the blank tape. Set the cursor
to start in the middle of the tape. Initialize the state
as 'A'
.
Line 6: Start a while
loop that runs until the state
becomes 'HALT'
. Inside the loop, the behavior depends on the current state
and the symbol under the cursor
.
Lines 7–17: In state 'A'
:
If the tape at the cursor is 0
, write 1
, move the cursor right (cursor += 1
), and switch to state 'B'
.
If the tape at the cursor is 1
, write 1
, move the cursor left (cursor -= 1
), and switch to state 'B'
.
Lines 19–29: In state 'B'
:
If the tape at the cursor is 0
, write 1
, move the cursor left, and switch to state 'A'
.
If the tape at the cursor is 1
, write 1
, move the cursor right, and transition to 'HALT'
.
Line 32: Adjust the cursor to stay within the bounds of the tape.
Line 37: After halting, return and print the final state of the tape.
Another code example of the 2-state BBM:
def busy_beaver(length=10):tape = [1] * length # Initialize tape with all 1scursor = length // 2state = 'A'while state != 'HALT':if state == 'A':if tape[cursor] == 0:# Write 1, move right, change to state Btape[cursor] = 1cursor += 1state = 'B'else:# Write 1, move left, change to state Btape[cursor] = 1cursor -= 1state = 'B'elif state == 'B':if tape[cursor] == 0:# Write 1, move left, change to state Atape[cursor] = 1cursor -= 1state = 'A'else:# Write 1, move right, HALTtape[cursor] = 1cursor += 1state = 'HALT'# Keep the cursor within the bounds of the tapecursor = max(0, min(cursor, length - 1))return tape# Example execution with default length=10result = busy_beaver()print("Final tape:", result)
Initial Tape Values:
First Code: Initializes the tape with all 0s (tape = [0] * length
).
Second Code: Initializes the tape with all 1s (tape = [1] * length
).
Behavior:
Both codes simulate a 2-state Busy Beaver machine with the same state transitions and rules (write 1, move left/right, change states), but they start with different initial configurations of the tape.
Execution and output:
When executed, both codes will produce different final tapes based on their initial values:
The first code will end with a tape where the initial 0s
are overwritten by the machine's operations.
The second code will end with a tape where all positions initially contain 1s, and some may be overwritten by the machine's operations.
Purpose:
The first code serves as a general implementation of a Busy Beaver machine that can be initialized with any tape configuration.
The second code is a specific example where the tape starts with all 1s
, demonstrating how the machine behaves from that initial configuration.
Free Resources