Set Theory · Application: Undecidability of Halting
Lesson 6
There are many programs that will not halt after being executed:
while True:
passfrom itertools import count
for n in count():
a = 2 * nn = 3
while n < 7:
if n > 5:
n = 0
n += 1def binary_search(xs, key):
lower, upper = 0, len(xs) - 1
while lower < upper:
middle = (lower + upper) // 2
if xs[middle] == key:
return middle
elif xs[middle] < key:
lower = middle
else:
upper = middle - 1
return -1
print(binary_search([-4, -2, 1, 7, 12, 29], 17))For the first three programs, it is immediately clear that they will loop indefinitely. However, finding and fixing the bug in the last program will take some time.