Advanced Topics in Theoretical Computer Science Part 2: Register - - PowerPoint PPT Presentation

advanced topics in theoretical computer science
SMART_READER_LITE
LIVE PREVIEW

Advanced Topics in Theoretical Computer Science Part 2: Register - - PowerPoint PPT Presentation

Advanced Topics in Theoretical Computer Science Part 2: Register machines (3) 21.11.2013 Viorica Sofronie-Stokkermans Universit at Koblenz-Landau e-mail: sofronie@uni-koblenz.de Wintersemester 2013-2014 1 Contents Recapitulation:


slide-1
SLIDE 1

Advanced Topics in Theoretical Computer Science

Part 2: Register machines (3) 21.11.2013 Viorica Sofronie-Stokkermans Universit¨ at Koblenz-Landau e-mail: sofronie@uni-koblenz.de Wintersemester 2013-2014

1

slide-2
SLIDE 2

Contents

  • Recapitulation: Turing machines and Turing computability
  • Register machines (LOOP, WHILE, GOTO)
  • Recursive functions
  • The Church-Turing Thesis
  • Computability and (Un-)decidability
  • Complexity
  • Other computation models: e.g. B¨

uchi Automata, λ-calculus

2

slide-3
SLIDE 3
  • 2. Register Machines
  • Register machines (Random access machines)
  • LOOP Programs
  • WHILE Programs
  • GOTO Programs
  • Relationships between LOOP, WHILE, GOTO
  • Relationships between register machines and Turing machines

3

slide-4
SLIDE 4

Until now

  • Register machines (definition; state; input/output; semantics)

Computed function Computable functions (LOOP, WHILE, GOTO, TM)

  • LOOP Programs (syntax, semantics)

Every LOOP program terminates for every input All LOOP computable functions are total Additional instructions

  • WHILE Programs (syntax, semantics)

WHILE programs do not always terminate WHILE computable functions can be undefined for some inputs

  • GOTO Programs (syntax, semantics)

GOTO programs do not always terminate

4

slide-5
SLIDE 5

LOOP Programs: Syntax

Definition

  • Atomic programs: For each register xi:

– xi := xi + 1 – xi := xi − 1 are LOOP instructions and also LOOP programs.

  • If P1, P2 are LOOP programs then

– P1; P2 is a LOOP program

  • If P is a LOOP program then

– loop xi do P end is a LOOP program (and a LOOP instruction)

5

slide-6
SLIDE 6

LOOP Programs: Semantics

Definition (Semantics of LOOP programs) Let P be a LOOP program. ∆(P) is inductively defined as follows: (1) On atomic programs: ∆(xi := xi ± 1)(s1, s2) iff:

  • s2(xi) = s1(xi) ± 1
  • s2(xj) = s1(xj) for all j = i

(2) Sequential composition: ∆(P1; P2)(s1, s2) iff there exists s′ s.t.:

  • ∆(P1)(s1, s′)
  • ∆(P2)(s′, s2)

(3) Loop programs: ∆(loop xi do P end)(s1, s2) iff there exist states s′

0, s′ 1, . . . , s′ n with:

  • s1(xi) = n
  • s1 = s′
  • s2 = s′

n

  • ∆(P)(s′

k, s′ k+1) for 0 ≤ k < n 6

slide-7
SLIDE 7

WHILE Programs: Syntax

Definition

  • Atomic programs: For each register xi:

– xi := xi + 1 – xi := xi − 1 are WHILE instructions and also WHILE programs.

  • If P1, P2 are WHILE programs then

– P1; P2 is a WHILE program

  • If P is a WHILE program then

– while xi = 0 do P end is a WHILE program (and a WHILE instruction)

7

slide-8
SLIDE 8

WHILE Programs: Semantics

Definition (Semantics of WHILE programs) Let P be a WHILE program. ∆(P) is inductively defined as follows: (1) On atomic programs: ∆(xi := xi ± 1)(s1, s2) iff:

  • s2(xi) = s1(xi) ± 1
  • s2(xj) = s1(xj) for all j = i

(2) Sequential composition: ∆(P1; P2)(s1, s2) iff there exists s′ s.t.:

  • ∆(P1)(s1, s′)
  • ∆(P2)(s′, s2)

(3) While programs: ∆(while xi = 0 do P end)(s1, s2) iff there exists n ∈ N and there exist states s′

0, s′ 1, . . . , s′ n with:

  • s1 = s′
  • s2 = s′

n

  • ∆(P)(s′

k, s′ k+1) for 0 ≤ k < n

  • s′

k(xi) = 0 for 0 ≤ k < n

  • s′

n(xi) = 0 8

slide-9
SLIDE 9

GOTO Programs: Syntax

Indices (numbers for the lines in the program) j ≥ 0 Definition

  • Atomic programs:

– xi := xi + 1 – xi := xi − 1 are GOTO instructions for each register xi.

  • If xi is a register and j is an index then

– if xi = 0 goto j is a GOTO instruction.

  • If I1, . . . , Ik are GOTO instructions and j1, . . . , jk are indices then

– j1 : I1; . . . ; jk : Ik is a GOTO program

9

slide-10
SLIDE 10

GOTO Programs: Semantics

Let P be a GOTO program of the form: P = j1 : I1; j2 : I2; . . . ; jk : Ik Let jk+1 be an index which does not occur in P (program end). Definition ∆(P)(s1, s2) holds iff for every n ≥ 0 there exist states s′

0, . . . , s′ n and indices

z0, . . . , zn s.t.:

  • s′

0 = s1, s′ n = s2; z0 = j1, zn = jk+1.

  • For 0 ≤ l ≤ n, if js : Is is the line in P with js = zl:

if Is = xi := xi ± 1 then: s′

i+1(xi) = s′ i (xi) ± 1

s′

i+1(xj) = s′ i (xj) for j = i

zi+1 = js+1 if Is = if xi = 0 goto jgoto then: s′

i+1 = s′ i

zi+1 =

  • jgoto

if xi = 0 js+1

  • therwise

10

slide-11
SLIDE 11

Register Machines

Definition A register machine is a machine consisting of the following elements:

  • A finite (but unbounded) number of registers x1, x2, x3 . . . , xn;

each register contains a natural number.

  • A LOOP-, WHILE- or GOTO-program.

11

slide-12
SLIDE 12

Register Machines: Computable function

  • Definition. A function f is
  • LOOP computable if there exists a register machine with a LOOP

program, which computes f

  • WHILE computable if there exists a register machine with a WHILE

program, which computes f

  • GOTO computable if there exists a register machine with a GOTO

program, which computes f

  • TM computableif there exists a Turing machine which computes f

12

slide-13
SLIDE 13

Computable functions

LOOP = Set of all LOOP computable functions WHILE = Set of all total WHILE computable functions WHILEpart = Set of all WHILE computable functions (including the partial ones) GOTO = Set of all total GOTO computable functions GOTOpart = Set of all GOTO computable functions (including the partial ones) TM = Set of all total TM computable functions TMpart = Set of all TM computable functions (including the partial ones)

13

slide-14
SLIDE 14

Relationships between LOOP, WHILE, GOTO

  • Theorem. LOOP ⊆ WHILE (every LOOP computable function is WHILE computable)

14

slide-15
SLIDE 15

WHILE and GOTO

Theorem. (1) WHILE = GOTO (2) WHILEpart = GOTOpart

15

slide-16
SLIDE 16

WHILE and GOTO

Theorem. (1) WHILE = GOTO (2) WHILEpart = GOTOpart Proof: To show:

  • I. WHILE ⊆ GOTO and WHILEpart ⊆ GOTOpart
  • II. GOTO ⊆ WHILE and GOTOpart ⊆ WHILEpart

16

slide-17
SLIDE 17

WHILE and GOTO

Theorem. (1) WHILE = GOTO (2) WHILEpart = GOTOpart Proof:

  • I. WHILE ⊆ GOTO and WHILEpart ⊆ GOTOpart

It is sufficient to prove that while xi = 0 do P end can be simulated with GOTO instructions. We can assume without loss of generality that P does not contain any while (we can replace the occurrences of “while” from inside out).

17

slide-18
SLIDE 18

WHILE and GOTO

Proof (ctd.) while xi = 0 do P end is replaced by: j1 : if xi = 0 goto j3; P′; j2 : if xn = 0 goto j1; ** Since xn = 0 unconditional jump ** j3 : xn := xn − 1 where:

  • xn is a new register, which was not used before.
  • P′ is obtained from P by assigning to all instructions without an index

an arbitrary new index.

18

slide-19
SLIDE 19

WHILE and GOTO

Proof (ctd.) while xi = 0 do P end is replaced by: j1 : if xi = 0 goto j3; P′; j2 : if xn = 0 goto j1; ** Since xn = 0 unconditional jump ** j3 : xn := xn − 1 where:

  • xn is a new register, which was not used before.
  • P′ is obtained from P by assigning to all instructions without an index

an arbitrary new index. Remark: Totality is preserved by this transformation. Semantics is the same.

19

slide-20
SLIDE 20

WHILE and GOTO

Proof (ctd.) Using the fact that while xi = 0 do P end can be simulated by a GOTO program we can show (by structural induction) that every WHILE program can be simulated by a GOTO program.

20

slide-21
SLIDE 21

Relationships between LOOP, WHILE, GOTO

  • Theorem. WHILE = GOTO; WHILEpart = GOTOpart

Proof: I. WHILE ⊆ GOTO; WHILEpart ⊆ GOTOpart (WHILE programs expressible as GOTO programs). Proof by structural induction. Induction basis: We show that the property is true for all atomic WHILE programs, i.e. for programs of the form xi := xi ± 1 (expressible as j : xi := xi ± 1). Let P be a non-atomic WHILE program. Induction hypothesis: We assume that the property holds for all “subprograms” of P. Induction step: We show that then it also holds for P. Proof depends on form of P. Case 1: P = P1; P2. By the induction hypothesis, there exist GOTO programs P′

1, P′ 2

with ∆(Pi) = ∆(P′

i ). We can assume w.l.o.g. that the indices used for labelling

the instructions are disjoint. Let P′ = P′

1; P′ 2 (a GOTO program). We can show

that ∆(P′)(s1, s2) iff ∆(P)(s1, s2) as before. Case 2: P = while xi = 0 do P1 end . By the induction hypothesis, there exists a GOTO program P′

1 such that ∆(P1) = ∆(P′ 1). Let P′ be the following GOTO

program: j1 : if xi = 0 goto j3; P′; j2 : if xn = 0 goto j1; j3 : xn := xn − 1 It can be checked that ∆(P′)(s1, s2) iff ∆(P)(s1, s2).

21

slide-22
SLIDE 22

WHILE and GOTO

Theorem. (1) WHILE = GOTO (2) WHILEpart = GOTOpart Proof:

  • II. GOTO ⊆ WHILE and GOTOpart ⊆ WHILEpart

It is sufficient to prove that every GOTO program can be simulated with WHILE instructions.

22

slide-23
SLIDE 23

WHILE and GOTO

Proof (ctd.) j1 : I1; j2 : I2; . . . ; jk : Ik is replaced by the following while program: xindex := j1; while xindex = 0 do if xindex = j1 then I ′

1 end;

if xindex = j2 then I ′

2 end;

. . . if xindex = jk then I ′

k end;

end

23

slide-24
SLIDE 24

WHILE and GOTO

Proof (ctd.) j1 : I1; j2 : I2; . . . ; jk : Ik is replaced by the following while program: xindex := j1; while xindex = 0 do if xindex = j1 then I ′

1 end;

if xindex = j2 then I ′

2 end;

. . . if xindex = jk then I ′

k end;

end For 1 ≤ i < k: If Ii is xi := xi ± 1: I ′

i is xi := xi ± 1; xindex := ji+1

If Ii is if xi = 0 goto jgoto: I ′

i is

if xi = 0 then xindex := jgoto else xindex := ji+1 end In addition, jk+1 = 0

24

slide-25
SLIDE 25

GOTO and WHILE are equally powerful

Consequences of the proof: Corollary 1 The instructions defined in the context of LOOP programs: xi := c xi := xj xi := xj ∗ xk xi = xj ∗ xk, if xi = 0 then Pi else Pj if xi ≤ xj then Pi else Pj can also be used in GOTO programs.

25

slide-26
SLIDE 26

GOTO and WHILE are equally powerful

Consequences of the proof: Corollary 2 Every WHILE computable function can be computed by a WHILE+IF program with one while loop only.

26

slide-27
SLIDE 27

GOTO and WHILE are equally powerful

Consequences of the proof: Corollary 2 Every WHILE computable function can be computed by a WHILE+IF program with one while loop only. Proof: We showed that: (i) every WHILE program can be simulated by a GOTO program (ii) every GOTO program can be simulated by a WHILE program with only

  • ne loop, containing also some if instructions (WHILE-IF program).

Let P be a WHILE program. P can be simulated by a GOTO program P′. P′ can be simulated by a WHILE-IF program with one WHILE loop only.

27

slide-28
SLIDE 28

GOTO and WHILE are equally powerful

Consequence of the proof: Every WHILE computable function can be computed by a WHILE+IF program with one while loop only. Other consequences

  • GOTO programming is not more powerful than WHILE programming

28

slide-29
SLIDE 29

GOTO and WHILE are equally powerful

Consequence of the proof: Every WHILE computable function can be computed by a WHILE+IF program with one while loop only. Other consequences

  • GOTO programming is not more powerful than WHILE programming

“Spaghetti-Code” (GOTO) ist not more powerful than “structured code” (WHILE)

29

slide-30
SLIDE 30

Register Machines: Overview

  • Register machines (Random access machines)
  • LOOP programs
  • WHILE programs
  • GOTO programs
  • Relationships between LOOP, WHILE, GOTO
  • Relationships between register machines and Turing machines

30

slide-31
SLIDE 31

Relationships

Already shown: LOOP ⊆ WHILE = GOTO WHILEpart = GOTOpart

31

slide-32
SLIDE 32

Relationships

Already shown: LOOP ⊆ WHILE = GOTO WHILEpart = GOTOpart To be proved:

  • LOOP = WHILE
  • WHILE = TM and WHILEpart = TMpart

32

slide-33
SLIDE 33

GOTO ⊆ TM

Theorem GOTO ⊆ TM and GOTOpart ⊆ TMpart

33

slide-34
SLIDE 34

GOTO ⊆ TM

Theorem. GOTO ⊆ TM and GOTOpart ⊆ TMpart Proof (idea) It is sufficient to prove that for every GOTO program P = j1 : I1; j2 : I2; . . . ; jk : Ik we can construct an equivalent Turing machine.

34

slide-35
SLIDE 35

GOTO ⊆ TM

Proof (continued) Let r be the number of registers used in P. We construct a Turing machine M with r half tapes over the alphabet Σ = {#, |}.

  • Tape i contains as many |’s as the value of xi is.
  • There is a state sn of M for every instruction jn : In.
  • When M is in state sn, it does what corresponds to instruction In:

– Increment or decrement the register – Evaluate jump condition – Change its state to the corresponding next state.

35

slide-36
SLIDE 36

GOTO ⊆ TM

Proof (continued) Let r be the number of registers used in P. We construct a Turing machine M with r half tapes over the alphabet Σ = {#, |}.

  • Tape i contains as many |’s as the value of xi is.
  • There is a state sn of M for every instruction jn : In.
  • When M is in state sn, it does what corresponds to instruction In:

– Increment or decrement the register – Evaluate jump condition – Change its state to the corresponding next state. It is clear that we can construct a TM which does everything above.

36

slide-37
SLIDE 37

GOTO ⊆ TM

Proof (continued)

  • Tape i contains as many |’s as the value of xi is.
  • There is a state sn of M for every program Pn = jn : In.
  • When M is in state sn, it does what corresponds to instruction In:

– Increment or decrement the register – Evaluate jump condition – Change its state to the corresponding next state.

In Mn xi := xi + 1 > |(i)R(i) xi := xi − 1 > L(i) #(i) → R(i) ↓|(i) #(i)

37

slide-38
SLIDE 38

GOTO ⊆ TM

Proof (continued)

  • Tape i contains as many |’s as the value of xi is.
  • There is a state sn of M for every program Pn = jn : In.
  • When M is in state sn, it does what corresponds to instruction In:

– Increment or decrement the register – Evaluate jump condition – Change its state to the corresponding next state.

In Mn xi := xi + 1 > |(i)R(i) xi := xi − 1 > L(i) #(i) → R(i) ↓|(i) #(i) Pn Mn Pn1; Pn2 > Mn1Mn2 if xi = 0 goto j > L(i) #(i) → R(i) → Mj ↓|(i) R(i) → Mn+1

38

slide-39
SLIDE 39

GOTO ⊆ TM

Proof (continued) In “Theoretische Informatik I” it was proved: For every TM with several tapes there exists an equivalent standard TM with only one tape.

39

slide-40
SLIDE 40

GOTO ⊆ TM

Proof (continued) In “Theoretische Informatik I” it was proved: For every TM with several tapes there exists an equovalent Standard TM with only one tape. Therefore there exists a Standard TM which simulates program P

40

slide-41
SLIDE 41

GOTO ⊆ TM

Proof (continued) In “Theoretische Informatik I” it was proved: For every TM with several tapes there exists an equivalent standard TM with only one tape. Therefore there exists a standard TM which simulates program P Remark: We will prove later that TM ⊆ GOTO and therefore TM = GOTO = WHILE.

41

slide-42
SLIDE 42

LOOP = TM

In what follows we consider only LOOP programs which have only one input.

42

slide-43
SLIDE 43

LOOP = TM

In what follows we consider only LOOP programs which have only one input. If there exists a total TM-computable function f : N → N which is not LOOP computable then we showed that LOOP = TM

43

slide-44
SLIDE 44

LOOP = TM

In what follows we consider only LOOP programs which have only one input. If there exists a total TM-computable function f : N → N which is not LOOP computable then we showed that LOOP = TM

Idea of the proof: For every unary LOOP-computable function f : N → N there exists a LOOP program Pf which computes it. We show that:

  • The set of all unary LOOP programs is recursively enumerable
  • There exists a Turing machine MLOOP such that if P1, P2, P3, . . . is an

enumeration of all (unary) LOOP programs then if Pi computes from input m

  • utput o then MLOOP computes from input (i, m) the output o.
  • We construct a TM-computable function which is not LOOP computable using

a “diagonalisation” argument.

44

slide-45
SLIDE 45

LOOP = TM

  • Lemma. The set of all LOOP programs is recursively enumerable.

45

slide-46
SLIDE 46

LOOP = TM

  • Lemma. The set of all LOOP programs is recursively enumerable.

Proof (Idea) Regard any LOOP program as a word over the alphabet: ΣLOOP = {; , x, : =, +, −, 1, loop, do, end} xi is encoded as xi. We can easily construct a grammar which generates all LOOP programs. Proposition (TI 1): The recursively enumerable languages are exactly the languages generated by arbitrary grammars (i.e. languages of type 0). Remark: The same holds also for WHILE programs, GOTO programs and Turing machines

46

slide-47
SLIDE 47

LOOP = TM

Lemma. There exists a Turing machine MLOOP which simulates all LOOP programs More precisely: Let P1, P2, P3, . . . be an enumeration of all LOOP programs. If Pi computes from input m output o then MLOOP computes from input (i, m) the output o.

47

slide-48
SLIDE 48

LOOP = TM

Lemma. There exists a Turing machine MLOOP which simulates all LOOP programs More precisely: Let P1, P2, P3, . . . be an enumeration of all LOOP programs. If Pi computes from input m output o then MLOOP computes from input (i, m) the output o. Proof: similar to the proof that there exists an universal TM, which simulates all Turing machines.

48

slide-49
SLIDE 49

LOOP = TM

Lemma. There exists a Turing machine MLOOP which simulates all LOOP programs. More precisely: Let P1, P2, P3, . . . be an enumeration of all LOOP programs. If Pi computes from input m output o then MLOOP computes from input (i, m) the output o. Proof: similar to the proof that there exists an universal TM, which simulates all Turing machines. Remark: The same holds also for WHILE programs, GOTO programs and Turing machines

49

slide-50
SLIDE 50

LOOP = TM

Theorem: LOOP = TM Proof: Let Ψ : N → N be defined by: Ψ(i) = Pi(i) + 1 Output of the i-th LOOP program Pi on input i to which 1 is added. Ψ is clearly total. We will show that the following hold: Claim 1: Ψ ∈ TM Claim 2: Ψ ∈ LOOP

50

slide-51
SLIDE 51

LOOP = TM

Claim 1: Ψ ∈ TM Proof: We have shown that:

  • the set of all LOOP programs is r.e., i.e. there is a Turing machine M0

which enumerates P1, . . . , Pn, . . . (as G¨

  • del numbers)
  • there exists a Turing machine MLOOP which simulates all LOOP

programs In order to construct a Turing machine which computes Ψ we proceed as follows:

  • We use M0 to compute from i the LOOP program Pi
  • We use MLOOP to compute Pi(i)
  • We add 1 to the result.

51

slide-52
SLIDE 52

LOOP = TM

Claim 2: Ψ ∈ LOOP Proof: We assume, in order to derive a contradiction, that Ψ ∈ LOOP, i.e. there exists a LOOP program Pi0 which computes Ψ. Then:

  • The output of Pi0 on input i0 is Pi0(i0).
  • Ψ(i0) = Pi0(i0) + 1 = Pi0(i0)

Contradiction!

52

slide-53
SLIDE 53

LOOP = TM

Claim 2: Ψ ∈ LOOP Proof: We assume, in order to derive a contradiction, that Ψ ∈ LOOP, i.e. there exists a LOOP program Pi0 which computes Ψ. Then:

  • The output of Pi0 on input i0 is Pi0(i0).
  • Ψ(i0) = Pi0(i0) + 1 = Pi0(i0)

Contradiction! Remark: This does not hold for WHILE programs, GOTO programs and Turing machines.

53

slide-54
SLIDE 54

LOOP = TM

Claim 2: Ψ ∈ LOOP Proof: We assume, in order to derive a contradiction, that Ψ ∈ LOOP, i.e. there exists a LOOP program Pi0 which computes Ψ. Then:

  • The output of Pi0 on input i0 is Pi0(i0).
  • Ψ(i0) = Pi0(i0) + 1 = Pi0(i0)

Contradiction! Remark: This does not hold for WHILE programs, GOTO programs and Turing machines. Why?

54

slide-55
SLIDE 55

LOOP = TM

Claim 2: Ψ ∈ LOOP Proof: We assume, in order to derive a contradiction, that Ψ ∈ LOOP, i.e. there exists a LOOP program Pi0 which computes Ψ. Then:

  • The output of Pi0 on input i0 is Pi0(i0).
  • Ψ(i0) = Pi0(i0) + 1 = Pi0(i0)

Contradiction! Remark: This does not hold for WHILE programs, GOTO programs and Turing machines. The proof relies on the fact that Ψ is total (otherwise Pi0(i0) + 1 could be undefined).

55

slide-56
SLIDE 56

Summary

We showed that:

  • LOOP ⊆ WHILE = GOTO ⊆ TM
  • WHILE = GOTO WHILEpart = GOTOpart ⊆ TMpart
  • LOOP = TM

56

slide-57
SLIDE 57

Summary

We showed that:

  • LOOP ⊆ WHILE = GOTO ⊆ TM
  • WHILE = GOTO WHILEpart = GOTOpart ⊆ TMpart
  • LOOP = TM

Still to show:

  • TM ⊆ WHILE
  • TMpart ⊆ WHILEpart

57

slide-58
SLIDE 58

Summary

We showed that:

  • LOOP WHILE = GOTO ⊆ TM
  • WHILE = GOTO WHILEpart = GOTOpart ⊆ TMpart
  • LOOP = TM

Still to show:

  • TM ⊆ WHILE
  • TMpart ⊆ WHILEpart

For proving this, another model of computation will be used: recursive functions

58