Theory of Computation Lecture 12: A Universal Program III

Slides:



Advertisements
Similar presentations
1 Turing Machines and Equivalent Models Section 13.2 The Church-Turing Thesis.
Advertisements

October 13, 2009Theory of Computation Lecture 11: A Universal Program III 1 Coding Programs by Numbers Gödel numbers are usually very large, even for small.
1 Introduction to Computability Theory Lecture15: Reductions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 1Universality Then we append the following instruction: [C]IF K = Lt(Z) + 1 
November 10, 2009Theory of Computation Lecture 16: Computation on Strings I 1Diagonalization Another example: Let TOT be the set of all numbers p such.
December 8, 2009Theory of Computation Lecture 22: Turing Machines IV 1 Turing Machines Theorem 1.1: Any partial function that can be computed by a Post-
November 3, 2009Introduction to Cognitive Science Lecture 15: Theory of Computation II 1 Languages Accepted by Turing Machines Example 2: Language L =
October 8, 2009Theory of Computation Lecture 10: A Universal Program II 1 Pairing Functions and Gödel Numbers This way the equation  x, y  = z defines.
September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 1 Macros Now we want to use macros of the form: W  f(V 1, …,
November 3, 2009Theory of Computation Lecture 14: A Universal Program VI 1 Recursively Enumerable Sets Definition: We write: W n = {x  N |  (x, n) 
Chapter 4: A Universal Program 1. Coding programs Example : For our programs P we have variables that are arranged in a certain order: Y 1 X 1 Z 1 X 2.
More Theory of Computing
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.
Recursive Algorithms &
4.1 Proofs and Counterexamples. Even Odd Numbers Find a property that describes each of the following sets E={…, -4, -2, 0, 2, 4, 6, …} O={…, -3, -1,
1 Turing’s Thesis. 2 Turing’s thesis: Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
Theory of Computation Lecture 5: Primitive Recursive Functions I
Recursively Enumerable and Recursive Languages
1 Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially.
1 Recursively Enumerable and Recursive Languages.
October 4, 2016Theory of Computation Lecture 9: A Universal Program I 1Minimalization Example 15: R(x, y) R(x, y) is the remainder when x is divided by.
CSE15 Discrete Mathematics 03/06/17
The Foundations: Logic and Proofs
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
Halting Problem Dr K R Bond 2009
Another Word on PRC Classes
Theory of Computation Lecture 10: A Universal Program I
Theory Of Computer Science
Diagonalization and Reducibility
Theory of Computation Lecture 23: Turing Machines IV
Theory of Computation Lecture 14: A Universal Program V
Recursively Enumerable Sets
Numerical Representation of Strings
Theory of Computation Lecture 22: Turing Machines III
Theory of Computation Lecture 16: A Universal Program VII
Theory of Computation Lecture 5: Programs and Computable Functions III
Theory of Computation Lecture 6: Primitive Recursive Functions I
Program Design Introduction to Computer Programming By:
Copyright © Cengage Learning. All rights reserved.
Theory of Computation Turing Machines.
Algorithm Discovery and Design
Theory Of Computer Science
The Programming Language L
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Pairing Functions and Gödel Numbers
Theory of Computation Lecture 21: Turing Machines II
Diagonalization and Reducibility
Recursively Enumerable Sets
Primitive Recursive Predicates
Subject Name: FORMAL LANGUAGES AND AUTOMATA THEORY
Theory of Computation Lecture 5: Programs and Computable Functions III
The Programming Language L
Theory of Computation Lecture 4: Programs and Computable Functions II
Theory of Computation Lecture 9: A Universal Program I
Pairing Functions and Gödel Numbers
Theory of Computation Lecture 6: Primitive Recursive Functions I
Some Primitive Recursive Functions
Theory of Computation Lecture 22: Turing Machines II
Theory of Computation Lecture 13: A Universal Program V
Recursively Enumerable Sets
Theory of Computation Lecture 17: Calculations on Strings II
Theory of Computation Lecture 12: A Universal Program IV
Theory of Computation Lecture 11: A Universal Program III
Theory of Computation Lecture 23: Turing Machines III
Presentation transcript:

Theory of Computation Lecture 12: A Universal Program III The Halting Problem Let us define the predicate HALT(x, y). For a given number y, let P be the program such that #(P ) = y. Then HALT(x, y) is true if P(1)(x) is defined and false if P(1)(x) is undefined. In other words: HALT(x, y)  program number y eventually halts on input x. Here comes a surprise: Theorem 2.1: HALT(x, y) is not a computable predicate. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III The Halting Problem Proof (by contradiction): Assume that HALT(x, y) were computable. Then we could write the following program P : [A] IF HALT(X, X) GOTO A This program P would compute the following function: P(1)(x) =  if HALT(x, x) = 0 if HALT(x, x) Now let #(P ) = y0. Then by the definition of HALT we get: HALT(x, y0)  HALT(x, x) For input x = y0 we then have: HALT(y0, y0)  HALT(y0, y0) Contradiction! October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III The Halting Problem So finally we have an example of a predicate that is not computable by any program in the language L . We would even like to conclude the following: There is no algorithm that, given a program of L and an input to that program, can determine whether or not the given program will eventually halt on the given input. This is called the unsolvability of the halting problem. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III The Halting Problem If there were such an algorithm, we could use it to determine the truth value of HALT(x, y) for given x and y: We would first obtain the program Q so that #(Q ) = y. Then we would check whether Q eventually halts on input x. However, we have reason to believe that any algorithm for computing on numbers can be carried out by a program of L (Church’s Thesis). So this would contradict the fact that HALT(x, y) is not computable. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III The Halting Problem It may surprise you that there is no algorithm for solving the halting problem. Is it not possible for a computer scientist to analyze a given program and find out whether it will terminate for a particular input or not (even if this analysis takes a very long time)? No, actually we can devise a very simple program in L for which to date nobody is able to tell whether it will ever terminate. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III The Halting Problem This program is based on Goldbach’s conjecture, which assumes that every even number  4 is the sum of two prime numbers. For example, 4 = 2 + 2, 6 = 3 + 3, 48 = 41 + 7. It would be easy to write a program in L that searches for a counterexample to this conjecture. This program would check the following predicate for increasing values n: (x)n(y)n[Prime(x) & Prime(y) & x + y = n] Nobody knows whether this program will ever halt. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality For each n > 0, let us define: (n)(x1, …, xn, y) = P(n)(x1, …, xn) , where #(P ) = y. Theorem 3.1 (Universality Theorem): For each n > 0, the function (n)(x1, …, xn, y) is partially computable. This is one of the most important theorems in computability theory. We will prove it by providing instructions for writing a program Un that computes (n) for each n > 0. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality In other words, for each n > 0 we want to have: Un(n+1)(x1, …, xn, xn+1) = (n)(x1, …, xn, xn+1) . These programs Un are called universal. For example, U1 can be used to compute any partially computable function of one variable. If there is a program P that computes f(x), and #(P ) = y, then f(x) = (1)(x, y) = U1(2)(x, y). It is useful to think of the programs Un in terms of interpreters of programs in L . October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality The universal programs must decode the number of the program given to them, keep track of the current snapshot during program execution, and generate the next snapshot based on the current one and the current instruction. When we write such programs, we will freely use macros referring to functions that we already know to be primitive recursive. We will also freely use label and variable names beyond those specified for the language L . October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality In describing the state of a computation, we assume all variables to have the value 0 if not assigned a different value. Then we can code the state of the computation by the Gödel number [a1, …, am], where ai is the value of the i-th variable in our ordered list. Obviously, m is chosen so that all ai for i > m are 0. For example, the state Y = 1, X = 2, Z2 = 1 is coded by the following number: [1, 2, 0, 0, 1] = 2  32  11 = 198. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality In order to store the current snapshot, we need to keep track of two numbers: K is the number of the instruction to be executed next, and S is the current state coded as a Gödel number (see previous slide). Now we are ready to write the program Un for computing Y = (n)(X1, …, Xn, Xn+1). We will explain Un piece by piece and finally put the pieces together. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality Z  Xn+1 + 1 S  ni=1 (p2i)Xi K  1 If Xn+1 = #(P ), where P consists of the instructions I1, …, Im, then Z = [#(I1), …, #(Im)]. S is initialized as [0, X1, 0, X2, …, 0, Xn], which puts the input values into the first n input variables and 0s into the other variables. K is given the value 1 so that the computation will begin with the first instruction. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality Then we append the following instruction: [C] IF K = Lt(Z) + 1  K = 0 GOTO F So if the computation has ended, GOTO F, where the proper value will be output. Otherwise, the current instruction is decoded and executed: U  r((Z)K) P  pr(U)+1 Remember that (Z)K = a, b, c is the number of the K-th instruction. So U = b, c is the code of the statement to be executed. The variable mentioned in this statement is the (c + 1)-th, i.e., the (r(U) + 1)-th. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality Then l(U) contains the type of the instruction to be executed. IF l(U) = 0 GOTO N IF l(U) = 1 GOTO A IF (P | S) GOTO N IF l(U) = 2 GOTO M If either the instruction is V  V, or the instruction is V  V-1 and V = 0 (as indicated by the absence of P in S), or the instruction is IF V0 GOTO L and V = 0, then nothing is done to S (“nothing” - GOTO N). If the instruction is V  V+1, then the exponent of P in S needs to be incremented (“add” – GOTO A). If the instruction is V  V-1 with V > 0, then the exponent of P in S needs to be decremented (“minus” – GOTO M). October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality If none of the four previous predicates were true, a GOTO command has to be executed: K  miniLt(Z) [l((Z)i) + 2 = l(U)] GOTO C So if the label l(U) – 2 exists in the program, the number K of the next instruction to be executed will be set to the first instruction with that label. Otherwise, K will be set to 0. As you remember, if K = 0 or K = Lt(Z) + 1, then the computation stops. In any case, our interpreter program executes a GOTO C to execute the next instruction. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality The program continues as follows: [M] S  S/P GOTO N [A] S  S  P [N] K  K+1 GOTO C The value of the variable in the current instruction is decremented or incremented by 1 by dividing or multiplying S by P, respectively. Then K is incremented and the next instruction executed. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality The program concludes with the following line: [F] Y  (S)1 This way, after termination of the interpreted program, its output value becomes the output value of the interpreter. On the next slide, we will list the entire interpreter program. October 17, 2017 Theory of Computation Lecture 12: A Universal Program III

Theory of Computation Lecture 12: A Universal Program III Universality Z  Xn+1 + 1 S  ni=1 (p2i)Xi K  1 [C] IF K = Lt(Z) + 1  K = 0 GOTO F U  r((Z)K) P  pr(U)+1 IF l(U) = 0 GOTO N IF l(U) = 1 GOTO A IF (P | S) GOTO N IF l(U) = 2 GOTO M K  miniLt(Z) [l((Z)i) + 2 = l(U)] GOTO C [M] S  S/P GOTO N [A] S  S  P [N] K  K+1 [F] Y  (S)1 October 17, 2017 Theory of Computation Lecture 12: A Universal Program III