Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Module 11 Proving more specific problems are not solvable Input transformation technique –Use subroutine theme to show that if one problem is unsolvable,

Similar presentations


Presentation on theme: "1 Module 11 Proving more specific problems are not solvable Input transformation technique –Use subroutine theme to show that if one problem is unsolvable,"— Presentation transcript:

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 Primality Testing Problem * Consider the following two problems –Halting Problem Input: Program P, unsigned int x Yes/No Question: Does P halt on x? –Primality Testing Problem (PTP) Input: Program P, unsigned int x Yes/No Question: Does P output correctly whether or not x is a prime number? Which problem seems harder and why?

4 4 Question * Suppose we construct a program P H which solves the Halting problem H under the following conditions –All of P H is known to be correct with the exception of one procedure P L. –This procedure P L is being used to solve the Primality Testing Problem. What can we conclude in this scenario?

5 5 Formalizing Technique 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 Conclude that L is unsolvable –Otherwise P L would exist and then H would be solvable –L will be a problem about program behavior

6 6 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

7 7 Constructing P H using P L Answer-preserving input transformations and Program P T

8 8 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

9 9 Pictoral Representation of P H * PHPH xYes/No PLPL Y/NPTPT P T (x)

10 10 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

11 11 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

12 12 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

13 13 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

14 14 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

15 15 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

16 16 Examples not involving the Halting Problem

17 17 Generalization As noted earlier, 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

18 18 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

19 19 Program P T string main(string x) { return(x concatenate “0”); }

20 20 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

21 21 Program P T string main(string x) { return( “0”); }

22 22 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 Domain of L 1 Yes inputsNo inputs Yes inputsNo inputs Domain of L 2

23 23 Proving a program behavior problem L is unsolvable

24 24 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

25 25 Construction review PHPH xYes/No We are building a program P H to solve the halting problem H 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 PLPL Y/N P H will use P L as a subroutine, and we have no idea how P L accomplishes its task

26 26 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

27 27 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?

28 28 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 int 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?

29 29 Input and Output of P T * Input of P T (Also Input of H) –Program Q H one input of type unsigned int –Non-negative integer y Program Q L that is the output of P T (Also 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 int 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

30 30 Example 1 * Input to P T Program Q H bool main(unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } Input y 5 Output of P T Program Q L bool Q H (unsigned int 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 int y = 5; Q H (y); return (Q YL (z)); } Q H,y PTPT QLQL

31 31 Example 2 Input to P T Program Q H bool main(unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } Input y 3 Output of P T Program Q L bool Q H (unsigned int 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 int y = 3; Q H (y); return (Q YL (z)); } Q H,y PTPT QLQL

32 32 P T in more detail

33 33 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 int y) PLPL PTPT PHPH Q H,y QLQL Yes/No

34 34 program1 main(program2 P, unsigned int y) { /* Will be viewing types program1 and program2 as STRINGS over the program alphabet  P */ program1 Q L = replace-main-with-Q H (P); /* 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 int 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 int y) /* Details hidden */ Code for P T PLPL PTPT PHPH Q H,y QLQL Yes/No

35 35 P T in action P T code for Q YL QHQH unsigned int y start Q YL Y/N z QLQL halt QHQH y Program Q H bool main(unsigned int 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 int 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 int y = 5; Q H (y); return (Q YL (z)); } PTPT Q YL PLPL PTPT PHPH Q H,y QLQL Yes/No

36 36 Constructing Q L (and thus P T )

37 37 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 int 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

38 38 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 int 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

39 39 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 int x) { /* comes from left-hand side } bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }

40 40 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 int 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 int x) { /* comes from left-hand side } bool Q YL (string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }

41 41 Another Example

42 42 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

43 43 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 int 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

44 44 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 int 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

45 45 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 int 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

46 46 Analyzing existing transformations Yes to No and No to Yes Violations

47 47 Is Y(P) = {aa}? * Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned int x) { /* comes from left-hand side } 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}? Analysis No input to H creates a Q L that is a no input for L No maps to no Yes input to H creates a Q L that is ALSO a no input for L Yes maps to no Transformation does not work Yes to No violation

48 48 Is Y(P) infinite? Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned int x) { /* comes from left-hand side } 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) infinite? Analysis No input to H creates a Q L that is a no input for L No maps to no Yes input to H creates a Q L that is a yes input for L Yes maps to yes Transformation works Answer-preserving

49 49 Is Y(P) finite? Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned int x) { /* comes from left-hand side } 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) finite? Analysis No input to H creates a Q L that is a yes input for L No maps to yes Yes input to H creates a Q L that is a no input for L Yes maps to no Transformation works Answer-reversing

50 50 Is Y(P) = {} or is Y(P) infinite? Program Q L bool main(string z) { Q H (y); /* ignore return value */ return(Q YL (z)); /* yes or no */ } bool Q H (unsigned int x) { /* comes from left-hand side } 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) = {} or is Y(P) infinite? Analysis No input to H creates a Q L that is a yes input for L No maps to yes Yes input to H creates a Q L that is ALSO a yes input for L Yes maps to yes Transformation does not work No to Yes violation


Download ppt "1 Module 11 Proving more specific problems are not solvable Input transformation technique –Use subroutine theme to show that if one problem is unsolvable,"

Similar presentations


Ads by Google