Download presentation
Presentation is loading. Please wait.
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 problem 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/problems REC L1L1 L2L2 L2L2 L1L1 L1L1 L2L2 L1L1 L2L2
6
6 What we will typically do Set of all languages/problems 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 problems 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 of L 1 map to yes inputs of L 2 no inputs of L 1 map to no inputs of L 2
9
9 Construction Overview P1P1 xYes/No Properties of the construction Input x is transformed into a new input 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:Domain for L 1 --> Domain of L 2 –For all x in Domain of L 1, P 3 (x) must be defined That is P 3 must halt with some output P 3 (x) –For all x in Domain of L 1 (x is a yes input for L 1 ) iff (P 3 (x) is a yes input for L 2 ) (x is a yes input for L 1 ) --> (P 3 (x) is a yes input for L 2 ) (x is a no input for L 1 ) --> (P 3 (x) is a no input for L 2 ) P2P2 P3P3 P1P1 x P 3 (x) Yes/No
12
12 Yes->Yes and No->No Domain of L 1 Yes inputs for L 1 P2P2 P3P3 P1P1 x P 3 (x) Yes/No No inputs for L 1 Yes inputs for L 2 No inputs for L 2 Domain of L 2
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 Domain of L 1 Yes inputsNo inputs Yes inputsNo inputs Domain of L 2
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 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 which shows that L 1 LRP <= L 2 LRP –Give a corresponding program P 3 which computes f Domain of L 1 Yes inputsNo inputs Yes inputsNo inputs Domain of L 2
15
15 Program P 3 string main(string x) { return(x concatenate “0”); }
16
16 Example 2 L 1 is {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 3 which computes f Domain of L 1 Yes inputsNo inputs Yes inputsNo inputs Domain of L 2
17
17 Program P 3 string main(string x) { return( “0”); }
18
18 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
19
19 Detailed Example
20
20 Problem Definitions L 1 is H Input –Program P’ that has one input of type unsigned int –non-negative integer y that is input to program P’ Yes/No Question –Does P’ halt on y? L 2 Input –Program P’’ that has one input of type string Yes/No question –Does Y(P’’) = the set of even length strings?
21
21 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
22
22 Two program roles 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 Q 1, Q 2, and Q 3 code for Q 2 is available to P 3
23
23 Analysis of inputs for L 2 L 2 –Input Program P that has one input of type string –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 Q bool main(string z) {while (1>0) ;} –Q loops on all inputs, so Y(Q) = {} –P 2 rejects program Q as input Consider the following program Q 2 bool main(string z) { if ((z.length %2) == 0) return (yes) else return (no); } –Y(Q 2 ) = set of even length strings –P 2 accepts program Q 2 as input
24
24 Declaration of P 3 What is the return type of P 3 ? –Type program1 (with one input of type string) What are the input parameters of P 3 –The same as the input parameters to P 1 ; in this case, type program2 (with one input of type unsigned int) unsigned int (input type to program2) program1 main(program2 Q 1, unsigned int y) P2P2 P3P3 P1P1 Q 1,y Q3Q3 Yes/No
25
25 program1 main(program2 P, unsigned int y) { /* Will be viewing types program1 and program2 as STRINGS over the program alphabet P */ program1 Q 3 = replace-main-with-Q 1 (P); /* Insert line break */ Q 3 += “\n”; /* Insert Q 2 */ Q 3 += “bool Q 2 (string z) {\n \t if ((z.length % 2) == 0) return (yes) else return (no);\n }”; /* Add main routine of Q 3 */ Q 3 += “bool main(string z) {\n\t”; /* determined by L 2 */ Q 3 += “unsigned int y =” Q 3 += convert-to-string(y); Q 3 += “;\n\t Q 1 (y)\n\t return(Q 2 (z));\n}”; return(Q 3 ); } program1 replace-main-with-Q 1 (program2 P) /* Details hidden */ string convert-to-string(unsigned int y) /* Details hidden */ Code for P 3 P2P2 P3P3 P1P1 Q 1,y Q3Q3 Yes/No
26
26 P 3 in action P2P2 P3P3 P1P1 Q 1,y Q3Q3 Yes/No P 3 code for Q 2 Q1Q1 unsigned int y start Q2Q2 Y/N z Q3Q3 halt Q1Q1 y Program Q 1 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 3 bool Q 1 (unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } bool Q 2 (string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { unsigned int y = 5; Q 1 (y); return (Q 2 (z)); } P3P3 Q2Q2
27
27 Example 1 Idea –Q 3 calls subroutine Q 1 on y to “test” if Q 1 halts on y –Q 3 then calls subroutine Q 2 where Q 2 has the right property for L 2 P2P2 P3P3 P1P1 Q 1,y Q3Q3 Yes/No Input to P 3 Program Q 1 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 3 Program Q 3 bool Q 1 (unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } bool Q 2 (string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { unsigned int y = 5; Q 1 (y); return (Q 2 (z)); }
28
28 Example 2 Idea –Q 3 calls subroutine Q 1 on y to “test” if Q 1 halts on y –Q 3 then calls subroutine Q 2 where Q 2 has the right property for L 2 P2P2 P3P3 P1P1 Q 1,y Q3Q3 Yes/No Input to P 3 Program Q 1 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 3 Program Q 3 bool Q 1 (unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } bool Q 2 (string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { unsigned int y = 3; Q 1 (y); return (Q 2 (z)); }
29
29 If Q 1 loops on y, Y(Q 3 )={ } –Q 3 begins by running Q 1 on y –Suppose Q 1 does NOT halt on y Q 3 never even looks at input z; it just loops –Typically, Y(Q 3 ) = { } means Q 3 is a no input to problem L 2 If Q 1 halts on y, Y(Q 3 ) = Y(Q 2 ) –Note, Q 2 could be ANY program we want –CHOOSE Q 2 such that Q 2 is a yes input to problem L 2 or if Y(Q 3 ) = { } means Q 3 is a yes input to problem L 2, then choose Q 2 such that Q 2 is a no input to problem L 2 Key Observation start Q2Q2 Y/N z Q3Q3 halt Q1Q1 y
30
30 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.