Whenever people ask about the stop problem, as it relates to programming, people answer "If you just add one loop, you have a stop program and therefore you cannot automate the task"
Has the meaning. If your program has an infinite loop, then when your program is running, you cannot find out if the program continues to crunch input, or if it is simply cyclically infinite.
But some of them seem counterintuitive. What should I do if I write a stop problem solver using the source code as the source code. rascher@localhost$ ./haltingSolver source.c
If my code (source.c) looks like this:
for (;;) { }
It seems to be very easy for my program to see this. “Look at the loop and look at the condition. If the condition is based only on literals and variables, then you always know the result of the cycle. If there are variables (for example, while (x <10)), see if these variables ever change. If no, then you always know the result of the cycle. "
Of course, these checks will not be trivial (calculating pointer arithmetic, etc.), but this does not seem impossible. eg:
int x = 0 while (x < 10) {}
. along with - although not trivially:
int x = 0 while (x < 10) { x++; if (x == 10) { x = 0 } }
What about user input? This is a kicker, that's what makes the program unpredictable.
int x = 0; while (x < 10) { scanf("%d", &x); }
Now my program can say: "If the user enters 10 or more, the program will stop. It will start again on all other inputs."
This means that even with hundreds of inputs, one should be able to list the conditions under which the program will stop. Indeed, when I write a program, I always make sure that someone has the opportunity to stop it! I am not saying that the created list of conditions is trivial to create, but for me this does not seem impossible. You can enter data from the user, use them to calculate index indices, etc. - but this simply adds to the number of conditions guaranteeing the completion of the program, does not make it impossible to list them.
So what is the problem with stopping? What I don’t understand is that we cannot write a problem to detect infinite loops? Or, why are "loops" such often cited examples?
UPDATE
So let me change the question a bit: what is the problem with stopping, how does this relate to computers? And then I will answer some of the comments:
Many said that the program must deal with "any arbitrary input." But computers do not have a single arbitrary input. If I enter only one byte of data, then I have only 2 ^ 8 possible inputs. So, as an example:
int c = getchar() switch (c) { case 'q': }
Suddenly I just explained all the possibilities. If c has a bit pattern of 0x71, it does one thing. For all other templates, it does something else. Even a program that accepts arbitrary line input is never "arbitrary", since the resources are finite, which means that although the theory of "arbitrary" is applied ... it is not entirely individual with practice.
Another example people refer to:
while (n != 1) if (n & 1 == 1) n = 3 * n + 1; else n /= 2;
If n is a 32-bit integer ... then I can visually tell you if this will stop.
I think this edit does not ask anything, but the most convincing example I've seen is this one :
Suppose you have a magic program / method to determine if a program is stopping.
public bool DeterminesHalt(string filename, string[] args){
Now let's say that we are writing a small piece of code, for example ...
public static void Main(string[] args){ string filename = Console.ReadLine();
So, for this example, we can write a program to make the exact opposite of our magic stop method. If we somehow determine that a given program will stop, we simply jump into an endless loop; otherwise, if we determine that the program is in an infinite loop, we end the program.
And again, if you intentionally write a program containing an infinite loop ... "Solving the problem with stopping" is a moot point, right?