halting-problem

Recognition of Undecidable Propositions(infinite loop)


Say I want to find a natural number n which n+n=3 To solve this computationally, I would run an algorithm:

int n = 1;
while(n+n!=3)
    n++;
System.out.println(n);

Of course we know that this loop is an infinite loop. But is there an algorithm that can predict whether this loop will be infinite or finite? (similar but different from the halting machine, since my desired algorithm only examines this loop while the halting machine can examine all loops) If there is, what would be the algorithm be?


Solution

  • In answer to the specific question asked ("is there an algorithm that can predict if this loop will be infinite or finite"), the algorithm would be simply to simply report "INFINITE".

    If you are looking for something more general (i.e. work on arbitrary source code), there are algorithms that work on various classes of algorithms/code. But it has been known for a long time that no such algorithm exists for the general case.