advanced topics in theoretical computer science
play

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:


  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

  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

  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

  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

  5. LOOP Programs: Syntax Definition • Atomic programs: For each register x i : – x i := x i + 1 – x i := x i − 1 are LOOP instructions and also LOOP programs. • If P 1 , P 2 are LOOP programs then – P 1 ; P 2 is a LOOP program • If P is a LOOP program then – loop x i do P end is a LOOP program (and a LOOP instruction) 5

  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: ∆( x i := x i ± 1)( s 1 , s 2 ) iff: • s 2 ( x i ) = s 1 ( x i ) ± 1 • s 2 ( x j ) = s 1 ( x j ) for all j � = i (2) Sequential composition: ∆( P 1 ; P 2 )( s 1 , s 2 ) iff there exists s ′ s.t.: • ∆( P 1 )( s 1 , s ′ ) • ∆( P 2 )( s ′ , s 2 ) (3) Loop programs: ∆(loop x i do P end)( s 1 , s 2 ) iff there exist states s ′ 0 , s ′ 1 , . . . , s ′ n with: • s 1 ( x i ) = n • s 1 = s ′ 0 • s 2 = s ′ n • ∆( P )( s ′ k , s ′ k +1 ) for 0 ≤ k < n 6

  7. WHILE Programs: Syntax Definition • Atomic programs: For each register x i : – x i := x i + 1 – x i := x i − 1 are WHILE instructions and also WHILE programs. • If P 1 , P 2 are WHILE programs then – P 1 ; P 2 is a WHILE program • If P is a WHILE program then – while x i � = 0 do P end is a WHILE program (and a WHILE instruction) 7

  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: ∆( x i := x i ± 1)( s 1 , s 2 ) iff: • s 2 ( x i ) = s 1 ( x i ) ± 1 • s 2 ( x j ) = s 1 ( x j ) for all j � = i (2) Sequential composition: ∆( P 1 ; P 2 )( s 1 , s 2 ) iff there exists s ′ s.t.: • ∆( P 1 )( s 1 , s ′ ) • ∆( P 2 )( s ′ , s 2 ) (3) While programs: ∆(while x i � = 0 do P end)( s 1 , s 2 ) iff there exists n ∈ N and there exist states s ′ 0 , s ′ 1 , . . . , s ′ n with: • s 1 = s ′ 0 • s 2 = s ′ n • ∆( P )( s ′ k , s ′ k +1 ) for 0 ≤ k < n • s ′ k ( x i ) � = 0 for 0 ≤ k < n • s ′ n ( x i ) = 0 8

  9. GOTO Programs: Syntax Indices (numbers for the lines in the program) j ≥ 0 Definition • Atomic programs: – x i := x i + 1 – x i := x i − 1 are GOTO instructions for each register x i . • If x i is a register and j is an index then – if x i = 0 goto j is a GOTO instruction. • If I 1 , . . . , I k are GOTO instructions and j 1 , . . . , j k are indices then – j 1 : I 1 ; . . . ; j k : I k is a GOTO program 9

  10. GOTO Programs: Semantics Let P be a GOTO program of the form: P = j 1 : I 1 ; j 2 : I 2 ; . . . ; j k : I k Let j k +1 be an index which does not occur in P (program end). Definition ∆( P )( s 1 , s 2 ) holds iff for every n ≥ 0 there exist states s ′ 0 , . . . , s ′ n and indices z 0 , . . . , z n s.t.: • s ′ 0 = s 1 , s ′ n = s 2 ; z 0 = j 1 , z n = j k +1 . • For 0 ≤ l ≤ n , if j s : I s is the line in P with j s = z l : s ′ i +1 ( x i ) = s ′ if I s = x i := x i ± 1 then: i ( x i ) ± 1 s ′ i +1 ( x j ) = s ′ i ( x j ) for j � = i z i +1 = j s +1 if I s = if x i = 0 goto j goto then: s ′ i +1 = s ′ i � j goto if x i = 0 z i +1 = j s +1 otherwise 10

  11. Register Machines Definition A register machine is a machine consisting of the following elements: • A finite (but unbounded) number of registers x 1 , x 2 , x 3 . . . , x n ; each register contains a natural number. • A LOOP-, WHILE- or GOTO-program. 11

  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

  13. Computable functions LOOP = Set of all LOOP computable functions WHILE = Set of all total WHILE computable functions WHILE part = Set of all WHILE computable functions (including the partial ones) GOTO = Set of all total GOTO computable functions GOTO part = Set of all GOTO computable functions (including the partial ones) TM = Set of all total TM computable functions TM part = Set of all TM computable functions (including the partial ones) 13

  14. Relationships between LOOP, WHILE, GOTO Theorem. LOOP ⊆ WHILE (every LOOP computable function is WHILE computable) 14

  15. WHILE and GOTO Theorem. (1) WHILE = GOTO (2) WHILE part = GOTO part 15

  16. WHILE and GOTO Theorem. (1) WHILE = GOTO (2) WHILE part = GOTO part Proof: To show: I. WHILE ⊆ GOTO and WHILE part ⊆ GOTO part II. GOTO ⊆ WHILE and GOTO part ⊆ WHILE part 16

  17. WHILE and GOTO Theorem. (1) WHILE = GOTO (2) WHILE part = GOTO part Proof: I. WHILE ⊆ GOTO and WHILE part ⊆ GOTO part It is sufficient to prove that while x i � = 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

  18. WHILE and GOTO Proof (ctd.) while x i � = 0 do P end is replaced by: j 1 : if x i = 0 goto j 3 ; P ′ ; j 2 : if x n = 0 goto j 1 ; ** Since x n = 0 unconditional jump ** j 3 : x n := x n − 1 where: • x n 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

  19. WHILE and GOTO Proof (ctd.) while x i � = 0 do P end is replaced by: j 1 : if x i = 0 goto j 3 ; P ′ ; j 2 : if x n = 0 goto j 1 ; ** Since x n = 0 unconditional jump ** j 3 : x n := x n − 1 where: • x n 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

  20. WHILE and GOTO Proof (ctd.) Using the fact that while x i � = 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

  21. Relationships between LOOP, WHILE, GOTO Theorem. WHILE = GOTO; WHILE part = GOTO part Proof: I. WHILE ⊆ GOTO; WHILE part ⊆ GOTO part (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 x i := x i ± 1 (expressible as j : x i := x i ± 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 = P 1 ; P 2 . By the induction hypothesis, there exist GOTO programs P ′ 1 , P ′ 2 with ∆( P i ) = ∆( 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 ′ )( s 1 , s 2 ) iff ∆( P )( s 1 , s 2 ) as before. Case 2: P = while x i � = 0 do P 1 end . By the induction hypothesis, there exists a 1 ). Let P ′ be the following GOTO GOTO program P ′ 1 such that ∆( P 1 ) = ∆( P ′ program: j 1 : if xi = 0 goto j 3; P ′ ; j 2 : if xn = 0 goto j 1; j 3 : xn := xn − 1 It can be checked that ∆( P ′ )( s 1 , s 2 ) iff ∆( P )( s 1 , s 2 ). 21

  22. WHILE and GOTO Theorem. (1) WHILE = GOTO (2) WHILE part = GOTO part Proof: II. GOTO ⊆ WHILE and GOTO part ⊆ WHILE part It is sufficient to prove that every GOTO program can be simulated with WHILE instructions. 22

  23. WHILE and GOTO Proof (ctd.) j 1 : I 1 ; j 2 : I 2 ; . . . ; j k : I k is replaced by the following while program: x index := j 1 ; while x index � = 0 do if x index = j 1 then I ′ 1 end; if x index = j 2 then I ′ 2 end; . . . if x index = j k then I ′ k end; end 23

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend