The Halting Problem, the most (in)famous undecidable problem, has important applications in theoretical and applied computer science and beyond, hence the interest in its approximate solutions.
Experimental results reported on various models of computation suggest that halting programs are not uniformly distributed – running times play an important role. A reason is that a program which eventually stops but does not halt “quickly”, stops at a time which is algorithmically compressible.
In this paper we work with running times to define a class of computable probability distributions on the set of halting programs in order to construct an anytime algorithm for the Halting problem with a probabilistic evaluation of the error of the decision.
The Halting Problem asks to decide, from a description of an arbitrary program and an input, whether the computation of the program on that input will eventually stop or continue forever. In 1936 Alonzo Church, and independently Alan Turing, proved that (in Turing’s formulation) an algorithm to solve the Halting Problem for all possible program-input pairs does not exist; two equivalent models have been used to describe computation by algorithms (an informal notion), the lambda calculus by Church and Turing machines by Turing. The Halting Problem is historically the first proved undecidable problem; it has many applications in mathematics, logic and theoretical as well as applied computer science, mathematics, physics, biology, etc. Due to its practical importance approximate solutions for this problem have been proposed for quite a long time, see [2,5–7,9,14,16,19,21,26].
Anytime algorithms trade execution time for quality of results [13]. These algorithms can be executed in two modes: either by a given contract time to execute or an interruptible method. Instead of correctness, an anytime algorithm returns a result together with a “quality measure” which evaluates how close the obtained result is to the result that would be returned if the algorithm ran until completion (which may be prohibitively long). To improve the solution, anytime algorithms can be continued after they have halted. That is similar to the use of iterative processes in numerical computing in which, after the process has been halted, if the output is not considered to be acceptable, then it can be refined by resuming the iterative process.
Following Manin [21] we use a more general form of anytime algorithm as an approximation for a computation which may never stop. An anytime algorithm for the Halting Problem works in the following way: to test whether a program eventually stops on a given input we first effectively compute a threshold time – the interruptible (stopping) condition – and then run the program for that specific time. If the computation stops, then the program was proved to halt; if the computation does not stop, then we declare that: (a) the program will never stop and (b) evaluate the probability of error, i.e. the probability that the program may eventually stop. The goal is to prove that the probability of error can be made as small as we wish. By running the program a longer time we can improve its performance either by getting to the halting time or by decreasing the probability of error. Another important goal is to develop feasible anytime algorithms for the Halting Problem.
In [6 ,7] anytime algorithms for the Halting Problem have been developed using the fact – proved in [7] – that programs which take a long time to halt stop at “algorithmically compressible times”, i.e. times which a computer can generate from “smaller” inputs. Although the set of algorithmically compressible times has constructive density zero, the stopping times obtained using this method are very large and the theoretical bounds cannot be improved in general [6]. However, experimental results in [30] for small Turing machines indicate much smaller stopping times. Furthermore, the experimental results in [27,30,31] and theoretical results in [14,15] show that halting programs are not uniformly distributed and their distributions depend on the running times of the specific model of computation.
In this paper we construct a class of computable probability distributions on the set of halting programs based on their running times. Each computable probability distribution induces a probability space on the set of halting programs. Using this probabilistic framework we construct an anytime algorithm for the Halting problem with a probabilistic evaluation of the error of the decision.
The paper is organised as follows. We start with a section on basic notation. Section 3 presents the computability and complexity part while Section 4 is dedicated to probability and statistics. Section 5 is dedicated to the presentation of the probabilistic framework for the anytime algorithms. We start by examining two plausible a priori halting probabilities. The analysis of their inadequacy leads to the introduction of running time probability spaces on the set of halting programs which, as their names indicate, are constructed using computable probability distributions on the set of running times. In Section 6 describe the anytime algorithm and prove its correctness. In Section 8 we propose methods to improve the performance of the algorithm and evaluate it power and limits. Finally, we discuss some open problems.
Notation
In the following we will denote by the set of positive integers and let ; is the set of reals. The domain of a partial function is denoted by : . We denote by the cardinality of the set S and by the power set of X.
We assume familiarity with elementary computability theory and algorithmic information theory [4,11,20].
For a partially computable function we denote by the statement “the algorithm computing F has stopped exactly in time t”. For we consider the computable set , and note that
Complexity and universality
The algorithmic complexity relative to a partially computable function is the partial function defined by . If for every , then . That is, the algorithmic complexity of x is the smallest description/encoding of x with respect to the interpreter/decoder F, or infinity if F cannot produce x.
A partially computable function U is called universal if for every partially computable function there exists a constant such that for every we have
A partially computable functionUis universal iff for every partially computable functionthere exists a constantsuch that for everywe have
The difference between (2) and (3) is in the role played by F: in the traditional condition (2), F appears through (which for some F can be incomputable), while in (3) F appears as argument of , making the second member of the inequality always computable.
A universal partially computable function U “simulates” any other partially computable function F in the following sense: if , then from (3) we deduce that , hence there exists an in such that . In particular, , for all .
The set (see (1) for ) is computably enumerable, but not computable (the undecidability of the Halting Problem), its complement is not computably enumerable, but the sets are all computable.
To solve the Halting Problem means to determine for an arbitrarily pair , where F is a partially computable function and , whether stops or not, or equivalently, whether , that is, , for some . In view of (2) or (3) solving the Halting Problem for a fixed universal U is enough to solve the Halting Problem. From now on we fix a universal U and study the Halting Problem , for .
A glimpse of probability theory
In this section we define the main notions from probability theory used in this paper. For more details see [10,25].
A measurable space consists of a non-empty set Ω and a Borel field of subsets of Ω, . A probability space is a triple , where is a measurable space and is a probability measure, that is, Pr satisfies the following two conditions: (a) the probability of a countable union of mutually-exclusive sets in is equal to the countable sum of the probabilities of each of these sets, and (b) . We interpret as “the family of events” and Ω as “the certain event”.
Consider a probability space and a measurable space . A random variable is a measurable function , that is, for every we have . In this case X induces a probability (called probability distribution of X) defined by
which identifies the probability space .
The random variable X has a discrete probability distribution if A is at most countable. If we denote by the probability of the event , then the discrete probability distribution of X is completely defined by the numbers , , with . A computable probability distribution is a discrete probability distribution such that the function is computable (in particular, is a computable real for each [23, p. 159]; see also [24,29]).
In what follows we assume that .
The Cumulative Distribution Function of a random variable X is the function defined by , . In case X is a random variable with a discrete distribution, is the stair-function (with piecewise-constant sections) given by
For example, the generally accepted model for “the time-to-the-first-success” is the geometric distribution – the discrete probability distribution that expresses the probability that the first occurrence of an event (“success”) requires k independent trials, each with the same success probability θ. More precisely, the random variable X that takes values in has a geometric distribution with the rate of success if , . In this case
and .
The Quantile Function of the random variable X with a discrete distribution is the function defined by . By definition, , for all .
For fixed , the value (number) is called the rth quantile of the random variable X. Quantiles are important indicators that give information about the location and clustering of the probability values . For example, if the data being studied are not actually distributed according to an assumed underlying probability distribution or if there are outliers far removed from the mean, then quantiles may provide useful information. Beside the classical quartiles – first, second (median), third – the lower and upper εth quantiles, and , give important informations about the “tails” of the probability distribution (for small ). For more details see [1].
For everywe have, hence.
Indeed, we have:
□
A probabilistic framework
In this section we describe a probabilistic framework for developing two anytime algorithms based on an analysis of the finite running times of all halting computations , .
Halting probability
Both approaches discussed in this paper depend – directly or indirectly – on a computable probability which has to model the informal notion of “halting probability” for programs for a universal U, that is, the probability that U stops on input x. Which probability measure should we choose?
First, various studies of concrete probability distributions for halting programs in different models of computations (see [15,27,30,31]) show that halting programs are not uniformly distributed and their probability distributions depend on the running times on the specific model of computation. This experimental evidence is reflected also in the theoretical result stating that programs which take a long time to halt stop at “algorithmically compressible times”, a set of constructive density zero [7].
Second, if we interpret the event “U stops on input x” as a “success” in a sequence of trials, then the running time of the computation becomes “the-time-to-the-first-success”. In this setting, the event “ stops exactly in time t”, that is “”, is interpreted as “t is the achieved time-to-the-first success”. Then, the truncated geometric distribution is a candidate for the halting probability. Is the geometric distribution probability a “natural” model for the halting probability? Can it be used for developing anytime algorithms for the Halting Problem? The answer to the first question is negative. Indeed, the phenomenon modelled by the geometric distribution requires a sequence of independent trials in which each trial has the same probability of success – a strong condition hardly satisfied by any U. For the second question we note that the computability of the probability – an essential property for evaluating the stopping condition of the anytime algorithm – depends on the computability of θ and , which may be problematic even if is computable, see [28].
This brief analysis suggests that instead of “assuming” an a priori halting probability we should instead construct a model for the halting probability based on the running times .
of the computations are the set of exact stopping times for the halting programs of U:
The setis infinite.
The statement in the lemma is true because for every there is a program which stops in time larger than M: indeed, otherwise all programs would stop in time at most M, hence would be decidable, a contradiction. □
The undecidability of the Halting Problem casts a “computational uncertainty” on the membership problem of the set . In what follows we model this phenomenon by introducing a probabilistic structure on .
Let us consider the family of (finite and countable) unions of sets , . This family includes and is closed under complement
and countable unions; accordingly, it is a Borel field of subsets of , which we denote by . To define the discrete probability measure on the measurable set we fix a computable probability distribution ρ on (see Section 5.3). Then, we put
Now we can introduce a probability structure on the set via a random variable. Let be the family of all subsets of . The function
has the property that for every , . Consequently, is a random variable – in fact a stopping time – which will be called the running time associated withU. As described in Section 4, the random variable induces the probability space on in which the probability is defined as follows:
It is seen that for every :
In what follows a computable probability space of the form defined in (5) will be called a running time probability space.
The random variable is completely specified by a computable probability distribution on the set of finite running times of programs ofU,
Of course, we need to prove that a computable probability distribution (7) exists: this will be done in Section 5.3.
The cumulative distribution function of the discrete random variable is then defined by the formula:
and the quantile function of is
For we now use the -quantile as a probabilistic threshold separating the “the upper ε-tail” of the distribution, i.e. those very large running times t making the event “” negligible according to .
Running time computable probability distributions
We now discuss examples of finite running time computable probability distributions for (7).
Every computable probability on is defined on a computably enumerable, but not computable set and has to satisfy the equality , for all , so it has to depend on U. Furthermore, to construct we need:
a computable function such that iff (the probability that stops on time t),
a computable sequence of computable reals .
If , then we can set . If , we need to normalise with , hence has to be computable. In this case
As an example we construct the computable probability distribution by using the function defined by
The function pr is computable because the sets are computable for every .
The real numbersare computable and.
To prove that is computable we use Theorem 4.2.3 in [29] which says that the limit of a computable sequence of rationals having a computable modulus of convergence is a computable real. To this aim we need to prove that the modulus of convergence of the series (9) is computable. Indeed, for every positive integers and n we have
for , a computable convergence modulus.
A similar argument works for the series (10) because the set is computable. □
Note that if , then for every we have , so .
Using Theorem 5.2 we construct the following computable probability distribution ρ on the set of finite running times :
Indeed, from (11) and (10) we have:
As described in Section 4, using ρ we define the computable discrete probability space , where is the set of all subsets of and .
The series (9) is a semi-measure [18, Section 4] with a computable sum2
The sum of a computable semi-measure may be not computable as Specker theorem [28] indicates.
– by Theorem 5.2, (10) – an essential property for the computability of the probability .
The above probability space – inspired from [7] – is “natural” because the discrete probability distribution combines the uniform distribution assumed in the halting probability Ω number, see [4], with the time complexity of halting programs (normalised by the computable number Υ, see (10)). In detail, the function (8) biases the programs x – assumed to be uniformly distributed – by dividing to the program’s stopping time t.
A program which eventually stops but does not halt “quickly” stops at an algorithmically compressible time, hence the probability of a program, that doesn’t stop for a long time, to halt tends to zero, see [6,7]. More precisely, if , then the longer t is, the smaller the halting probability of x is; if the program never halts, that is , for all t, then the halting probability of x tends to zero when . Any computable probability distribution not reflecting this phenomenon is “un-natural”.
To further justify the “naturalness” of the probability we now show that it reflects the behaviour of both halting and non-halting programs. To this aim we use the series (9) to define a variation of ρ, namely a semi-computable probability distribution r on the set of all running times, finite or infinite, as follows:
As by (10) and (11)
we can define for to obtain the semi-computable probability space , where is the set of all subsets of .
In contrast with – which deals only with finite running times – handles also the infinite running time, the running time of non-halting programs. The normalisation factor Υ makes “reflect” the behaviour of non-halting programs too as the restriction of to is
In (8) t can be replaced with or, more generally, with , where g is a non-decreasing, unbounded, computable function: in this way we obtain a class of computable probabilistic distributions on .
In what follows, a computable probability distribution ρ on will be extended to by setting for every .
Finally, we note that the problem whether a concrete computable probability distribution is “natural” depends on various factors, some objective, others subjective. There are a few ways to mitigate subjectivity, in particular, to make (11) more “practical”. One possibility is to use instead of t a very slow increasing computable function . A more substantial improvement can be obtained using Proposition 1.5.2 in [22]. Yet another way will be discussed in Section 7.
The probabilistic anytime algorithm
As we mentioned in Section 3, to solve the Halting Problem is enough to fix a universal U and to decide, for an arbitrary program x, whether or .
Our aim is to construct tan anytime algorithm for testing the incomputable predicate “”. The decision to accept/reject the hypothesis “” will be based on the running time of the computation . A decision made by the anytime algorithm is erroneous when it returns the output “”, when, in fact, (that is, eventually stops after a very long time).
The Halting Problem will be re-formulated within the probabilistic framework presented in Section 5 as follows:
The decision of rejecting will be taken on the basis of a critical time region. In both proposed anytime algorithms, the critical regions will not depend on x, that is, , for every .
An erroneous decision occurs when we reject on the basis of B, but is true. The quality of this decision is expressed by the probability of an erroneous decision, i.e. the probability that a halting program x stops in a time .
In what follows we will work with an a priori running time probability space defined in (7) and the running time random variable defined in (6). Our main example is , where ρ comes from (8).
In what follows we fix a computable probability distribution .
First we apply Proposition 4.1 to the random variable :
For everywe havehence.
We now use the inequality (12) in Corrolary 6.1 to propose the following probabilistic anytime algorithm for the Halting Problem:3
A probabilistic anytime algorithm is different from a Monte Carlo algorithm. For such an algorithm there is no need of amplification as the quality measure is fixed a priori by the bound on the probability of error.
Fixwith. Let x be an arbitrary program forU. If the computationdoes not stop in time less than or equal to, then declare that.
If the computation stops in time less than or equal to , then obviously . Otherwise, the answer to the question whether is unknown and algorithmically unknowable. The above anytime algorithm gives an approximate answer. To analyse the quality of the answer produced by this anytime algorithm we choose the computable critical time region4
is independent of x; recall that , .
and the critical program region
Note that
The first inclusion above is not necessarily an equality as there may exist such that and .
The anytime algorithm may output the answer “” when in fact . To evaluate the quality of the anytime algorithm we need to “compare” the set – which gives the “anytime” answers “” – with the exact set – giving the correct answers “”. To this aim we evaluate the “size” of the set with Pr.
For every
As , we have
so from Corrolary 6.1 we deduce that for every we have:
□
Corollary 6.2 is stronger than the ones obtained in [6,7] where the probability and the stopping decision depend on the program x.
To implement the anytime algorithm above we need an algorithm to compute
As the set is only computably enumerable, we will not be able to compute exactly , but an upper bound for it. To this aim we consider a computably enumeration of and compute the following new bound:
where
Obviously, the anytime algorithm will work correctly with the larger bound, but this will increase its time complexity.
Testing the quality of the running time distribution
Inference-based-decisions are made using statistical procedures based on sets of observations. An inference-based-decision of a hypothesis results in one of two outcomes: the hypothesis is accepted or rejected. The outcome can be correct or erroneous. The set of observations leading to the decision “reject the hypothesis” is called the critical region.
Fix the probability space induced by a random variable X. Consider a critical region , and an observed value . For every , a hypothesis is a statement such that “ is true” and “ is false” are measurable sets from .
An inference-based-decision has the following form:
An error occurs if we reject on the basis of B, when is true. The probability of error, that is, the probability of an erroneous decision, is . Of course, only decisions with (very) low probability of error are of genuine interest.
Making the “right” choices for the running time computable probability distributions is essential for successful applications. There are a few ways to guide and improve the quality of these choices. One possibility is to test how “natural” is a particular computable probability distribution for some universal U using the sampling algorithm. For example we can use the two-sample Kolmogorov–Smirnov goodness-and-fit test (see [8, pp. 309–314]) to test how “natural” is a particular computable probability distribution, say , for a given universal U.
We randomly sample to obtain a long sequence of independent, identically distributed running times according to the discrete random variable . This can be achieved by a dovetailing method to generate sufficiently many L halting programs and their running times . Then we implement a random sampling (see, for example, [3,17]) to extract N identically distributed running times from , which represent N independent, identically distributed replicates of the random variable .
We can now use the associated Empirical Cumulative Distribution Function defined by
The two-sample Kolmogorov–Smirnov test compares these two empirical distribution functions in order to accept/reject the null hypothesis that the two datasets were drawn from “the same stochastic source”. The null hypothesis, denoted by , states that the data produced by the sampling algorithm for the particular universal U fits the computable probability distribution . The decision of accepting/rejecting is taken on the basis of numerical comparison of and .
Conclusions
In this paper we have proposed a probabilistic anytime algorithm for the Halting Problem. The anytime algorithm depends on the model of computation U; its quality depend on the computable probability distribution on the set stopping times.
The main motivation comes from experimental results reported in [27,30,31] and the theoretical results in [14,15]: they all suggest that halting programs are not uniformly distributed and depend on the running times of the specific model of computation.
We have used the fact that programs which take a long time to halt stop at “algorithmically compressible times” [7] to construct a class of computable probability distributions on the set stopping times of halting programs. Each computable probability distribution induces a running time probability space on the set of halting programs, the probabilistic framework for our anytime algorithms.
Next we discuss some features of the proposed anytime algorithm. We start with positive features. (P1) The cut-off temporal bound does not depend on programs. (P2) The a priori class of computable probabilities distributions presented in Section 5.3are not arbitrarily pre-imposed: they reflect the halting behaviour of the chosen universal machine through its running times. (P3) We can test empirically the choice of the computable probability distribution and sampling, hence adopt parameters suiting different universal machines.
However, the approach has limits. (L1) Because of (P1) and the use of a universal machine, the cut-off temporal bound could be large. This can be mitigated to some extent by (P3). (L2) Working with a fixed universal machine and programs x instead of pairs (program, y) increases the computational time as the simulation of the computation on U takes longer than running .
It is a natural follow-up to study the computational complexity of the proposed anytime algorithms and, complimentary, to test experimentally their performance for classes of interesting programs.
Footnotes
Acknowledgements
We thank N. Allen, M. Holmes, Yu. Manin, L. Staiger and G. Tee for useful comments and suggestions. Special thanks to the anonymous referee for excellent critical remarks and suggestions that improved the paper. This work has been supported in part by the Quantum Computing Research Initiatives at Lockheed Martin.
References
1.
B.C.Arnold, N.Balakrishnan and N.N.Nagaraja, A First Course in Order Statistics, John Wiley, New York, 2008.
2.
L.Bienvenu, D.Desfontaines and A.Shen, What percentage of programs halt?, in: Automata, Languages, and Programming I, M.M.Halldórsson, K.Iwama, N.Kobayashi and B.Speckmann, eds, LNCS, Vol. 9134, Springer, 2015, pp. 219–230.
3.
K.Bringmann and K.Panagiotou, Efficient sampling methods for discrete distributions, Algorithmica (2016), 1–25. doi: 10.1007/s00453-016-0205-0.
4.
C.S.Calude, Information and Randomness: An Algorithmic Perspective, 2nd edn, Springer, Berlin, 2002.
5.
C.S.Calude and D.Desfontaines, Universality and almost decidability, Fundamenta Informaticae138(1–2) (2015), 77–84.
6.
C.S.Calude and D.Desfontaines, Anytime algorithms for non-ending computations, International Journal of Foundations of Computer Science26(4) (2015), 465–475. doi:10.1142/S0129054115500252.
7.
C.S.Calude and M.A.Stay, Most programs stop quickly or never halt, Advances in Applied Mathematics40 (2008), 295–308. doi:10.1016/j.aam.2007.01.001.
8.
W.J.Conover, Practical Nonparametric Statistics, John Wiley, New York, 1971.
9.
B.Cook, A.Podelski and A.Rybalchenko, Proving program termination, Communications ACM54(5) (2011), 88–98. doi:10.1145/1941487.1941509.
10.
A.DasGupta, Probability for Statistics and Machine Learning, Springer, New York, 2011.
11.
R.Downey and D.Hirschfeldt, Algorithmic Randomness and Complexity, Springer, Heidelberg, 2010.
12.
C.A.Furia, D.Mandrioli, A.Morzenti and M.Rossi, Modeling Time in Computing, Springer, Berlin, 2012.
13.
J.Grass, Reasoning about computational resource allocation. An introduction to anytime algorithms, Magazine Crossroads3(1) (1996), 16–20. doi:10.1145/332148.332154.
14.
J.D.Hamkins and A.Miasnikov, The halting problem is decidable on a set of asymptotic probability one, Notre Dame Journal of Formal Logic47(4) (2006), 515–524. doi:10.1305/ndjfl/1168352664.
15.
S.Köhler, C.Schindelhauer and M.Ziegler, On approximating real-world halting problems, in: Fundamentals of Computation Theory 2005, M.Liskiewicz and R.Reischuk, eds, LNCS, Vol. 3623, Springer, 2005, pp. 454–466. doi:10.1007/11537311_40.
16.
R.H.Lathrop, On the learnability of the uncomputable, in: Proceedings International Conference on Machine Learning, L.Saitta, ed., Morgan Kaufmann, 1996, pp. 302–309.
17.
P.S.Levy and S.Lemeshow, Sampling of Populations. Methods and Applications, 3rd edn, John Wiley, NJ, 1999.
18.
M.Li and P.M.B.Vitányi, An Introduction to Kolmogorov Complexity and Its Applications, 3rd edn, Springer Verlag, New York, 2008.
19.
N.Lynch, Approximations to the halting problem, Journal of Computer and System Sciences9 (1974), 143–150. doi:10.1016/S0022-0000(74)80003-6.
20.
Y.I.Manin, A Course in Mathematical Logic for Mathematicians, 2nd edn, Springer, Berlin, 2010.
21.
Y.I.Manin, Renormalisation and computation II: Time cut-off and the halting problem, Mathematical Structures in Computer Science22 (2012), 729–751. doi:10.1017/S0960129511000508.
22.
Y.I.Manin, Zipf’s law and L. Levin probability distributions, Functional Analysis and Its Applications48(2) (2014), 116–127. doi:10.1007/s10688-014-0052-1.
T.Mori, Y.Tsujii and M.Yasugi, Computability of probability distributions and distribution functions, in: 6th International Conference on Computability and Complexity in Analysis, Schloss Dagstuhl–Leibniz-Zentrum für Informatik, A.Bauer, P.Hertling and K.-I.Ko, eds, Dagstuhl, 2009, pp. 185–196.
25.
P.Olofsson, Probability, Statistics, and Stochastic Processes, Wiley-Interscience, New York, 2005.
26.
A.Rybalov, On the generic undecidability of the halting problem for normalized Turing machines, Theory of Computing Systems60 (2017), 671–676.
27.
F.Soler-Toscano, H.Zenil, J.-P.Delahaye and N.Gauvrit, Calculating Kolmogorov complexity from the output frequency distributions of small Turing machines, PLoS ONE9(5) (2014), e96223.
28.
E.Specker, Nicht konstruktiv beweisbare Sätze der Analysis, The Journal of Symbolic Logic14 (1949), 145–158. doi:10.2307/2267043.
29.
K.Weihrauch, Computable Analysis. An Introduction, Springer, Berlin, 2000.
30.
H.Zenil, Computer runtimes and the length of proofs, in: Computation, Physics and Beyond, M.J.Dinneen, B.Khoussainov and A.Nies, eds, LNCS, Vol. 7160, Springer, 2012, pp. 224–240. doi:10.1007/978-3-642-27654-5_17.
31.
H.Zenil and J.-P.Delahaye, On the algorithmic nature of the world, in: Information and Computation. Essays on Scientific and Philosophical Understanding of Foundations of Information and Computation, G.Dodig-Crnkovic and M.Burgin, eds, World Scientific, Singapore, 2010, pp. 477–499.