Docsity

Notes on Idea Technique - Computability and Languages | CSE 460, Papers of Computer Science

Toggle sidebar
bg1
1
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 x
• Yes/No Question: Does P halt on x?
– Primality Testing Problem (PTP)
• Input: Program P, unsigned x
• Yes/No Question: Does P output correctly whether
or not x is a prime number?
• Which problem seems harder and why?
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Notes on Idea Technique - Computability and Languages | CSE 460 and more Papers Computer Science in PDF only on Docsity!

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

Primality Testing Problem

• Consider the following two problems

– Halting Problem

  • Input: Program P, unsigned x
  • Yes/No Question: Does P halt on x?

– Primality Testing Problem (PTP)

  • Input: Program P, unsigned 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 P (^) L 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

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

10

Answer-preserving input

transformation P

T

• 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

PT PL

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

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

yes input to H PT no input to L PL 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 inputs

for H

No inputs

for H

Yes inputs

for L

No inputs

for L

Domain of L

PT PL

PH

x (^) PT(x) Yes/No

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

• Notation

H <= L

Domain of H

Yes inputs No inputs

Yes inputs No inputs

Domain of L

19

Program P T

string main(string x)

return(x concatenate “0”);

20

Example 2

• L 1 is the set of all strings over {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 PT which computes f

Domain of L 1

Yes inputs No inputs

Yes inputs No inputs

Domain of L 2

Program P T

string main(string x)

return( “0”);

22

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/do?

Domain of L 1

Yes inputs No inputs

Yes inputs No inputs

Domain of L 2

23

Proving a program behavior

problem L is unsolvable

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 Q (^) L that has one input of type string
  • Yes/No question
    • Does Y(Q (^) L) = the set of even length strings?

• Assume program P L

solves L

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 P L

  • Solves L
  • We don’t know how
    • Consider the following program Q (^) L

with 2 procedures Q 1 and Q YL

bool main(string z) { Q 1 (5); /* ignore return value */ return(QYL(z)); } bool Q 1 (unsigned x) { if (x > 3) return (no); else loop; } bool QYL(string y) { if ((y.length( ) % 2) = = 0) return (yes); else return(no); }

  • What does PL output when given

Q L as input?

29

Input and Output of PT *

• Input of PT

• (Also Input of H)

  • Program Q (^) H
    • one input of type unsigned int
  • Non-negative integer y
    • Program Q (^) L that is the output of PT
    • (Also input of L) bool main(string z) { QH (y); /* QH and y come left-hand side / / ignore return value / return(QYL(z)); } bool QH (unsigned x) { / comes from left-hand side } bool QYL(string y) { if ((y.length( ) % 2) = = 0) return (yes); else return(no); }

Q H,y PT Q L

30

Example 1 *

Input to P (^) T

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

Input y 5

Output of P (^) T

Program Q (^) L bool QH (unsigned y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } bool QYL(string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { unsigned y = 5; QH (y); return (QYL(z)); }

Q H,y PT Q L

31

Example 2

Input to P (^) T

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

Input y 3

Output of P (^) T

Program Q (^) L bool QH (unsigned y) { if (y ==5) return yes; else if (y ==4) return no; else while (1>0) {}; } bool QYL(string z) { if ((z.length % 2) == 0) return (yes) else return (no); } bool main(string z) { unsigned y = 3; QH (y); return (QYL(z)); }

Q H,y PT Q L

32

P T in more detail

Declaration of PT

• What is the return type of PT?

– Type program1 (with one input of type string)

• What are the input parameters of PT?

– The same as the input parameters to H; in this case,

  • type program2 (with one input of type unsigned int)
  • unsigned int (input type to program2)

program1 main(program2 QH , unsigned y)

PT PL

PH

QH,y (^) Q (^) L Yes/No

37

Start with no input for H

• If Q H , y is a no input

to the Halting problem

• Program Q L

bool main(string z) { QH(y); /* ignore return value / return(Q?L(z)); / yes or no? / } bool QH(unsigned x) { / comes from left-hand side } bool Q?L(string y) {

  • Thus Y(Q (^) L) = {}
  • Q (^) H loops on y
  • Determine if this

makes Q L a no or yes

input instance to L

38

Answer-preserving input

transformation

• If Q H , y is a no input

to the Halting problem

  • Thus Y(Q (^) L) = {}
  • Q (^) H loops on y
  • Determine if this

makes Q L a no or yes

input instance to L

• Program Q L

bool main(string z) { QH(y); /* ignore return value / return(QYL(z)); / yes / } bool QH(unsigned x) { / comes from left-hand side } bool QYL(string y) {

  • Now choose a Q (^) YL (or

Q NL) that is a yes (or

no) input instance to L

Make yes for H map to yes for L

• If Q H , y is a no input

to the Halting problem

  • Thus Y(Q (^) L) = {}
  • Q (^) H loops on y
  • Determine if this

makes Q L a no or yes

input instance to L

  • Now choose a Q (^) YL (or

Q NL) that is a yes (or

no) input instance to L

• Program Q L

bool main(string z) { QH(y); /* ignore return value / return(QYL(z)); / yes / } bool QH(unsigned x) { / comes from left-hand side } bool QYL(string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }

40

Possible shortcut

Program Q (^) L bool main(string z) { QH (y); /* ignore return value / if ((z.length( ) % 2) = = 0) return (yes); else return (no); } bool QH (unsigned x) { / comes from left-hand side }

Program Q (^) L bool main(string z) { QH (y); /* ignore return value / return(QYL(z)); / yes / } bool QH (unsigned x) { / comes from left-hand side } bool QYL(string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }

41

Another Example

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 Q (^) L that has one input of type string
  • Yes/No question
    • Is Y(Q (^) L) finite?

• Assume program P L

solves L

46

Analyzing proposed

transformations

4 possibilities

47

Problem Setup

• Input of Transformation

• Program Q H , unsigned x

• Output of Transformation

• Program Q L

bool main(string z) { QH(y); /* ignore return value / return(QYL(z)); / yes or no */ } bool QH(unsigned x) {} bool QYL(string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }

• Problem L

  • Input: Program P
  • Yes/No Question: Is Y(P) = {aa}?

• Question: Is the

transformation on the

left an answer-

preserving or answer-

reversing input

transformation from H

to problem L?

Key Step

• Input of Transformation

• Program Q H , unsigned x

• Output of Transformation

• Program Q L

bool main(string z) { QH(y); /* ignore return value / return(QYL(z)); / yes or no */ } bool QH(unsigned x) {} bool QYL(string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }

• Problem L

  • Input: Program P
  • Yes/No Question: Is Y(P) = {aa}?

• The output of the

transformation is the

input to the problem.

• Plug Q L in for

program P above

• Is Y(Q L) = {aa}?

49

Is Y(QL) = {aa}?

• Problem L

  • Input: Program P
  • Yes/No Question: Is Y(P) = {aa}?
  • Analysis
  • If QH loops on x, Y(Q (^) L)={}
  • No input to H creates a Q (^) L that is a no input for L
  • If QH halts on x, Y(Q (^) L) = {even length strings}
  • Yes input to H creates a Q (^) L that is a no input for L
  • Transformation does not work
  • All inputs map to no inputs

• Input of Transformation

• Program Q H , unsigned x

• Output of Transformation

• Program Q L

bool main(string z) { QH(y); /* ignore return value / return(QYL(z)); / yes or no */ } bool QH(unsigned x) {} bool QYL(string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }

50

Three other problems

• Problem L 1

  • Input: Program P
  • Yes/No Question: Is Y(P) infinite?

• Problem L 2

  • Input: Program P
  • Yes/No Question: Is Y(P) finite?

• Problem L 3

  • Input: Program P
  • Yes/No Question: Is Y(P) = {} or is Y(P) infinite?

• Input of Transformation

• Program Q H , unsigned x

• Output of Transformation

• Program Q L

bool main(string z) { QH(y); /* ignore return value / return(QYL(z)); / yes or no */ } bool QH(unsigned x) {} bool QYL(string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }

Is Y(P) infinite?

• Problem L 1

  • Input: Program P
  • Yes/No Question: Is Y(P) infinite?
  • Analysis
  • If QH loops on x, Y(Q (^) L)={}
  • No input to H creates a Q (^) L that is a no input for L
  • If QH halts on x, Y(Q (^) L) = {even length strings}
  • Yes input to H creates a Q (^) L that is a yes input for L
  • Transformation works
  • Answer-preserving

• Input of Transformation

• Program Q H , unsigned x

• Output of Transformation

• Program Q L

bool main(string z) { QH(y); /* ignore return value / return(QYL(z)); / yes or no */ } bool QH(unsigned x) {} bool QYL(string y) { if ((y.length( ) % 2) = = 0) return (yes); else return (no); }

55

Definitions

• Configuration

  • Functional Definition
    • Given the original program and the current

configuration of a computation, someone should

be able to complete the computation

  • Contents of a configuration for a C++ program
    • current instruction to be executed
    • current value of all variables

• Computation

  • Complete sequence of configurations

56

Computation 1

1 int main(int x,y) { 2 int r = x % y; 3 if (r== 0) goto 8; 4 x = y; 5 y = r; 6 r = x % y; 7 goto 3;

8 return y; }

Input: 10 3

  • Line 1, x=?,y=?,r=?
  • Line 2, x=10, y=3,r=?
  • Line 3, x=10, y=3, r=
  • Line 4, x=10, y=3, r=
  • Line 5, x= 3, y=3, r=
  • Line 6, x=3, y=1, r=
  • Line 7, x=3, y=1, r=
  • Line 3, x=3, y=1, r=
  • Line 8, x=3, y=1, r=
  • Output is 1

Computation 2

int main(int x,y) {

2 int r = x % y;

3 if (r== 0) goto 8;

4 x = y;

5 y = r;

6 r = x % y;

7 goto 3;

8 return y; }

Input: 53 10

  • Line 1, x=?,y=?,r=?
  • Line 2, x=53, y=10, r=?
  • Line 3, x= 53, y=10, r=
  • Line 4, x=53, y=10, r=
  • Line 5, x=10, y=10, r=
  • Line 6, x=10, y=3, r=
  • Line 7, x=10, y=3, r=
  • Line 3, x=10, y=3, r=
  • ...

58

Computations 1 and 2

  • Line 1, x=?,y=?,r=?
  • Line 2, x=53, y=10, r=?
  • Line 3, x= 53, y=10, r=
  • Line 4, x=53, y=10, r=
  • Line 5, x=10, y=10, r=
  • Line 6, x=10, y=3, r=
  • Line 7, x=10, y=3, r=
  • Line 3, x=10, y=3, r=
  • ...
  • Line 1, x=?,y=?,r=?
  • Line 2, x=10, y=3,r=?
  • Line 3, x=10, y=3, r=
  • Line 4, x=10, y=3, r=
  • Line 5, x= 3, y=3, r=
  • Line 6, x=3, y=1, r=
  • Line 7, x=3, y=1, r=
  • Line 3, x=3, y=1, r=
  • Line 8, x=3, y=1, r=
  • Output is 1

59

Observation

int main(int x,y) {

2 int r = x % y;

3 if (r== 0) goto 8;

4 x = y;

5 y = r;

6 r = x % y;

7 goto 3;

8 return y; }

  • Line 3, x= 10, y=3, r=
    • Program and current configuration - Together, these two pieces of information are enough to complete the computation - Are they enough to determine what the original input was? - No! - Both previous inputs, 10 3 as well as 53 10 eventually reached the same configuration (Line 3, x=10, y=3, r=1)

Module 13

• Studying the internal structure of REC, the

set of solvable problems

– Complexity theory overview

– Automata theory preview

• Motivating Problem

– string searching