Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 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 Lecture 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 Lecture 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 Question 1 What can we conclude from the following scenario? –We prove/know problem L 2 is solvable –We show that we can construct a program P 1 which solves L 1 using any program P 2 which solves problem L 2 as a subroutine. –We conclude that Does this occur in “real-life programming”?

3 3 Question 2 What can we conclude from the following scenario? –We prove/know problem L 1 is not solvable –We show that we can construct a program P 1 which solves L 1 using any program P 2 which solves problem L 2 as a subroutine. –We conclude that

4 4 Rephrasing key step We show that we can construct a program P 1 which solves L 1 using any program P 2 which solves language L 2 as a subroutine. –This can be rephrased in the following 2 ways: If L 2 is solvable, then L 1 is solvable –Scenario in question 1 If L 1 is not solvable, then L 2 is not solvable –Scenario in question 2

5 5 Illustration of “If L 1 is not solvable, then L 2 is not solvable” Set of all languages REC L1L1 L2L2 L2L2 L1L1 L1L1 L2L2 L1L1 L2L2

6 6 What we will typically do Set of all languages REC L1L1 L2L2 If L 1 is not solvable, then L 2 is not solvable

7 7 Proving “If L 2 is solvable, then L 1 is solvable” Assume L 2 is solvable Let P 2 be a program which solves L 2 Construct a program P 1 which solves L 1 using P 2 –We have no idea how P 2 solves L 2 We treat P 2 as a black box –L 1 and L 2 are now SPECIFIC languages Thus, we can use properties of L 1 and L 2 in this construction Argue P 1 solves L 1

8 8 Constructing P 1 from P 2 Many ways to construct P 1 from P 2 We focus on one method –Construct a program P 3 which computes a function f which I call an answer-preserving input transformation –P 3 (or f) transforms inputs to problem L 1 into inputs to problem L 2 so that yes inputs map to yes inputs no inputs map to no inputs

9 9 Construction Overview P1P1 xYes/No Properties of the construction Input string x is transformed into a new string P 3 (x) x is an input to program P 1 (problem L 1 ) P 3 (x) is an input to program P 2 (problem L 2 ) We must give actual program P 3 P 3 will use specific knowledge about L 1 and L 2 We use P 2 as a black box routine P2P2 Y/NP3P3 P 3 (x)

10 10 Answer-preserving input transformations in detail Properties of f and program P 3

11 11 Properties of P 3 (f) P 3 must compute an answer-preserving input transformation f:  * -->  * –For all x in  *, P 3 (x) must be defined That is P 3 must halt with some output P 3 (x) –For all x in  *, (x in L 1 ) iff (P 3 (x) in L 2 ) (x in L 1 ) --> (P 3 (x) in L 2 ) Not (x in L 1 ) --> Not (P 3 (x) in L 2 ) P2P2 P3P3 P1P1 x P 3 (x) Yes/No

12 12 Yes->Yes and No->No ** L1L1 L1L1 ** L2L2 L2L2 P2P2 P3P3 P1P1 x P 3 (x) Yes/No

13 13 No harder If there is such an answer-preserving input transformation f (and the corresponding program P 3 ), we say that L 1 is no harder than L 2 Notation –L 1 <= L 2 ** L1L1 L1L1 ** L2L2 L2L2

14 14 Example L 1 is the set of even length strings over {0,1} –what is the set of all inputs, yes inputs, no inputs? L 2 is odd length strings over {0,1} Tasks –Give an answer-preserving input transformation f which shows that L 1 <= L 2 –Give a corresponding program P 3 which computes f ** L1L1 L1L1 ** L2L2 L2L2

15 15 Example 2 L 1 is {0,1} * –what is the set of all inputs, yes inputs, no inputs? L 2 is {0} Tasks –Give an answer-preserving input transformation f which shows that L 1 <=L 2 –Give a corresponding program P 3 which computes f ** L1L1 L1L1 ** L2L2 L2L2

16 16 Constructing an example P 3

17 17 Example L 1 is H Input –Program P’ –input y to program P’ Yes/No Question –Does P’ halt on y? L 2 Input –Program P’’ Yes/No question –Does Y(P’’) = the set of even length strings?

18 18 Construction overview again P1P1 xYes/No We are building a program P 1 to solve L 1 which, in this case, is the halting problem H P3P3 P 3 (x) P 1 will use P 3 as a subroutine, and we must explicitly construct P 3 using specific properties of L 1 and L 2 P2P2 Y/N P 1 will use P 2 as a subroutine, and we have no idea how P 2 accomplishes its task

19 19 Keep this in mind Programs which are PART of program P 1 and thus “executed” when P 1 executes –Program P 3, an actual program we construct –Program P 2, an assumed program which solves problem L 2 Programs which are INPUTS/OUTPUTS of programs P 1, P 2, and P 3 and which are not “executed” when P 1 executes –Programs P’, P’’, and P’’’ code for P’’ is available to P 3

20 20 Analysis of L 2 L 2 –Input Program P –Yes/No question Does Y(P) = the set of even length strings? Program P 2 –Solves L 2 –We don’t know how Consider the following program P bool main(string z) {while (1>0) ;} –P loops on all inputs, so Y(P) = {} –P 2 rejects program P as input Consider the following program P’’ bool main(string z) { if ((z.length %2) == 0) return (yes) else return (no); } –Y(P’’) = set of even length strings –P 2 accepts program P’’ as input

21 21 Declaration of P 3 What is the return type of P 3 ? –Type program What are the input parameters of P 3 –The same as the input parameters to P 1 ; in this case, Type program Type input to the above program program main(program P’, input type y) P2P2 P3P3 P1P1 P’,y P’’’ Yes/No

22 22 Make P’ and P’’ be two procedures of P’’’ main function of P’’’ –input argument for P’’’ is of the same type as that for P’’ –first line: declare a variable y and make it have the same type and value as the input y passed to P 3 –second line: call P’ with y as the parameter P’(y); –Ignore what P’ returns; only interested if P’ halts on y –third line: call P’’ with the input z as the parameter and return what P’’ does return(P’’(z)); Pseudocode for P 3 P2P2 P3P3 P1P1 P’,y P’’’ Yes/No

23 23 P 3 illustrated P2P2 P3P3 P1P1 P’,y P’’’ Yes/No P 3 code for P’’ P’ string y start P’’ Y/N z P’’’ halt P’ y Program P’ int main(A[10]) { int max,i max = A[0]; for (i=1;i<10;i++) if (A[i] > max) max = A[i]; return max; } Input y 0,1,5,3,2,7,5,8,2,10 Program P’’’ int P’(A[10]) { int max,I; max = A[0]; for (i=1;i<10;i++) if (A[i] > max) max = A[i]; return max; } bool P’’(string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { int y[10]={0,1,5,3,2,7,5,8,2,10}; P’(y); return (P’’(z)); } P3P3 P’’

24 24 Example 1 Idea –P’’’ calls subroutine P’ on y to “test” if P’ halts on y –P’’’ then calls subroutine P’’ where P’’ has the right property P2P2 P3P3 P1P1 P’,y P’’’ Yes/No Input to P 3 Program P’ int main(A[10]) { int max,i max = A[0]; for (i=1;i<10;i++) if (A[i] > max) max = A[i]; return max; } Input y 0,1,5,3,2,7,5,8,2,10 Output of P 3 Program P’’’ int P’(A[10]) { int max,I; max = A[0]; for (i=1;i<10;i++) if (A[i] > max) max = A[i]; return max; } bool P’’(string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { int y[10]={0,1,5,3,2,7,5,8,2,10}; P’(y); return (P’’(z)); }

25 25 Example 2 Idea –P’’’ calls subroutine P’ on y to “test” if P’ halts on y –P’’’ then calls subroutine P’’ where P’’ has the right property P2P2 P3P3 P1P1 P’,y P’’’ Yes/No Input to P 3 Program P’ bool main(string y) { if (y.length = 5) return (yes); while (1 > 0); } Input y abcdef Output of P 3 Program P’’’ int P’(string y) { if (y.length = 5) return (yes); while (1 > 0); } bool P’’(string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { string y = “abcdef”; P’(y); return (P’’(z)); }

26 26 If P’ loops on y, Y(P’’’)={ } –P’’’ begins by running P’ on y –Suppose P’ does NOT halt on y P’’’ never even looks at input z; it just loops –Typically, Y(P’’’) = { } means P’’’ is a no input to problem L 2 If P’ halts on y, Y(P’’’) = Y(P’’) –Note, P’’ could be ANY program we want –CHOOSE P’’ such that P’’ is a yes input to problem L 2 or if Y(P’’’) = { } means P’’’ is a yes input to problem L 2, then choose P’’ such that P’’ is a no input to problem L 2 Key Observation start P’’ Y/N z P’’’ halt P’ y

27 27 Summary Answer-preserving input transformations –L 1 <= L 2 –Construct P 1 from P 2 Similarities with closure property constructions –Use P 2 as a subroutine Differences with closure property constructions –Use specific properties of L 1 and L 2 –P 3 is inside P 1 and it maps inputs of L 1 to inputs of L 2 –Often have programs as inputs and outputs


Download ppt "1 Lecture 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