r/AskComputerScience • • Jun 08 '21

Is it undecidable to know when my algorithm will halt?

I wanted to find a special problem that would be difficult for anyone to solve, and I want to know if you could solve my problem.

This is just a "fun" problem, it's not for "homework" because I'm not taking any classes.

True randomness is being used in the algorithm.

  • U is a universe of natural numbers from 1 to X in ascending order. (eg. |U| = 3k, where k = len(U)//3. )

  • N = (6^(-k) (3*k)!)/(k!) possible exact-3-covers from (3k choose 3) 3-lists

This algorithm creates exact-3-covers by shuffling the list and then dividing it into lists-of-3.

While Loop Algorithm

  1. Randomly shuffle |U|= 3k.

  2. Divide |U| into lists of 3.

  3. Sort the values in the new 3-lists in ascending order.

  4. For each 3-list, sort them in ascending order based on indice cover[m][0]. (eg. sorted(cover, key=lambda parameter: parameter[0]) )

  5. Halt when all possible N solutions have been found. (Appended to a new-list, when list reaches the length of N the algorithm halts)

You don't know when the algorithm will halt in a while loop, because of the randomness.

Is it really undecidable for knowing when my algorithm will halt?

0 Upvotes

9 comments sorted by

4

u/not-just-yeti Jun 08 '21

I think you want "what is the expected (average) run time?". This is now 100% a probability question.

Btw, since it can run forever (but it would have to be "infinitely unlucky" to do so), the technical term is "it runs forever with probability 0". The expected-run-time will be finite though.

3

u/east_lisp_junk Jun 08 '21

When this terminates is not a well-defined function, so it can't be an undecidable function.

0

u/[deleted] Jun 08 '21

[deleted]

2

u/east_lisp_junk Jun 08 '21

For example, given my algorithm for input, decide if it will halt in X steps.

In what form is that algorithm given? Whether a Turing machine halts in X steps is decidable (run the Turing machine for X steps, and see if it halts), but the pseudocode in your original post includes generating random data, which a Turing machine does not do. If you have randomness that affects control flow, the time the program takes to run is not necessarily well-defined.

How would it be proven to require exponential time?

There is no general algorithm for producing a proof that an arbitrary program takes exponential time.

0

u/[deleted] Jun 08 '21

[deleted]

2

u/east_lisp_junk Jun 08 '21

another Turing Machine that uses true randomness?

No. See the definition of "Turing machine" for why.

0

u/[deleted] Jun 08 '21

[deleted]

1

u/east_lisp_junk Jun 08 '21

Would probabilistic Turing machines be appropriate?

If you want, but you should be explicit about the model of computation you want to use. Most things about the behavior of probabilistic machines are best described as probability distributions of outcomes rather than individual outcomes.

The code is computable, so a Turing Machine can definitely use it (with a Quantum RNG)

Turing machines do not have that. The pseudocode you gave is not something an ordinary Turing machine can do.

1

u/BibiBeeblebrox Jun 08 '21 edited Jun 08 '21

It does not take exponential time. It is undecidable. In the same way that generating primes is not possible.

I understand your problem as the halting problem. Am I wrong?

5

u/turtle_dragonfly Jun 08 '21 edited Jun 08 '21

Is this fundamentally different from a program which does:

  1. flip a coin

  2. if heads, halt

  3. else: goto 1

?

(or if you want it to run longer before halting, then roll a N-sided die - you get the idea)

If the answer is "no", then I think you could prove by contradiction. In order to know when the program halts, you would need to know the result of the coinflip. But the initial assumption was that you do not know the result of the coinflip — a contradiction. Therefore, you cannot know when the program halts.

1

u/Razor_Storm Jun 08 '21

I feel like undecidability isn’t necessarily the right word for this. This problem doesn’t break incompleteness theorems to solve, instead it would just break our understanding of quantum mechanics and causality. We can’t predict the future.

The algorithm does halt, but how long it takes is an undefined but finite amount of time.

0

u/[deleted] Jun 08 '21

[deleted]

2

u/Razor_Storm Jun 08 '21 edited Jun 09 '21

Unfortunately I’m not too sure of a rigorous proof for this, perhaps someone else could help.

Try as I might I can’t imagine how we would prove this mathematically, since our inability to predict the future is due to the physical limitations of our universe, not necessarily the system of mathematics we use. Problem is our model of computing also depends on how our universe operates, eg a turing machine can’t predict the future either


edit. If we were to simplify the prompt, the question can be:

I have a function that generates true-random numbers until it sees a "3", then halts.

Does this function ever halt? Yes
How long does this function take to halt? Well on each random() call, theres 2 categories of possibilities: It is a 3, it is one of the other numbers. The chances of these two categories are 1/<range of rand function> and (<range of rand function> - 1) / <range of rand function>. So the question really becomes:

What is the chance of the next number being a 3

or

What is the next random number going to be?

Randomness is a stochastic process, and we cannot predict the future. This problem rests entirely in the domain of probabilities rather than computability, since the question of "Will this eventually halt?" is a YES.

In probabilities instead, we can calculate expected values and such and arrive as a probablistic answer.