theory of computer science
play

Theory of Computer Science April 19, 2017 D2. LOOP- and - PowerPoint PPT Presentation

Theory of Computer Science April 19, 2017 D2. LOOP- and WHILE-Computability D2.1 Introduction Theory of Computer Science D2. LOOP- and WHILE-Computability D2.2 LOOP Programs D2.3 Syntactic Sugar Malte Helmert D2.4 WHILE Programs


  1. Theory of Computer Science April 19, 2017 — D2. LOOP- and WHILE-Computability D2.1 Introduction Theory of Computer Science D2. LOOP- and WHILE-Computability D2.2 LOOP Programs D2.3 Syntactic Sugar Malte Helmert D2.4 WHILE Programs University of Basel April 19, 2017 D2.5 Digression: the Ackermann Function D2.6 Summary Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 1 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 2 / 45 Overview: Computability Theory Further Reading (German) Computability Theory ◮ imperative models of computation: Literature for this Chapter (German) D1. Turing-Computability D2. LOOP- and WHILE-Computability D3. GOTO-Computability ◮ functional models of computation: Theoretische Informatik – kurz gefasst by Uwe Sch¨ oning (5th edition) D4. Primitive Recursion and µ -Recursion D5. Primitive/ µ -Recursion vs. LOOP-/WHILE-Computability ◮ Chapter 2.3 ◮ undecidable problems: ◮ Chapter 2.5 D6. Decidability and Semi-Decidability D7. Halting Problem and Reductions D8. Rice’s Theorem and Other Undecidable Problems Post’s Correspondence Problem Undecidable Grammar Problems G¨ odel’s Theorem and Diophantine Equations Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 3 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 4 / 45

  2. D2. LOOP- and WHILE-Computability Introduction Further Reading (English) Literature for this Chapter (English) D2.1 Introduction Introduction to the Theory of Computation by Michael Sipser (3rd edition) ◮ This topic is not discussed by Sipser! Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 5 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 6 / 45 D2. LOOP- and WHILE-Computability Introduction D2. LOOP- and WHILE-Computability Introduction Formal Models of Computation: LOOP/WHILE/GOTO LOOP, WHILE and GOTO Programs: Basic Concepts Formal Models of Computation ◮ Turing machines ◮ LOOP, WHILE and GOTO programs ◮ LOOP, WHILE and GOTO programs are structured like ◮ primitive recursive and µ -recursive functions programs in (simple) “traditional” programming languages ◮ use finitely many variables from the set { x 0 , x 1 , x 2 , . . . } In this and the following chapter we get to know that can take on values in N 0 three simple models of computation (programming languages) ◮ differ from each other in the allowed “statements” and compare their power to Turing machines: ◮ LOOP programs � today ◮ WHILE programs � today ◮ GOTO programs � next chapter Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 7 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 8 / 45

  3. D2. LOOP- and WHILE-Computability LOOP Programs D2. LOOP- and WHILE-Computability LOOP Programs LOOP Programs: Syntax Definition (LOOP Program) LOOP programs are inductively defined as follows: ◮ x i := x j + c is a LOOP program D2.2 LOOP Programs for every i , j , c ∈ N 0 (addition) ◮ x i := x j − c is a LOOP program for every i , j , c ∈ N 0 (modified subtraction) ◮ If P 1 and P 2 are LOOP programs, then so is P 1 ; P 2 (composition) ◮ If P is a LOOP program, then so is LOOP x i DO P END for every i ∈ N 0 (LOOP loop) German: LOOP-Programm, Addition, modifizierte Subtraktion, Komposition, LOOP-Schleife Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 9 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 10 / 45 D2. LOOP- and WHILE-Computability LOOP Programs D2. LOOP- and WHILE-Computability LOOP Programs LOOP Programs: Semantics LOOP Programs: Semantics Definition (Semantics of LOOP Programs) Definition (Semantics of LOOP Programs) A LOOP program computes a k -ary function effect of x i := x j + c : f : N k 0 → N 0 . The computation of f ( n 1 , . . . , n k ) works as follows: ◮ The variable x i is assigned the current value of x j plus c . 1 Initially, the variables x 1 , . . . , x k hold the values n 1 , . . . , n k . ◮ All other variables retain their value. All other variables hold the value 0. 2 During computation, the program modifies the variables as described on the following slides. 3 The result of the computation ( f ( n 1 , . . . , n k )) is the value of x 0 after the execution of the program. German: P berechnet f German: P berechnet f Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 11 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 12 / 45

  4. D2. LOOP- and WHILE-Computability LOOP Programs D2. LOOP- and WHILE-Computability LOOP Programs LOOP Programs: Semantics LOOP Programs: Semantics Definition (Semantics of LOOP Programs) Definition (Semantics of LOOP Programs) effect of x i := x j − c : effect of P 1 ; P 2 : ◮ The variable x i is assigned the current value of x j minus c ◮ First, execute P 1 . if this value is non-negative. Then, execute P 2 (on the modified variable values). ◮ Otherwise x i is assigned the value 0. ◮ All other variables retain their value. German: P berechnet f German: P berechnet f Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 13 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 14 / 45 D2. LOOP- and WHILE-Computability LOOP Programs D2. LOOP- and WHILE-Computability LOOP Programs LOOP Programs: Semantics LOOP-Computable Functions Definition (Semantics of LOOP Programs) effect of LOOP x i DO P END: Definition (LOOP-Computable) ◮ Let m be the value of variable x i at the start of execution. A function f : N k 0 → p N 0 is called LOOP-computable ◮ The program P is executed m times in sequence. if a LOOP program that computes f exists. German: f ist LOOP-berechenbar Note: non-total functions are never LOOP-computable. (Why not?) German: P berechnet f Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 15 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 16 / 45

  5. D2. LOOP- and WHILE-Computability LOOP Programs D2. LOOP- and WHILE-Computability Syntactic Sugar LOOP Programs: Example Example (LOOP program for f ( x 1 , x 2 )) D2.3 Syntactic Sugar LOOP x 1 DO LOOP x 2 DO x 0 := x 0 + 1 END END Which (binary) function does this program compute? Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 17 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 18 / 45 D2. LOOP- and WHILE-Computability Syntactic Sugar D2. LOOP- and WHILE-Computability Syntactic Sugar Syntactic Sugar or Essential Feature? Example: Syntactic Sugar Example (syntactic sugar) ◮ We investigate the power of programming languages We propose five new syntax constructs (with the obvious semantics): and other computation formalisms. ◮ x i := x j for i , j ∈ N 0 ◮ Rich language features help when writing complex programs. ◮ x i := c for i , c ∈ N 0 ◮ Minimalistic formalisms are useful for proving statements ◮ x i := x j + x k for i , j , k ∈ N 0 over all programs. ◮ IF x i � = 0 THEN P END for i ∈ N 0 � conflict of interest! ◮ IF x i = c THEN P END for i , c ∈ N 0 Idea: Can we simulate these with the existing constructs? ◮ Use minimalistic core for proofs. ◮ Use syntactic sugar when writing programs. German: syntaktischer Zucker Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 19 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 20 / 45

  6. D2. LOOP- and WHILE-Computability Syntactic Sugar D2. LOOP- and WHILE-Computability Syntactic Sugar Example: Syntactic Sugar Example: Syntactic Sugar Example (syntactic sugar) Example (syntactic sugar) x i := x j for i , j ∈ N 0 x i := c for i , c ∈ N 0 Simple abbreviation for x i := x j + 0. Simple abbreviation for x i := x j + c , where x j is a fresh variable, i.e., an otherwise unused variable that is not an input variable. (Thus x j must always have the value 0 in all executions.) Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 21 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 22 / 45 D2. LOOP- and WHILE-Computability Syntactic Sugar D2. LOOP- and WHILE-Computability Syntactic Sugar Example: Syntactic Sugar Example: Syntactic Sugar Example (syntactic sugar) Example (syntactic sugar) x i := x j + x k for i , j , k ∈ N 0 IF x i � = 0 THEN P END for i ∈ N 0 Abbreviation for: Abbreviation for: x i := x j ; x j := 0; LOOP x k DO LOOP x i DO x i := x i + 1 x j := 1 END END; LOOP x j DO Analogously we will also use the following: P ◮ x i := x j − x k END ◮ x i := x j + x k − c − x m + d where x j is a fresh variable. ◮ etc. Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 23 / 45 Malte Helmert (University of Basel) Theory of Computer Science April 19, 2017 24 / 45

Recommend


More recommend