r/computerscience • u/Nytra • 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?
View all comments
Show parent comment
1
u/The_Coalition Jan 02 '26
I don't know what you mean by writing out repr(P) multiple times. repr(P) is not itself a Turing machine. It's just a string of input symbols - in a real programming language, you can think of it as its source code. When thinking this way, you can imagine that P contains an interpreter for that source code. Or when thinking about C, you can think of P as a function that takes a function pointer, calls it and flips its return value, while repr(P) is a function pointer to P.