Skip to content

Instantly share code, notes, and snippets.

@storopoli
Created August 5, 2024 20:06
Show Gist options
  • Save storopoli/ad11ae6ebe4326bf950b85c090ae17ed to your computer and use it in GitHub Desktop.
Save storopoli/ad11ae6ebe4326bf950b85c090ae17ed to your computer and use it in GitHub Desktop.
The Halting problem
fn halts(program: A) -> bool

fn b(program: A) {
    if halts(A) {
        loop {}
    } else {
        return ();
    }
}

What happens if we pass b to b()?

  • If halts(b) is true, then b(b) will loop forever.
  • If halts(b) is false, then b(b) will halt.

So halts(b) is true if and only if halts(b) is false. This is a contradiction, so halts(b) is undecidable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment