r/computerscience • • Oct 26 '26

A question about Turing Machines

I have a question that popped in my mind about Turing Machines and the Busy Beaver function.

So, from the knowledge I have, programming languages are Turing complete, meaning they can do everything a Turing Machine can, which would mean that there is a way to translate a Turing Machine program to any Turing complete programming language, right?

Following from that, let's say we have a really simple program in any programming language that loops from 1 to 108 and do some computation inside that loop

Since the number of steps this program takes is higher than 107, does it mean it can't be translated to a 4 states 2 symbol machine, since BB(4) is 107?

How does the translation from a simple loop with N steps work?

21 Upvotes

9 comments sorted by

12

u/finedesignvideos Oct 26 '26

That intuition is correct, The naive translation would involve having a counter and stopping when the counter reaches 108. Just checking if a counter is 108 would naively require as many states as there are bits in 108 (written in binary), which is 7.

1

u/currentscurrents Oct 26 '26

Just checking if a counter is 108 would naively require as many states as there are bits in 108 (written in binary), which is 7.

I don't think that's true, or at least there are non-naive ways to check if a counter > n that don't need log2(n) states.

You can do logic using the additional storage of the tape itself, and check a counter of any size using a fixed number of states.

2

u/finedesignvideos Oct 26 '26 edited Oct 27 '26

Sure you can do operations on a counter of any size using a fixed number of states, but the fact that 108 is a specific number will need to be encoded in the states.

More formally for each n, checking if the counter is at least n (n is not a part of the input, it is part of the problem statement) would require a different Turing machine. Since the number of TMs with k states is only like k^O(k) that gives an Omega(log n/log log n) lower bound on the number of states needed.

2

u/buwlerman 29d ago

You're assuming that the function taking the bound n to the minimal number of states of the Turing machine is monotonic, which is not true.

For any specific n there could be structure that allows checking equality much more efficiently than for some arbitrary m < n.

1

u/finedesignvideos 29d ago

Hmm, I think I just misused Omega. This might actually be something I do more often than just on Reddit, so thanks for pointing it out. 

I really just meant to point out that there can be no fixed bound [or even o(log n/log log n) bound] on the number of states needed to do the "loop n times" behavior.

1

u/claytonkb Oct 26 '26

Since the number of steps this program takes is higher than 107, does it mean it can't be translated to a 4 states 2 symbol machine, since BB(4) is 107?

It can't be translated to such a machine that halts, because no such machine exists (by definition of the Busy Beaver number for 4,2 Turing machines). So for any given halting Turing machine, there is some "biggest number" which that machine can handle, and that biggest number just is the Busy Beaver for that machine's state,symbol class. Every natural number larger than that BB number is "beyond" the capability of such machines, which halt, to ever touch.

1

u/Smart-Abalone-1885 29d ago

I think your answer is technically correct, but not in the spirit of the question. The OP is asking about what a machine can do, which implies not just calculating a result, but NOT calculating past it. In other words, outputting the result. Since a Turning machine can do nothing but shift, print/erase, and halt, to halt is the equivalent of to output.

1

u/claytonkb 28d ago

Hmm, I think that's exactly what I did say but maybe I was not clear enough. If we include non-halting machines, a tiny counter program is sufficient to output any natural number in N. But if we intend for a program p of length |p| to Halt on universal Turing-machine M (thus, signaling that it has finished or "outputted"), then there is always some largest element n in N beyond which any program p of length |p| cannot compute and halt, i.e. n=M(p). Every n' > n cannot be the output of M(p), if it halts. That is to say, n is the Busy Beaver for programs of length |p| on universal Turing-machine M. (Note that this is a slightly modified definition from the usual Busy Beaver definition but is logically equivalent.) Anyway, just offering this as a clarification FWIW...