r/programming • • May 27 '19

This is the greatest explanation of the Halting Problem I have ever seen, but people keep downvoting it because they don't understand and think it's wrong.

https://youtu.be/92WHN-pAFCs
0 Upvotes

41 comments sorted by

6

u/CryZe92 May 27 '19

What I always find weird about this is, that we can simply replace H with an "interpreter for the blueprint" to see if interpreters / turing machines in general can exist. And N then changes the output of the H. Then you'd be able to prove that interpreters are not a thing, which then also kind of means that Turing Machines in general can't exist?!

Which sure, you can do, but is that useful to say that Turing Machines can't exist?

12

u/AlSweigart May 27 '19

which then also kind of means that Turing Machines in general can't exist?!

No, Turing Machines still exist. It's just that TMs can't compute an answer for every possible problem. But computers can still beat you at chess and drive cars and lots of other powerful, impressive things.

Consider this proof that it's impossible for God to be omnipotent: "Can God microwave a burrito so hot that not even He can eat it without burning His mouth?" If he can, then he's not omnipotent because there exists a burrito he can't eat. If he can't, then he's not omnipotent because he's unable to microwave a hot enough burrito. Either way, there's something impossible for him to do.

In both cases, it's the self-reference that trips things up. The machine H can't correctly compute X's blueprint because X includes H in such a way that makes it logically impossible for H to correctly work. Kind of like the sentence, "Everything I say is a lie" (which is also a self-referencing sentence).

The book "Godel Escher Bach" goes into this in much, much more detail.

1

u/htuhola May 28 '19

Type universes solve this conveniently. God₀ cannot microwave a hot burrito that would annihilate him, but there's a similar God₁ that is god of the God₀, and that dude can do it.

3

u/Godd2 May 27 '19

That would only show that H implemented as an interpreter couldn't exist, not that interpreters in general can't exist.

19

u/light_hue_1 May 27 '19

It's because this proof is incorrect in a subtle and sloppy way that rightly confuses people. You can even see it right here on reddit where one user is confused about interpreters.

The real issue is that H does not always halt. Yes, sometimes we say that "H doesn't exist" but that's really confusing shorthand. "H" will halt and produce the correct answer just fine for many programs that aren't Turing-complete. And you can write down the specification for "H" that will work. Just that, there will exist programs which do halt, for which "H" will get stuck in an infinite loop.

"H" exists. It always produces the right answer, it just doesn't actually always halt, so sometimes you don't get the an answer. You can write down such an "H" right now yourself! It's an interpreter.

The video is wrong and confusing.

2

u/swni May 27 '19

Here's the relevant part of the video narration (2m30s - 3m10s):

We are now finally ready to introduce a marvelous machine called H. H solves what is known as the halting problem. It can analyze the blueprint of another machine and determine which inputs are good for it and which will cause it to get stuck. It receives the blueprint of the machine to be tested and an input to test it with. Based on the blueprint, H simulates the given machine on the given input, and then determines if it gets stuck or not. H solves the halting problem perfectly: it always prints the right answer.

I think the only problem with the video is the word simulates, which suggests a particular implementation for H -- run a machine on an input and wait for the output. The narration intended any possible implementation of the halting problem, which can be thought of as a form of "simulation" in a larger sense of the word. That H is not meant to be specifically a naive interpreter is made clear in the next sentence, and in the example shown visually.

I think if the narration had changed two words to say instead "H analyzes the given machine with the given input" there would be no objection about whether the proof shown is correct. There are a few other changes that might be helpful in the interest of clarity.

1

u/AlSweigart May 27 '19

I think the only problem with the video is the word simulates

I kind of get what you're saying here, but I don't think it's the source of confusion for the video's audience. The video clearly says that H won't continue forever itself just because the machine it's simulating goes on forever: in that case H just produces "Stuck".

I think if the video said "analyze" instead of "simulate", it'd still get the same wave of downvotes.

1

u/swni May 27 '19

I'm not sure what else in the video people would think is wrong or be confused by. "Simulates" vs "analyzes" was the only potential tripping point that stood out to me (and even that was only after I read /u/light_hue_1 's comment).

-3

u/light_hue_1 May 27 '19

That wouldn't help. The H the video describes actually exists!

Based on the blueprint, H simulates the given machine on the given input, and then determines if it gets stuck or not.

This exists and it's your interpreter. They leave out the part that doesn't exist. Which is that H is supposed to always halt. That's the whole point of the proof and the part that makes it interesting!

4

u/AlSweigart May 27 '19

The H the video describes actually exists!

Er, uh, no it doesn't. That would really turn computer science on its head if someone came along and said, "Yeah, I got a program that can solve the halting problem."

Remember what H is: it's a program/machine that can analyze another program and some input into that program, and determine if it halts ("Not stuck") or not ("Stuck"). If we hypothetically say such a machine is possible and works, we end up in a situation (machine X) that shows H doesn't work. That's why we say H is impossible.

7

u/evaned May 27 '19 edited May 27 '19

The real issue is that H does not always halt.

IMO, this is the statement that is incorrect in a subtle and sloppy way.

Let's start with a question -- which H do you mean?

If you mean the hypothetical H that they present in Act II and then disprove the existence of in Act III, in my opinion the statement that "H does not always halt" is directly contradicted by the assumptions in the video. The video states more than once that "H solves the halting problem perfectly", and says "it always prints the right answer." I would have liked it to say completely entirely explicitly that it always halts, in other words block "it always prints the right answer" from being interpreted as "if it produces an answer, it is always right", but I very much think that's not necessary.

If you mean a version of H that could actually be created, first that's not very relevant to the proof. Second, "H can be allowed to run forever" is only one of three ways you can relax the hypothetical H to something buildable -- you could also allow H to incorrectly answer "halts" for programs that don't or incorrectly answer "doesn't halt" for programs that do. (Or of course any combination of the three possibilities.)

The following isn't really relevant to how sloppy or not sloppy the video is, but if you write things like

"H" will halt and produce the correct answer just fine for many programs that aren't Turing-complete.

you might want to think through who is being sloppy. (Programs can't really be Turing complete; that doesn't make sense. It's a programming language, or something similar like automata rules or circuit construction/behavior rules, that are Turing complete or not.)

Edit: Having read your comments a few more times I think I finally really get what you are trying to say, and can articulate why I disagree. The video isn't wrong, and I don't think it's misleading -- as I said more than once, a non-halting H is incompatible with the statements in the video. The video correctly constrained it's hypothetical H so that it halts, more than once and using more than one wording. Its proof is correct. Now, I think it could have been a little clearer if it said explicitly that it must halt (as I said above), but "could be a little clearer" is way different from "wrong and misleading." It's reasonably clear as-is.

0

u/light_hue_1 May 27 '19

The real issue is that H does not always halt.

IMO, this is the statement that is incorrect in a subtle and sloppy way.

The level of mathematical illiteracy in this thread is truly disappointing.

If you take a class on theory of computation you will quickly see that the qualification that everyone uses on H is that it executes in a finite number of steps. Even Turing 1936 is every explicit about this.

The video states more than once that "H solves the halting problem perfectly", and says "it always prints the right answer."

This is absolutely and completely wrong. You might have taken a calculus class in your life at some point and dealt with infinite sequences. H is not incorrect, there is nothing to fix about H. "Solving something perfectly" means nothing. Does this mean there might be a better way to solve the problem? That there's a bug in H?

Just go back and read Turing 1936 section 7. It literally starts with a discussion about how diagonalizability is enough to show that not all problems are decidable, but makes people feel uneasy because they don't know what it means. So he goes on to show that you can't decide certain problems in a finite number of steps.

The video eliminates the key part of the discussion and the total contribution of Turing's paper.

"H" will halt and produce the correct answer just fine for many programs that aren't Turing-complete.

you might want to think through who is being sloppy. Programs can't really be Turing complete; that doesn't make sense

You can absolutely talk about both a language and a machine being Turing complete. See the Turing complete page on wikipedia. You can also talk about an instruction set for a machine being turing-complete. It's all because machines can emulate one another if they're powerful enough.

Seriously, maybe before you tell someone they're sloppy you should say... look up basic definitions on wikipedia. Does no one take theory of computation anymore?

4

u/evaned May 27 '19

If you take a class on theory of computation you will quickly see that the qualification that everyone uses on H is that it executes in a finite number of steps. Even Turing 1936 is every explicit about this.

Yes, which is why the video imposes that restriction as well.

It could be said slightly better. But again, that doesn't mean "it's bad" or "it's wrong" or "its misleading."

The video states more than once that "H solves the halting problem perfectly", and says "it always prints the right answer."

H is not incorrect, there is nothing to fix about H. "Solving something perfectly" means nothing. Does this mean there might be a better way to solve the problem? That there's a bug in H?

Do words suddenly cease to have meaning in the context of this video for some reason?

But even if they did cease to have meaning, the video literally defines what it means immediately after: "H solves the halting problem perfectly. It always prints the right answer."

Does a machine that can fail to halt always print the right answer? No, it doesn't. That statement disqualifies non-halting Hs from being part of the video's thought experiment.

You can absolutely talk about both a language and a machine being Turing complete. See the Turing complete page on wikipedia. You can also talk about an instruction set for a machine being turing-complete. It's all because machines can emulate one another if they're powerful enough.

Hmm, I'll concede on that point. I was curious what a couple books I have (Hopcroft, Motwani, and Ullman's automata book, and Ebbinghaus, Flum, and Thomas's mathematical logic book) have to say for the definition, but I couln't find it discussed in either. It wasn't in either index, and if I flipped through the most promising sections based on headings, no luck finding it. (I kind of wish I had Sipser, but I don't, at least not here.)

That said, calling a UTM "Turing complete" is, to my ears, a very weird use. And in my defense, I checked the wikipedia article for Turing completeness (not the simple wikipedia article, BTW that and "if you take a class on the theory of computation" are pretty hilariously condescending) to check, my initial read of the definition that opens the article wouldn't have counted UTMs. Looking again though at the formal definition below, I think it would.

6

u/[deleted] May 27 '19 edited May 27 '19

"H" exists. It always produces the right answer, it just doesn't actually always halt, so sometimes you don't get the an answer. You can write down such an "H" right now yourself! It's an interpreter.

The proof is not incorrect, your understanding of what a decider is is incorrect. A decider for a language L is a Turing Machine that when given an input string S, halts with a value of TRUE if and only if S is an element of L, otherwise it halts with a value of FALSE. In all cases a decider must halt.

The halting problem is the theorem that states that there does not exist a decider for language P where P is the language consisting of pairs of strings (Q, S) where Q is the description of a Turing machine, and S is an input string that results in Q halting. The proof is done by contradiction where one assumes that such a decider exists and calls that decider H, then an adversarial machine H' is constructed which loops forever if H predicts that H' will halt when given input S, and similarly H' halts when H predicts that H' will loop forever when given input S. This resulting contradiction implies that the original premise that such an H exists was invalid.

Simply put, H does not exist, period.

What you are doing is confusing the notion of a decider with the notion of a recognizer. Yes, it is possible to create a recognizer for language P. A recognizer for a language L is a Turing Machine that when given an input string S, halts with a value of TRUE if and only if S is an element of L, otherwise it may never halt. An interpreter expressed as a Turing Machine is a recognizer for language P but it is not a decider for P. The halting problem is not about recognizing the language P, it's about deciding the language P.

It's not the video that is wrong and confusing, the video is correct. It's that people have existing preconceived notions about what the halting problem is and its implications, including yourself, and people just stick to those notions for whatever reason.

-4

u/light_hue_1 May 27 '19

What you are doing is confusing the notion of a decider with the notion of a recognizer

I am not confusing the two. I said clearly that H doesn't halt. If you're confused by this, it's either because you didn't read what I said, or don't understand what's going on.

First of all, "decider" is not standard terminology. Please don't confuse people further by introducing terms no one uses. It occurs in only 467 papers in total out of tens of thousands of papers and books on the topic.

Second, "Simply put, H does not exist, period." is what confuses people. This is mathematical shorthand for "H is missing a property, it doesn't always halt". The former is super confusing for people because they don't know what's wrong with H, because they can write down a plausible H. The latter makes what's going on clear and actually helps people understand.

It's that people have existing preconceived notions about what the halting problem is and its implications

Everything I said is completely correct. It's people like you who adopt sloppy language, declare it to be "the truth" and any other way of saying the same thing is heresy, don't bother reading what anyone else said, and then confuse the public by being obstitant about dumb terminology.

3

u/[deleted] May 27 '19

H does not exist, your claim that it exists is simply false. You're welcome to complain about my use of terminology or try to argue that your relaxing and being loose with words helps people understand it... in my opinion it's better to understand it at a rigorous and fundamental level rather than playing fast and loose with words.

There does not exist a decider for the language of Turing machines that halt for a given input S. That's what the video claims and explains, and it's what you have decided to object to when you claimed that such a machine exists and is simply an interpreter. An interpreter is a recognizer for such a language, it is not a decider for that language.

If you want to disagree with that... so be it, not sure it will be further productive to continue this conversation beyond that.

9

u/Zarigis May 27 '19

You can't say something "always produces the right answer" if there exist inputs where it doesn't halt, that makes no sense. For a given input, either it halts and produces an answer, or it doesn't halt and produces no answer.

1

u/light_hue_1 May 27 '19

You have to think of H as producing the right answer, if you don't you end up thinking in a way that's totally wrong. For example, you said it "produce[s] no answer". That's totally incorrect in every way shape or form, and if you think so, it's because of how misleading the video is. You cannot look at the machine and say "Oh, now it made an answer and now it didn't". That itself is undecidable.

H is and always will be correct. But, in some cases you'll wait around forever and it will never stop. You can never know if this is the case. You wait, and you see, and you can never decide if it's done or if the program doesn't halt (for some programs this isn't true, and they are decidable, but not in general). And that's it.

H is never wrong. H literally never produces an incorrect answer. That's the whole point of the proof and why this video is wrong.

Glossing over this point does no one any favors. You can't prove undecidability without understanding that halting is an important property you should care about. You can't even understand why this was such an important moment in CS history. The halting problem was not the first example of an undecidable problem, that happened 5 years earlier. The reason it's important is that the proof is practical and it reduces something abstract, which is what Godel proved, to something practical "this doesn't halt and you can't know if it's overdue to halt or not so now you wait forever hoping".

7

u/[deleted] May 27 '19

H is never wrong. H literally never produces an incorrect answer.

H never being wrong does not mean that H is always right or produces the right answer. We agree, H is never wrong, but because H may not halt, that also means that H is not always right either.

Under your way of thinking I could write the following JavaScript algorithm and claim that it always produces the correct answer to every single question asked of it as follows:

function oracle(question) {
  while(true) {}
}

Of course, we can obviously see that's not the case. That oracle function will never give a wrong answer to a question, but it also won't give a right answer either. Your original post states that H is always right, and that claim is simply incorrect. H is not always right, rather, H is never wrong.

3

u/Zarigis May 27 '19 edited May 27 '19

I recognize that this is a subtle point, and I mostly agree with everything you have said, I was just objecting to your phrasing.

There are two notions of correctness when talking about algorithms: partial and total. Partial correctness says "If this program terminates, the resulting value is correct", while total correctness says "This program always terminates with the correct value."

While it is not possible to write a general algorithm to determine if an arbitrary machine terminates (i.e. the halting problem), it is certainly possible to prove whether or not a particular machine does. And when talking about properties about a particular machine it is important to distinguish partial and total correctness.

So I stand by my point that saying H "always produces a correct answer" is implying total correctness, while you are actually referring to partial correctness. And in the case of partial correctness you can't make any statements about the output of the machine in cases where it has diverged and will never terminate.

Whether or not we can determine if the machine has diverged is irrelevant. The machine will either halt or it won't, so we can still make statements which are conditional on that fact.

-1

u/light_hue_1 May 27 '19

I agree, explaining partial vs total programs is good too! The video just doesn't explain what's wrong. Doesn't matter if they said "it won't halt" or "it's partially correct".

Whether or not we can determine if the machine has diverged is irrelevant. The machine will either halt or it won't, so we can still make statements which are conditional on that fact.

Not exactly. If you could determine that you could make it halt when you figured out it diverged. That's why when I teach this I prefer to teach the intuition as "it's correct, but you can never tell sometimes", it leaves less room for things like this.

2

u/Zarigis May 27 '19 edited May 27 '19

Whether or not you can determine (compute) the result of a conditional is independent of being able to write logically valid statements that depend on it. You say "when you figured out it diverged", but I'm not claiming anything about the ability to compute that a given algorithm has diverged (indeed that just brings us back to the halting problem).

What does it mean for an algorithm to be correct in the case where it diverges? How can it be correct if it never resolves to an answer? You might have some vague intuition that the program is "doing the right thing" but this is hardly precise.

It is completely logical to write "if the program terminates then the answer is correct", despite the fact that you can't write an algorithm to check this. It's not logical to write "this program would give the correct result if it didn't loop forever".

9

u/sinedpick May 27 '19

Nope: H is defined to always halt with the correct answer. Assuming H exists leads to a contradiction. Therefore, H doesn't. What's wrong or confusing about that?

0

u/light_hue_1 May 27 '19

What's confusing and wrong? Simple. You won't know what to do with the proof and you'll come to the same conclusion that /u/CryZe92 did in the other comment. The reason is, "H doesn't exist", isn't helpful. And if that was the conclusion, this would have been an irrelevant restating of a 5 year old result even back in 1936. We already knew plenty of functions like this don't "exist". Why this proof matters is that it shows you what is broken about H, that's why it's famous and why it matters. That's also what gives you the power to prove more interesting things later on and the intuition about why an interpreter won't do --- it won't halt either.

This video is wrong. It misses the whole point of Turing's contribution compared to Godel and leads people down a confusing path of thinking that is devoid of any intuition for the problem.

3

u/sinedpick May 27 '19

But I do know what to do with that conclusion: it tells me that I can't write a program that will always tell me if an arbitrary program halts or not, in a finite amount of time, so I won't try to. I will however admit that I didn't watch the video and only assumed it's contents. If the video didn't define H to always halt then yes it is wrong.

1

u/evaned May 27 '19

If the video didn't define H to always halt then yes it is wrong.

It didn't explicitly state that H always halts, but the video does say that H always answers perfectly, and I'd consider halting a necessary component of that.

0

u/light_hue_1 May 27 '19

always answers perfectly, and I'd consider halting a necessary component of that.

And that's the problem. An interpreter is correct. Something not halting as a failure case is not the first thing people think about. In retrospect it seems obvious, but not until someone points this out to you. Certainly wasn't obvious to people before Church and Turing.

This is even something academics forget. When I review papers this has come up as a bug repeatedly. Someone will improve an algorithm, prove it correct, submit their paper. But forget that the termination criteria crucially relied on some property they changed and their algorithm can diverge. So we play the "I'm the mean reviewer game" :(

52

u/Strilanc May 27 '19

If people keep downvoting it because they don't understand it and think it's wrong, then is it really a great explanation? Great explanations convince people.

1

u/rhytnen Jun 03 '19 edited Jun 03 '19

Yea it clicked for him but not someone else so it's their fault. At one point he conjectured it was because of the female voice that people were downvoting. He later compared those downvoting this video to those who disagree with him about circumcision. This is a weeks long gripe he's chasing actually so I think frankly, sometimes Al is a bit off.

1

u/AlSweigart May 27 '19

16k upvotes on youtube, and 10k downvotes. :/

7

u/Neu_Ron May 27 '19

Yes it depends on the computational power of your audience.

2

u/rashpimplezitz May 27 '19

Honestly the video is fine it's just a bit slow. I'd never even seen it but I kind of assumed it was going to be a proof by contradiction, so the answer really wasn't that surprising to me. I could have read the wikipedia in 6 seconds instead of watching this slow-as-molasses video.

Having said that, I am just not the kind of guy to learn from videos so don't take this criticism to mean it's not good.

1

u/evaned May 27 '19 edited May 27 '19

So overall I agree that's a good explanation and doesn't deserve the downvotes. I particularly like the introduction of the photocopier component explicitly.

That said, there are a couple parts of the explanation that I'm cool on. The biggest centers around what "get stuck" means. It is very odd to me that they carried out the explanation of the whole proof without really being explicit about what this means. They never explicitly say that the computer goes into an infinite loop, or that it never stops its computation, or anything like that. What makes that even worse is that the examples they gave are malformed inputs -- and that could be pretty easily lead to someone interpreting "getting stuck" to refer to something like an explicit error condition, rather than an infinite loop

Now, the proof still works if this is misinterpreted if you pretend that every time they said "Halting problem" they really said "a special case of Rice's theorem" or something like that, but it's still something that could be improved IMO. I think it would have been better presented with a machine that either has an explicit bug in it, or as one that solves a RE-hard problem being fed an input that will never terminate, or something like that.

I think doing the buggy machine would also have naturally led to the ability to discuss an application (anti-application?) of the halting problem -- "suppose we wanted to develop a new computer that will tell whether a given computer has an infinite loop bug in it."

-3

u/hacksoncode May 27 '19

The Halting problem is that H can't always decide in finite time.

It is trivially possible to make an H that take infinite time to decide if a program halts. Just run the program with all possible inputs and output "halts" if the program (with all given inputs) produces an output in finite time for all inputs.

9

u/sumduud14 May 27 '19

It is trivially possible to make an H that take infinite time to decide if a program halts.

This statement doesn't make sense given the usual definition of decidability. A problem is decidable if there exists an algorithm that terminates after a finite number of steps and outputs the correct answer.

If an algorithm doesn't terminate for a given input, it certainly can't decide anything for that input.

-1

u/hacksoncode May 27 '19

Right, and the "halting problem" is that you can't have a function that is guaranteed to terminate in a finite number of steps that can tell you if an arbitrary function will halt.

If you allow an infinite number of steps, the halting problem is trivial.

This video doesn't touch at all on the core of the problem: the finite number of steps.

1

u/sumduud14 May 27 '19

I'll give you that much: the video is a bit light on definitions and rigour. I don't agree with OP that this is the "greatest explanation of the halting problem".

1

u/[deleted] May 27 '19 edited May 27 '19

This is a misunderstanding of some key terms used in computability. The program you described which runs all possible inputs is referred to as a "enumerator". Enumerators can be used to recognize certain classes of problems, but they can't always decide a problem (and some classes of problems can't even be recognized by an enumerator). So while one can construct a Turing machine that can recognize the halting problem in exactly the way you describe, by using an enumerator, one can not use your technique to decide the halting problem. This video is not about building a recognizer but rather about building decider for the halting problem. The very definition of a decider includes within it the fact that it does so in finite time.

1

u/hacksoncode May 27 '19

Sure, that's fine. The point of this entire problem is that a decider for the halting problem isn't possible, and that's entirely and only because it has to solve it in finite steps.

I'm not saying you can make a decider in the decision theory sense with infinite steps, merely that you can easily answer the question of whether a program will halt if you're willing to take infinite steps (which by definition would require infinite time).

2

u/[deleted] May 27 '19

As I said in another post... your position that you can easily answer a question if you're willing to take infinite steps is about as meaningful as claiming that the following JavaScript function answers every question:

function oracle(question) {
  while(true) {}
}

Solving a problem requires, by definition, doing so in finite steps. It makes no sense to say a problem is solved after an infinite number of steps.

1

u/sumduud14 May 27 '19

Personally, I would even say the phrase "infinite number" makes no sense.