Theory of Computer Science D2. LOOP- and WHILE-Computability Malte Helmert University of Basel April 20, 2016
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Overview: Computability Theory Computability Theory imperative models of computation: D1. Turing-Computability D2. LOOP- and WHILE-Computability D3. GOTO-Computability functional models of computation: D4. Primitive Recursion and µ -Recursion D5. Primitive/ µ -Recursion vs. LOOP-/WHILE-Computability undecidable problems: 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
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Further Reading (German) Literature for this Chapter (German) Theoretische Informatik – kurz gefasst by Uwe Sch¨ oning (5th edition) Chapter 2.3 Chapter 2.5
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Further Reading (English) Literature for this Chapter (English) Introduction to the Theory of Computation by Michael Sipser (3rd edition) This topic is not discussed by Sipser!
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Introduction
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Formal Models of Computation: LOOP/WHILE/GOTO Formal Models of Computation Turing machines LOOP, WHILE and GOTO programs primitive recursive and µ -recursive functions In this and the following chapter we get to know three simple models of computation (programming languages) and compare their power to Turing machines: LOOP programs � today WHILE programs � today GOTO programs � next chapter
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP, WHILE and GOTO Programs: Basic Concepts LOOP, WHILE and GOTO programs are structured like programs in (simple) “traditional” programming languages use finitely many variables from the set { x 0 , x 1 , x 2 , . . . } that can take on values in N 0 differ from each other in the allowed “statements”
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP Programs
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP Programs: Syntax Definition (LOOP Program) LOOP programs are inductively defined as follows: x i := x j + c is a LOOP program 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
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP Programs: Semantics Definition (Semantics of LOOP Programs) A LOOP program computes a k -ary function f : N k 0 → N 0 . The computation of f ( n 1 , . . . , n k ) works as follows: 1 Initially, the variables x 1 , . . . , x k hold the values n 1 , . . . , n k . 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
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP Programs: Semantics Definition (Semantics of LOOP Programs) effect of x i := x j + c : The variable x i is assigned the current value of x j plus c . All other variables retain their value. German: P berechnet f
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP Programs: Semantics Definition (Semantics of LOOP Programs) effect of x i := x j − c : The variable x i is assigned the current value of x j minus c if this value is non-negative. Otherwise x i is assigned the value 0. All other variables retain their value. German: P berechnet f
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP Programs: Semantics Definition (Semantics of LOOP Programs) effect of P 1 ; P 2 : First, execute P 1 . Then, execute P 2 (on the modified variable values). German: P berechnet f
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP Programs: Semantics Definition (Semantics of LOOP Programs) effect of LOOP x i DO P END: Let m be the value of variable x i at the start of execution. The program P is executed m times in sequence. German: P berechnet f
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP-Computable Functions Definition (LOOP-Computable) A function f : N k 0 → p N 0 is called LOOP-computable if a LOOP program that computes f exists. German: f ist LOOP-berechenbar Note: non-total functions are never LOOP-computable. (Why not?)
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary LOOP Programs: Example Example (LOOP program for f ( x 1 , x 2 )) LOOP x 1 DO LOOP x 2 DO x 0 := x 0 + 1 END END Which (binary) function does this program compute?
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Questions Questions?
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Syntactic Sugar
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Syntactic Sugar or Essential Feature? We investigate the power of programming languages and other computation formalisms. Rich language features help when writing complex programs. Minimalistic formalisms are useful for proving statements over all programs. � conflict of interest! Idea: Use minimalistic core for proofs. Use syntactic sugar when writing programs. German: syntaktischer Zucker
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) We propose five new syntax constructs (with the obvious semantics): x i := x j for i , j ∈ N 0 x i := c for i , c ∈ N 0 x i := x j + x k for i , j , k ∈ N 0 IF x i � = 0 THEN P END for i ∈ N 0 IF x i = c THEN P END for i , c ∈ N 0 Can we simulate these with the existing constructs?
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) x i := x j for i , j ∈ N 0 Simulation with existing constructs?
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) x i := x j for i , j ∈ N 0 Simple abbreviation for x i := x j + 0.
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) x i := c for i , c ∈ N 0 Simulation with existing constructs?
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) x i := c for i , c ∈ N 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.)
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) x i := x j + x k for i , j , k ∈ N 0 Simulation with existing constructs?
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) x i := x j + x k for i , j , k ∈ N 0 Abbreviation for: x i := x j ; LOOP x k DO x i := x i + 1 END Analogously we will also use the following: x i := x j − x k x i := x j + x k − c − x m + d etc.
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) IF x i � = 0 THEN P END for i ∈ N 0 Simulation with existing constructs?
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) IF x i � = 0 THEN P END for i ∈ N 0 Abbreviation for: x j := 0; LOOP x i DO x j := 1 END; LOOP x j DO P END where x j is a fresh variable.
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) IF x i = c THEN P END for i , c ∈ N 0 Simulation with existing constructs?
Introduction LOOP Programs Syntactic Sugar WHILE Programs Ackermann Function Summary Example: Syntactic Sugar Example (syntactic sugar) IF x i = c THEN P END for i , c ∈ N 0 Abbreviation for: x j := 1; x k := x i − c ; IF x k � = 0 THEN x j := 0 END; x k := c − x i ; IF x k � = 0 THEN x j := 0 END; IF x j � = 0 THEN P END where x j and x k are fresh variables.
Recommend
More recommend