[My apologies, I am not a computer scientist, merely an interested amateur. I apologise if this question does not make sense, is a known result, or a duplicate]

To quote Wikipedia:

The halting problem is the problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running, or continue to run forever.

This cannot be solved in general for all possible program-input pairs.

However, for a subset of programs/inputs we can determine by inspection, or simply running them, whether they will halt - e.g. I believe that a program with no looping or recursion will always halt, and a program with an impossible loop-ending condition will never halt.

One could imagine a program which when taking a program/input runs it for a length of time and reports 'halts' if it halts in that time, 'doesn't halt' if it has entered an infinite loop in that time, or 'undetermined' if neither has happened yet.

If we ran the program for increasing lengths of time, we must expect the proportion of programmes for which 'undetermined' is returned to reduce - i.e. 10% of programs may halt or enter an infinite loop when run for 1 hour, but 20% when run for 10 hours.

Can we, and do we know what the expected outputs of such a machine might be given a sufficient time? i.e. do 'almost all', 'most', 'some' or 'almost no' programs halt? Do 'more' programs enter an infinite loop than halt?

And if we cannot answer this question in general, can we answer it for a Turing machine with a limited number of states? e.g. do most 4-state Turing machines halt?

  • $\begingroup$ This is not well-defined, since there is an infinite amount of Turing machines. Can you please define more concretely what "proportion" means in this case? $\endgroup$
    – nir shahar
    Commented Mar 14, 2022 at 22:42
  • $\begingroup$ @nir shahar Either Chaitin's Omega or the density of decidable Halting statements should make the OP happy. Hopefully I'll have time eventually to write an answer. $\endgroup$
    – Arno
    Commented Mar 15, 2022 at 7:59
  • 1
    $\begingroup$ @nirshahar: I think it might help the inquirer to point out that the proportion depends on the order in which one enumerates programmes, though of course it is fairly natural to order them by size, within which the order does not matter (presuming a finite number of symbols in the language). But convergence of the series of proportions is not obvious to me. $\endgroup$
    – PJTraill
    Commented Mar 21, 2022 at 9:30
  • $\begingroup$ P.S. I should have talked of programme-input pairs rather than programmes. $\endgroup$
    – PJTraill
    Commented Mar 22, 2022 at 15:49

1 Answer 1


There are infinitely many Turing machines, so the notion of 'most' is a bit tricky to define. But with a reasonable interpretation, the answer will depend on the programming language. So, the question cannot be answered in general terms.

To get some flavor for why this might be: consider an assembly language that has 10000 opcodes, where 9000 of them are "halt" instructions that when executed cause the program immediately to halt, 999 of them are arithmetic instructions (that don't trigger any control flow), and 1 is a conditional branch. Then in some sense, most programs halt, because a random program is likely to contain one of the halt instructions before its first branch instruction. Conversely, consider an assembly language that has 10000 opcodes, where 9000 of these are instructions that immediately enter an infinite loop, 998 are arithmetic instructions, one is a halt instruction, and one is a conditional branch. Then most programs don't halt, because most contain one of the infinite-loop instructions before the first halt or conditional branch.

This proportion is closely related to Chaitin's constant. The value of Chaitin's constant cannot be computed by any algorithm.

Finally, the question as you have posed it is in some sense not well-defined. "Halting" is a property of a program and an input. It doesn't make sense to ask whether a program halts, or calculate the proportion of programs that halt. So, we can't ask what proportion of 4-state Turing machines halt. We could ask what proportion of 4-state Turing machines halt on all inputs. This is tricky, though; given a Turing machine, checking whether it halts on all inputs is not computable.

  • $\begingroup$ Do you have any ideas about the last part of the question, about Turing machines with a given number of states? $\endgroup$
    – PJTraill
    Commented Mar 21, 2022 at 9:35
  • $\begingroup$ @PJTraill, I don't, but I also don't think it is well-defined yet (see the last paragraph of my answer, as edited). $\endgroup$
    – D.W.
    Commented Mar 22, 2022 at 7:51
  • $\begingroup$ Of course you are right. I think they either forgot about the input altogether at some point in their post or intended it to be implicitly understood. One should presumably limit the size of all elements (alphabet, states, transitions, input (non+blank cells)). Unfortunately the inquirer seems to have lost interest! $\endgroup$
    – PJTraill
    Commented Mar 22, 2022 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.