Definition
Reachable Code Problem
The reachable code problem is a decision problem that asks, for a given program and a natural number , whether there exists an input for program such that the code with line number is executed when running with input .
Semi-Decidability
The reachable code problem is semi-decidable.
A recogniser can enumerate candidate inputs and simulate the program on for increasing time bounds . If, during any simulation, the execution reaches line , the procedure halts and answers true.
More formally, the following search procedure recognises positive instances:
If such an input exists, the search eventually finds it. If no input reaches line , the procedure runs forever.
Why limiting ?
The bound is what makes the procedure semi-decidable: each simulation is forced to stop after finitely many steps. Without that limit, one simulated input could run for too long or diverge, and the search might never move on to later candidates because of the order of enumeration. The bound does not make the problem decidable; it only guarantees that a positive instance can eventually be found if one exists.
A naive unbounded enumeration would look like this:
for all input I in Σ*: for all k in N: simulate Π(I) for k steps if line n is reached: return trueThe inner loop must be bounded to ensure that every candidate input is checked only for finitely many steps before the search proceeds.
Reduction from the Halting Problem
Undecidability via reduction
We reduce the halting problem to the reachable code problem.
Let be an instance of the halting problem. Choose a line label that does not occur in . Construct a new program as follows:
Void Π'(Program Π, String I) Π(I); L: /* empty line */ return;Then the line with label is reachable in if and only if halts on input .
- If halts on , then execution continues to line .
- If does not halt on , then line is never reached.
Therefore, a decider for the reachable code problem would decide the halting problem. Since the halting problem is undecidable, the reachable code problem is also undecidable.