def halt(f, i):The proof for this is simple (but still confusing too wrap your head around) and uses program, which we'll call bang, that halts for some inputs and not for others.
'''Iff f(i) halts, return True.'''
*some algorithm here*
def bang(f):
'''Return 0 if halt(f, f) is False, else don't halt.'''
# if halt(f, f) is True, go into an infinite loop.
while halt(f, f):
pass
# if halt(f, f) is False, then stop.
return 0
So what happens if we run bang(bang)? There are two possibilities:
- bang halts, meaning halt(bang, bang) was false. BUT that means halt identified bang as a program that did not halt!
- bang does not halt, meaning halt(bang, bang) was true. BUT then halt identified bang as a program that does halt!
Thus, we have a proof by contradiction: bang halts if, and only if, it doesn't halt.
So, if at this point you are completely confused that's okay! I had to work through the explanation several times after class before it started to click. Then I sat my room mate down and took him through the proof. After explaining it to him several times, I felt like an expert.
No comments:
Post a Comment