A plan is a list of things to do. When a computer runs, it is doing the things that are written in a plan. When you solve a problem like 23 × 3, you are also following a plan.
Plans are made of steps. To follow a plan, you do what each plan step says to do, in the order they are written. But sometimes a step can tell you to move to a different step in the plan, instead of the next one. And sometimes it can tell you to do different things if you see something different. It can say “Go back to step 4” … or “If the water is not hot yet, wait two minutes, then go back to step 3.”
Here is a plan:
Walk to the store.
Buy a food.
Come back home.
You’re done!
Here is another plan:
Walk to the store.
Buy a food.
Come back home.
Go back to step 1.
There is something funny about the second plan! If we started following that plan, we would never stop. We would just keep walking to the store, buying a food, and walking back home. Forever. (Or until we decide it is a dumb plan and we should stop following it. But a computer couldn’t do that.)
You may have heard songs like “The Song That Never Ends” or “Ninety-Nine Bottles of Drinks on the Wall”. Both of these songs are like plans. When you are done singing a part of the song, you follow a plan step to get to the next part. In “The Song That Never Ends”, you just go back to the beginning. But in “Ninety-Nine Bottles of Drinks on the Wall”, you take one away from the number of bottles of drinks. And if there are no more bottles, you stop! But if there are more bottles, you sing the next part. Even though it is a very long song, it does have an end.
(There is a bad joke about people who write plans for computers. It is also a joke about hair soap. There is a plan written on the hair soap bottle:
Put hair soap in your hair.
Use water to get the hair soap out of your hair.
Repeat.
The person who writes plans for computers starts washing their hair and does not know when to stop!
Normal people know that “repeat” just means “do it a second time, then stop” and not “keep doing it forever”. But in a computer plan, it would mean “do it forever”.)
It is nice to know out how long a plan will take for us to do. It is really nice to know if it is one of those plans that never ends. If it is, then we could just say, “I won’t follow this plan! It never ends! It is like that dumb song or the bad joke!”
Can we have plans for thinking about other plans? Yes, we can!
Suppose that we found a plan, and we did not know what kind of plan it is. Maybe it is a plan for how to make a food. Or maybe it is a plan for how to go by car to another city. Or maybe it is a plan for how to build a house.
We don’t know. Can we have a plan for finding out?
Yes! Here is a plan for telling what kind of plan it is:
Get paper and a writing stick.
Start at the first step of the plan we are reading.
Read that step. (Do not do the things that step says to do! You are only reading that plan, not following it. You are following this plan.)
Write down all of the names of real things (like food, roads, or wood) that the step uses. Do not write down anything that is not a name of a real thing. Do not write down numbers, action words, colors, or other words like those.
Are there more steps in the plan we are reading? If so, go to the next step of the plan we are reading, and go back to go back to step 3 of this plan. If not, go on to step 6 of this plan.
Look at the paper that we wrote things down on.
If most of the things on the paper are food and kitchen things, say that the plan is a plan for making food.
If most of the things on the paper are car things, roads, and places, say that the plan is a plan for going to a city.
If most of the things on the paper are wood and building things, say that the plan is a plan for building a house.
If most of the things on the paper are paper, writing sticks, and steps of plans, say that the plan is a plan for reading plans!
So we can have a plan for reading and thinking about other plans. This plan is not perfect, but it is pretty good. It can even tell if a plan is a plan for reading plans. This is like looking in the mirror and knowing that you are seeing yourself. It is a very interesting thing!
But …. can we make a plan for telling if a plan will end or not? That is a hard problem.
Let’s imagine that we have a plan for reading other plans and saying if they will end. Our imaginary plan is called E, for Ending. We want to know if a plan like E is possible. We do not know what the steps of plan E are. All we know is that we are imagining that we can follow plan E to read another plan and say whether it will end or not. (We need a name for this other plan. We’ll call it X.)
But wait! We know there are plans that sometimes end, and sometimes go on forever. Here is one —
Plan Z:
Start with a number.
If our number is zero, stop.
Make our number smaller by 1.
Go to step 2.
Plan Z will always stop if the number we start with is bigger than zero and is a whole number. But if our number is one-half (or something else not whole) then Z will never end. That is because our number will go right past zero without ever being zero.
Plan Z is not really whole by itself. It needs something else that we give it: the number in step 1. We can think of this number as “food” for the plan. The “food” is something Z needs in order to go, or even to make sense. Some food is good for you, and some is bad for you … … and whether Z ends or not depends on what number we feed it.
Plan Z ends if we feed it the number 1 or 42, but not if we feed it the number one-half.
And so when we ask “Will plan X end?” we really should ask “Will plan X end, if we feed F to plan X?”
So in order to follow plan E, we need to know two things: a plan X, and a something called F. (What kind of something? Whatever kind X wants. If X wants a number, then F is a number.
If X wants a cookie, then F is a cookie. If X wants a plan to read, then F is a plan.) Following E will then tell us if X-fed-with-F will end or run forever.
Now here is another plan —
Plan G:
Start with a plan. Call it plan X.
Follow plan E to read plan X, with plan X as food. This will tell us if plan X will end or not.
Now, if E told us that X never ends, then stop!
But if E told us that X stops, then sing “The Song That Never Ends”.
So when we follow plan G, we don’t do the same thing that X does. We do the other thing! If X never ends, then G ends. And if X ends, then G never ends.
But what happens if X is G? G is a plan, and G wants a plan for its food. So we can feed G to G itself! If we feed G to G, then G will end if G doesn’t end. And G will go on forever if G ends.
That does not make any sense at all. Everything about that makes no sense! It is like saying “If the cat is white, then the cat is not white.” It is really wrong!
What part is wrong, though? G is very simple. There is nothing wrong with G. The wrongness is in the thing that we imagined:
Plan E, the plan that can tell us if any plan will end or not.
This means that E is not really possible. That is the part that looked like it might make sense, but really it did not. Oh well. It sure would be nice if E was possible. But it is not.
The Halting Problem (Part One)
A plan is a list of things to do.
When a computer runs, it is doing the things that are written in a plan.
When you solve a problem like 23 × 3, you are also following a plan.
Plans are made of steps.
To follow a plan, you do what each plan step says to do, in the order they are written.
But sometimes a step can tell you to move to a different step in the plan, instead of the next one.
And sometimes it can tell you to do different things if you see something different.
It can say “Go back to step 4” … or “If the water is not hot yet, wait two minutes, then go back to step 3.”
Here is a plan:
Walk to the store.
Buy a food.
Come back home.
You’re done!
Here is another plan:
Walk to the store.
Buy a food.
Come back home.
Go back to step 1.
There is something funny about the second plan!
If we started following that plan, we would never stop.
We would just keep walking to the store, buying a food, and walking back home.
Forever.
(Or until we decide it is a dumb plan and we should stop following it.
But a computer couldn’t do that.)
You may have heard songs like “The Song That Never Ends” or “Ninety-Nine Bottles of Drinks on the Wall”.
Both of these songs are like plans.
When you are done singing a part of the song, you follow a plan step to get to the next part.
In “The Song That Never Ends”, you just go back to the beginning.
But in “Ninety-Nine Bottles of Drinks on the Wall”, you take one away from the number of bottles of drinks.
And if there are no more bottles, you stop!
But if there are more bottles, you sing the next part.
Even though it is a very long song, it does have an end.
(There is a bad joke about people who write plans for computers.
It is also a joke about hair soap.
There is a plan written on the hair soap bottle:
Put hair soap in your hair.
Use water to get the hair soap out of your hair.
Repeat.
The person who writes plans for computers starts washing their hair and does not know when to stop!
Normal people know that “repeat” just means “do it a second time, then stop” and not “keep doing it forever”. But in a computer plan, it would mean “do it forever”.)
It is nice to know out how long a plan will take for us to do.
It is really nice to know if it is one of those plans that never ends.
If it is, then we could just say, “I won’t follow this plan! It never ends! It is like that dumb song or the bad joke!”
The Halting Problem (Part Two)
Can we have plans for thinking about other plans? Yes, we can!
Suppose that we found a plan, and we did not know what kind of plan it is.
Maybe it is a plan for how to make a food.
Or maybe it is a plan for how to go by car to another city.
Or maybe it is a plan for how to build a house. We don’t know.
Can we have a plan for finding out?
Yes! Here is a plan for telling what kind of plan it is:
Get paper and a writing stick.
Start at the first step of the plan we are reading.
Read that step.
(Do not do the things that step says to do!
You are only reading that plan, not following it.
You are following this plan.)
Write down all of the names of real things (like food, roads, or wood) that the step uses.
Do not write down anything that is not a name of a real thing.
Do not write down numbers, action words, colors, or other words like those.
Are there more steps in the plan we are reading?
If so, go to the next step of the plan we are reading, and go back to go back to step 3 of this plan.
If not, go on to step 6 of this plan.
Look at the paper that we wrote things down on.
If most of the things on the paper are food and kitchen things, say that the plan is a plan for making food.
If most of the things on the paper are car things, roads, and places, say that the plan is a plan for going to a city.
If most of the things on the paper are wood and building things, say that the plan is a plan for building a house.
If most of the things on the paper are paper, writing sticks, and steps of plans, say that the plan is a plan for reading plans!
So we can have a plan for reading and thinking about other plans.
This plan is not perfect, but it is pretty good.
It can even tell if a plan is a plan for reading plans.
This is like looking in the mirror and knowing that you are seeing yourself.
It is a very interesting thing!
But …. can we make a plan for telling if a plan will end or not?
That is a hard problem.
Edited to add the italicized comment on step 3.
The Halting Problem (Part Three)
Let’s imagine that we have a plan for reading other plans and saying if they will end.
Our imaginary plan is called E, for Ending. We want to know if a plan like E is possible.
We do not know what the steps of plan E are.
All we know is that we are imagining that we can follow plan E to read another plan and say whether it will end or not.
(We need a name for this other plan. We’ll call it X.)
But wait! We know there are plans that sometimes end, and sometimes go on forever. Here is one —
Plan Z:
Start with a number.
If our number is zero, stop.
Make our number smaller by 1.
Go to step 2.
Plan Z will always stop if the number we start with is bigger than zero and is a whole number.
But if our number is one-half (or something else not whole) then Z will never end.
That is because our number will go right past zero without ever being zero.
Plan Z is not really whole by itself.
It needs something else that we give it: the number in step 1.
We can think of this number as “food” for the plan.
The “food” is something Z needs in order to go, or even to make sense.
Some food is good for you, and some is bad for you …
… and whether Z ends or not depends on what number we feed it.
Plan Z ends if we feed it the number 1 or 42, but not if we feed it the number one-half.
And so when we ask “Will plan X end?” we really should ask “Will plan X end, if we feed F to plan X?”
So in order to follow plan E, we need to know two things: a plan X, and a something called F.
(What kind of something? Whatever kind X wants.
If X wants a number, then F is a number. If X wants a cookie, then F is a cookie.
If X wants a plan to read, then F is a plan.)
Following E will then tell us if X-fed-with-F will end or run forever.
Now here is another plan —
Plan G:
Start with a plan. Call it plan X.
Follow plan E to read plan X, with plan X as food.
This will tell us if plan X will end or not.
Now, if E told us that X never ends, then stop!
But if E told us that X stops, then sing “The Song That Never Ends”.
So when we follow plan G, we don’t do the same thing that X does.
We do the other thing!
If X never ends, then G ends.
And if X ends, then G never ends.
But what happens if X is G?
G is a plan, and G wants a plan for its food. So we can feed G to G itself!
If we feed G to G, then G will end if G doesn’t end.
And G will go on forever if G ends.
That does not make any sense at all.
Everything about that makes no sense!
It is like saying “If the cat is white, then the cat is not white.”
It is really wrong!
What part is wrong, though?
G is very simple. There is nothing wrong with G.
The wrongness is in the thing that we imagined: Plan E, the plan that can tell us if any plan will end or not.
This means that E is not really possible.
That is the part that looked like it might make sense, but really it did not.
Oh well.
It sure would be nice if E was possible.
But it is not.