Download presentation
Presentation is loading. Please wait.
1
1 Module 11 Proving more specific problems are not solvable Input transformation technique –Use subroutine theme to show that if one problem is unsolvable, so is a second problem –Need to clearly differentiate between use of program as a subroutine and a program being an input to another program
2
2 Basic Idea/Technique
3
3 Proving a problem L is unsolvable Assume P L is a procedure that solves problem L –We have no idea how P L solves L Construct a program P H that solves H using P L as a subroutine –We use P L as a black box –(We could use any unsolvable problem in place of H) Argue P H solves H –But we know H is unsolvable Conclude that L is unsolvable –Otherwise P L would exist and then H would be solvable –L will be a problem about program behavior
4
4 Focusing on H In this module, we will typically use H, the Halting Problem, as our known unsolvable problem The technique generalizes to using any unsolvable problem L’ in place of H. –You would need to change the proofs to work with L’ instead of H, but in general it can be done The technique also can be applied to solvable problems to derive alternative consequences We focus on H to simplify the explanation
5
5 Constructing P H using P L Answer-preserving input transformations and Program P T
6
6 P H has two subroutines There are many ways to construct P H using program P L that solves L We focus on one method in which P H consists of two subroutines –Procedure P L that solves L –Procedure P T which computes a function f that I call an answer-preserving (or answer-reversing) input transformation More about this in a moment
7
7 Two Representations of P H * PHPH P,yYes/No PLPL Y/NPTPT P T (P,y) bool P H (Program P, unsigned y) { return P L (P T (P,y)); }
8
8 Answer-preserving input transformation P T Input –An input to H Output –An input to L such that yes inputs of H map to yes inputs of L no inputs of H map to no inputs of L Note, P T must not loop when given any legal input to H
9
9 Why this works * PHPH PLPL PTPT yes input to Hyes input to L yes no input to Hno input to L no We have assumed that P L solves L bool P H (Program P, unsigned y) { return P L (P T (P,y)); }
10
10 Answer-reversing input transformation P T Input –An input to H Output –An input to L such that yes inputs of H map to no inputs of L no inputs of H map to yes inputs of L Note, P T must not loop when given any legal input to H
11
11 Why this works PHPH PLPL PTPT yes input to Hno input to L yes no input to Hyes input to L no We have assumed that P L solves L no yes bool P H (unsigned x) { return complement(P L (P T (P,y))); }
12
12 Yes→Yes and No→No Domain of H Yes inputs for H No inputs for H Yes inputs for L No inputs for L Domain of L PLPL PTPT PHPH x P T (x) Yes/No
13
13 Notation and Terminology If there is such an answer-preserving (or answer-reversing) input transformation f (and the corresponding program P T ), we say that H transforms to (many-one reduces to) L Notation H ≤ L Domain of H Yes inputsNo inputs Yes inputsNo inputs Domain of L
14
14 Examples not involving the Halting Problem
15
15 Generalization While we focus on transforming H to other problems, the concept of transformation generalizes beyond H and beyond unsolvable program behavior problems We work with some solvable, language recognition problems to illustrate some aspects of the transformation process in the next few slides
16
16 Example 1 L 1 is the set of even length strings over {0,1} –What are the set of legal input instances and no inputs for the L 1 LRP? L 2 is the set of odd length strings over {0,1} –Same question as above Tasks –Give an answer-preserving input transformation f that shows that L 1 LRP ≤ L 2 LRP –Give a corresponding program P T that computes f Domain of L 1 Yes inputsNo inputs Yes inputsNo inputs Domain of L 2
17
17 Program P T string main(string x) { return(x concatenate “0”); }
18
18 Example 2 L 1 is the set of all strings over {0,1} –What is the set of all inputs, yes inputs, no inputs for the L 1 LRP? L 2 is {0} –Same question as above Tasks –Give an answer-preserving input transformation f which shows that the L 1 LRP ≤ L 2 LRP –Give a corresponding program P T which computes f Domain of L 1 Yes inputsNo inputs Yes inputsNo inputs Domain of L 2
19
19 Program P T string main(string x) { return( “0”); }
20
20 Example 3 L 1 –Input: Java program P that takes as input an unsigned int –Yes/No Question: Does P halt on all legal inputs L 2 –Input: C++ program P that takes as input an unsigned int –Yes/No Question: Does P halt on all legal inputs Tasks –Describe what an answer-preserving input transformation f that shows that L 1 ≤ L 2 would be/do? Domain of L 1 Yes inputsNo inputs Yes inputsNo inputs Domain of L 2
21
21 Proving a program behavior problem L is unsolvable
22
22 Problem Definitions * Halting Problem H –Input Program Q H that has one input of type unsigned int non-negative integer y that is input to program Q H –Yes/No Question Does Q H halt on y? Target Problem L –Input Program Q L that has one input of type string –Yes/No question Does Y(Q L ) = the set of even length strings? Assume program P L solves L
23
23 Construction review PHPH xYes/No We are building a program P H to solve H bool P H (unsigned x) { return } PTPT P T (x) P H will use P T as a subroutine, and we must explicitly construct P T using specific properties of H and L P T (P,y) PLPL Y/N P H will use P L as a subroutine P L ( );
24
24 P’s and Q’s Programs which are PART of program P H and thus “executed” when P H executes –Program P T, an actual program we construct –Program P L, an assumed program which solves problem L Programs which are INPUTS/OUTPUTS of programs P H, P L, and P T and which are not “executed” when P H executes –Programs Q H, Q L, and Q YL code for Q YL is available to P T
25
25 Two inputs for L * Target Problem L –Input Program Q that has one input of type string –Yes/No question Does Y(Q) = the set of even length strings? Program P L –Solves L –We don’t know how Consider the following program Q 1 bool main(string z) {while (1>0) ;} –What does P L output when given Q 1 as input? Consider the following program Q 2 bool main(string z) { if ((z.length %2) = = 0) return (yes) else return (no); } –What does P L output when given Q 2 as input?
26
26 Another input for L * Target Problem L –Input Program Q that has one input of type string –Yes/No question Does Y(Q) = the set of even length strings? Program P L –Solves L –We don’t know how Consider the following program Q L with 2 procedures Q 1 and Q YL bool main(string z) { Q 1 (5); /* ignore return value */ return(Q YL (z)); } bool Q 1 (unsigned x) { if (x > 3) return (no); else loop; } bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return(no); } What does P L output when given Q L as input?
27
27 Input and Output of P T * Input of P T (and H) –Program Q H one input of type unsigned int –Non-negative integer y Program Q L that is the output of P T and input of L bool main(string z) { Q H (y); /* Q H and y come left-hand side */ /* ignore return value */ return(Q YL (z)); } bool Q H (unsigned x) { /* comes from left-hand side } bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return(no); } QH,yQH,y PTPT QLQL
28
28 Example 1 * Input to P T Program Q H bool main(unsigned y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } Non-negative integer y 5 Output of P T Program Q L bool Q H (unsigned y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } bool Q YL (string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { unsigned y = 5; Q H (y); return (Q YL (z)); } Q H,y PTPT QLQL
29
29 Example 2 Input to P T Program Q H bool main(unsigned y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } Non-negative integer y 3 Output of P T Program Q L bool Q H (unsigned y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } bool Q YL (string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { unsigned y = 3; Q H (y); return (Q YL (z)); } Q H,y PTPT QLQL
30
30 P T in more detail
31
31 Declaration of P T What is the return type of P T ? –Type program1 (with one input of type string) What are the input parameters of P T ? –The same as the input parameters to H; in this case, type program2 (with one input of type unsigned int) unsigned int (input type to program2) program1 main(program2 Q H, unsigned y) PLPL PTPT PHPH Q H,y QLQL Yes/No
32
32 program1 main(program2 Q H, unsigned y) { /* Will be viewing types program1 and program2 as STRINGS over the program alphabet P */ program1 Q L = replace-main-with-Q H (Q H ); /* Insert line break */ Q L += “\n”; /* Insert Q YL */ Q L += “bool Q YL (string z) {\n \t if ((z.length % 2) == 0) return (yes) else return (no);\n }”; /* Add main routine of Q L */ Q L += “bool main(string z) {\n\t”; /* determined by L */ Q L += “unsigned y =” Q L += convert-to-string(y); Q L += “;\n\t Q H (y)\n\t return(Q YL (z));\n}”; return(Q L ); } program1 replace-main-with-Q H (program2 P) /* Details hidden */ string convert-to-string(unsigned y) /* Details hidden */ Code for P T PLPL PTPT PHPH Q H,y QLQL Yes/No
33
33 P T in action P T code for Q YL Program Q H bool main(unsigned y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } Input y 5 Program Q L bool Q H (unsigned y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } bool Q YL (string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { unsigned y = 5; Q H (y); return (Q YL (z)); } PLPL PTPT PHPH Q H,y QLQL Yes/No
34
34 Constructing Q L (and thus P T ) How to choose Q YL or Q NL
35
35 Start with no input for H If Q H, y is a no input to the Halting problem Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q ?L (z)); /* yes or no? */ } bool Q H (unsigned x) { /* comes from left-hand side } bool Q ?L (string y) { } –Thus Y(Q L ) = {} –Q H loops on y –Determine if this makes Q L a no or yes input instance to L
36
36 Answer-preserving input transformation If Q H, y is a no input to the Halting problem –Thus Y(Q L ) = {} –Q H loops on y –Determine if this makes Q L a no or yes input instance to L Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes */ } bool Q H (unsigned x) { /* comes from left-hand side } bool Q YL (string y) { } –Now choose a Q YL (or Q NL ) that is a yes (or no) input instance to L
37
37 Make yes for H map to yes for L If Q H, y is a no input to the Halting problem –Thus Y(Q L ) = {} –Q H loops on y –Determine if this makes Q L a no or yes input instance to L –Now choose a Q YL (or Q NL ) that is a yes (or no) input instance to L Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes */ } bool Q H (unsigned x) { /* comes from left-hand side } bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }
38
38 Possible shortcut Program Q L bool main(string z) { Q H (y); /* ignore return value */ if ((z.length( ) % 2) = = 0) return (yes); else return (no); } bool Q H (unsigned x) { /* comes from left-hand side } Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes */ } bool Q H (unsigned x) { /* comes from left-hand side } bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }
39
39 Another Example
40
40 Problem Definitions Halting Problem H –Input Program Q H that has one input of type unsigned int non-negative integer y that is input to program Q H –Yes/No Question Does Q H halt on y? Target Problem L –Input Program Q L that has one input of type string –Yes/No question Is Y(Q L ) finite? Assume program P L solves L
41
41 Start with no input for H If Q H, y is a no input to the Halting problem Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q ?L (z)); /* yes or no? */ } bool Q H (unsigned x) { /* comes from left-hand side } bool Q ?L (string y) { } –Thus Y(Q L ) = {} –Q H loops on y –Determine if this makes Q L a no or yes input instance to L
42
42 Answer-reversing input transformation If Q H, y is a no input to the Halting problem Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q NL (z)); /* no */ } bool Q H (unsigned x) { /* comes from left-hand side } bool Q NL (string y) { } –Thus Y(Q L ) = {} –Q H loops on y –Determine if this makes Q L a no or yes input instance to L –Now choose a Q YL (or Q NL ) that is a yes (or no) input instance to L
43
43 Make yes for H map to no for L If Q H, y is a no input to the Halting problem Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q NL (z)); /* no */ } bool Q H (unsigned x) { /* comes from left-hand side } bool Q NL (string y) { if ((y.length( ) % 2) = = 0) return(yes); else return(no); } –Thus Y(Q L ) = {} –Q H loops on y –Determine if this makes Q L a no or yes input instance to L –Now choose a Q YL (or Q NL ) that is a yes (or no) input instance to L
44
44 Analyzing proposed transformations 4 possibilities
45
45 Problem Setup Input of Transformation Program Q H, unsigned x Output of Transformation Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned x) {} bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); } Problem L Input: Program P Yes/No Question: Is Y(P) = {aa}? Question: Is the transformation on the left an answer- preserving or answer- reversing input transformation from H to problem L?
46
46 Key Step Input of Transformation Program Q H, unsigned x Output of Transformation Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned x) {} bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); } Problem L Input: Program P Yes/No Question: Is Y(P) = {aa}? The output of the transformation is the input to the problem. Plug Q L in for program P above Is Y(Q L ) = {aa}?
47
47 Is Y(Q L ) = {aa}? Problem L Input: Program P Yes/No Question: Is Y(P) = {aa}? Analysis If Q H loops on x, Y(Q L )={} No input to H creates a Q L that is a no input for L If Q H halts on x, Y(Q L ) = {even length strings} Yes input to H creates a Q L that is a no input for L Transformation does not work All inputs map to no inputs Input of Transformation Program Q H, unsigned x Output of Transformation Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned x) {} bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }
48
48 Three other problems Problem L 1 Input: Program P Yes/No Question: Is Y(P) infinite? Problem L 2 Input: Program P Yes/No Question: Is Y(P) finite? Problem L 3 Input: Program P Yes/No Question: Is Y(P) = {} or is Y(P) infinite? Input of Transformation Program Q H, unsigned x Output of Transformation Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned x) {} bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }
49
49 Is Y(Q L ) infinite? Problem L 1 Input: Program P Yes/No Question: Is Y(P) infinite? Analysis If Q H loops on x, Y(Q L )={} No input to H creates a Q L that is a no input for L If Q H halts on x, Y(Q L ) = {even length strings} Yes input to H creates a Q L that is a yes input for L Transformation works Answer-preserving Input of Transformation Program Q H, unsigned x Output of Transformation Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned x) {} bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }
50
50 Is Y(Q L ) finite? Problem L 2 Input: Program P Yes/No Question: Is Y(P) finite? Analysis If Q H loops on x, Y(Q L )={} No input to H creates a Q L that is a yes input for L If Q H halts on x, Y(Q L ) = {even length strings} Yes input to H creates a Q L that is a no input for L Transformation works Answer-reversing Input of Transformation Program Q H, unsigned x Output of Transformation Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned x) {} bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }
51
51 Is Y(Q L ) = {} or is Y(Q L ) infinite? Problem L 3 Input: Program P Yes/No Question: Is Y(P) = {} or is Y(P) infinite? Analysis If Q H loops on x, Y(Q L )={} No input to H creates a Q L that is a yes input for L If Q H halts on x, Y(Q L ) = {even length strings} Yes input to H creates a Q L that is a yes input for L Transformation does not work All inputs map to yes inputs Input of Transformation Program Q H, unsigned x Output of Transformation Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned x) {} bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.