Write a computer program, let's call it H(P, I) , that takes any other program ( P...

Check the final answer first, then review the worked steps.

Answer

It is impossible to write such a program.

Reasoning

Assume $H(P, I)$ exists. Define $D(P) = \text{if } H(P, P) \text{ then loop else halt}$. Run $D(D)$. If $D(D)$ halts, $H(D, D)$ must return 'loop', so $D(D)$ loops. Contradiction.

Step-by-step solution

  1. Understand the problem: You are asking for a program $H(P, I)$ that decides the Halting Problem.
  2. Apply the proof by contradiction: Assume $H(P, I)$ exists. Create a new program $D(P)$ that calls $H(P, P)$. If $H(P, P)$ says 'halts', $D$ enters an infinite loop. If $H(P, P)$ says 'loops', $D$ halts.
  3. Analyze the paradox: Run $D(D)$. If $D(D)$ halts, $H$ must have said it loops, which is a contradiction. If $D(D)$ loops, $H$ must have said it halts, which is also a contradiction.
  4. Conclude: Because this leads to a logical impossibility, such a program $H$ cannot exist.