Recap (1) 1. Automata, grammars and other formalisms can be considered as mechanical devices to solve mathematical problems

Similar documents
Decidability: Church-Turing Thesis

Decision Problems with TM s. Lecture 31: Halting Problem. Universe of discourse. Semi-decidable. Look at following sets: CSCI 81 Spring, 2012

Decidability (What, stuff is unsolvable?)

Turing Machines, diagonalization, the halting problem, reducibility

The Turing Machine. Computability. The Church-Turing Thesis (1936) Theory Hall of Fame. Theory Hall of Fame. Undecidability

Non-emptiness Testing for TMs

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k.

CSCI3390-Lecture 6: An Undecidable Problem

Models. Models of Computation, Turing Machines, and the Limits of Turing Computation. Effective Calculability. Motivation for Models of Computation

CS20a: Turing Machines (Oct 29, 2002)

Final exam study sheet for CS3719 Turing machines and decidability.

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

TURING MAHINES

Introduction to Turing Machines. Reading: Chapters 8 & 9

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Computability Crib Sheet

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

1 Definition of a Turing machine

ACS2: Decidability Decidability

4.2 The Halting Problem

Decidable Languages - relationship with other classes.

Limits of Computability

What are the recursion theoretic properties of a set of axioms? Understanding a paper by William Craig Armando B. Matos

Undecidability. Andreas Klappenecker. [based on slides by Prof. Welch]

Reductions in Computability Theory

CPSC 421: Tutorial #1

ECS 120 Lesson 18 Decidable Problems, the Halting Problem

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

CSCE 551: Chin-Tser Huang. University of South Carolina

Notes for Lecture Notes 2

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

DM17. Beregnelighed. Jacob Aae Mikkelsen

The Unsolvability of the Halting Problem. Chapter 19

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

Turing Machines Part III

Further discussion of Turing machines

6.8 The Post Correspondence Problem

Turing Machines. Lecture 8

Context-free grammars and languages

Informal Statement Calculus

1 Acceptance, Rejection, and I/O for Turing Machines

Undecibability. Hilbert's 10th Problem: Give an algorithm that given a polynomial decides if the polynomial has integer roots or not.

Computational Models Lecture 8 1

V Honors Theory of Computation

Gödel s Incompleteness Theorem. Overview. Computability and Logic

Turing Machine Recap

Computability Theory. CS215, Lecture 6,

1 Computational Problems

Theory of Computation - Module 4

Automata Theory and Formal Grammars: Lecture 1

17.1 The Halting Problem

Final Exam Comments. UVa - cs302: Theory of Computation Spring < Total

Part I: Definitions and Properties

Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 8 Nancy Lynch

Artificial Intelligence. 3 Problem Complexity. Prof. Dr. Jana Koehler Fall 2016 HSLU - JK

Most General computer?

Computational Models Lecture 8 1

Turing Machines Decidability

Turing Machines (TM) The Turing machine is the ultimate model of computation.

Theory of Computation

CSE 105 THEORY OF COMPUTATION

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

König s Lemma and Kleene Tree

} Some languages are Turing-decidable A Turing Machine will halt on all inputs (either accepting or rejecting). No infinite loops.

CS 125 Section #10 (Un)decidability and Probability November 1, 2016

Introduction to Languages and Computation

Peano Arithmetic. CSC 438F/2404F Notes (S. Cook) Fall, Goals Now

15-251: Great Theoretical Ideas in Computer Science Fall 2016 Lecture 6 September 15, Turing & the Uncomputable

DR.RUPNATHJI( DR.RUPAK NATH )

Theory of computation: initial remarks (Chapter 11)

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

About the relationship between formal logic and complexity classes

This is logically equivalent to the conjunction of the positive assertion Minimal Arithmetic and Representability

Notes for Math 290 using Introduction to Mathematical Proofs by Charles E. Roberts, Jr.

Large Numbers, Busy Beavers, Noncomputability and Incompleteness

CS 361 Meeting 26 11/10/17

Turing Machines. Wolfgang Schreiner

CS 121, Section 2. Week of September 16, 2013

258 Handbook of Discrete and Combinatorial Mathematics

Undecidable Problems and Reducibility

Computational Models Lecture 8 1

Functions on languages:

Homework 8. a b b a b a b. two-way, read/write

PREDICATE LOGIC: UNDECIDABILITY AND INCOMPLETENESS HUTH AND RYAN 2.5, SUPPLEMENTARY NOTES 2

Theory of Computation

Theory of computation: initial remarks (Chapter 11)

Section 14.1 Computability then else

Lecture Notes: The Halting Problem; Reductions

CISC 876: Kolmogorov Complexity

CSE 4111/5111/6111 Computability Jeff Edmonds Assignment 3: Diagonalization & Halting Problem Due: One week after shown in slides

Computability Theory

ADVANCED CALCULUS - MTH433 LECTURE 4 - FINITE AND INFINITE SETS

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 27

Computation Histories

The purpose here is to classify computational problems according to their complexity. For that purpose we need first to agree on a computational

MA/CSSE 474 Theory of Computation

Computational Theory

Transcription:

Computability 1 Recap (1) 1. Automata, grammars and other formalisms can be considered as mechanical devices to solve mathematical problems Mathematical problems are often the formalization of some practical problem Example: the problem of deciding if a string belongs to a language can be seen as the mathematical formalization of the recognition of a statement in a programming language

Computability 2 Recap (2) 2. Some formalisms are more powerful than others TMs can accept languages that are not recognizable by NDPDAs 3. No formalism (among the ones we have seen) is more powerful than TMs Some formalisms are as powerful as TMs (e.g., two-stack automata)

Computability 3 Some questions (1) Are the introduced formalisms adequate to capture the essence of a mechanical solver? Differential equations Finding a path in a graph Does the ability of a mechanism to solve a problem depend on the way the problem is formalized?

Some questions (2) Do there exist computing formalisms more powerful than TMs? Some (future) super computer? Once a problem has been suitably formalized, can we always solve it by means of some mechanical device? Do we have the answers? Computability 4

Computability 5 Computability theory We want to show that our formalisms are adequate for any particular problem to be solved mechanically What is a problem? We need to investigate the power of TMs (and equivalent formalisms) w.r.t. any other theoretical or practical computer device We study the limits of mechanical problem solving Can we mechanically solve any definable problem?

Computability 6 A historical aside Aristotle s analysis of inference patterns (syllogisms) remained the only logical paradigm for two millennia and forms the basis of modern propositional logic His aim was to develop a universal method of reasoning by which one could learn everything there is to know about reality Both Leibniz and Pascal (17 th century) realized that syllogistic analysis could be done mechanically By machines feasible even with the limited technology of their time! Leibniz dreamed of a calculus ratiocinator: when there are disputes among persons, we can simply say calculemus, without further ado, to see who is right

Our formalisms Several problems can be formalized as language recognition or translation problems x L? y= τ(x)? More precisely, every mathematical problem can be formalized as above Computability 7

Formalization of a mathematical problem Our formalisms are suitable for all problems with denumerable domains Elements of such a domain can be put in a bijective correspondence with the elements of N The original problem is reduced to computing a function f: N N Computability 8

Example Problem: find a solution to a system of equations of the type a 1 x 1 +a 2 x 2 =c 1 b 1 x 1 +b 2 x 2 =c 2 where a 1, a 2, b 1, b 2, c 1, c 2 are integers It can be seen as computing a function f:z 6 Q 2 (integers and rational numbers respectively), defined as f(a 1, a 2, b 1, b 2, c 1, c 2 )=<r 1, r 2 > where r 1, r 2 are the values for the unknowns that solve the equations Computability 9

Computability 10 Recognition vs translation Recognition and translation are two formulations of a problem that can be reduced to one another From translation to recognition If I have a machine that can solve all problems of the form y = τ(x) and I wish to use it to solve the problem x L?, it suffices to define τ(x) = if x L then 1 else 0 From recognition to translation If I have a machine that can solve all problems of the form x L?, I can define the language L τ ={x$y y= τ(x)} For a fixed x, I can enumerate all possible strings y over the output alphabet and for each of them ask the machine if x$y L τ Sooner or later, if τ(x) is defined, I will find the string for which the machine answers positively The procedure is longish But here we are not concerned with the length of the computation

Remarks All the examined formalisms are discrete Denumerable mathematical domains defined in a finite way but this is in agreement with digital technologies The class of problems that can be solved by a TM is independent of the chosen alphabet (as long as it has at least two symbols) Computability 11

TMs and programming languages Given a TM M it is possible to build a Pascal (or C or FORTRAN or ) program that simulates M The computer runs the program with an arbitrarily large amount of memory Given any Pascal (or ) program it is possible to build a TM that computes the same function computed by the program TMs have the same expressive power as high-level programming languages Computability 12

Computability 13 Church s thesis (part I) There is no formalism to model any mechanical calculus that is more powerful than the TM or equivalent formalisms It is not a theorem (in principle, it should be checked every time anyone comes up with a new computational model)

Computability 14 Algorithms Algorithm is a fundamental concept in computer science Intuitively, by algorithm we mean a procedure to solve problems by means of an automatic computing device also seen as an abstract way to represent computer programs In summary, the notion of algorithm captures the notion of abstract sequence of commands to solve a problem in a mechanical way

(Informal) Properties of algorithms (1) 1. The sequence of statements must be finite 2. Any statement must be executable by some mechanical computing processor 3. The computing processor is provided with a memory to store intermediate results 4. Computation is discrete Information is coded digitally Computation proceeds through discrete steps Computability 15

Computability 16 (Informal) Properties of algorithms (2) 5. Algorithms are executed deterministically 6. There is no finite bound on input and output data 7. There is no bound on the available amount of storage required to perform computations 8. There is no bound on the number of discrete steps required to perform a computation

Computability 17 Church s thesis (part II) Any algorithm can be coded in terms of a TM (or an equivalent formalism) No algorithm can solve problems that cannot be solved by a TM: the TM is the most powerful computer that we have and will ever have!

Computability 18 Important question (and partial answer) Which are the problems that can be solved algorithmically (or, with an equivalent term, automatically )? Answer: These are exactly the problems that can be solved by the (relatively simple) TM!

TM: open questions (by now) TM = device to solve a given predefined problem A TM can be seen as an abstract, special-purpose non-programmable computer Questions: Can TMs model programmable computers? Can TMs compute all functions from N to N? Computability 19

Algorithmic enumeration A set S can be algorithmically enumerated (E) if we can find a bijection between S and N E : S N E can be calculated through an algorithm (i.e., a TM by Church s thesis) Example: Algorithmic enumeration of {a,b} * ε a b aa ab ba bb aaa aab 0 1 2 3 4 5 6 7 8 Computability 20

Important fact TMs can be algorithmically enumerated We need to show the algorithm that does it Some hypotheses (no loss of generality): Single tape TM Fixed alphabet A (e.g., A = 3, A = {0, 1, _}) Computability 21

Enumerating TMs (1) Example: TMs with two states The possible transition functions are 0 1 _ 0 1 _ q 0 q 0 q 1 q 1 <q 0, 0, S> MT 0 MT 1 NB: TMs differ also by their final states With 2 states there are 2 2 =4 possible sets of final states Computability 22

Enumerating TMs (2) How many transition functions of 2-state TMs? δ: Q A Q A {R,L,S} { } In general: how many functions f: D R? R D ( x D we have R choices} so with Q = 2, A = 3, (2 3 3+1) (2 3) = 19 6 transition functions of TMs with 2 states Considering the 2 2 choices for the final states, we have 19 6 2 2 TMs Let us sort these TMs: {M 0, M 1, M 19 6 22-1 } Computability 23

Enumerating TMs (3) Analogously we can sort the (3 3 3+1) (3 3) 2 3 TMs with 3 states and so on. We obtain an enumeration E: {TMs} N The enumeration E is algorithmic (or effective): we can always write a program in C (i.e., a TM ) that, given n, produces the n-th TM and vice versa E(M) is called the Gödel number of M and E a Gödelization Computability 24

Computability 25 Some conventions Since we are speaking of numbers, the following will be considered equivalent: Problem Computing a function f: N N Moreover: f y = function computed by the y-th TM

Computability 26 First answer Can TMs model programmable computers? Yes! Consider the Universal Turing Machine (UTM) The UTM computes the function g(y,x)=f y (x) f y (x) = function computed by the y-th TM on input x

Computability 27 The UTM is a TM UTM does not seem to belong to the family {M y } because f y is a function of one variable, while g is a function of two variables but we know that N N N ( x + y)( x + y + 1) d ( x, y) = + 2 x 6 1 3 4 0 2 5

Computability 28 How does the UTM work? (1) We can encode g(y,x) as a g^(n) = g(d -1 (n)), with n=d(y,x), <y,x>=d -1 (n) d and d -1 are both computable Organization of a UTM that computes g^ Given n it computes d -1 (n) =<y,x> Then it builds the transition function of M y (by computing E -1 (y)) and stores it on the tape of the UTM: $ q a q a S $....

How does the UTM work? (2) In another tape portion we store an encoding of the configuration of M y # 0 1 0.. 1 q 1 1 0 # NB: The special symbols (#, $, states, ) are used as separators and do not occur elsewhere At the end, the UTM leaves on the tape f y (x) if and only if M y terminates its computation on x Computability 29

Computability 30 Remarks The TM is a very abstract and simple model of a computer Let us continue the analogy: TM: computer with a single, hard-coded program An ordinary TM always executes the same algorithm, i.e., it always computes the same function UTM: computer with program stored in memory: y = program x = input to the program

Computability 31 Second answer Can TMs compute all functions from N to N? More precisely does the UTM compute all functions from N to N? No, there are functions that cannot be computed by any UTM I.e., by Church s thesis: there are problems that cannot be solved algorithmically It is not only an intuition, we can prove it

Cardinalities of sets of functions Two interesting questions: How many functions f: N N are there? Which are the functions f y : N N? Let us start with how many : {f: N N} {f: N {0,1} } {f: N N } {f: N {0,1} } = (N) = 2 א 0 א 0 = cardinality of the set N of all natural numbers read aleph-naught or aleph-zero 2 א 0 = cardinality of the set R of all real numbers Computability 32

Problems vs Solutions The set of problems: {f: N N } {f: N {0,1} } = (N) = 2 א 0 The set of functions computed by TM {f y : N N} is by definition denumerable NB: E: {M y } N induces E^: N {f y } not one-to-one (in many cases f y = f z, with z y) but it suffices to be able to state that {f y : N N} = א 0 < 2 א 0 most of the problems cannot be solved algorithmically! There are many more problems than programs! Computability 33

Computability 34 Definable problems In order to define a problem we need to use a sentence (string) of some language: f(x) = x 2 f(x) = x g(z)dz a the number that multiplied by itself is equal to y Any language is a subset of A *, which is a denumerable set The set of the problems that can be defined is also denumerable Question: {Solvable Problems} = {Definable Problems}? Certainly {Solvable Problems} {Definable Problems}

Computability 35 Example The halting problem I build a program I give it some input data I know that in general the program might not terminate its execution (it could run into a loop ) Can I determine (in advance) if this will occur? This problem can be expressed in terms of TMs: Given a function g(y,x) = 1 if f y (x), g(y,x) = 0 if f y (x) = Is there a TM that computes g?

Computability 36 Which problems can be solved? A TM that computes g does not exist That s why a computer (which is a program) cannot warn us that the program we just wrote will run into an infinite loop on certain data (while it can easily report a missing } ) Some examples: Determining whether an arithmetic expression is well parenthesized is a solvable (decidable) problem Determining whether a given program will run into an infinite loop on a given input is an algorithmically unsolvable (undecidable) problem

Proof methods Proof by induction This technique can be used, e.g., to show that an FSA is coherent with the language it is defined for Constructive proof Proof by contradiction. There are other useful approaches Computability 37

Computability 38 Proofs by diagonalization (1) The original diagonalization argument was used by Georg Cantor in 1891 to prove that R has greater cardinality than N It is used to prove the undecidability of some famous problems The notion of proof by diagonalization refers to a common pattern

Computability 39 Proofs by diagonalization (2) Informally, it obtains a contradiction when there exists a set of functions A B which is indexed by A. If f k is the function indexed by k A, a diagonalization argument is f f f f 1 2 3 4 " f f f f 1 2 3 4 1 (1) (1) (1) (1) " f f f f 1 2 3 4 2 (2) (2) (2) (2) " f f f f The diagonal of the array is the list of values given by f k (k). 1 2 3 4 3 (3) (3) (3) (3) " f f f f 1 2 3 4 4 (4) (4) (4) (4) " # # # # #!

Proofs by diagonalization (3) We define the diagonal element as a function d:a B that differs from the diagonal at every value. d is a function A B, so it appears on the list but it also differs from every member of the list at the diagonal hence we have a contradiction Computability 40

Computability 41 Informally No TM can decide whether, for a generic TM M and a generic input x, M halts on input x Here by halts, we mean halts in a final state NB: It is always possible to build a TM that will eventually terminate if and only if it reaches a final state (emulation)

Computability 42 Formally No TM can compute the total function g: N N {0,1} defined as g(y,x)= if f y (x) then1 else 0 f y (x) means that M y comes to halt in a final state on reading x so that f y (x) is defined

Computability 43 Proof (1) It employs a typical diagonal technique Let us assume (by contradiction) that g(y,x) = if f y (x) then 1 else 0 is computable From g, let us define function h such that h(x) = if g(x,x) = 0 then 1 else g(x,x) = 0 corresponds to f x (x) = If g were computable then h would be computable too

Proof (2) Notice that if h is computable then h = f i for some i. Let us compute h in i If h(i) = f i (i) = 1 then g(i,i) = 0, that is, f i (i)= CONTRADICTION If h(i) = f i (i) = then g(i,i) = 1 that is, f i (i) CONTRADICTION Computability 44

An important lemma (1) The function h (x)=if f x (x) then 1 else 0 is not computable It is not a corollary, but a lemma of the previous claim (halting problem) This result cannot be derived from the previous one Computability 45

Computability 46 An important lemma (2) Notice that h (x) is a special case of function g(y,x) g(y,x) = if f y (x) then 1 else 0 because h (x)=g(x,x) and g was just proved to be uncomputable The uncomputability of h(x) is not an immediate consequence of the uncomputability of g(y,x): If a problem is unsolvable, then a special case of it might be solvable e.g., some properties that cannot be decided for recursively enumerable languages can be decided for regular languages Instead, a generalization of an unsolvable problem is necessarily unsolvable If a problem is solvable, a generalization of it might be unsolvable But any specialization of it is certainly solvable

Another important result (1) The function k(y) = 1 if f y is total, i.e., k(y) = if ( x N f y (x) ) then 1 else 0 is not computable This problem presents a quantification w.r.t. all possible input data. In some cases we could be able to establish, for a fixed value of variable x, whether f y (x) perhaps even for every single, fixed value of x without however being able to answer the question is f y a total function? Computability 47

Another important result (2) From a practical viewpoint, this problem is (perhaps) even more relevant than the previous one Given a (generic) program, we want to know if it will terminate the execution for every input data or if it may, for some data, run into an endless loop In the halting problem, instead, we were interested in knowing whether a given (generic) program with some given (generic) input data terminates Computability 48

Computability 49 Proof (1) Standard technique: diagonal + contradiction, with some technicalities. Hypothesis: k(y) = if ( x N f y (x) ) then 1 else 0 is computable and (by definition) total Then define g(x) = w = index (Gödel number) of the x-th TM (in E) that computes a total function If k is computable and total, then so is g: compute k(0), k(1),, let w 0 be the first value such that k(w 0 ) = 1, then let g(0) = w 0 ; then let g(1) = w 1, w 1 being the second value such that k(w 1 ) = 1; the procedure is algorithmic; furthermore, since there are infinitely many total functions, g(x) is certainly defined for each x, hence it is total.

Computability 50 Proof (2) g is also strictly monotonic: w x+1 > w x ; hence g -1 is also a function, strictly monotonic too, but not total: g -1 (w) is defined only if w is the Gödel number of a total function Then: 1. We define h(x) = f g(x) (x) + 1 = f w (x) + 1 f w is computable and total hence so is h 2. Therefore, we have h = f w i for some w i since h is total, g -1 (w i ), let g -1 (w i ) = x i What is the value of h(x i )? h(x i ) = f g(xi )(x i ) + 1 = f wi (x i ) + 1 (from (1)) h = f wi h(x i ) = f wi (x i ) (from (2)) Contradiction!

Computability 51 Solvability and solutions (1) Observation: knowing that a problem is solvable does not mean that we know how to solve it (and what the solution is) In mathematics we often have non-constructive proofs: one shows that a mathematical object exists, but does not compute it In our case: a problem is solvable if there exists a TM that solves it for some problems one can reach the conclusion that there exists a TM that solves them, but despite this one cannot build it A trivial case: the problem consists of answering a question with a yes/no answer (a so-called closed question): Is it true that the number of atoms in the universe is 10 10101010? Is it true that the perfect chess game will end in a draw? (before 1995...) Is it true that ( x,y,z,w N x y +z y =w y y>2)?.

Computability 52 Solvability and solutions (2) In the previous examples, one knows a priori that the answer is either Yes or No though one does (did) not know which one it is Problem = function; solve a problem = compute a function What function can one associate with the previous problems? If one encodes TRUE=1; FALSE=0, all the above problems are expressed by one of the following two functions: f 1 (x) = 1, x, f 2 (x) = 0, x Both functions are computable More abstractly: g(10,20) = 1 if f 10 (20), g(10,20) = 0 if f 10 (20) = g(100,200) = 1 if f 100 (200), g(100,200) = 0 if f 100 (200) = g(7,28) = 1 if f 7 (28), g(7,28) = 0 if f 7 (28) =. As standalone problems, these are all solvable However, we do not necessarily know the solution

Non-trivial examples (1) Let us now consider less trivial cases: f(x) = x-th digit of the decimal expansion of π f is computable (we know algorithms (TMs) to compute it) Let us investigate the computability of the following function g(x) = if in π exactly x consecutive 5 digits then 1 else 0 By computing the sequence (π =3.14159 ) {f(0) = 3, f(1) = 1, f(2) = 4, f(3) = 1, f(4) = 5, f(5) = 9, } We get g(1) = 1 In general the plot of function g will be something like: 1 0 1 3 x 5 y 9 10 Computability 53

Computability 54 Non-trivial examples (2) For some value of x we might find that g(x) = 1 More so, if g(x)=1, sooner or later we will find it, if we are patient But could we conclude that, for instance, g(100000000) = 0 if after computing f(1000000000000000) we have not (yet) found 100000000 consecutive 5 s? Can we rule out the following conjecture? For every x, by producing a sufficiently long sequence of π, sooner or later we will find x consecutive 5 s If this conjecture were true, then it would follow that g is the constant function g(x) = 1 x, and we could conclude that we can compute g. In conclusion, at the current state of the art, we can neither conclude that g is computable, nor that it is not.

Computability 55 Non-trivial examples (3) Now consider the following slight modification of g: h(x) =if in π at least x consecutive 5 s then 1 else 0 if g(x) = 1 then also h(x) = 1; Notice however that if, for some x, h(x) = 1, then h(y)=1 y x. The plot of h is like one the following two: 1) h(x) = 1 x 2) x h(x) h(x) = 1 x x = 0 x > x

Computability 56 Non-trivial examples (4) Then h certainly is in the following set of functions {h h (x) = 1 x x h (x) = 0 x x x x Each function in this set is trivially computable > x} {h h(x) = 1 x} for any fixed x it is immediate to construct a TM that computes h ; similarly for h x Therefore h is certainly computable there exists a TM that computes it Can we compute h? (more precisely stated: Do we know which of the functions in the above set is h?) No (at the moment): among the infinite TM s that compute the functions of the above set we do not know which is the right one!

Computability 57 Decision problem A decision problem is a question that has two possible answers: yes or no. The question is about some input. Examples: Given a graph G and a set of vertices K, is K a clique? Given a graph G and a set of edges M, is M a spanning tree? Given a set of axioms, a set of rules, and a formula, is the formula provable under the axioms and rules?

Semidecidability A problem is semidecidable if there is an algorithm that says yes if the answer is yes however it may loop forever if the answer is no. Let us consider again the example of the halting problem in a TM It is undecidable, but it is semidecidable: if the TM stops, sooner or later we will find out How can we obtain a semidecidability result? Computability 58

Computability 59 Example: does a TM halt for some value? The problem of determining if z f x (z) is semidecidable Sketch of the proof If we compute f x (0) and find f x (0) then the answer is yes; What if the computation of f x (0) does not terminate and f x (1) : how can we find out?

Sketch of proof Then we use the following trick (once more a diagonal technique): We simulate 1 execution step of f x (0): if we stop, then the answer is yes; Otherwise we can simulate one computation step of f x (1); Again, if it does not stop, we can simulate 2 steps of f x (0); next, 1 step of f x (2); 2 steps of f x (1); 3 of f x (0); and so on, according to the scheme in the figure: input argument z 3 2 1 0 1 2 3 4 n. of steps Computability 60

Computability 61 Conclusion There is a large number of undecidable problems that are semidecidable Typical example: runtime errors in programs Observe that the semidecidable problem is: The presence of the error (if there is an error I can find it) Not its absence! Important implications on verification by testing Famous statement by Dijkstra: testing can prove the presence of errors, not their absence

Recursive sets Let us focus on the problems stated in such a way that the answer is binary: Problem = does x belong to set S? (where S N) All binary problems can be (re)phrased in such a way Characteristic function of a set S: c S (x) = if x S then 1 else 0 A set S is recursive (or decidable) if and only if its characteristic function is computable c S is total by definition Computability 62

Computability 63 Recursively enumerable S is recursively enumerable (RE) (or semidecidable) if and only if: S is the empty set, or S is the image of a total, computable function g s S=I g S={x x=g S (y), y N} S={g S (0), g S (1), g S (2), } The term recursively enumerable comes from this enumeration and the term semidecidable can be explained intuitively: if x S then, by enumerating the elements of S, sooner or later one finds x and is able to get a correct (yes) answer to the question; but what if x S?

Theorem (½ + ½ = 1) (A) If S is recursive, then it is also RE (i.e., decidable is more demanding than semidecidable) (B) S is recursive if and only if both S itself and its complement S^ = N - S are RE Two semidecidabilities make a decidability Here, answering NO to a problem is exactly as difficult as answering YES to its complement Corollary: the class of decidable sets (languages, problems, ) is closed under complement Computability 64

Proof (A) Claim: Recursive -> RE If S is empty, it is RE by definition If S, let c s be its characteristic function since S, k S, therefore k c s (k) = 1 Let us define the generating function g s as follows: g s (x) = if c s (x) = 1 then x else k g s is total and computable, and I gs = S S is RE This is a non-constructive proof: We don t know whether S We don t require an algorithm to find a specific k We just know that g s exists if S : this is enough for us! Computability 65

Computability 66 Proof (B) (B) is equivalent to: (B.1) S recursive both S and S^ RE and (B.2) both S and S^ RE S recursive (B.1.1) S recursive S RE (part A) (B.1.2) S recursive c S (x) (= 1 if x S, c S (x) = 0 if x S) computable c S^(x) (= 0 if x S, c S (x) = 1 if x S) computable S^ recursive S^ RE (B.2) S RE construct the enumeration S={g S (0), g S (1), g S (2), } S^ RE construct S^={g S^(0), g S^(1), g S^(2), } but S S^ = N, S S^ = hence x N, y x=g S^(y) x=g S (y) ( z x=g S^(z) x=g S (z)) x belongs to one and only one of the two enumerations If one constructs the enumeration {g S (0),g S^(0), g S (1), g S^(1), g S (2), g S^(2), } one can certainly find in it any x: if x is at an odd position, then x S, if it is at an even position then x S^. Hence c S can be computed

Computability 67 A statement with practical impact Consider the set S with the following features: i S f i total (i.e., S contains only indexes of total computable functions) f total and computable i S f i = f (i.e., S contains all of them) S is the set of indexes of total computable functions then S is not RE Provable by diagonalization This means that there does not exist a RE formalism (Automata, grammars, recursive functions, ) that can define all computable total functions, and only them: FSAs define total computable functions, but not all of them; TMs define all computable functions, but including also the non-total ones Similarly, the C programming language allows one to code any algorithm, but also the nonterminating ones There is no subset of C that defines exactly all the terminating programs! The set of C programs in which for loops comply with given constraints that guarantee termination includes terminating programs only, but necessarily not all terminating programs

Computability 68 Getting rid of partial functions Let us extend a function, for instance by extending N with a new value { }, or simply by assigning f a conventional value when f is undefined The trick does not work, because of the following result: There is no total computable function that is an extension of the following function (computable but not total) g(x) = if f x (x) then f x (x) + 1, otherwise One can take any partial function and make it total, but in doing that one may lose computability Again, provable by diagonalization

Computability 69 Another useful result Theorem S is RE S = D h, with h computable and partial: S = {x h(x) } and S is RE S = I g, with g computable and partial: S = {x x = g(y), y N} We can now show that there exist semidecidable sets that are not decidable K = {x f x (x) } is semidecidable because K = D h with h(x) = f x (x). We know however that the characteristic function of K, c K (x) = if f x (x) then 1 else 0 is not computable K is not decidable

Computability 70 Conclusion P(N) Recursive sets RE sets Note that inclusions are all strict RE sets (i.e., languages recognized by TMs) are not closed w.r.t. complement

Closure properties Language family Formalism Union Intersection Complement c Set difference * Kleene star. Concatenation Regular FSA, NDFSA reg. exp. reg. gram. Deterministic context-free DPDA X X X X X Contextfree NDPDA Contextfree gram. X X X Recursively enumerable TM, NDTM General gram. X X Contextsensitive Contextsensitive gram. Recursive (Decider)

Computability 72 Kleene s fixed-point theorem Let t be a total and computable function. Then it is always possible to find an integer p such that f p =f t(p) Function f p is called a fixed point of t

Rice s theorem Let F be a set of computable functions The set S of (the indices of) TMs that compute the functions of F S = { x f x F } is decidable if and only if either F = or F is the set of all computable functions in all nontrivial cases S is not decidable! Computability 73

Computability 74 Proof (1) By contradiction, suppose that S is recursive, F and F is not the set of all computable functions Let us consider the characteristic function c S of S c S (x) =if f x F then 1 else 0 By hypothesis, c S is computable, so by enumerating each TM M i, we can find (1) the first i S such that f i F and (2) the first j S such that f j F

Computability 75 Proof (2) Since c S is computable, then so is c S : c S (x)= if f x F then i else j (3) By Kleene s theorem, there exists an x such that f c S (x )=f x (4) There are two cases Suppose c S (x )=i then by (3) f x F, but by (4) f x = f i and by (1) f i F: contradiction. Suppose instead c S (x )=j, then by (3) f x F, but by (4) f x =f j and by (2) f j F: contradiction

From Rice s theorem Rice s theorem has strong negative implications: There is an endless list of interesting problems whose undecidability follows trivially from Rice s theorem For any chosen set F={g}, by Rice s theorem it is not decidable whether a generic given TM computes g or not Computability 76

Practically Program correctness: does P solve a given specified problem? (does M x compute the function that constitutes the set {f}?) Program equivalence (does M x compute the function that constitutes the set {f y }?) Does a program have any property concerning the function it computes (function with even values, function with a limited image, )? Computability 77

Computability 78 Problem reduction (1) A problem P is said to be reduced to a problem P if an algorithm for solving P is used to solve P, i.e.: P is solvable There is an algorithm that, for any given instance of P : 1. determines a corresponding instance of P 2. algorithmically builds the solution to the instance of P from the solution to the instance of P Example: Suppose the problem of searching an element in a set can be solved Then I can solve the problem of computing the intersection of two sets

Computability 79 Problem reduction (2) Formally: We want to check whether x S We are able to check whether y S If there is a computable, total function t such that x S t(x) S then we can answer the question x S? algorithmically

Computability 80 Reduction - the other way around The procedure can also work in the opposite way: We want to know whether we can solve x S We know that we cannot solve y S (S is not decidable) If we find a computable, total function t such that y S t(y) S then we can conclude that x S is not decidable

Computability 81 Another example of reduction We already used implicitly this way of reasoning several times: From the undecidability of the halting problem for TMs we derived in general the undecidability of the problem of termination of any computer computation: Consider a TM M y, an integer x, a C program P, an input file f We can build a C program P that simulates M y and we store x in an input file f P terminates its computation on f if and only if g(y,x) If we could decide if P terminates its computation on f then we could also solve the halting problem for the TM

Computability 82 A rather general mechanism (1) Is the problem does a generic program P access an uninitialized variable? decidable? Let us assume (by contradiction) that it is decidable Then we can consider the halting problem and reduce it to the following new problem: Given a generic program P^ that takes as input some generic data D, we can build a program P as follows: begin var x, y: P^; y := x end making sure that identifiers x and y are not used in P^ It is clear that the assignment statement y := x results in accessing an uninitialized variable, because x does not occur in P^ Hence the uninitialized variable x is accessed in P if and only if P^ terminates. If we could solve the problem of uninitialized variable access then we could also solve the termination problem, which we cannot

Computability 83 A rather general mechanism (2) The same technique can be applied to prove the undecidability of many other typical properties of program execution: Array indices out of bounds Division by 0 Dynamic type compatibility Typical runtime errors