

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of algorithm reductions and provides examples of reducing the undecidable halting problem to the v7 problem and the 2-halt problem. The v7 problem determines if a variable ever becomes 7 during program execution, while the 2-halt problem checks if two programs halt on the same input. How to create reductions using program transformations and proves their correctness.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Algorithm Design and Analysis 4/8/
Instructor: Mike Kowalczyk
Suppose we want to solve the problem of figuring out if the variable v ever becomes 7 as program P runs on input i. Let’s call this the v7 problem. It turns out to be undecidable, meaning there is no algorithm which returns the correct output for every input. A problem instance consists of a pair (P, i), and the answer is “yes” if the program P has a variable v and v becomes 7 at some point during execution on input i, and “no” otherwise. We would like to make a reduction Halt ≤m v7. This would show that v7 is undecidable. Remark: In our discussion of algorithms and reductions here, we are assuming determinism (in particular, no randomness or nondeterministic program forking).
reduceHaltToV7(Program P, input i) { Define program P’’ = "Same as P, except all instances of variable v are replaced by some unused variable."
Define program P’ = "1) Run P’’ on i
return (P’, i); }
Let’s prove that this is a reduction from the halting problem to the v7 problem. We need to show that every instance of the halting problem is mapped to an instance of the v7 problem, and “yes” and “no” instances of the halting problem map to “yes” and “no” instances of the v7 problem, respectively. If (P, i) is an instance of the halting problem, that means P halts on i. Then P ′′^ also halts on i. Thus, P ′^ reaches line 2, and v gets set to 7 during P ′^ execution on input i. In other words, (P ′, i) is a “yes” instance of the v7 problem. Now suppose that the input (P, i) is a “no” instance of the halting problem. Then P doesn’t halt on input i. Then P ′′^ doesn’t halt on input i either, and P ′′^ never sets v to 7 on input i (it doesn’t even use the variable at all). Thus, (P ′, i) is a “no” instance of the v7 problem, and our reduction is complete. Halt ≤m v7. In particular, since Halt is undecidable, we can also conclude that v7 is undecidable.
Define the 2Halt problem as follows: “On input (P, Q, i), the output should be “yes” if programs P and Q both halt on input i, and “no” otherwise.”. Let’s try writing a reduction from Halt to show that 2Halt is undecidable.
reduceHaltTo2Halt(Program P, input i) { return (P,P,i); }
Let’s prove correctness of the reduction. If (P, i) is a “yes” instance of Halt, then P halts on i and (P, P, i) is a “yes” instance of 2Halt because both input programs halt on input i (they’re both P ). If (P, i) is a “no” instance of Halt, then P doesn’t halt on i and therefore (P, P, i) is a “no” instance of 2Halt because neither input program halts on input i (again, they’re both P ). We conclude that Halt ≤m 2 Halt and since Halt is known to be undecidable, 2Halt is also undecidable.