Download presentation

Presentation is loading. Please wait.

1
1 Lecture 10 Proving more specific problems are not recursive Reduction 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 language L 2 is recursive –We show that we can construct a program P 1 which decides L 1 using any program P 2 which decides language 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 language L 1 is not recursive –We show that we can construct a program P 1 which decides L 1 using any program P 2 which decides language L 2 as a subroutine. –We conclude that

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

5
5 Illustration of “If L 1 is not recursive, then L 2 is not recursive” 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 recursive, then L 2 is not recursive

7
7 Proving “If L 2 is recursive, then L 1 is recursive” Assume L 2 is recursive Let P 2 be a program which decides L 2 Construct a program P 1 which decides L 1 using P 2 [subroutine theme] –We have no idea how P 2 decides L 2 We still 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 decides 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 we call a many-one reduction –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 Many-one Reductions in Detail Properties of f and program P 3

11
11 Properties of P 3 (f) P 3 must compute a many-one reduction function 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 Many-one Reduction If there is such a many-one reduction function f (and the corresponding program P 3 ), we say that L 1 many-one reduces to L 2 Notation –L 1 b m L 2 – b denotes L 1 is no harder than L 2 ** L1L1 L1L1 ** L2L2 L2L2

14
14 Example L 1 is even length strings over {0,1} L 2 is odd length strings over {0,1} Tasks –Give a reduction function f which shows that L 1 b m L 2 –Give a corresponding program P 3 which computes f ** L1L1 L1L1 ** L2L2 L2L2

15
15 Example 2 L 1 is {0,1} * L 2 is {0} Tasks –Give a reduction function f which shows that L 1 b m 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 L(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’’’

20
20 Analysis of L 2 L 2 –Input Program P’’ –Yes/No question Does L(P’’) = the set of even length strings? Program P 2 –Solves L 2 –We don’t know how Consider a program P such that L(P) = {} –P 2 rejects program P as input Consider the following program P’’ –If input z has even length then yes else no –L(P’’) = set of even length strings –P 2 accepts program P’’ as input

21
21 Specifying P 3 Remember, we are solving H (L 1 ), not L 2 Input x to P 3 is an input to H –Program P’ –Input string y to program P’ Output P 3 (x) of P 3 is an input to problem L 2 –Program P’’’ Specification for P 3 –P’’’ = P 3 (x) = P 3 (P’,y) –L(P’’’) = L(P’’) = set of even length strings iff P’ halts on y P2P2 P3P3 P1P1 x P 3 (x) Yes/No

22
22 How does P 3 work? Key –P 3 creates P’’’ by modifying program P’ to run y to “test” if P’ halts on y –P 3 then appends a program P’’ where P’’ has the right property Example P2P2 P3P3 P1P1 P’,y P’’’ Yes/No Input to P 3 Program P’ Variables Integer array A[10] Integer max,i; Instructions read input string into array A; max = A[0]; for (i=1;i<10;i++) IF A[i] > max THEN max = A[i]; return max; Input y 0;1;5;3;2;7;5;8;2;10 Output of P 3 Program P’’’ Variables Integer array A[10] Integer max,i; Instructions Initialize A to contain y; max = A[0]; for (i=1;i<10;i++) IF A[i] > max THEN max = A[i]; return max; If input z has even length THEN yes ELSE no

23
23 Specification for program P’’’ –L(P’’’) = even length strings if and only if P’ halts on y –In actuality If P’ halts on y, L(P’’’) = L(P’’) = set of even length strings If P’ does not halt on y, P’’’ will loop on all strings –Thus L(P’’’) = {} Program P’’’ P2P2 P3P3 P1P1 P’,y P’’’ Yes/No /* Run P’’ on z */ If (z has even length) THEN yes ELSE no start P’’ Y/N z P’’’ Program P’’’ Let z denote the input string to P’’’ halt P’ y Run P’ on y

24
24 If P’ loops on y, L(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, L(P’’’) = { } means P’’’ is a no input to problem L 2 If P’ halts on y, L(P’’’) = L(P’’) –Note, P’’ could be ANY program we want –CHOOSE P’’ such that P’’ is a yes input to problem L 2 or if L(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 Step start P’’ Y/N z P’’’ halt P’ y

25
25 P 3 illustrated P2P2 P3P3 P1P1 P’,y P’’’ Yes/No Program P’ Variables Integer array A[10] Integer max,i; Instructions read input string into array A; max = A[0]; for (i=1;i<10;i++) IF A[i] > max THEN max = A[i]; return max; Input y 0;1;5;3;2;7;5;8;2;10 Program P’’’ Variables Integer array A[10] Integer max,i; Instructions Initialize A to contain y; max = A[0]; for (i=1;i<10;i++) IF A[i] > max THEN max = A[i]; return max; If input z has even length THEN yes ELSE no P3P3 P’ string y P3P3 start P’’ Y/N z P’’’ halt P’ y

26
26 Pseudocode for P 3 –Make P’ a procedure of P’’’ –Make the first line of the main procedure for P’’’ a call to P’ with y as the input P’(y) Ignore what P’ returns; only interested if P’ halts on y –Make P’’ a procedure of P’’’ –Make the second line of the main procedure for P’’’ a call to P’’ with the input z to P’’’ as the input P’’(z) Note P’’’ will return what P’’(z) returns P 3 in more detail P2P2 P3P3 P1P1 P’,y P’’’ Yes/No

27
27 Summary Many-one Reductions –L 1 b m 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

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google