Theory of Computation Course note based on Computability, Complexity, - - PowerPoint PPT Presentation

theory of computation
SMART_READER_LITE
LIVE PREVIEW

Theory of Computation Course note based on Computability, Complexity, - - PowerPoint PPT Presentation

A Universal Program (4) Theory of Computation Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science , 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker. course note


slide-1
SLIDE 1

A Universal Program (4)

Theory of Computation

Course note based on Computability, Complexity, and Languages: Fundamentals of Theoretical Computer Science, 2nd edition, authored by Martin Davis, Ron Sigal, and Elaine J. Weyuker.

course note prepared by Tyng–Ruey Chuang

Institute of Information Science, Academia Sinica Department of Information Management, National Taiwan University

Week 5, Spring 2010

1 / 19

slide-2
SLIDE 2

A Universal Program (4)

About This Course Note

◮ It is prepared for the course Theory of Computation taught at

the National Taiwan University in Spring 2010.

◮ It follows very closely the book Computability, Complexity,

and Languages: Fundamentals of Theoretical Computer Science, 2nd edition, by Martin Davis, Ron Sigal, and Elaine

  • J. Weyuker. Morgan Kaufmann Publishers. ISBN:

0-12-206382-1.

◮ It is available from Tyng-Ruey Chuang’s web site:

http://www.iis.sinica.edu.tw/~trc/ and released under a Creative Commons “Attribution-ShareAlike 3.0 Taiwan” license: http://creativecommons.org/licenses/by-sa/3.0/tw/

2 / 19

slide-3
SLIDE 3

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

The Stepping Function STP

A simple modification of the program Un would enable us to prove that following predicate is computable: STP(x1, . . . , xn, y, t) ⇔ Program number y halts after t or fewer steps on inputs x1, . . . , xn ⇔ There is a computation of program y

  • f length ≤ t + 1, beginning with

inputs x1, . . . , xn We simply need to add a counter to determine when we have simulated t steps. However, we can prove a stronger result.

3 / 19

slide-4
SLIDE 4

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Function STP is Primitive Recursive

Theorem 3.2. For each n > 0, the predicate STP(n)(x1, . . . , xn, y, t) is primitive recursive. ✷ The idea is to provide numeric versions of the notations of snapshot and successor of snapshot, and to show that the necessary functions are primitive recursive. We first define the following functions for extracting the components of the ith instruction of program number y: LABEL(i, y) = l((y + 1)i) VAR(i, y) = r(r((y + 1)i)) + 1 INSTR(i, y) = l(r((y + 1)i)) LABEL′(i, y) = l(r((y + 1)i)) ˙ −2

4 / 19

slide-5
SLIDE 5

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Function STP is Primitive Recursive, Continued

Next we define some predicates that indicate, for program y and the snapshot represented by x = i, s, where i is the number of the instruction to be executed and s the current state (i.e., variable S in Un), what kind of action is to be performed next. SKIP(x, y) ⇔ [INSTR(l(x), y) = 0 & l(x) ≤ Lt(y + 1)] ∨ [INSTR(l(x), y) ≥ 2 & ∼ (pVAR(l(x),y)|r(x))] INCR(x, y) ⇔ INSTR(l(x), y) = 1 DECR(x, y) ⇔ INSTR(l(x), y) = 2 & pVAR(l(x),y)|r(x) BRANCH(x, y) ⇔ INSTR(l(x), y) > 2 & pVAR(l(x),y)|r(x) & (∃i)≤Lt(y+1)LABEL(i, y) = LABEL′(l(x), y)

5 / 19

slide-6
SLIDE 6

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Function STP is Primitive Recursive, Continued

Now we can define SUCC(x, y), which for program number y, computes the successor to the snapshot represented by x.

SUCC(x, y) =            l(x) + 1, r(x) if SKIP(x, y) l(x) + 1, r(x) · pVAR(l(x),y) if INCR(x, y) l(x) + 1, r(x)/pVAR(l(x),y) if DECR(x, y) mini≤Lt(y+1)[LABEL(i, y) = LABEL′(l(x), y)], r(x) if BRANCH(x, y) Lt(y + 1) + 1, r(x)

  • therwise.

6 / 19

slide-7
SLIDE 7

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Function STP is Primitive Recursive, Continued

We also need INIT(n)(x1, . . . , xn) = 1,

n

  • i=1

(p2i)xi which gives the representation of the initial snapshot for input x1, . . . , xn, and TERM(x, y) ⇔ l(x) > Lt(y + 1) which tests whether x represents a terminal snapshot for program y.

7 / 19

slide-8
SLIDE 8

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Function STP is Primitive Recursive, Continued

Putting these together we can define a primitive recursive function that gives the numbers of the successive snapshots produced by a given program: SNAP(n)(x1, . . . , xn, y, 0) = INIT(n)(X1, . . . , xn) SNAP(n)(x1, . . . , xn, y, i + 1) = SUCC(SNAP(n)(x1, . . . , xn, y, i), y) Thus, STP(n)(x1, . . . , xn, y, t) ⇔ TERM(SNAP(n)(x1, . . . , xn, y, t), y) It is clear that STP(n)(x1, . . . , xn, y, t) is primitive recursive. ✷

8 / 19

slide-9
SLIDE 9

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

A Normal Form for Partial Computable Functions

Theorem 3.3. Let f (x1, . . . , xn) be a partially computable

  • function. Then there is a primitive recursive predicate

R(x1, . . . , xn, y) such that f (x1, . . . , xn) = l(min

z

R(x1, . . . , xn, z)) ✷

  • Proof. Let y0 be the number of a program that computes

f (x1, . . . , xn). Let R(x1, . . . , xn, z) be the following predicate STP(n)(x1, . . . , xn, y0, r(z)) & (r(SNAP(n)(x1, . . . , xn, y0, r(z))))1 = l(z)

9 / 19

slide-10
SLIDE 10

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

A Normal Form for Partial Computable Functions

Theorem 3.3. Let f (x1, . . . , xn) be a partially computable

  • function. Then there is a primitive recursive predicate

R(x1, . . . , xn, y) such that f (x1, . . . , xn) = l(min

z

R(x1, . . . , xn, z)) ✷

  • Proof. Let y0 be the number of a program that computes

f (x1, . . . , xn). Let R(x1, . . . , xn, z) be the following predicate STP(n)(x1, . . . , xn, y0, r(z)) & (r(SNAP(n)(x1, . . . , xn, y0, r(z))))1 = l(z) If the above predicate is defined, then for any such z, the computation by program y0 terminates in r(z) or few steps, and l(z) is the value held in the output variable Y .

9 / 19

slide-11
SLIDE 11

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

A Normal Form for Partial Computable Functions

Theorem 3.3. Let f (x1, . . . , xn) be a partially computable

  • function. Then there is a primitive recursive predicate

R(x1, . . . , xn, y) such that f (x1, . . . , xn) = l(min

z

R(x1, . . . , xn, z)) ✷

  • Proof. Let y0 be the number of a program that computes

f (x1, . . . , xn). Let R(x1, . . . , xn, z) be the following predicate STP(n)(x1, . . . , xn, y0, r(z)) & (r(SNAP(n)(x1, . . . , xn, y0, r(z))))1 = l(z) If the above predicate is defined, then for any such z, the computation by program y0 terminates in r(z) or few steps, and l(z) is the value held in the output variable Y . If on the other hand, the predicate is undefined, then STP(n)(x1, . . . , xn, y0, t) must be false for all t. That is, f (x1, . . . , xn) ↑. ✷

9 / 19

slide-12
SLIDE 12

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

A Characterization of Partially Computable Functions

Theorem 3.4. A function is partially computable if and only if it can be obtained from the initial functions by a finite number of applications of composition, recursion, and minimalization. ✷

10 / 19

slide-13
SLIDE 13

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

A Characterization of Partially Computable Functions

Theorem 3.4. A function is partially computable if and only if it can be obtained from the initial functions by a finite number of applications of composition, recursion, and minimalization. ✷

  • Proof. (⇐) That every function which can be so obtained is

partially computable is a consequence of Theorems 1.1, 2.1, 2,2, 3.1, and 7.2 in Chapter 3. That is, there is a program in S for the function so obtained.

10 / 19

slide-14
SLIDE 14

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

A Characterization of Partially Computable Functions

Theorem 3.4. A function is partially computable if and only if it can be obtained from the initial functions by a finite number of applications of composition, recursion, and minimalization. ✷

  • Proof. (⇐) That every function which can be so obtained is

partially computable is a consequence of Theorems 1.1, 2.1, 2,2, 3.1, and 7.2 in Chapter 3. That is, there is a program in S for the function so obtained. (⇒) Given a partially computable function — a program in language S — Theorem 3.3 in this Chapter show how to express this function in the form l(min

z

R(x1, . . . , xn, z)) where R is a primitive recursive predicate. Finally, R is used in a minimalization and then composed with the primitive recursive function l. ✷

10 / 19

slide-15
SLIDE 15

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

A Characterization of Computable Functions

When minz R(x1, . . . , xn, z) is a total function, we say that we are applying the operation of proper minimalization to R. Now, if l(min

z

R(x1, . . . , xn, z)) is total, then R(x1, . . . , xn, z) must be total too. Hence we have: Theorem 3.5. A function is computable if and only if it can be

  • btained from the initial functions by a finite number of

applications of composition, recursion, and proper minimalization. ✷

11 / 19

slide-16
SLIDE 16

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Review: Sets and Characteristic Functions

Given a predicate P on a set S, there is a corresponding subset R

  • f S consisting of all elements a ∈ S for which P(a) = 1. We write

R = {a ∈ S | P(a)}.

12 / 19

slide-17
SLIDE 17

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Review: Sets and Characteristic Functions

Given a predicate P on a set S, there is a corresponding subset R

  • f S consisting of all elements a ∈ S for which P(a) = 1. We write

R = {a ∈ S | P(a)}. Conversely, given a subset R of a given set S, the expression x ∈ R defines a predicate P on S: P(x) = 1 if x ∈ R if x ∈ R. The predicate P is called the characteristic function of the set R.

12 / 19

slide-18
SLIDE 18

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Review: Sets and Characteristic Functions

Given a predicate P on a set S, there is a corresponding subset R

  • f S consisting of all elements a ∈ S for which P(a) = 1. We write

R = {a ∈ S | P(a)}. Conversely, given a subset R of a given set S, the expression x ∈ R defines a predicate P on S: P(x) = 1 if x ∈ R if x ∈ R. The predicate P is called the characteristic function of the set R. Note the easy translations between the two notations: {x ∈ S | P(x) & Q(x)} = {x ∈ S | P(x)} ∩ {x ∈ S | Q(x)}, {x ∈ S | P(x) ∨ Q(x)} = {x ∈ S | P(x)} ∪ {x ∈ S | Q(x)}, {x ∈ S | ∼ P(x)} = S − {x ∈ S | P(x)}.

12 / 19

slide-19
SLIDE 19

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Sets and Classes of Functions

◮ The predicate HALT(x, y) is the characteristic function of the

set {(x, y) ∈ N2 | HALT(x, y)}.

◮ A set B ⊆ Nm is said to belong to some class of functions

means that the characteristic function P(x1, . . . , xn) of B belongs to the class in question.

◮ B is computable or recursive is just to say that P(x1, . . . .xn)

is a computable function.

◮ B is a primitive recursive set if P(x1, . . . .xn) is primitive

recursive.

13 / 19

slide-20
SLIDE 20

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Sets and Classes of Functions

◮ The predicate HALT(x, y) is the characteristic function of the

set {(x, y) ∈ N2 | HALT(x, y)}.

◮ A set B ⊆ Nm is said to belong to some class of functions

means that the characteristic function P(x1, . . . , xn) of B belongs to the class in question.

◮ B is computable or recursive is just to say that P(x1, . . . .xn)

is a computable function.

◮ B is a primitive recursive set if P(x1, . . . .xn) is primitive

recursive. Theorem 4.1. Let the sets B, C belong to some PRC class C . The so do the sets B ∪ C, B ∩ C, and ¯ B. ✷

13 / 19

slide-21
SLIDE 21

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Need Only Consider Subsets of N

Theorem 4.2. Let C be a PRC class, and let B be a subset of Nm, m ≥ 1. Then B belongs to C if and only if B′ = {[x1, . . . , xm] ∈ N | (x1, . . . , xm) ∈ B} belongs to C . ✷.

  • Proof. If PB(x1, . . . , xm) is the characteristic function of B, then

PB′(x) ⇔ PB((x)1, . . . , (x)m) & Lt(x) ≤ m & x > 0 is the characteristic function of B′. Clearly, PB′ belongs to C if PB belongs to C . On the other hand, if PB′(x) is the characteristic function of B′, then PB(x1, . . . , xm) ⇔ PB′([x1, . . . , xm]) is the characteristic function of B. Clearly, PB belongs to C if PB′ belongs to C . ✷

14 / 19

slide-22
SLIDE 22

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Recursively Enumerable

  • Definition. The set B ⊆ N is called recursively enumerable if

there is a partially computable function g(x) such that B = {x ∈ N | g(x) ↓}. ✷

15 / 19

slide-23
SLIDE 23

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Recursively Enumerable

  • Definition. The set B ⊆ N is called recursively enumerable if

there is a partially computable function g(x) such that B = {x ∈ N | g(x) ↓}. ✷

◮ A set is recursively enumerable just when it is the domain of a

partially computable function.

15 / 19

slide-24
SLIDE 24

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Recursively Enumerable

  • Definition. The set B ⊆ N is called recursively enumerable if

there is a partially computable function g(x) such that B = {x ∈ N | g(x) ↓}. ✷

◮ A set is recursively enumerable just when it is the domain of a

partially computable function.

◮ If P is a program that computes function g above, then B is

the set of all input to P for which P eventually halts.

15 / 19

slide-25
SLIDE 25

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Recursively Enumerable

  • Definition. The set B ⊆ N is called recursively enumerable if

there is a partially computable function g(x) such that B = {x ∈ N | g(x) ↓}. ✷

◮ A set is recursively enumerable just when it is the domain of a

partially computable function.

◮ If P is a program that computes function g above, then B is

the set of all input to P for which P eventually halts.

◮ B can be thought of intuitively as a set for which there exists

a semi-decision procedure to solve the membership problem of

  • B. This algorithm answers “yes” for number n ∈ B, but never

terminates for n ∈ B.

15 / 19

slide-26
SLIDE 26

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Recursively Enumerable

  • Definition. The set B ⊆ N is called recursively enumerable if

there is a partially computable function g(x) such that B = {x ∈ N | g(x) ↓}. ✷

◮ A set is recursively enumerable just when it is the domain of a

partially computable function.

◮ If P is a program that computes function g above, then B is

the set of all input to P for which P eventually halts.

◮ B can be thought of intuitively as a set for which there exists

a semi-decision procedure to solve the membership problem of

  • B. This algorithm answers “yes” for number n ∈ B, but never

terminates for n ∈ B.

◮ The term recursively enumerable is usually abbreviated r.e.

15 / 19

slide-27
SLIDE 27

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

Recursive Sets

Theorem 4.3. If B is a recursive set, then B is r.e.

  • Proof. Consider the following program P

[A] IF ∼ (X ∈ B) GOTO A Since B is recursive, the predicate x ∈ B is computable and P can be expanded to a program of S . Let P computes the function h(x). Then, clearly, B = {x ∈ N | h(x) ↓}. ✷

16 / 19

slide-28
SLIDE 28

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

What If Both B and ¯ B Are r.e.?

Theorem 4.4. The set B is recursive if and only if B and ¯ B are both r.e.

17 / 19

slide-29
SLIDE 29

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

What If Both B and ¯ B Are r.e.?

Theorem 4.4. The set B is recursive if and only if B and ¯ B are both r.e.

  • Proof. (⇒) If B is recursive, then by Theorem 4.1 so is ¯
  • B. By

Theorem 4.3, they are both r.e.

17 / 19

slide-30
SLIDE 30

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

What If Both B and ¯ B Are r.e.?

Theorem 4.4. The set B is recursive if and only if B and ¯ B are both r.e.

  • Proof. (⇒) If B is recursive, then by Theorem 4.1 so is ¯
  • B. By

Theorem 4.3, they are both r.e. (⇐) If both B and ¯ B are r.e., then there are programs P and Q such that B = {x ∈ N | Ψ(1)

P (x) ↓}

¯ B = {x ∈ N | Ψ(1)

Q (x) ↓}

17 / 19

slide-31
SLIDE 31

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

What If Both B and ¯ B Are r.e.?

Theorem 4.4. The set B is recursive if and only if B and ¯ B are both r.e.

  • Proof. (⇒) If B is recursive, then by Theorem 4.1 so is ¯
  • B. By

Theorem 4.3, they are both r.e. (⇐) If both B and ¯ B are r.e., then there are programs P and Q such that B = {x ∈ N | Ψ(1)

P (x) ↓}

¯ B = {x ∈ N | Ψ(1)

Q (x) ↓}

Then B is recursive as it is computed by the following program: [A] IF STP(1)(X, #(P), T) GOTO C IF STP(1)(X, #(Q), T) GOTO E T ← T + 1 GOTO A [C] Y ← 1 ✷ 17 / 19

slide-32
SLIDE 32

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

The Intersection of Two r.e. Sets

Theorem 4.5. If B and C are r.e. sets so are B ∩ C and B ∪ C.

18 / 19

slide-33
SLIDE 33

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

The Intersection of Two r.e. Sets

Theorem 4.5. If B and C are r.e. sets so are B ∩ C and B ∪ C.

  • Proof. Let

B = {x ∈ N | g(x) ↓} C = {x ∈ N | h(x) ↓} where g and h are partially computable. Let f (x) be the function computed by the program Y ← g(X) Y ← h(X) Hence B ∩ C = {x ∈ N | f (x) ↓} hence B ∩ C is r.e.

18 / 19

slide-34
SLIDE 34

A Universal Program (4) Universality (4.3) Recursively Enumerable Sets (4.4)

The Union of Two r.e. Sets

  • Proof. (Continued) Let g and h be computed by programs P and

Q, respectively. Let k(x) be the function computed by the program: [A] IF STP(1)(X, #(P), T) GOTO E IF STP(1)(X, #(Q), T) GOTO E T ← T + 1 GOTO A Then k(x) is defined just in case either g(x) or h(x) is defined. That is, B ∪ C = {x ∈ N | k(x) ↓} so that B ∪ C is also r.e. ✷

19 / 19