by wizeman · 4y ago · 0 comments
> Turing famously showed that computers can’t decide whether your code halts.
I would say this is actually false, even though almost everybody thinks it's true. At least, if you're interested in actually solving problems rather than being interested in what is mostly a mathematical/theoretical curiosity.
The Halting Problem is famously only undecidable if the code you're analyzing is being modeled on a "Turing machine" or something equally "powerful" to it. The problem is, computers are not as powerful as Turing machines, and furthermore, Turing machines (or something equivalent to them) neither exist nor can ever exist in practice, because it's impossible to build a "machine" with truly infinite memory.
In fact, if the machine where the code is running has finite memory, then the Halting problem is actually very easily solved (well, in theory). And there already exists various known algorithms that detect cycles of values (where the "value" in this context is the state of the program):
https://en.wikipedia.org/wiki/Cycle_detection
As you can see, if you use one of these cycle detection algorithms, then the Halting Problem is not undecidable. It's easily solvable. The problem is that, while these known algorithms are able to solve the problem in constant memory, there are no known algorithms to solve it in a time-efficient way yet. But again, it is decidable, not undecidable.
Now, I understand how Turing machines as a model can be useful, as the simplifying assumption of never having to worry about a memory limit might allow you to more easily do types of analysis that could be more difficult to do otherwise. And sure, the way the Halting Problem was "solved" was very clever (and I actually suspect that's a major reason why it has reached its current legendary status).
But this simplifying assumption should have never allowed a result like the Halting Problem which is known to be wrong for the type of computing that we actually care about to be elevated to the status that it currently has, and by that I mean, to mislead everyone into thinking that the result applies to actual computers.
So again, I would say, be careful whenever you see a Turing machine being mentioned. I would say it would be better to view them as mostly a mathematical/theoretical curiosity. And yes, they can also be a powerful and useful tool IF you understand its limitations. But you should never confuse this model for what actually is the real world.
> Henry Rice proved a much more devastating result: “computers can’t decide anything interesting about your code’s input-output!”
Since Rice's theorem (and many other computer science results!) depends on the Halting Problem being true, while it is actually false for real-world machines, my understanding is that Rice's theorem is also false for real-world machines.
But Rice's theorem (and sentences like the article is using) is absolutely another example of a huge number of cases where the Halting Problem has seemingly mislead almost everyone into thinking that something can't be solved when it actually can be solved.
I wonder how much more research could have advanced (like for example, in SMT solvers, formal methods, etc) if everyone actually believed that it's possible for an algorithm to decide whether your program has a bug in it.
How many good people were discouraged into going into this area of research because of this widespread belief that this pursuit is proven to be unachievable in the general case?
Now, I'm not a computer scientist nor a mathematician or logician. So I could be wrong. If so, I would be interested in knowing how I'm wrong, as I've never seen this issue being discussed in a thorough way.
Edit: another (according to my understanding) completely misleading phrase in the tutorial exemplifying what I'm describing:
> we learned Turing’s proof that halts is actually impossible to implement: any implementation you write will have a bug!
Now, to be clear I'm not blaming the author of the tutorial, as this is just one very tiny example of what actually is an extremely widespread belief across the whole industry.
Furthermore, it is true that computers have a finite number of states, but this number is intractable for most problems in verification. There are several well known cryptographic problems that take on the order of the lifetime of the universe to solve in bounded memory... if you're trying to write a program to verify one of these algorithms the boundedness of memory will probably not help you much.
I'd argue the complete opposite. It's very meaningful for me to distinguish whether a program works correctly, crashes due to running out of memory or loops forever.
In fact, this would be a huge, huge deal if you could solve it in an efficient way.
> There are several well known cryptographic problems that take on the order of the lifetime of the universe to solve in bounded memory... if you're trying to write a program to verify one of these algorithms the boundedness of memory will probably not help you much.
I think you missed one of my points:
> while these known algorithms are able to solve the problem in constant memory, there are no known algorithms to solve it in a time-efficient way yet
Yet being the key word here. As far as I know it's not proven that it's impossible to build a time-efficient algorithm, only that (as far as I understand) it's unlikely unless P=NP. But we don't know whether P=NP.
And there's another issue here as well: I'm not even sure if P=NP actually has any meaning in this context, because I assume issues related to P=NP are usually analyzed in the context of Turing machines.
This actually ties into the other point I mentioned:
> How many good people were discouraged into going into this area of research because of this widespread belief that this pursuit is proven to be unachievable in the general case?
Fair for many applications. I work with computers that write proofs.
> Yet being the key word here. As far as I know it's not proven that it's impossible to build a time-efficient algorithm, only that (as far as I understand) it's unlikely unless P=NP. But there's another issue here as well: we don't know whether P=NP.
There are worse complexity classes than NP, for example EXPTIME, which we know are not P by the time hierarchy theorem.
> How many good people were discouraged into going into this area of research because of this widespread belief that this pursuit is proven to be unachievable in the general case?
Well, not me! Formal methods and program synthesis are alive and well, but it's important to researchers in these areas to understand what parts of our work are decidable and what aren't. I should mention that Writing efficient SMT solvers is an important aspect of this even when the theories are undecidable, and tailoring tools to real user patterns can really blunt the problem of undecidability in practical use cases.
I mentioned this in another comment: isn't EXPTIME only defined for Turing machines?
Which again, just touches on all of my points.
For all we know, if you've reached the conclusion that an algorithm's complexity is EXPTIME, this conclusion could be just as false as the Halting problem and Rice's theorem are for real-world computers.
> Writing efficient SMT solvers is an important aspect of this even when the theories are undecidable,
My point is that you shouldn't believe that the theories are undecidable because those analysis were done using Turing machines as models.
And the other point is that sure, there are many people doing formal methods, etc. But how many more would there be if most people believed the problem to be solvable?
>> How many good people were discouraged into going into this area of research because of this widespread belief that this pursuit is proven to be unachievable in the general case?
Few if any, as those who are good enough have no difficulty understanding both the seminal importance of Turing's work and the realities of actual computing devices.
Great. And the entire field of static analysis is available for you to do this. But when discussing the formal consequences of the halting problem it is just completely pedantic to show up and point out that actually you can run Coverity and it'll spit out some pretty useful results on most programs.
I'm glad that my points were so clear and obvious to you!
Why?
Why are you assuming that the only way to figure out if a program halts is by simulating running it step by step?
And not by analyzing the description of the program?
Yes, it halts No, it loops forever Can't decide.
Wouldn't that still be useful in practice?
Especially if "can't decide" means "can't decide using the resources limit you provided" so that the test returns consistent results. (As apposed to different results depending on the differing resources between machines the test ran on.)
Using cycle detection for solving the finite version of the halting problem is a good example of this. You are not even trying to solve the problem. You are simply brute-forcing it by running two copies of the program at different speeds and comparing their internal states.
An actual solution would try to analyze the program to see whether it a) halts; b) enters a cycle; or c) attempts to use more memory than the space bound. But it feels unnatural that you could do that analytically without being able to say that the program attempts to use ever-increasing amounts of memory. Based on what we understand of computation, it's more plausible that analyzing a program is impossible in the general case, and finite bounds simply give us the ability to simulate the outcome.
After computability theory was "solved", complexity theory became the new frontier. But it turned out to be much harder. While you can teach many of the key proofs in computability theory to undergrads, complexity theorists still haven't managed to solve basic questions like P vs. NP. While you can simulate an arbitrary program, reasoning about its behavior seems to be effectively impossible in the general case.
My problem is when Turing machines are used to justify something being true when it is actually false for the vast majority of cases that we actually care about.
Sure, the problem is undecidable if your program requires infinite memory because it's trying to solve some mathematical problem (i.e. something related to infinity).
But for most programs, we would actually prefer knowing whether they will run into a memory limit or whether they cycle forever (or not), which is a decidable problem.
> You are not even trying to solve the problem. You are simply brute-forcing it by running two copies of the program at different speeds and comparing their internal states.
Indeed! But at least now we know that it's possible to solve the problem.
So here's a question which is actually more interesting, now that we know it's possible to solve it: can we solve the same problem without simulating how the program runs step-by-step?
Or in other words, can we reduce the time complexity and/or increase the efficiency of such algorithms?
That's the actual interesting question to me.
I agree with the rest of your comment.
Despite a century of research, simulation is still pretty much the only tool we have. Simulation can also be used to rule out many hypothetical solutions using similar tricks to the proof of Rice's theorem.
Assume that program A, with input X, decides whether program X with input X halts within a fixed resource bound. Assume that the resource bound is high enough that running A with an input of size |A| + C, for a reasonable constant C, uses much less resources than the bound. Then we can write a program A' that runs A with the input. If A says that the input halts (within the bound), A' enters an infinite loop. If A says that the input does not halt (within the bound), A' halts. If we run A' with input A', it halts iff A says A' does not halt (within the bound) with input A'.
We can avoid the situation by allowing A to make mistakes, by allowing it to say "don't know", or by allowing it to exceed the resource bound.
Exactly.
When running A, in some cases you would necessarily need more memory to run it than the memory bound that you defined for the input program, if you want it to work for all input programs without mistakes and without saying "don't know".
But that doesn't say anything about the time complexity, or does it?
By the time hierarchy theorem, class P (polynomial time algorithms) is a strict subset of EXPTIME.
Accordingly, this proves that in your suggested finite machine, the halting program cannot be solved by a polynomial time algorithm.
Isn't EXPTIME completeness only defined for Turing machines?
Which again, just proves all of my points.
For all we know, if you've reached the conclusion that an algorithm is EXPTIME-complete, this conclusion could be just as false as the Halting problem and Rice's theorem are for real-world computers.
Can you point me somewhere that proves this exact statement you're making? Or at least, explains why it is true.
I'm interested in reading about it.
I mean, assuming you are correct (and I have no reason to believe you aren't) it still doesn't guarantee that the problem is intractable (as EXPTIME-complete algorithms can still run very quickly in practice), but yes, I think it would suggest that it is intractable (for real-word applications).
I routinely solve instances of problems in EXPTIME to solve practical problems with no difficulty…
But often mathematical models are more informative and interesting than the concrete physical objects they abstract.
Yes, I agree.
But a model of a machine with finite states is more informative and interesting for applying it to real-world computers than a model of a Turing machine.
Why? Because the first model tells you the Halting problem is decidable and the second one tells you it's undecidable. And as I mentioned, for programs running on real-world computers the Halting problem is decidable.
I don't agree at all. I do static analysis for my career. Trying to model the actual set of available memory configurations of a physical machine is going to scale way way way worse for most meaningful problems than approaching this the usual way.
I don't really understand your argument.
I didn't say anything about how you need to solve problems like those described by the Halting problem and Rice's theorem for finite-state machines.
So I'm not constraining how you would have to solve this issue. You can model the memory configuration if you want. But you don't have to model it in your algorithm. It's just that your algorithm is allowed to assume that the amount of memory available for the program being analyzed is finite (if it wants to).
But anyway, the complexity / efficiency of an algorithm that solves the problem is a different issue that than the decidability of the problem, the latter of which many people get it wrong.
You need to read this book:
https://www.amazon.com/Quantum-Computing-since-Democritus-Aa...
(The title notwithstanding, this book is about a lot more than just quantum computing. In particular, it is about computational complexity theory, which is exactly where your line of inquiry leads. It is a very productive area of research.)
Is that actually proven?
Or is it possible that in fact, there might be an efficient algorithm for solving the halting problem in practice for computers, but it's just that we haven't discovered it yet?
Just because the state space is big doesn't mean that there aren't shortcuts to figure out in a much more efficient way whether a program loops forever.
Could we solve it without brute force? Well, there are plenty of math problems we can’t prove; we can write a program that only halts if counter example is found, and we would be unable to prove if the program halts. We can also write program that will halt if it can prove ZF set theory is false, but we already know it’s impossible to prove that (it only possible to prove it is false). So symbolically deciding if a program halts is also impossible in the general case.
Yes, but again, you're missing my point: you would be able to prove if the program halts.
It's just that in this particular case it would not necessarily be useful, because it just might happen that to solve the mathematical problem it would require more memory than you have available.
So if the halting detector says: "the program halted due to running out of memory", the results would be inconclusive for answering a difficult mathematical problem.
But that's not what most programs do, in fact, the vast majority of programs would benefit immensely from knowing whether they will exceed some finite memory limit.
> We can also write program that will halt if it can prove ZF set theory is false, but we already know it’s impossible to prove that (it only possible to prove it is false).
The same point above applies.
> So symbolically deciding if a program halts is also impossible in the general case.
No, it's not. You completely missed my point. It is 100% decidable. It's only undecidable if you're imagining running this program on an imaginary machine which cannot physically be constructed.
It seems incredibly likely that this question has a complexity of O(exp(N)) which very quickly makes the halting problem infeasible to solve for modern computers.
That's an oxymoron, because Turing machines have a state space of infinite bits by definition. I understand you mean "deterministic finite-state machines" rather than "Turing machines".
> It seems incredibly likely that this question has a complexity of O(exp(N)) which very quickly makes the halting problem infeasible to solve for modern computers.
I mean, I agree that it's likely, but again, is this proven?
I'm not aware that it is and therefore I think this is actually missing many of the points I mentioned.
It could be false for all we know.
Rice's theorem is much easier for computers with finite memory than for those with infinite memory. This is because a finite amount of memory gives a bound on the combined size of an analyzing program and the analyzed program. In particular, the only program that can analyze all programs is the empty program.
For your proposed example, a cycle detection program executed on a computer with finite memory cannot analyze all programs the computer can execute (unless it doesn't analyze them at all). Consequently, if there are both programs that halt and programs that do not, the computer cannot determine whether they have a cycle or not, i.e. halting is undecidable unless it is trivially decidable.
I'd be curious whether this suffices to convince you the halting problem exists for computers in the real world as well. If not, I'd be curious to read your objections.
That is correct. A cycle detection program that can analyze all input programs with a memory bound of "N bytes" would need more than N bytes of memory to run for some input programs.
For example, the tortoise and hare algorithm needs at most 2*N bytes of memory to analyze any program that runs with a memory limit of N bytes.
> I'd be curious whether this suffices to convince you the halting problem exists for computers in the real world as well. If not, I'd be curious to read your objections.
It does not. That only means that you if you, say, want to analyze how a program behaves when ran in a computer with 16 GB of state, you need to analyze it on a computer that has more than 16 GB of state.
It would be an incredibly useful analysis if we could discover time-efficient algorithms to accomplish this.
Then we must differ on what the "halting problem" refers to. I would say that a computer suffers from the halting problem if there is no program it can run that can determine whether arbitrary programs it can run halt or not. You seem to agree that this is the case for a computer with a fixed amount of memory (as you say, a computer with more memory is needed to analyze all programs for such a computer).
I can then only ask what is this thing that is not the halting problem (as I understand it) that you think does not exist for computers in the real world?
Well, but even if you define it your way, then computers don't necessarily suffer from that problem, do they?
Because you can limit how much memory usage a program can run with. So for example, if you have a computer which can handle 16 GB of state, you can analyze an arbitrary program X on this computer, where the analyzer is able to use the entire 16 GB of state.
The analyzer can say: this program X will halt if you give it 8 GB of state to run.
So now you run program X with an operating-system-enforced RAM+disk limit of 8 GB and you'd be quite happy to know that it will always halt.
This would be a very interesting and useful thing to do.
The analyzer would also always be able to tell if the program crashes because it ran out of memory (and why). So you could tell that 8 GB is not enough to run this program, which would also be very interesting to know, because this would imply that the program would crash in production.
What is not clear to me is this scenario that you're thinking:
Let's say your computer has 16 GB of state.
But your analyzer is not able to tell what happens to the program if it needs 16 GB of state or more to run.
But... your computer can't even run programs with more than 16 GB of state!
So... how is it useful to not know this? Why is this version of the Halting problem more useful than my version?
> I can then only ask what is this thing that is not the halting problem (as I understand it) that you think does not exist for computers in the real world?
The Halting problem is not usually defined like I define it or like you seemed to have defined it.
It's usually defined assuming that the program being analyzed can run with literally unbounded memory, which is not useful for most real-world programs because real-world programs cannot use an unbounded amount of memory.
I think that’s what makes computability theory interesting, especially if you add that our very Mathematics “break down” at a “trivially” small scale and that Turing machines will happily go on and on, literally being mathematically reasoned about, because we hit the edges of it sooner!
Not the whole universe, exactly. Just the parts that are possible to access :)
> I’m not really sure it is a good rebuke of the Halting problem that “we can brute force our way out of it”.
Why do you think the only way to solve the Halting problem on a model of a machine with finite memory is to brute-force our way out of it?
Another person mentioned the same thing, that it would take an exponential number of steps (in the number of bits in the state space) to simulate running a program.
But why are you both assuming we can only solve the problem by simulating running the program and not by analyzing the program description?
How so?
We know the Halting theorem and Rice's theorem to be decidable for finite-state machines, so how does that prove anything about the time complexity of analyzing whether the program halts?
> The only question here is whether a computer is a Turing-machine
For me that's an absurd question, as it's impossible to build a machine as powerful as a Turing machine.
> With arbitrary side effects, you are back to “can the heat death of the universe be considered O(1)”, which is, well an interesting thought, but that just demonstrates infinity’s “size”.
Sorry, I don't understand this argument :)
while(random() != 0) {
wait(1second);
}
will this halt?You can use cycle detection to reject programs that have cycles as "may halt" but not "will halt"
Now if you were to use a pseudo-random generator, and presume that this is the only function sampling from it, then all of a sudden the halting problem for this generator is well-defined. It also becomes a very simple question about the pseudo-random generator. If the random() function is truly random, then you are talking about a machine more powerful than a turing machine.
For cryptographic quality random generators, I am not sure how much is known.
In any case, the question is a simple one, though answering it can be difficult in some cases.
The Halting Problem applies as long as you're able to programmatically combine two programs into a program that executes one with the other as its input. Given such a facility you can write a literal program whose input is a halting analyzer and whose output is a program on which the halting analyzer does not halt. Moreover the size of the output program seems to be something like twice the size of the analyzer plus the size of the program that combines pairs of programs as above.
On computers with finite memory, this program (deriving from an analyzer a program on which the analyzer fails to halt) may itself not halt only if it runs out of memory. One conclusion is then a lower bound for the size of an analyzer as a fraction of available memory, and it seems the fraction would be close to a third.
My personal opinion is this makes it practically impossible to make an analyzer. I think this because the size measure of the analyzer relative to memory is not in bytes but in terms of information content. What I mean is that size may refer to the size of a decompossion program plus a compressed archive of the would-be analyzer (this is an equivalent analyzer of smaller size). So the analyzer program would have compressed source code on the order of a third of available memory. Even worse, if we continue making computers with more memory, we would need bigger and bigger analyzers. Moreover, these cannot be procedurally generated by some algorithm that takes as input memory size, as this would violate the unbounded computation halting problem. So we would need bespoke large analyzer algorithms. Finally, just proving the correctness of such a code base that is not generated in some principled manner (as it would then be compressible) is also something practically impossible. In conclusion, such effort would be better spent on designing Turing-incomplete domain-specific languages with guaranteed behavior for which an analyzer is unnecessary. The latter is what people actually work with.
In any case, below is the algorithm which takes as input a halting analyzer H and produces a program QQ on which the halting analyzer does not halt. It would perhaps be instructive to implement it and apply it to the cycle detection problem.
---
Let H be some halting analyzer. By that I mean a program with the property that if HP, the program executing H with input P, halts with output 0, then executing P would not halt.
Let N be a program that halts on input 0 and does not halt otherwise.
Let N(HP) be the program that executes HP, and if the latter halts, executes N with input the result of executing HP. The behavior of N(HP) is that it halts if executing P would not halt in a way H could detect, and does not halt otherwise.
Let Q be the program which takes input P and executes the program N(H(PP)). That is such that program QP, which executes Q on input P, halts if executing PP would not halt in way H can detect, and does not halt otherwise.
Consider now the behavior of the program QQ, which excecutes Q with itself as input. It halts if executing QQ would not halt in a way H could detect, which is self-contradictory. So QQ most definitely does not halt.
It follows that H(QQ) either does not halt or outputs 0. Outputting 0 is again self-contradictory, because that would mean executing N(H(QQ)) would halt, and by assumption QQ, which does not halt, is the program which executes N(H(QQ)).
In conclusion, any halting analyzer H does not halt on input QQ, that is, the program which executes Q on itself as input, where Q is the program which takes input P, generates the program PP which would execute P on itself as input, and then executes N(H(PP)).
If the program P, which is the program being analyzed, uses at most N bytes of memory, then the Tortoise and Hare algorithm will always successfully determine whether P halts or not, if you give it 2*N bytes of memory.
Specifically, if you run "QQ" with the Tortoise and Hare algorithm, you have 2 options:
1) If you give it a finite amount of memory (i.e. if you run it on a computer or some other kind of deterministic finite-state machine), then it will not do what you think it does.
This is because the Tortoise and Hare algorithm, when applied to itself and having a finite memory limit, would exit unsuccessfully due to running out of memory, which would tell you nothing about whether it halts or not.
2) If you would analyze what it does on a Turing machine (i.e. an imaginary machine with infinite memory), then it would never halt, because it would always be trying to use more memory.
I don't know if you realize this, but the underlying issue is that a Halting analyzer always needs to use more memory to analyze an input program than the amount of memory that the input program uses.
Which means, of course, that when you apply the Halting analyzer to itself, it would need to use infinite memory in order to finish successfully, which is impossible.
This is why the Halting problem is undecidable when programs are allowed to use infinite memory: because the Halting analyzer uses more memory than the input program.
It is also why the Halting problem is decidable for finite-state machines.
Q is a program that takes one input P.
But then you said "QQ is a program which executes Q with itself as input".
So in the program QQ, the first Q uses the second Q as input, but what does the second Q use as input?
But Q is the source code of a program that needs an input.
How would you determine if Q halts or not, if you don't give it an input?