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 (2) 20.11.2014 Viorica Sofronie-Stokkermans Universit at Koblenz-Landau e-mail: sofronie@uni-koblenz.de Wintersemester 2014-2015 1 Contents Recapitulation:


  1. Advanced Topics in Theoretical Computer Science Part 2: Register machines (2) 20.11.2014 Viorica Sofronie-Stokkermans Universit¨ at Koblenz-Landau e-mail: sofronie@uni-koblenz.de Wintersemester 2014-2015 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. Last time: Register Machines The register machine gets its name from its one or more “registers”: In place of a Turing machine’s tape and head (or tapes and heads) the model uses multiple, uniquely-addressed registers, each of which holds a single positive integer. In comparison to Turing machines: • equally powerful fundament for computability theory • Advantage: Programs are easier to understand similar to ... the imperative kernel of programming languages pseudo-code 4

  5. Last time: 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. 5

  6. Last time: Register Machines – State Definition (State of a register machine) The state s of a register machine is a map: s : { x i | i ∈ N } → N which associates with every register a natural number as value. Definition (Initial state; Input) Let m 1 , . . . , m k ∈ N be given as input to a register machine. In the input state s 0 we have • s 0 ( x i ) = m i for all 1 ≤ i ≤ k • s 0 ( x i ) = 0 for all i > k Definition (Output) If a register machine started with the input m 1 , . . . , m k ∈ N halts in a state s term then: s term ( x k +1 ) is the output of the machine. 6

  7. Last time: Register Machines – Semantics Definition (The semantics of a register machine) The semantics ∆( P ) of a register machine P is a (binary) relation ∆( P ) ⊆ S × S on the set S of all states of the machine. ( s 1 , s 2 ) ∈ ∆( P ) means that if P is executed in state s 1 then it halts in state s 2 . 7

  8. Last time: Computed function Definition (Computed function) f : N k → N A register machine P computes a function if and only if for all m 1 , . . . , m k ∈ N the following holds: If we start P with initial state with the input m 1 , . . . , m k then: • P terminates if and only if f ( m 1 , . . . , m k ) is defined • If P terminates, then the output of P is f ( m 1 , . . . , m k ) • Additional condition We additionally require that when a register machine halts, all the registers (with the exception of the output register) contain again the values they had in the initial state. – Input registers x 1 , . . . , x k contain the initial values – The registers x i with i > k + 1 contain value 0 Consequence: A machine which does not fulfill the additional condition (even only for some inputs) does not compute a function at all. 8

  9. Last time: Computed function Example: The program: P := loop x 2 do x 2 := x 2 − 1 end; x 2 := x 2 + 1; loop x 1 do x 1 := x 1 − 1 end does not compute a function: At the end, P has value 0 in x 1 and 1 in x 2 . 9

  10. Last time: 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 LOOP = Set of all LOOP computable functions WHILE = Set of all WHILE computable functions GOTO = Set of all GOTO computable functions TM = Set of all TM computable functions 10

  11. 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 11

  12. Last time: LOOP Programs - Syntax Definition (1) Atomic programs: For each register x i : – x i := x i + 1 – x i := x i − 1 are LOOP instructions and also LOOP programs. (2) If P 1 , P 2 are LOOP programs then – P 1 ; P 2 is a LOOP program (3) If P is a LOOP program then – loop x i do P end is a LOOP instruction and a LOOP program. The set of all LOOP programs is the smallest set with the properties (1),(2),(3). 12

  13. Last time: 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 ) if and only if: – s 2 ( x i ) = s 1 ( x i ) + 1 – s 2 ( x j ) = s 1 ( x j ) for all j � = i • ∆( x i := x i − 1)( s 1 , s 2 ) if and only if: � s 1 ( x i ) − 1 if s 1 ( x i ) > 0 – s 2 ( x i ) = 0 if s 1 ( x i ) = 0 – s 2 ( x j ) = s 1 ( x j ) for all j � = i 13

  14. Last time: LOOP Programs - Semantics Definition (Semantics of LOOP programs) Let P be a LOOP program. ∆( P ) is inductively defined as follows: (2) Sequential composition: • ∆( P 1 ; P 2 )( s 1 , s 2 ) if and only if there exists s ′ such that: – ∆( P 1 )( s 1 , s ′ ) – ∆( P 2 )( s ′ , s 2 ) (3) Loop programs • ∆(loop x i do P end)( s 1 , s 2 ) if and only if 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 Remark: The number of steps in the loop is the value of x i at the beginning of the loop. Changes to x i during the loop are not relevant. 14

  15. Last time: LOOP programs - Semantics Program end: If there is no next program line, then the program execution terminates. We say that a LOOP program terminates on an input n 1 , . . . , n k if its execution on this input terminates (in the sense above) after a finite number of steps. Theorem. Every LOOP program terminates for every input. Consequence: All LOOP computable functions are total. 15

  16. LOOP Programs Additional instructions • x i := 0 loop x i do x i := x i − 1 end • x i := c for c ∈ N x i := 0;  x i := x i + 1;    c times . . .   x i := x i + 1  • x i := x j x n := 0; ( x n new register, not used before) loop x j do x n := x n + 1 end; x i := 0; loop x n do x i := x i + 1 end; 16

  17. LOOP Programs Additional instructions • x i := x j + x k x i := x j ; loop x k do x i := x i + 1 end; • x i := x j − x k x i := x j ; loop x k do x i := x i − 1 end; • x i := x j ∗ x k x i := 0; loop x k do x i := x i + x j end; 17

  18. LOOP Programs Additional instructions In what follows, x n , x n +1 , . . . denote new registers (not used before). • x i := e 1 + e 2 ( e 1 , e 2 arithmetical expressions) x i := e 1 ; x n := e 2 ; loop x n do x i := x i + 1 end; x n := 0 • x i := e 1 − e 2 ( e 1 , e 2 arithmetical expressions) x i := e 1 ; x n := e 2 ; loop x n do x i := x i − 1 end; x n := 0 • x i := e 1 ∗ e 2 ( e 1 , e 2 arithmetical expressions) x i := 0; x n := e 1 ; loop x n do x i := x i + e 2 end; x n := 0 18

  19. LOOP Programs Additional instructions • if x i = 0 then P 1 else P 2 end x n := 1 − x i ; x n +1 := 1 − x n ; loop x n do P 1 end; loop x n +1 do P 2 end; x n := 0; x n +1 := 0 • if x i ≤ x j then P 1 else P 2 end x n := x i − x j ; if x n = 0 then P 1 else P 2 end x n := 0 19

  20. 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 20

  21. 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 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 instruction and a WHILE program. The family of all WHILE programs is the smallest set with properties (1),(2),(3) 21

  22. 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 ) if and only if: – s 2 ( x i ) = s 1 ( x i ) + 1 – s 2 ( x j ) = s 1 ( x j ) for all j � = i • ∆( x i := x i − 1)( s 1 , s 2 ) if and only if:  s 1 ( x i ) − 1 if s 1 ( x i ) > 0  – s 2 ( x i ) = 0 if s 1 ( x i ) = 0  – s 2 ( x j ) = s 1 ( x j ) for all j � = i 22

  23. WHILE Programs: Semantics Definition (Semantics of WHILE programs) Let P be a WHILE program. ∆( P ) is inductively defined as follows: (2) Sequential composition: • ∆( P 1 ; P 2 )( s 1 , s 2 ) if and only if there exists s ′ such that: – ∆( P 1 )( s 1 , s ′ ) – ∆( P 2 )( s ′ , s 2 ) 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