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

3

u/60hzcherryMXram Dec 31 '25

This response is right in that the halting problem should first and foremost be thought of as a theoretical result from Turing machines, and that whether a Python program exists that prints its own source code is irrelevant.

2

u/thehypercube Dec 31 '25

Not really. The proof is exactly the same whether you use Turing machines or Python programs.
The existence of quines is indeed irrelevant, but they do exist, and claiming that they are impossible makes the response wrong.

4

u/[deleted] Dec 31 '25

I did not claim quines are impossible.

0

u/Nytra Jan 01 '26 edited Jan 01 '26

So if the first program is one infinite tape, when it feeds 'itself' into H, it feeds a copy of the instructions of itself. Is that actually the same program as the original tape or is it a different one?