Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a program terminates?

Is there a general rule that can be used to determine this? E.g:

int i = 10;
while (i > 1 ) {
  if (i%2 == 0) i = i/2;
  else i = 3*i - 1;
}
like image 421
fastcodejava Avatar asked Dec 30 '25 09:12

fastcodejava


1 Answers

This is the halting problem. There does not exist an algorithm capable of doing what you ask.

In particular, if there was such an algorithm, then the collatz conjecture, related to the function in your question, would be trivial (or at least a lot easier).

like image 95
aaronasterling Avatar answered Jan 02 '26 11:01

aaronasterling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!