Top Banner
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
30

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

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 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,

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

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

2

Question 1• What can we conclude from the following

scenario?– We prove/know problem L2 is solvable

– We show that we can construct a program P1 which solves L1 using any program P2 which solves problem L2 as a subroutine.

– We conclude that

• Does this occur in “real-life programming”?

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

3

Question 2• What can we conclude from the following

scenario?– We prove/know problem L1 is not solvable

– We show that we can construct a program P1 which solves L1 using any program P2 which solves problem L2 as a subroutine.

– We conclude that

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

4

Rephrasing key step• We show that we can construct a program P1

which solves L1 using any program P2 which solves problem L2 as a subroutine.

– This can be rephrased in the following 2 ways:

• If L2 is solvable, then L1 is solvable

– Scenario in question 1

• If L1 is not solvable, then L2 is not solvable

– Scenario in question 2

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

5

Illustration of “If L1 is not solvable, then L2 is not solvable”

Set of all languages/problems

RECL1

L2

L2 L1 L1L2

L1 L2

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

6

What we will typically do

Set of all languages/problems

REC

L1L2

If L1 is not solvable, then L2 is not solvable

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

7

Proving “If L2 is solvable, then L1 is solvable”

• Assume L2 is solvable• Let P2 be a program which solves L2

• Construct a program P1 which solves L1 using P2

– We have no idea how P2 solves L2

• We treat P2 as a black box

– L1 and L2 are now SPECIFIC problems

• Thus, we can use properties of L1 and L2 in this construction

• Argue P1 solves L1

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

8

Constructing P1 from P2

• Many ways to construct P1 from P2

• We focus on one method – Construct a program P3 which computes a

function f which I call an answer-preserving input transformation

– P3 (or f) transforms inputs to problem L1 into inputs to problem L2 so that

• yes inputs of L1 map to yes inputs of L2

• no inputs of L1 map to no inputs of L2

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

9

Construction Overview

P1

x Yes/No

•Properties of the construction

•Input x is transformed into a new input P3(x)

•x is an input to program P1 (problem L1)

•P3(x) is an input to program P2 (problem L2)

•We must give actual program P3

•P3 will use specific knowledge about L1 and L2

•We use P2 as a black box routine

P2Y/NP3

P3(x)

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

10

Answer-preserving input transformations in detail

Properties of f and program P3

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

11

Properties of P3 (f)

• P3 must compute an answer-preserving input transformation f:Domain for L1 --> Domain of L2

– For all x in Domain of L1, P3(x) must be defined

• That is P3 must halt with some output P3(x)

– For all x in Domain of L1

• (x is a yes input for L1) iff (P3(x) is a yes input for L2)

• (x is a yes input for L1) --> (P3(x) is a yes input for L2)

• (x is a no input for L1) --> (P3(x) is a no input for L2)

P2P3

P1

x P3(x) Yes/No

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

12

Yes->Yes and No->No

Domain of L1

Yes inputsfor L1

P2P3

P1

x P3(x) Yes/No

No inputsfor L1

Yes inputsfor L2

No inputsfor L2

Domain of L2

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

13

No harder

• If there is such an answer-preserving input transformation f (and the corresponding program P3), we say that L1 is no harder than L2

• Notation– L1<= L2

Domain of L1

Yes inputs No inputs

Yes inputs No inputsDomain of L2

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

14

Example

• L1 is the set of even length strings over {0,1}

– What is the set of all inputs, yes inputs, no inputs for the L1 LRP?

• L2 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 L1 LRP <= L2 LRP

– Give a corresponding program P3 which computes f

Domain of L1

Yes inputs No inputs

Yes inputs No inputsDomain of L2

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

15

Program P3

string main(string x)

{

return(x concatenate “0”);

}

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

16

Example 2

• L1 is {0,1}*

– What is the set of all inputs, yes inputs, no inputs for the L1 LRP?

• L2 is {0}– Same question as above

• Tasks– Give an answer-preserving input transformation f which

shows that the L1 LRP <=L2 LRP

– Give a corresponding program P3 which computes f

Domain of L1

Yes inputs No inputs

Yes inputs No inputsDomain of L2

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

17

Program P3

string main(string x)

{

return( “0”);

}

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

18

Example 3

• L1 – Input: Java program P that takes as input an unsigned int– Yes/No Question: Does P halt on all legal inputs

• L2

– 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 L1 <=L2 would be

Domain of L1

Yes inputs No inputs

Yes inputs No inputsDomain of L2

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

19

Detailed Example

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

20

Problem Definitions

• L1 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?

• L2

• Input– Program P’’ that has

one input of type string

• Yes/No question– Does Y(P’’) = the set

of even length strings?

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

21

Construction overview again

P1

x Yes/No

•We are building a program P1 to solve L1 which, in this case, is the halting problem H

P3P3(x)

•P1 will use P3 as a subroutine, and we must explicitly construct P3 using specific properties of L1 and L2

P2Y/N

•P1 will use P2 as a subroutine, and we have no idea how P2 accomplishes its task

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

22

Two program roles• Programs which are PART of program P1 and

thus “executed” when P1 executes– Program P3, an actual program we construct– Program P2, an assumed program which solves

problem L2

• Programs which are INPUTS/OUTPUTS of programs P1, P2, and P3 and which are not “executed” when P1 executes– Programs Q1, Q2, and Q3

• code for Q2 is available to P3

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

23

Analysis of inputs for L2

• L2

– Input• Program P that has one

input of type string

– Yes/No question• Does Y(P) = the set of

even length strings?

• Program P2

– Solves L2 – We don’t know how

• Consider the following program Qbool main(string z)

{while (1>0) ;}

– Q loops on all inputs, so Y(Q) = {}

– P2 rejects program Q as input

• Consider the following program Q2

bool main(string z)

{ if ((z.length %2) == 0) return (yes)

else return (no); }

– Y(Q2) = set of even length strings

– P2 accepts program Q2 as input

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

24

Declaration of P3

• What is the return type of P3?– Type program1 (with one input of type string)

• What are the input parameters of P3

– The same as the input parameters to P1; in this case,• type program2 (with one input of type unsigned int)• unsigned int (input type to program2)

program1 main(program2 Q1, unsigned int y)

P2P3

P1

Q1,y Q3 Yes/No

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

25

program1 main(program2 P, unsigned int y) {

/* Will be viewing types program1 and program2 as STRINGS over the program alphabet P */

program1 Q3 = replace-main-with-Q1(P);/* Insert line break */

Q3 += “\n”;

/* Insert Q2 */

Q3 += “bool Q2(string z) {\n \t if ((z.length % 2) == 0) return (yes) else return (no);\n }”;

/* Add main routine of Q3 */

Q3 += “bool main(string z) {\n\t”; /* determined by L2 */

Q3 += “unsigned int y =”

Q3 += convert-to-string(y);

Q3 += “;\n\t Q1(y)\n\t return(Q2(z));\n}”;

return(Q3);}

program1 replace-main-with-Q1(program2 P) /* Details hidden */string convert-to-string(unsigned int y) /* Details hidden */

Code for P3P2P3

P1

Q1,y Q3 Yes/No

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

26

P3 in action P2P3

P1

Q1,y Q3 Yes/No

P3

code for Q2

Q1

unsigned int ystart Q2

Y/Nz

Y/N

Q3

haltQ1

y

Program Q1bool main(unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {};}

Input y5

Program Q3bool Q1(unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {};}bool Q2(string z) {

if ((z.length % 2) == 0) return (yes) else return (no);}bool main(string z) { unsigned int y = 5; Q1(y); return (Q2(z));}

P3

Q2

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

27

Example 1

• Idea – Q3 calls subroutine Q1 on y to “test” if Q1 halts on y

– Q3 then calls subroutine Q2 where Q2 has the right property for L2

P2P3

P1

Q1,y Q3 Yes/No

Input to P3

Program Q1bool main(unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {};}

Input y5

Output of P3

Program Q3bool Q1(unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {};}bool Q2(string z) {

if ((z.length % 2) == 0) return (yes) else return (no);}bool main(string z) { unsigned int y = 5; Q1(y); return (Q2(z));}

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

28

Example 2

• Idea – Q3 calls subroutine Q1 on y to “test” if Q1 halts on y

– Q3 then calls subroutine Q2 where Q2 has the right property for L2

P2P3

P1

Q1,y Q3 Yes/No

Input to P3

Program Q1bool main(unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {};}

Input y3

Output of P3

Program Q3bool Q1(unsigned int y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {};}bool Q2(string z) {

if ((z.length % 2) == 0) return (yes) else return (no);}bool main(string z) { unsigned int y = 3; Q1(y); return (Q2(z));}

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

29

• If Q1 loops on y, Y(Q3)={ }

– Q3 begins by running Q1 on y

– Suppose Q1 does NOT halt on y

• Q3 never even looks at input z; it just loops

– Typically, Y(Q3) = { } means Q3 is a no input to problem L2

• If Q1 halts on y, Y(Q3) = Y(Q2)

– Note, Q2 could be ANY program we want

– CHOOSE Q2 such that Q2 is a yes input to problem L2

• or if Y(Q3) = { } means Q3 is a yes input to problem L2, then choose Q2 such that Q2 is a no input to problem L2

Key Observation

start Q2Y/N

zY/N

Q3

haltQ1

y

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

30

Summary

• Answer-preserving input transformations– L1 <= L2

– Construct P1 from P2

• Similarities with closure property constructions– Use P2 as a subroutine

• Differences with closure property constructions– Use specific properties of L1 and L2

– P3 is inside P1 and it maps inputs of L1 to inputs of L2

– Often have programs as inputs and outputs