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
50
Embed
1 Module 11 Proving more specific problems are not solvable Input transformation technique –Use subroutine theme to show that if one problem is unsolvable,
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
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
Basic Idea/Technique
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
Question *
• Suppose we construct a program PH which solves the Halting problem H under the following conditions– All of PH is known to be correct with the
exception of one procedure PL.
– This procedure PL is being used to solve the Primality Testing Problem.
• What can we conclude in this scenario?
5
Formalizing Technique
• Assume PL is a procedure that solves problem L– We have no idea how PL solves L
• Construct a program PH that solves H using PL as a subroutine– We use PL as a black box– (We could use any unsolvable problem in place of H)
• Argue PH solves H• Conclude that L is unsolvable
– Otherwise PL would exist and then H would be solvable– L will be a problem about program behavior
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
Constructing PH using PL
Answer-preserving input transformations and Program PT
8
PH has two subroutines
• There are many ways to construct PH using program PL that solves L
• We focus on one method in which PH consists of two subroutines– Procedure PL that solves L– Procedure PT which computes a function f that I
call an answer-preserving (or answer-reversing) input transformation
• More about this in a moment
9
Pictoral Representation of PH *
PH
x Yes/NoPLY/NPT
PT(x)
10
Answer-preserving input transformation PT
• 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, PT must not loop when given any legal input to H
11
Why this works *
PH
PLPT
yes input to H yes input to L yes
no input to H no input to L no
We have assumed that PL solves L
12
Answer-reversing input transformation PT
• 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, PT must not loop when given any legal input to H
13
Why this works *
PH
PLPT
yes input to H no input to L yes
no input to H yes input to L no
We have assumed that PL solves L
no
yes
14
Yes->Yes and No->No
Domain of H
Yes inputsfor H
No inputsfor H
Yes inputsfor L
No inputsfor L
Domain of L
PLPT
PH
x PT(x) Yes/No
15
Notation and Terminology
• If there is such an answer-preserving (or answer-reversing) input transformation f (and the corresponding program PT), we say that H transforms to (many-one reduces to) L
• NotationH <= L
Domain of H
Yes inputs No inputs
Yes inputs No inputsDomain of L
16
Examples not involving the Halting Problem
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
Example 1 *
• L1 is the set of even length strings over {0,1}– What are the set of legal input instances and 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 that
shows that L1 LRP <= L2 LRP
– Give a corresponding program PT that computes f
Domain of L1
Yes inputs No inputs
Yes inputs No inputsDomain of L2
19
Program PT
string main(string x)
{
return(x concatenate “0”);
}
20
Example 2 *
• L1 is the set of all strings over {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 PT which computes f
Domain of L1
Yes inputs No inputs
Yes inputs No inputsDomain of L2
21
Program PT
string main(string x)
{
return( “0”);
}
22
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
23
Proving a program behavior problem L is unsolvable
24
Problem Definitions *
• Halting Problem H– Input
• Program QH that has one input of type unsigned int
• non-negative integer y that is input to program QH
– Yes/No Question• Does QH halt on y?
• Target Problem L– Input
• Program QL that has one input of type string
– Yes/No question• Does Y(QL) = the set of
even length strings?
• Assume program PL solves L
25
Construction review
PH
x Yes/No
•We are building a program PH to solve the halting problem H
PTPT(x)
•PH will use PT as a subroutine, and we must explicitly construct PT using specific properties of H and L
PLY/N
•PH will use PL as a subroutine, and we have no idea how PL accomplishes its task
26
P’s and Q’s• Programs which are PART of program PH and
thus “executed” when PH executes– Program PT, an actual program we construct– Program PL, an assumed program which solves
problem L
• Programs which are INPUTS/OUTPUTS of programs PH, PL, and PT and which are not “executed” when PH executes– Programs QH, QL, and QYL
• code for QYL is available to PT
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 PL
– Solves L– We don’t know how
• Consider the following program Q1
bool main(string z)
{while (1>0) ;}
– What does PL output when given Q1 as input?
• Consider the following program Q2
bool main(string z)
{ if ((z.length %2) = = 0) return (yes)
else return (no); }
– What does PL output when given Q2 as input?
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 PL
– Solves L– We don’t know how
• Consider the following program QL with 2 procedures Q1 and QYL