r/computerscience • • Dec 31 '25

Halting problem (Can a program contain itself?)

Please correct me if I'm wrong here. The usual proof is about a program passing its own source code to the machine and then changing the result to be wrong... But what if the running program and the source code it passes are not the same program?

If a running program reads its source code from an external file after it already started running, how do you know that its the same exact code as what is already running? It could be a different program.

If the source code of the program contained a copy of its own source code, it wouldn't actually be the same source code as the original program unless infinitely recursive and therefore impossible.

Basically my thinking is that the whole thing requires a program to contain itself which is impossible.

Does this break the proof?

1 Upvotes

47 comments sorted by

View all comments

Show parent comment

1

u/not-just-yeti Dec 31 '25 edited Jan 05 '26

When you say a program that passes in itself as input,

Programs are (initially) given their input by the user. So what is being said is "a program THAT SOMEBODY ELSE CALLS, PASSING IN ITS OWN SOURCE-CODE as input … leads to a contradiction".

The proof goes "If you could write the a program HALT, then: here's how I'll tweak your program to get my program TWIST. Hey, by the way, what would TWIST return upon calling it on the string that happens to be the-source-code-for-TWIST?"

So you can feed TWIST any string [its own source-code, or another program's source-code, or the compleat works of Shakespeare]. We just reason that IF that string does happen to be the source-code for TWIST then our program won't stop, but it won't run forever either (which means the program TWIST can't actually exist, which in turn means you couldn't have really written HALT after all).