GATE / CS ARCHIVE

GATE CSE 1999 / QUESTION 10(a)

Termination of the diagonal function

Theory of Computation · Decidability & Computability · Full GATE CSE 1999 paper

GATE 1999, Q10(a) 2 marks · Descriptive
Report issue

Decidability & Computability

Question 10(a), GATE 1999: Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Show FUNNY terminates for every f.
Question 10(a), GATE 1999: Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Show FUNNY terminates for every f.
Tap to enlarge
Shared context

Assume a total, correct procedure HALTS(f,x) reports whether f(x) terminates. Define FUNNY(f)=IF HALTS(f,f) THEN NOT(f(f)) ELSE TRUE. Show FUNNY terminates for every f.

Answer & solution

Answer: Under the hypothetical HALTS assumption, both selected branches terminate. (no official key was published)

Interpret f as a program that can be supplied its own description as input; for the NOT expression restrict attention to programs returning Boolean values when they halt. This restricted class already suffices for the impossibility proof.

HALTS(f,f) terminates by the assumed totality of the decision procedure. If it returns FALSE, FUNNY immediately returns TRUE without running the nonterminating f(f). If it returns TRUE, its correctness guarantees that f(f) terminates. Evaluating that result and applying Boolean NOT therefore also terminates.

Thus for every such input program f, FUNNY(f) terminates and returns a Boolean. This is a conclusion conditional on the assumed existence of HALTS, not an independently implementable algorithm. Short-circuit branch selection is essential: the unselected branch must not evaluate f(f).

Original paper, page 7