You are on page 1of 258
COMPUTABILITY An introduction to recursive function theory NIGEL CUTLAND Depariment of Pure Mathematics, University of Hull ao Lani \oIe BIBL gan 8 CAMBRIDGE UNIVERSITY PRESS. Cambridge London New York New Rochelle Melbourne Sydney Published bythe Press Syndicate ofthe Univesity of Cambridge ‘The Pit Building, Trumpington Street. Cambridge CB2 1RP [32 East STth Sire, New York, NY 10022. USA 1 Stamford Road. Oakleigh. Melbourne 3166. Ausialia ‘SCambridge University Pres 1980 First published 1980 Reprinied 1983, 1984 Printed in Great Britain a The Pitman Press. Bath Library of Congress Cataloguing in Publication Data Cutland. Nige, Computability: an introduction wo recursive function theory. Bibliography: p. Includes indo 1 Computable functions. 2, Recursion theory Tle QAs.59.C87 519.4 7951825 ISBN 0521 22384 9 hard covers ISBN 0 521 29465 7 paperback Contents Preface Prologue. Prerequisites and notation 1 Sets 2 Functions 3 Relations and predicates 4 Logical notation 5 References. Computable functions 1 Algorithms, or effective procedures 2 The unlimited register machine 3 URM-computable functions 4 Decidable predicates and problems 5 Computability on other domains Generating computable functions 1 The basie functions 2 Joining programs together 3 Substitution 4 Recursion 5 Minimalisation ‘Other approaches to computability: Church's thesis 1 Other approaches to computability 2 Partial recursive functions (Giidel-Kleene) 3 A digression: the primitive recursive funetions 4 Turing-computability 5 Symbol manipulation systems of Post and Markov {6 Computability on domains other than N 7 Church's thesis Numbering computable functions 1 Numbering programs 2 Numbering computable functions 3 Discussion: the diagonal method 4 The -m-n theorem Contents v Universal programs 8s 1 Universal functions and universal programs 85 2 Two applications of the universal program 90 3 Effective operations on computable Functions 93 ‘Appendix. Computability ofthe function a, 95 Decidability, undecidablity and partial decidabitity 100 1 Undecidable problems in computability 101 2 The word problem for groups 106 3 Diophantine equations 107 4 Sturn algorithm 108 5 Mathematical logic 109 6 Partially decidable predicates 12 Recursive and recursively emumerable sets 121 1 Recursive sets a 2 Recursively enumerable sets 123, 3. Productive and ereative sets 133 4 Simple sets 140 Arithmetic and GadePs incompleteness theorem 143 1 Formal arithmetic 143 2 Incompleteness 146 3 Gidefs incompleteness theorem 149 4 Undecidability 155 Reducibility and degrees 157 1 Many-one reducibility 158 2 Degrees 161 3 m-complete re. sets 165 4 Relative computability 167 5 Turing reducibility and Turing degrees 14 Effective operations on patil functions 182 1 Recursive operators 182 2 Effective operations on computable functions 189 3 The first Recursion theorems 192 4 An application to the semantics of programming languages 196 ‘The second Recursion theorem, 200 1 The second Recursion theorem 200 2 Discussion 207 3 MyhilPs theorem 210 Complexity of computation 212 1 Complexity and complexity measures 213 2 The Speed-up theorem 218 3 Complexity classes 223 4 The elementary functions 2s Contents 13. Further study Bibliography index of notation Subject index 236 239 24 246 Preface The emergence of the concept of a computable function over fiy years ‘ago marked the birth of @ new branch of mathematics: its importance may bbe judged from the fact that it has had applications and implications in fields as diverse as computer science, philosophy and the foundations of mathematics, as well as in many other areas of mathematics itself. This book is designed to be an introduction to the basic ideas and results of ‘computability theory (or recursian theory, as it is traditionally known ‘among mathematicians), ‘The initial purpose of computability theory is to make precise the intuitive idea of @ computable function; that is, a function whose values ‘ean be calculated in some kind of automatic or effective way. Thereby we ccan gain a clearer understanding of this intuitive idea; and only thereby ccan we begin to explore in a mathematical way the concept of compu- ‘ability as well as the many related ideas such as decidability and effective cenumerability. A rich theory then arises, having both positive and negative aspects (here we are thinking of HOH-computability and «zideci- ability results), which i is the aim of this book to introduce. We could describe computability theory, from the viewpoint of computer science, as beginning with the question What can computers do in principie (without restrictions of space, time or money)?-and, by implication - What are their inherent theoretical limitations? Thus this book is not about real computers and their hardware, nor is it about programming languages and techniques. Nevertheless, our subject ‘matter is part of the theoretical background to the real world of ‘computers and their use, and should be of interest to the computing ‘community. For the basic definition of computability we have used the ‘idealised computer’ or register machine approach; we have found that this is readily ‘arasped by students, most of whom are aware of the idea of a computer: (We do not, however, assume such an awareness (although it is helpful) Preface ix and even less do we assume any practical experience with computers or calculators.) Our approach is mathematically equivalent to the many others that have been discovered, including Turing machines, the favourite of many. (We discuss these equivalences in chapter 3.) This text grew out of a course given to undergraduates in mathematics and computer science at the University of Hull. The reader envisaged is a ‘mathematies student with no prior knowledge of this subject, or a student of computer science who may wish to supplement his practical expertise with something of the theoretical background to his subject. We have ‘simed at the second or third year undergraduate levei, although the earlier chapters covering the basic theory (chapters 1-7) should be within the grasp of good students in sixth forms, high schools and colleges (and their teachers). The only prerequisites are knowledge of the mathemati- coal language of sets and functions (reviewed in the Prologue) and the ability to follow a line of mathematical reasoning, ‘The later chapters (8-12) are largely independent of each other. Thus & short introductory course could consist of chapters 1-7 supplemented by selection according to taste from chapters 8-12, It has been our aim in these later chapters to provide an introduction to some of the ramifications and applications of basic computability theory, and thereby provide a stepping stone towards more advanced study. To this end, the final chapter contains a brief survey of possible directions for further study, and some suggestions for further reading. (The two main texts that might be regarded as natural sequeis to this one are M. L. Minsky, Computation: Finite and Infinite Machines, which would complement the present volume by its broad and comprehensive study of computation (as ‘opposed fo computability), and H, Rogers, Theory of Recursive Functions and Effective Computability, which provides a more advanced treatment of recursion theory in depth.) Many people have helped towards the writing of this book. I would first thank John Cleave, who taught me recursive function theory in a gradu- ate course at the University of Bristol in 1966, and introduced me fo the register machine approach that T have used here. I have greally appreci- ated the sustained interest and encouragement from Stan Wainer (who also made valuable suggestions for the material in chapters 10 and 12) and David Jordan: 1 thank them, I would also like to thank David Jordan and Dick Epstein for reading a draft of the manuscript and making many valuable comments and corrections. I am grateful to the Cambridge University Press for their interest and advice which has resulted in the ‘emergence of the completed manuscript. Preface x Finally, a big thank you to my wife Mary for her patience and encouragement during the many phases of writing and preparation of this, ook; her idealism and understanding have been a sustaining influence throughout Prologue Prerequisites and notation ‘The only prerequisite to be able to read this book is familiarity with the basic notations of sets and functions, and the basie ideas of mathematical reasoning. Here we shall review these matters, and explain the notation ‘and terminology that we shall use. This is mostly standard; so for the reader who prefers to move straight to chapter 1 and refer back to this prologue only as necessary, we point out that we shall use the word function to mean a partial function in general. We discuss this more fully below. 1 Sots Generally we shal use capital lesters A, B, C... to denote set We write x 6 to mean that x is a member of A, and we write xiAto mean that x is not a member of A. The notation {x:... x..} where x. is some stafement involving x means the set ofall objects x for which... is te, Thus {x x i an even natural number) is the sot 10, 2,4,6,...}. TFA, B are sels, we write A gB to mean that A is contained in B (or A is e subset of B); we use the notation A <= B to mean that Ag B but A # B (ic. A is a proper subset of B). The union of the sets A, B is the sot (8:46 A oF x B (or both)}, and is denoted by A w B; the intersetion of A, B is the sot (WXGA and xoB) and is denoted by 4clB. The difference (or relative complement) of the sets A, B is the setfxx GA and xé B} and is denoted by A \B. The empty set is denoted by 0, We use the standard symbol N to denote the set of natural numbers {0, 1, 2, 3,...}. If A is @ set of natural numbers (Le. AgN) we write 4 to denote the complement of A relative to M, ie. MIA. We write) for the set of positive natural numbers (1,2, 3, and as usual Z denotes the set of integers Prologue 2 We write (x, y) to denote the ordered pair of elements x and y; thus (s,») # (yx) in general If A, B are sets, the Cartesian product of A and B is the set {(x, yx G A and y G B}, and is denoted by 4 x B. More generally, for elements Xi, X, We Write (KijnX,) 10 denote the ordered n-tuple of Xjya %,; an SHuple is often represented by a single boldfaced symbol such a6 x. If Aju, A, are sets we write AIX. x 4, for the set of mtuples {(xin., x): Xi G Ai and xe Adu x, 6 Au}. The product Ax A x... x A (w times) is abbreviated by AN At means A. 2. Funetions ‘We assume familiarity with the basic idea of a function, and the distinction between a function f and a particular value /(x) at any given x where f'is defined." If fis a function, the domain of fis the set {x: M(x) is defined}, and is denoted Dom(i); we say that x) is undefined if xéDomf). The set {/(x): x G Domi()} is called the range of /, and is denoted by Ran(). If A and B are sets we say that fis a function from A to B if Dom(/) c.A and Ran(/) ¢ B. We use the notation fA -> B to mean that is a function from A to B with Dom(/)~ A. ‘A funetion fis said to be injective if whenever x, y 6 Dom) and x # y, then /&x) # /09). If fis injective, then J denotes the inverse of /, ie, the unique function g such that Dom(g) = Ran() and g(/(x)) = x for x6 Dom(/). A function ffrom A to B is surjetive if Ran(/) = B. IffA-* B, we say that fis an injection (from A to B) if it is injective, and a surjection (from A to B) if itis surjective, It is a bijection if itis both an injection and a surjection. Suppose that fis a function and X is a set. The restriction of f to X, denoted by UX, is the function with domain ADom(/) whose value for x G Xn Dom() is x). We write (4) for Ran(}X). If ¥ is a set, then the inverse image of Yunderfis the set'y) = {x: ((X}G Yf. (Note that this is defined even when fis not injective.) If /, g are functions, we say that g extends f if Dom(,) Q Dom(g) and fos) = g(x) for all xGDom(/): in short, / =x[Dom(/). This is written "e * Usually in mathematical texts a function fis defined to be a set of ordered pais such that if x, yeland (, 2), then y = % and fe is defined to be this. We do not insist on tis definition oF a function, but our exposition i consistent with 2 Functions 3 ‘The composition of two functions /, g is the fimetion whose domain is the set {x: xeDom(g) and (xe Dom()}, and whose value is (g(x) when defined, This fimetion is denoted je. We denote by /, the function that is defined nowhere; i.e. /, has the property that Dom(/,) = Ran(/,) = 0. Clearly /, — [0 for any function g, Often in computability we shall encounter functions, or expressions involving functions, that are not always defined. In such situations the following notation is very useful. Suppose that a(x) and (3(x) are expres sions involving the variables x = (x... X,). Then we write a(x)*0(x) to mean that for any x, the expressions a(x) and (x) are either both defined, or both undefined, and if defined they are equal. Thus, for example, if /, g are functions, writing/(x) = g(x) is another way of saying that /= g: and for any number y,/(x) —y means that (x) is defined and f(s) = y (since y is always defined). Functions of natural numbers For most ofthis book we shall be concerned with functions of natural numbers; that is, funetions from {oN for various M, most commonly n= 1 or 2. ‘A function f fom\fo is\called an n-ary function. The value of f at an ntuple (%, .. aie Dom() is watten Xun %), oF 0), if x represents (Ri, X,). In some texts the phrase partial function is used to describe a function from N’ to M whose domain is not necessarily the Whole of M", For us the word function means partial function. On occasion we will, nevertheless, write partial function to emphasise this fact. A total function fronivto i8\a function whose domain is the whole of Particularly with number theoretic functions, we shall blur the dis- tinction between a function and its particular values in two fairly standard and unambiguous ways, First we shall allow a phrase such as “Let io. X,) be a function .." as a means of indicating that f is an M-ary function. Second, we shall often describe a funetion in terms of its general value when this is given by a formula. For instance, ‘the function +2” means “the unary function f whose value at any XGMIIS x"; similarly, ‘the ‘function x+ y's the binary function whose value at (x, y) © PF is x+y. ‘We describe the zero function MN by 0: and generally, for m € M, we ‘denote the funetion —N-» NV whose valu is always m by the boldface symbol m. Prologue 4 3. Relations and predicates If A is a set, a property M(x... x,) that holds (or is true) for some M-tuples from 4* and does not hold (or is false) for all other M-tuples from A is called an 2i-ary relation or predicate on A.? For example, the property x <,y is a binary relation (or predicate) on N; 2.<3 holds (or is true) whereas 9 < $ does not hold (or is false). As another example, any nary function f fiom tS M gives rise to an (n+ )-aty predicate Ai(x, y) given by MOsiyos Xy 9) if and only i. y. Equivalence relations and orders (The student unfemilar with these notions may prefer to delay reading this paragraph until it is needed in chapter 9.) In chapter 9 we shall encounter two special kinds of relations onaset A (@) A binary relation R on a set A is called an equivalence relation if it has the following properties forall x, ¥, 2 G A @) (Feflexivity) R¢, x); Gi) (symmetry) if R¢s, y) then RG x); (ii) (ransitivity) if R(x, y) and RG, 2) then Rx, 2) We think of R¢s, y) as saying that x, y are equivalent (in some particular sense). Then we define the equivalence class of x as the set {y: R(t, y). consisting of all things equivalent tox. () A binary relation R on a set A is called a partial order if, for all KZA, G) Gireftexivty) not Rs, x) (ii) (transitivity) if 7%, y) and 72y, 2) then 72x, 2). A partial order is usually denoted by the symbol <, and we write x < y rather than <(x, y). A partial order is often defined by first defining < (meaning < or), withthe properties @ x35 ii) if denotes implies and is implied by. We use the symbols V, 3 to mean “for air and “there exists’ in the standard way ‘The symbol is used in the text to indicate the end of a proof, 5. References Each chapter is divided into sections, and items in each section ‘are numbered consecutively. A reference such as theorem 5-14 means theorem 1.4 of chapter 5: this is the fourth numbered item of § 1 in that chapter. When referring within a chapter the number of the chapter is omitted. Exercises are included in this system of numbering. Thus exercise 6-1.8(2) means the second exercise of exercises 1.8, found in chapter 6, [Reference to entries inthe bibliography is made by citing the author ‘and year of publication of the work referred to. 1 Computable functions We begin this chapter with a discussion of the fundamental idea of an algorithm or effective procedure. In subsequent sections we deseribe the way in which this idea can be mado precise using a kind of idealised computer; this lays the foundation for a mathematical theory of compu- tability and computable functions 1, Algorithms, or effective procedures ‘When taught arithmetic in junior school we all learnt to add and to multiply two numbers. We were not merely taught that any two numbers have a sum and a product - we were given methods or rules for finding sums and products. Such methods or rules are examples of algorithms or effective procedures. Theit implementation requires no ingenuity or even intelligence beyond that needed t0 obey the teacher's instructions. More generally, an algorithm or effective procedure is a mechanical rule, or automatic method, or programme for performing some mathe- ‘matical operation. Some more examples of operations for which easy algorithis can be given are (1.1) (@ given m finding the rath prime number, @)differemiating a polynomial, (©) finding the highest common factor of two numbers (the Euclidean algorithm), (4) given two numbers x, y deciding whether x isa multiple ofp Algorithms can be represented informally as shown in fig. fa ‘The input is the raw data or object on which the operation is to be performed (eg. a polynomial for (1.1) (8), pair of mumbers for (1.1) (6) and (j)) and the output is the result of the operation (e.g. for (1.1) 2), the 4erived polynomial, and for (1.1) (@), the answer yes or no). The outpat is produced mechanically by the black box - which could be thought of as a 1 Computable functions 8 calculating machine, a computer, or a schoolboy correctly taught-or even a very clever dog trained appropriately. The algorithm is the procedure or method that is carried out by the black box to obtain the output from the input. When an algorithm or effective procedure is used to calculate the values of a numerical fumetion then the function in question is described by phrases such as effectively calculable, or algorithmically computable, or effectively computable, or just computable, For instance, the functions xy, HCF(x, y) = the highest common factor of x and y, and /(M) = thenth prime number, are computable in this informal sense, as already {ndicated, Consider, on the other hand, the following function: ( 1 ifthere is a run of exactly m consecutive 7s devimal expansion of ir, 8G) 0 otherwise Most mathematicians would accept that g is a perfectly legitimate function. But is g computable? There is a mechanical procedure for generating successive digits in the decimal expansion of 7r,' sO the following ‘procedure’ for computing g suggests itself, “Given n, start generating the decimal expansion of ir, one digit at a time, and watch for 7s, If at some stage a run of exactly m consecutive 7s has appeared, then stop the process and put g(n) = 1. If no such sequence ‘of 78 appears put gfn) = 0." ‘The problem with this ‘procedure’ is that, if for a particular m there is no sequence of exactly m consecutive 7s, then there is no stage in the process ‘where we can stop and conclude that this is the ease, For all we know at any particular stage, such a sequence of 7 could appear in the part of the expansion of ir that has not yet been examined. Thus the “procedure” will go on for ever for inputs m such that g(n) = 0; so it is not an effective procedure, (It is conceivable that there i an effective procedure for computing g based, perhaps, on some theoretical properties of 7r. At the present time, however, no such procedure is known.) "This will be established in chapter 3 (example 7.18). 2 The unlimited register machine 9 ‘This example pinpoints two features implicit in the idea of an effective procedure - namely, that such a procedure is carried out in a sequence of stages or steps (each completed in a finite time), and that any output should emerge after a finite number of steps. So far we have described informally the idea of an algorithm, or effective procedure, and the associated notion of computable function ‘These ideas must be made precise before they can become the basis for a ‘mathematical theory of computability - and HOrt-computability. ‘We shall make our definitions in terms of a simple “idealised computer’ that operates programs. Clearly, the procedures that can be carried out by. 1 real computer are examples of effective procedures. Any particular real computer, however, is limited both in the size of the numbers that it ean receive as input, and in the amount of working space available; it is in these respects that our ‘computer’ will be idealised in accordance with the informal idea of an algorithm. The programs for our machine will be finite, and we will require that a completed computation takes only a finite number of steps. Inputs and outputs will be restricted to natural mumbers; this is not a significant restriction, since operations involving other kinds of object can be coded as operations on natural numbers, (We discuss this more fully in § 5.) 2. ‘The unlimited register machine Our mathematical idealistion of «computer is called an unlimited register machine (URM); it is a slight variation of a machine first conceived by Shepherdson & Sturgis [1963]. In this section we describe the URM and how it works; we begin to explore what it ean doin 8 ‘The URM has an infinite number of registers labelled Ri, Ry R3, ++» cach of which at any moment of time contains natural number; we denote the mumber contained in Ry by ry. This can be represented as follows RR, R3 ARS RORT nila els jee] The contents of the registers may be altered by the URM in response to certain instructions that it can recognise. These instructions correspond to very simple operations used in performing calculations with numbers. A. finite list of instructions constitutes a program. Te instructions are of four kinds, as follows. 1 Computable functions 10 Zero instructions For cach n = 1, 2, 3... there is a zero instruction Zn). The response of the URM to the instruction Z(\) is to change the contents of R, to 0, leaVing all other registers unaltered. Example Suppose that the URM is in the following configuration RIR2R3RARS RS s [23 0 and obeys the zero instruction 2(3) Then th resulting configuration is o PREP] ‘The response of the URM to a zero instruction Z(M ) is denoted by 0 Ry ‘or 7, = 0 (this is read r, becomes 0} Successor instructions For cach n = 12, 3... there is @ successor instruction S(n). The response of the URM to the instruction S(1i) is to inerease the number contained in R, by 1, leaving all other registers ‘unaltered Example Suppose that the URM is in the configuration (*) above and obeys the successor instruction $(5). Then the new con- figuration is RIR2R3R-ARSRO edie mt ey [sfefolafslo] ‘The effect of a successor instruction S(n) is denoted by r, +1 > Ry, oF ryt ty* L (ry becomes r, +1). Transfer instructions For each m = 1, 2, 3p0 and m = 1y 2, 3yu there is a transfer instruction Tim, n). The response of the URM to the instruction T(at, n) is to replace the contents of R, by the number 7 contained in Ry (ie. tansfer ry into R,); all other registers (including R,,) are unaltered. Example Suppose that the URM is in the configuration (**) above and obeys the transfer instruction T(S, 1). Then the resulting 2 The unlimited register machine u configuration is ‘The response of the URM to a transfer instruction Tim, n) is denoted by Igo Ry OF Fy = Ig BECOMES Fg) Jump instructions In the operation of an informal algorithm there may bbe a stage when alterative courses of action are prescribed, depending ‘on the progress of the operation up to that stage. In other situations it may bbe necessary to repeat a given routine several times. The URM is able to reflect such procedures as these using jump instructions ', these will allow jumps backwards or forwards in the list of instructions, We shall, for example, be able to use a jump instruction to produce the following response: TE r, = ty goto the 10th instruction in the program; otherwise, go ‘on to the next instruction in the program.’ “The instruction elcii this response will be written J, 6, 10). Generally, for each m= 1, 2, 3yn, 2 = 1, 2, Bon and 4 = 1, 2, 3, there isa jump instruction J(m, nm, q). The response of the URM to the instruction Jfmn.g) is as follows. Suppose that this instruction ‘encountered in @ program P. The contents of R,, and R, ate compared, but all registers are left unaltered. Then ifr, = ry the URM proceeds to the vth instruction of Ps if'ry# ty, the URM proceeds to the next instruction in P, If the jump is impossible because P has less than q instructions, then the URM stops operation, Zero, successor and transfer instructions are called arithmetic instruc tions We summarise the response of the URM to the four kinds of instruc- tion in table 1 Computations ‘To perform a computation the URM must be provided with a program P and an initial configuration - i.e. a sequence 01,02,03,... of natural numbers in the registers Ry Ry R3y + ++ + Suppose that P consists of 5 instructions Ti, Zjy. Z, The URM begins the computation by obeying Z, then Z, Z,, and so on unless a jump 1 Computable functions 2 Table 1 ‘Type of instruction Instruction _ Response of the URM Zero 2a) Replace r, by 0. (0-* R,, oF 7, = 0) Successor Sin) Add Ho Fy (fy 41 > Rev or, = 1, + D ‘Transfer Ten, ») Replace 1, by rae (fy Rey OFF St) Jump Jom, ng) If =r jump to the Zayon A it general as follows. The URM starts by obeying. instruc- tion fi, At any future stage in the computation, suppose that the URM is obeying instruction 1, Then having done so it proceeds to the next instruction in the computation, defined as follows; iff, is nota jump instruction, the next instruction is Aj; Le ifte= Ufe+i otherwise, if 1, Hem, n, g) the next instruction is 1 where ry rare the current contents of R., and R,. ‘The URM proceeds thus as long as possible; the computation stops when, and only when, there is no next instruction; ic. if the URM has just obeyed instruction J, and the ‘next instruction in the computation’ according to the above definition is /, where v>s. This can happen in the following ways: (if k= 5 (the last instruction in P has been obeyed) and J, is an arithmetic instruction, (i) iff, = (a8, 1, gary = 7, and gs, Git) iff, = Km, n, gr, trpand k= 5, We say then that the computation stops after instruction 1° the final configuration is the sequence n, ry ry... the contents of the registers at this stage. ° 1 Computable functions 4 Let us now continue the computation begun in example 2.1 Example 2.1 (continued) RIR2RIRIRS Next instruction 9]slifolo I o]o 0] c I 9]o >] 0 he o9ls]2fofo] Ig since n= 13) Final 7 config-(2|9]2]0]0 Ir: stor, uration This computation stops as indicated because there is no seventh instruction in the program. 22. Exercise Carry out the computation under the program of example 2.1 with initial configuration 8, 4, 2, 0,0, The essence of a program and the progress of computations under it is often conveniently described informally using a flow diagram. For ‘example, a flow diagram representing the program of example 2.1 is given in fig. |B. (We have indicated alongside the flow diagram the typical configuration of the registers at various stages in a computation.) Note the convention that tests or questions (corresponding to jump instructions) are placed in diamond shaped boxes. The translation of this flow diagram into the program of exercise 2.1 is almost self-explanatory. Notice that the backwards jump on answer ‘No to the second question 7i= 1,” is achieved by the fifth instruction JL, 1, 2) which is an unconditional jump: we always have n= n, so this instruction causes a jump to J, whenever itis encountered, When writing a program to perform a given procedure it is often hlpfal to write an informal flow diagram as an intermediate stop: the translation of a flow diagram into a program is then usually routine 2 The unlimited register machine 18 Fig. ib, Flow diagram forthe program of example 2.1, ‘Typical configuration RIR,R, [ok After keyeles round the loop ‘There are, of course, computations that never stop: for example, no ‘computation under the simple program S(0), J(, 1, 1) ever stops. Computation under this program is represented by the flow diagram in fig. 1 ¢ The jump instruction invariably causes the URM to retum, or loop back, to the instruction S(I). ‘There are more sophisticated ways in which a computation may run for ever, but always this is caused essentially by the above kind of repetition or looping back in the execution of the program. 1 Computable functions 16 Fig te 2.3 Exercise ‘Show that the computation under the program of example 2.1 ‘with intial configuration 2, 3, 0,0, 0,.. never stops. ‘The question of deciding whether @ particular computation eventually stops or not is one to which we will return later. Some notation will help us now in our discussion, Let aj, ay, «3, .« m be ‘an infinite sequence from N and let P be a program; we will write (Play, a, ay.) for the computation under P with initial configuration ay, dy, ay... G) Play, 25, 5,0.) mean that the computation Play, dy dy.) eventually stops; ii) P@ya,ay...)ft0 mean thatthe computation Play, «2, «By..) Never Stops In most initial configurations that we shall consider, all but finitely many of the a, will be 0. Thus the following notation is useful. Let 4p, bea finite sequence of natural numbers; we write iv) Play, ayo. ay) For the computation POA, Ase Oy, 0, 0,00) Hence (9) Play, you. a is means that Play dye dy 040, Op Ns (i) Play dys fla)t means that Play ays dy 0, 0, Ovo If Often a computation that stops is said to converge, and one that never stops is said to diverge. 3. URM-computable functions Suppose that / is a function frm! to%(n> 1); what does it ‘mean to say that f is computable by the URM? It is natural to think in terms of computing a value ffa,..., 4,) by means of a program P on initial configuration a, dyn yQQ0,... That is, we consider computations of the form Pa, a; ay. If any such computation 3 URM-computable factions a stops, we need to have a single number that we can regard as the output or result of the computation; we make the convention that this is the number 1 finally contained in Ry The final contents of the other registers can be regarded as rough work or jottings, that can be ignored once we have the desired result in Rj Since @ computation P/aly.., a,) may not stop, we can allow our definition of computability to apply to functions f from M" to N whose domain may not be all of N°; i. partial functions. We shall require that the relevant computations stop (and give the correct result!) precisely for inputs from the domain of f Thus we make the following definit 3.1 Definitions Let fbe a partial function from to NY (@) Suppose that P is a program, and let a”, a2, (The computation P(ui, ap. + + «) converges to b if Play, 2» ++ #.>.and in the final configuration is in Rj. We waite this Pltiyng a) Gi) URM-compuies f if, for every dpaytyy B Pla... ay{b if and only if (4i,.., aye Domi) and Win.» a) = b. (In particular, thismeans” that P(aiya»)Lif and only if (ai,... a,Je Dom().) (®) The function f is URM-computable if there is a program that URM-computes f- ‘The class of URM-computable functions is denoted bY and nary URM-computable functions by %,. From now on we will use the term computable to mean URM-computable, except in chapter 3 where other notions of computability are discussed. We now consider some easy examples of computable functions 32 Examples @ xy. We obtain x + y by adding 1 to x (using the successor instruction) y times. A program to compute x + y must begin on initial configuration % % 0, 0, 0; our program will keep adding 1 10 ry using Ry as a counter to keep a record of how many times n is thus increased. A typical ‘configuration during the computation is RiRIR, RERS. xtk 1 Computable functions 18 The program will be designed to stop when k =y, leaving x + y in Ri as requited ‘The procedure we wish to embody in our program is represented by the flow diagram in fig. ld. A program that achieves this isthe following AIG,2,5)5 ASO) I ASG) 1300 (The dotted arrow, which is not part of the program, is to indicate to the reader that the final instruction has the effect of always jumping back «0 the first instruction) Note that the STOP has been achieved by a jump instruction tA" which does not exist, Ths, x+y is computable Fig. ld. Flow diagram for addition (example 3.2(8). START (Since we are restricting ourselves to functions from M to N, this isthe best approximation to the function x— 1.) We will write program embodying the following procedure. Given initial configuration x, 0, 0, 0,.., first check whether x = 0; if so, stop: otherwise, run two counters, containing & and k + J, starting with = 0. A typical configuration during a computation will be RORY Rs Rt x +i ]o] [x] eet qo Te 5 URM-computable functions 19 Check whether x = & + 1; i's the required result is k; otherwise increase both counters by 1, and check again. ‘A flow diagram representing this procedure is given in fig. le. A program that caries out this procedure isthe following: Zi1049) ASG) AId3IA igs@ ! Zs8G) | 2,313) inten Thus the function x —'1 is computable Fig. le, Plow diagram for s— 1 (example 3.2(8). “Typieal configuration RR: R, 1 Computable functions 20 Of) ifkiseven, undefined ifx is odd. In this example, Dom(/) = E (the even natural numbers) so we must ensure that our program does not stop on odd inputs, ‘A procedure for computing /(x) is as follows. Run two counters, containing f and 2k for =0,1/2, 3,; for successive values of k, cheek whether x ~ 2f; if So, the answer isk; otherwise inerease & by one, and repeat. If xis odd, this procedure will clearly continue for ever. ‘The typical configuration will be Ri OR, Rs x] [#0 initially. A flow diagram for the above process is given in fig. 1 Fig. V. Flow diagram for example 3.26). START 3 URM-computable functions 21 ‘A program that executes it is ASL26) ASG) ASQ) SQ) AJLD ATG) Hence fis computable, Note. The programs in these examples are in no sense the only programs that will compute the functions in question, Given any program P (ic. any finite list of instructions), and m >-1, by thinking of the effect of P on initial configurations of the form Bi, dyn dy 0, Ope We See that there is @ unique M-ary function that P computes, denoted by fp *: From the definition it is clear that (the unique b such that Pfal.. «na.)1b, PPM, 2654)=4 EPCs, 5 gdb | undefined, if Pay... a8 In a later chapter we shall consider the problem of determining/I? for any given program P, It is clear that a particular computable function can be computed by many different programs; for instance, any program can be altered by ‘adding instructions that have no effect. Less twivially, there may be 4ifferent informal methods for calculating particular function, and when formalised as programs these would give different programs for the same function. In terms of the notation we have introduced, we can have different programs P\ and P,» with /£" =P)" for some (or all) n. Later we shall consider the problom of deciding whether or not two programs compute the same functions, 33 Exercises 1 ‘Show that the following functions are computable by devising, ‘programs that will compute ther @) Kx) © Mya | 1 Computable functions 2 0 ife M, We say that an object d e D is coded by the natural number a(d). Suppose now that fis @ funetion from D to D; then f is naturally cotied by the function /* from fad to N that maps the code of an object de Domi) tothe code of id). Explicitly we have = afar Now we may extend the definition of URM-computability to D by saying that fis computable if /* is 2 computable function of natural numbers. 5.1 Example Consider the domain Z, An explicit coding is given by the function a where rete! if'n>0, \-2n-1 itn <0. Then ais given by um ={ 2 if mis even, * "| Aim +1) iftmis odd. Consider now the function x-1 on Z; if we eall this function /, then foi" given by fl ifx=0(.e.x= a0), (y= (x2 fx > Oand-xis even (ie.x=a (n,n > 0), Lxt2_ iftris odd, (ie. = a/n), <0), Its « routine exercise to write a program that computes /*; hence x <1 is a computable funetion on Z. ‘The definitions of computable nary function on a domain D and decidable predicate on D are obtained by the obvious extension of the above idea, 52 Exercises 1. Show that the function 2x on Z is computable, 2. Show that the predicate “x > Q" is a decidable predicate on Z. 2 Generating computable functions In this chapter we shall see that various methods of combining compu- table functions give rise to other computable functions. This will enable us to show quite rapidly that many commonly occurring functions are computable, without writing a program each time - a task that would be rather laborious and tedious. 1, The basic funetions First we note that some particularly simple functions are computable; from these basic functions (defined in lemma 1.1 below) we shall then build more complicated computable functions using the tech- niques developed in subsequent sections. Li. Lemma The following basic functions are compuable (a) the zero function (0(8) =O forall x); (®) the successor function x1; (©) for each n> 1 and 1 <1-< n, the projection function U' given by Up) = Proof. These funetions correspond tothe arithmetic instructions for the URM, Specifically, programs are as follows: (a) 0: program Z() () x +1: program S(); (c)_ Uj: program Tii, 1). 2. Joining programs together Tn each of §§ 3-5 below we need to write programs that incorporate other programs as subprograms ot subroutines. In this section ‘we deal with some technical matters so as to make the program writing of later sections as straightforward as possible, 2 Generating computable functions 6 A simple example of program building is when we have programs P and Q, and we wish to write a program for the composite procedure: first do P, and then do Q, Our instinct is to simply write down the instructions in P followed by the instructions in Q. But there are two technical points to consider. Suppose that P = Zi, Zyyus 1, A computation under P is compieted when the ‘next instruction for the computation’ is 1, for some v >s; we then require the computation under our composite program to proceed to the first instruction of Q. This will happen automatically if v = s +1, but not otherwise. Thus for building composite programs we must confine our attention fo programs that invariably stop because the next instruction is Z,.» Such programs are said to be in standard form, Clearly itis only jump instructions that can cause a program to step in non-standard fashion, ‘Thus we have the following definition. 21. Definition A program P © Zi, Zyyn Z, is in standard form if, for every jump instruction J(aH,n, g) in P we have g 0. Proof. Suppose that P = Zy Zo Z, To obtain P* from P simply change the jump instructions so that all jump stops occur because the jump is to Z,... Explicitly, put P* = /*, 2.42? where if J is not a jump instruction, then Z* = (*; mm atten tt ={ feast, ithe nea), then (im, n,s+1) ifq>s+1 ‘Then clearly P* is as required. 2 Joining programs together 2 Let us assume now that the programs P and O are in standard form, ‘The second problem when joining P and Q concems the jump instruc- tions in O. A jump J(m, n, g) occurring in O commands a jump to the th instruction of O (if ry = r,)- But the tith instruction of O will bicorne the 5 + 4th instruction in the composite program; thus each jump J(m, n, q) in © must be modified to become Jm, ms + q) im the composite program if the sense is to be preserved. Now without any further worry we can define the join or concatenation of two programs in standard form: 23, Definition Let P and 0 be programs of lengths 5, «respectively, in standard fo. Teeinar—cntntonat Pant, witen Forse program Z, Zyouy Zy Zygon Zi where P= Zi, nZy and the instructions J,,i... 1+, are the instructions of O with each jump Jatin, q) replaced by Jim, nig) With this definition it is clear that the effect of PO is as desired: any ‘computation under PO is identical to the corresponding computation under P followed by the computation under O whose initial configuration is the final configuration from the computation under P. ‘There are two further considerations before we can proceed to the major tasks of this chapter. Suppose that we wish to compose a program having a given program P as a subroutine. To write Q it is often important to be able to find some registers that are unaffected by computations under P. This ean be done as follows. Since P is finite, there is a smallest number w such that none of the registers R, for v > w is mentioned in P| ie. if Z (m), oF $(2), or Thm, »), or 3m, mq) is an instruction in P, thewM w remain unaltered, and have no effect on the values of 1... ry Thus when writing our new program O the registers Ror v > w can be used, for example, to store information without affecting any computation under the subroutine P. ‘We denote the mumber u by p(P). Finally, we introduce some notation that will greatly simplify the main proofs of this chapter. Suppose that P is a program in standard form designed to compute a function /(xi,... x4). Often when using P as a 2 Generating computable functions 28 subroutine ina larger program the inputs Siesta for which MXivus Xs) is desired may be held in registers Ri... ., Ry Tather than Roos Ry as the program P requires; further, the output /ixi>... x,) ray be required for future purposes to be in some register R, rather than the conventional Ri; and finally the working registers R, .., Ryip) for P may contain all kinds of unwanted information. We can modify P to take account of all ofthese points as follows. We write Pli, > for the program in fig. 2a that translates the flow diagram alongside. The program P[/i, + ln-* has the effect of computing /(0,,., F,) and placing the result in R/. Moreover, the only registers affected by this program are (at most) R, Ry...» Rep) and Ri (We have assumed in defining PUj, Wt] that Rn, Rly are distinct from Ri,.., R,, ; this will be the case in all our uses of this notation. The reader should be able to modify the definition for situations here this is not the case.) Fig, 2a Flow diagram for PU, Loa —= =o jzorn Clear R,. Ru ) ——oel *ZiptP)) P Tay 3 Substitution 29 3. Substitution ‘A common way of manufacturing new functions from old is to substitute functions into other functions, otherwise known as compos tion of functions. In the following theorem we show that when this process is applied to computable functions, the resulting functions are also computable. In short, we say thatis closed under the operation of substitution. 3.1. Theorem Suppose that ff, yy and gilWun Bq(X) are computable Junctions, where x= (sion, %)- Then the function h(x) given by Ni) 9.8) is computable. (ote. Ws) is defined if and only if wil MX) are all defined and (iG), ..g))eDom(), thus, if f- and gir.» g* are all total Junctions, then his total) Proof, Suppose that F, Gl... Gy are programs in standard form which compute ff gi... g respectively. We will write a program i that embodies the following natural procedure for computing h. ‘Given x, use the programs Gi... G, to compute in succession BiG), 2:08). gk, making a note of these values as they are obtained. Then use the program F to compute /(gi(R)y. (3) We must take a little care to avoid losing information needed at later stages in the procedure, namely x and those values g(x) already obtained, Putting m = max(rt, k p(F). p(GY,..»p(Gy), we shall begin by storing x in Rij Rmty: the registers Ragin Revintk will be used to store the values ¢,(8) as they are computed for i= Ty 2 h These registers are completely ignored by computations under F, Gu+ ++, G, A typical configuration during computation under #1 will be Storage registers Boca Rm 1.Ren RAT Hn +1 Rintne2.. R 2 f x I kx) | ew] | sits) [e [el ‘An informal flow diagram for computing / is given in fig. 26. This is easily translated into the following program H that computes fi 2 Generating computable functions Td, m 4-1) Tn, m+n) Gif +Lm+2, ..m+n>m+ntl] Onlin * lym2amct nt mb > KD Flim r+ L..tnrt eT] Fig. 26, Substitution (theorem 3.1) ————_*———_, Store in Rasieon-sRmon (Recall the meaning, of this notation from §2) 30 3 Substitution 31 Clearly a computation (x) will stop if and only if each computation G(@) stops (== 6) and the computation F(wie).» BO) Stops, which is exactly as required. [New functions can be obtained from any given function by rearranging or identifying its variables, or by adding new dummy variables; for instance, from a function (yj y2) we can obtain AiG xy) May, xi) (rearrangement), hls) =f.) (identification), fig(xi Xp, %3) = My X,) (adding dummy variables). ‘The following application of theorem 3.1 shows that any of these opera- tions (or @ combination of them) transforms computable functions into computable functions. 3.2. Theorem Suppose that fijiyy is a computable function and that Mig Xyyons By 1S a sequence of k of the variables X),., X, (possibly with repetitions). Then the function h given by Ns) — flips Xi) 1s computable. Proof. Writing x = (Xi,.... X) we have that AlRFAU'RAU') avons UA) which is computable, by Lemma L.1(e) and theorem 3.1. Using this result we ean see that theorem 3.1 also holds when the functions gi,.., %¢ Substituted into f are not necessarily functions of all of the variables xi... x, a in the following example. 33. Example ‘The function (xi, x, x;) = Xi + x, +; is computable; this can be deduced from the fact that x+y is computable (example 1-3.2()), by substituting x i++, for x, and x, for y in x 4- y. 2 Generating computable functions 32 Substitution combined with the prineipie described in the next section gives a powerful method of generating computable functions, 34. Exercises |, Without writing any programs, show that for every m GN the following functions are computable: (a) m (cecall that m(x) =m, for all x), ) me. 2. Suppose that (x, y) is computable, and m eM. Show thatthe function ftx)=I(x, m) is computable. 3, Suppose that g(x) is a total computable function. Show that the predicate Ai(x, y) given by Mos, y) ="800) = 9" is decidable 4. Recursion Recursion is a method of defining a function by specifying each of its values in terms of previously defined values, and possibly using other already defined functions. To be precise, suppose that f(s) and g(x, y, =) ate funetions (not necessarily total or computable). Consider the following ‘definition’ of a new funetion A(x, y): G1) BAGO, Gi) AG y +1) 26% y, AGG Y)). At first sight this may seem a litle dubious as a definition, for in the second line it appears that his being defined in terms of itself - a cireular definition! However, with a little thought we ean convince ourselves that this is a valid definition: to find the value of f(s, 3) for instance, first find ‘(s, 0) using (4.1 Ji; then, knowing A(x, 0), use (4.1 Mii) to obtain h(x. 1); similarly, obtain A(X, 2), and finally A(x, 3) by further applications of (4. Gi). Thus, cireularity is avoided by thinking of the values of h(x, y) as being defined one ata time, always in terms ofa value already obtained. 4 Recursion 33 ‘A function h defined thus is said to be defined by recursion from the functions f and g; the equations 4.1 are known as recursion equations. Unless both/and g are total, then has defined by (4.1) may not be total; the domain off will satisfy the conditions (Domi) iff x 6 Domi), (x.y + De Dom( iff (% yieDom(A) and (x,y, fix, y)je Dom(g), Let us summarise the above discussion in a theorem, whose proof we omit. 42. Theorem Let x = (inn %), and suppose that ix) and g(x, y, 2) are functions; then there is a unique function h(x) satisfying the recursion equations Gs, OX), Gs,» + atx, ys sy). Note. When = 0 (ie. the parameters x do not appear) the recursion ‘equations take the form AO) nye where a eN. (HO). 43, Examples (@) Addition: for any x, y we have x40 x+QeD=Gty)+1 ‘Thus addition (ie. the function A(x, y from the functions /(x) ~ x and g(x,y. 2) (0) yl: with the convention that 0! ort, (tD!-yWy +n. Thus the function y! is defined by recursion from 1 and the funetion ay") = zy +. x+y) is defined by recursion 1 1, we have that ‘There are forms of definition by recursion that are more general than the one we have discussed; we shall encounter an example of this in § 5, and a fuller discussion of this topic is included in chapter 10. In contexts 2 Generating computable functions 34 where general kinds of recursion are being considered, the particularly simple kind of definition given by (4.1) is called primitive recursion Many commonly occurring functions have easy definitions by (primi- tive) recursion, so for establishing computability the next theorem is extremely useful, Briefly, it shows that‘is closed under definition by 44. Theorem Suppose that fix) and s(x, y, 2) are computable functions, where X= (inn, x); then the fimetion yxy) obtained from f and g by recursion is computable. Proof. Let F and G be programs in standard form which compute the functions/(x) and g(x, y, 2). We will devise a program H for the function ‘nf, y) given by the recursion equations 4.1, Given an initial configura- Aion Kivu, ay Yo 0, 0, 0. H will first compute fx, 0) (using F): then, if y#0, 1 will use G to compute successively ACx, 1, if, Dywon fs and then stop. Let_m = maxin +2, p(F), p(G))\ we begin by storing x, y in Rictives Ry + 95 The next two registers will be used to store the current value of the numbers K and A(x, W) for k= 0,1, 2a y. Writing 1 for m+n,atypical configuration during the procedure will thus be Storage registers RR, RR ORR oL 5 5 with A= 0 inital ‘An informal low diagram forthe procedure is given in fig 2c. This flow diagram translates easily into the following program that computes Tm +1) Tin-1,m4-n 4-1) FUL yoy HOE +3] JHE 1 Dip) Glm+1,..men,r+ 2,143 or +3] S+2) Ja.) 4, T(r43,1) Hence h is computable. 4 Recursion 35 Fig, 2c, Recursion (theorem 4.4), [enon ] We now proceed to use theorems 3.1 and 44 to compile a collection of computable functions. The collection is potentially infinite, so our choice is influenced by (i) the needs of subsequent development of our theory, and (ji) the desire to give credence to the thesis that all functions that we ‘would regard as computable in the informal sense are indeed URM- computable, For reasons which will become apparent later we shall include some functions such as x + y and x — 1 for which we have already written programs. We shall use repeatedly the fact that,by theorem 3.2, in a definition by recursion such as (4.1), the computable functions f and g need not bbe functions of all of the named variables for the function h to be ‘computable. 2 Generating computable functions 36 43. Theorem The following functions are computable. (Proofs are given as the functions are listed.) (a) x+y Proof. Example 4.3(a) gives a definition by recursion from the computable functions x and 2~ | (>) ay Proof. x0 = 0, xiy *)= xy “x, is a definition by recursion from the computable functions 0(x) and 2 +x. (©) Proof x°=1, 29"! = wx;by recursion and (/>)* (xl Proof 0—1-0, (41) = 1 =x; by recursion OX=YEE sherwine (tvofiubtracton) Proof x0=x, x= (+ D= (xy) Is by recursion and (d) (0 s000)=P 3: fof exercises 13.3) Proof. se(0) = 0, se(x + Di; by recursion. io Pa 0° (ef. example 1-4.2(8)) Proof. sg(x) ~ 1 — sex); by substitution, (2) and (). (A) boul Proof, Ix- yl= (x —y) + (y — x); by substitution, @ ado. (@ x! Proof. Example 4.3(6) gives a definition by recursion from computable functions. (O) min(x, y) = minimum of x and y. Proof. min(x, y) = x— (xy) by substitution. (8) max(x, y) = maximum of x and y. Proof. max(x, y)=x~ (y —x); by substitution, ( tm(x, y) ~ remainder when y is divided by x (o obtain a total function, we adopt the convention rm(0, y) = ¥). Proof. We ha ve J am(x, y)+l if emix, y) +1 # x, (@) B@)=P, mx, y+ ‘This gives the following definition by recursion: rmx, 0) = 0, mmx, y +1 rm(x, y) +1) sete - (rm(x, y) + 1). 4 Recursion 37 ‘The second equation can be writen smi, y+ 1)= gin, mtx, y)) where g(x 2) = @ + 1) se(h(e + 1); and g is computable by several applications of substitution Hence rmx, y) is computable (zn)at(x, y) = quotient when y is divided by x (to obtain a total “fimetion we define qt(O, y) = 0). Proof Since fi fats, y) +1 ifrm(s, y¥lex, ols Talx, y) iftntx, y) = Hx, we have the following definition by recursion from computable functions ate, 0 Ux, ¥ +1) ™ QU, 9) + 880 omy} 1D. | ify divides y), (on dive 3)™ | sas (We adopt the convention that O10 but Off ify # 0.) Hence xy is decidable (recall definition I-41). Proof. div(x, y) = Setam(x, y)), computable by subst- tution ‘The following are useful corollaries involving decidable predicates. 46. Corollary (Definition by cases) Suppose that ffsyf(x) are total computable functions, and M®ro» Mi) are decidable predicates, such that for every x exactly ‘oe of Minn My) holds, Then the function g(x) given by (M6) iP Mice) holds, |G) M09) holds, AG) ifM,f) holds, is computable. Proof. gtx) = eshte) +. * ey), computable by substi tion using addition and multiplication, 47. Corollary (Algebra of decidability) Suppose that Mis) and Q(x) are decidable predicates; then the following are also decidable. (@ tnotMxY 2 Generating computable functions 38 ©) Mojandgay (© "MO or Oi)" Proof. Tae characteristic functions ofthese predicates areas follows: (a) “not Aft)": 1-eM00, (6) “M(x) and (2(x)": ey) ¢, (0). (©) *M(x) oF Q(8)": max(ey(x), €,(8)) (Where we take “or” in the inclusive sens). Each of the functions on the right is computable provided cy and cp ate by substitution in functions from theorem 4.5 Recursion can be used to establish the computability of functions obtained by other function building techniques, which we now describe. First, we introduce some notation. Suppose that /(x, 2) is any function; the bounded sum Ye0, Ow, l Oifx=Oory=0. 4 Recursion 41 Proof. (a) D(x) = Ey*xdiv(y, x) (where div is as in theorem 4.5(4). 1 if DG) = 2 (ie. x> 1 and the only divisors of x () Prt) are land x), \o otherwise - re = se(1D@0-20. “o. (@) Po=o, Pxti= az (p,! +1 > p, and 2s prime), Which is a definition by recursion; the predicate *z > y and 2 is prime’ is decidable, so using corollary 4.14 (and the note folow- ing) we have a computable function (@ (y= fiz X(py** fa), which is computable since the pre- dicate ‘py Tx’ is decidable Note. The function (x), is needed in the following kind of situation. A sequence $= (ai, ay Myo, ay) from fol can be coded by the single number b= pilp2%! + + Ph"; then the length of s and the numbers 4a, can be recovered effectively from b as follows: n= p20, there are unique expressions for x in the forms Q) x=2P +24, +28, with heb, <..Oand 1 Oand1 0) is defined in terms of ‘earlier’ values passe divides y so ‘(x, y, 2) GS, is a decidable predicate of x, y, z, r; and if it holds, then x, ys 2<¥v, Hence, using the techniques and functions of earlier sections we can show thatthe following predieate is decidable Ry, u) «vs the code number ofa suitable set of tiple and Bz) Church (1936). A-definable functions. (Church [1936] or 1941) (©) Gédel-Kleene (1936). ?-recursive functions and partial recursive functions (§ 2 ofthis chapter) (d) Turing (1936). Functions computable by finite machines known as Turing machines. (Turing [1936]; § 4 ofthis chapter.) (©) Post (1943). Functions defined from canonical deduction systems. (Post [1943], Minsky [1967I; § 5 of this chapter.) 2 Partial recursive functions 49 (9 Markov (1951). Functions given by certain algorithmsover a finite alphabet. (Markov [1954], Mendelson [1964]; § 5 of this chapter.) (8) Shepherdson-Sturgis (1963), URM-compulable functions (Shepherdson & Sturgis [1963],) ‘There is great diversity among these various approaches; each has its ‘own rationale for being considered a plausible characterisation of computability. The remarkable result of investigation by many rescar- ‘hers isthe following 11. The Fundamental result Each of the above proposals for a characterisation of the notion of effective computability gives rise to the same class of functions, the class that we have denote d ¢ ‘Thus we have the simplest possible answer to the first question posed above, Before discussing the second question, we shall examine briefly the approaches of Gadel-Kleene, Turing, Post and Markov, mentioned above, and we will sketch some of the proofs of the equivalence of these with the URM approach, The reader interested to discover full details of these and other approaches, and proofs of all the equivalences in the Fundamental result, may consult the references indicated. 2. Partial recursive functions (Gadel-Kleene) 21. Definition The class 5? of partial recursive functions is the smallest class of partial functions that contains the basic functions 0, x + 1, LJ? lemma 2-1.1) and is closed under the operations of substitution, recursion and ‘inimalistion. (Equivalently, isthe class of partial functions that can be built up from the basic fimctions by a finite number of operations of substitution, recursion or minimalisaion,) [Note that in the definition of the class J2, no restriction is placed on the use of the /zoperator, so that? contains non-total functions. Gadel and Kleene originally confined their attention to total functions; the class of functions first considered was the class &1g of p-recursive finctions, defined like “above, except that applications of the jz-operator are allowed only if a ‘otal function results. Thusis a class of total functions, and clearly <2. In fact, 1%, contains all of the total 3 Other approaches to computability 50 functions that are in 32, although this is not immediately obvious; see corollary 2.3 below for a proof. Hence & is a natural extension ofito a class of partial fimetions, ‘The term recursive function is used nowadays to describe /i-recursive functions; so @ recursive function is always total -it is a totally defined partial recursive function. The term general recursive function is some- times used to describe /x-recursive functions, although historically, this was the name Kleene gave to the total functions given by his equation calculus approach ((a) in § 1). It was Kleene who proved the equivalence of general recursive functions (given by the equation calculus) and ix-recursive functions, We now outline a proof of 2.2. Theorem R= ¢ Proof. From the main results of chapter 2 (lemma 1.1, theorems 3.1, 4.4, 5.2) it follows that © 3 For the converse, suppose that /(x) is a URM-computable function, computed by a program P = Zjvn, 1, By a step in a computation P(s) we ‘mean the implementation of one instruction. Consider the following funetions connected with computations under P. contents of R\ aller # steps in the computation | P09), if Péx) has not already stopped; the final contents of Rif P(x) has stopped afer fewer than ¢ steps J’ numberof the next instruction, when ¢ steps of the computation P(x) have been performed, 116.9 = $j PG has ga clopped after ¢ steps or fewer; 0 if P(x) has stopped after t steps or fewer, arly © and / ate total functions. If Ax) is defined, then P(x) converges after exactly f, steps, where MUG, 0= 0), and then (00) = o(%, to} If, on the other hand, /(x) is not defined, then P(x) diverges, and so I(x, is never zero, Thus p.t, #) = 0) is undefined. Hence, in ether case, we 3 Primitive recursive functions 31 have fox) «ols, tJ(%, 9 =O. So, to show that /'is partial recursive, itis sufficient to show that ¢ and j are recursive functions. It is clear that these functions are computable in the informal sense - we can simply simulate the computation P(x) for up to r steps. By a detailed analysis of computations P(x) and utilising many of the functions obtained in chapter 2, it is not dificult, though rather tedious, to show that c and j are recursive; in fact, they can be obtained from the basic functions without the use of minimalisation (so they are primitive recursive ~ soe § 3 of this chapter). (A detailed proof of rather ‘more than this will be given in chapter 5 - theorem 1.2 and Appendix), Hence fis partial recursive 23. Corollary Every total function in 91 belongs to i%y Proof. Suppose that /(x) is a total funetion in 1%; then f is LIRM- computable by a program P. Let ¢ and j be the functions defined in the proof of theorem 2.2; as noted there, these can be obtained without any use of minimalisation, so in particular they are iiipFurther, since f is total, Pix) converges for every x, so the function pLi((, #) = 0) is total and belongs to %. Now (6s) = (x, page. 0= 0), $0 falso isin 580, A predicate M(x) whose characteristic function cy is recursive is called 4 recursive predicate. In view of theorem 2.2, a recursive predicate is the same as a decidable predicate, 3. A digression: the primitive recursive functions This is a natural point to mention an important subclass of 58, the class of primitive recursive functions® although they do not form part of the ‘main line of thought in this chapter. These functions were referred to in chapter 2 § 5 3.1. Definition (@) The class 9°91 of primitive recursive functions is the smallest class of functions that contains the basic funetions 0, x + 1, UT, and is closed under the operations of substitution and recursion, 3 Other approaches to compulability 52 () A primitive recursive predicate is one whose characteristic function is primitive recursive. ‘All of the particular computable functions obtained in §§ 1, 3, 4 of chapter 2 are primitive recursive, since minimalisation was not used there, We have already noted that the functions ¢ and / used in the proof of theorem 2.2 are primitive recursive. Further, from theorems 2-4.10 and 2-4.12 we sce that OW is closed under bounded sums and products, and under bounded minimalisation. Thus the class of primitive recursive functions is quite extensive. There are nevertheless recursive funetions (or, equivalently, total computable functions) that are not primitive recursive, Indeed, the Ackermann function af example 2-5.5 was given as an instance of such 4 function. A detailed proof that the Ackermann function is not primitive recursive is rather lengthy, and we refer the reader to Péter [1967, chapter 9] or Mendelson [1964, p. 250, exercise 11]. Essentially one shows that (A grows faster than any given primitive recursive function, (To see how fast i grows try to calculate a few simple values.) In chapter 5 we will be able to give an example of a total computable (recursive) function that we shall prove is not primitive recursive, Cur conclusion is that although the primitive recursive functions form a natural and very extensive class, they do nor include all computable functions and thus fali short as a possible characterisation of the informal notion of computability. 4. ‘Turing-computability ‘The definition of computability proposed by A. M. Turing [ 1936) is based on an analysis of a human agenfs implementation of an algorithm, using pen and paper. Turing viewed this as a succession of very simple acts ofthe following kinds (a) writing or erasing a single symbol. (®) ‘transferring attention fiom one part of the paper to another At each stage the algorithm specifies the action to be performed next. This depends only on (i) the symbol on the part of the paper currently being scrutinised by the agent, and (i) the current state (of mind) of the agent. For the purposes of implementing the algorithm this is assumed to bbe determined entirely by the algorithm and the history of the operation so far. It may incorporate a partial record of what has happened to date, Dut it will not reflect the mood or intelligence of the agent, or the state of his indigestion. Moreover, there are only finitely many distinguishable 4 Turing-computability 3 States in which the agent can be, because he is finite. The state of the agent ‘may, of eoutse, change as a result of the action taken at this stage. Turing devised finite machines that carry out algorithms conceived in this way. There is different machine for each algorithm. We shall briefly doseribe these machines, which have become known as Turing machines. 4, Turing machines. ‘A Turing machine M is a finite device, which performs opera- tions on a paper tape. This tape is infinite in both directions, and is divided into single squares along its length. (The tape represents the paper used by @ human agent implementing an algorithm; each square represents a portion of the paper capable of being viewed in a given instant. In any particular terminating computation under M only @ finite part of the tape will be used, although we may not know in advance how much will be needed. The tape is nevertheless infinite, corresponding to the human situation where we envisage an unlimited supply of clean paper.) ‘At any given time each square of the tape is either blank or contains a single symbol fiom a fixed finite list of symbols $i, 52... sy. the alphabet of M. We will let B denote a blank, and count it as the symbol s, belonging to M's alphabet M has a reading head which at any given time scans or reads a single ‘square of the tape. We can visualise this as shown in fig. 3a ‘Mis capable of three kinds of simple operation on the tape, namely: Fig. 3a. A Turing machine, “ EELECEL 43 Other approaches ta computability 34 (a) erase the symbol in the square being scanned and replace it by another symbol from the alphabet of M; (®) move the reading head one square to the right of that being scanned (or, equivalently, move the tape one square tothe lef); (©) move the reading head one square to the left of that being scanned (or, equivalently, move the tape one square tothe right), At any given time M is in one of a fixed finite mumber of states, represented by symbols <71,... gq. During operation the state of M can change, We may envisage the symbol for the current state as being displayed in a window on the exterior of M (as in fig. 3 a), and think of this, as a partial guide to what has happened to date and what will happen in the future The action that M takes at any instant depends on the current state of M and on the symbol currently being scanned. This dependence is described in M ’s specification which consists of a finite set Q of quadr- ples, each of which takes one of the following forms sy 1 x1 (2% It is not our purpose here to develop the theory of Turing machines and Turing-computable functions; the interested reader should consult the ‘books by Davis [1958] or Minsky [1967] listed in the bibliography. ‘The fundamental result linking Turing-computability with partial recursive functions and URM-computability is the following, 43, Theorem ha bho ek Proof. There are various ways of establishing this result, which we indicate in barest outline. ‘A direct proof that 3* c.4? is somewhat similar to the proof that %.c 3 (theorem 2.2). The tape configurations and states of a Turing machine during a computation can be coded by natural numbers, and the opers- tion of the machine is then represented by recursive functions of these numbers. For the converse inclusion, 3 g/%@ne can show directly that 39% contains the basic functions and is closed under substitution, recursion, and minimalisation. This is done in detail in Davis (1958). Alternatively, fone can show that @ 3% by showing that URMs are equivalent in power to a succession of simpler machines, ending with Turing machines. ‘This is the proof given in their original paper by Shepherdson & Sturgis [1963}, 5. Symbol manipulation systems of Post and Markov E. L. Post and A. A. Markov formulated their ideas of effectiveness in terms of stings of symbols. They recognised that objects (including numbers) to which effective processes apply can always be represented as strings of symbols; in fact, in contexts such as symbolic logic, abstract algebra and the analysis of languages the objects actually 3 Other approaches to computability 58 ae strings of symbols. Both Post and Markov, fiom different points of view, considered that effective operations on strings of symbols are those that are built up from very simple manipulations of the strings them- selves Post's central idea was that of @ canonical system, which we describe below. Such systems do not compute functions; they generate sets of strings. This is because Post aimed to characterise formal logical systems; jie. systems that generate theorems fiom axioms by the mechanical application of rules of logic. Thus a notion of effectiveness emerges from Posfs work, initially inthe guise of effectively (or mechanically) generated sets. We shall see how a notion of a Postcomputable function can be derived from this I paragraph 5.17 below we explain the way in which Markov's approach is related to that of Post. We must now define some notation to aid our discussion. Let $= {inns ay be a finite set of symbols, called an alphabet, A string from X is any sequence a. 4, of symbols from 2. Strings are sometimes called words, by analogy with ordinary language. For any alphabet 1, we ‘write £9" denote the set of all strings from 1. Included in J* is the empty string, denoted .1, that has no symbols. If a = bib, *- b,,and r= Clu ate strings then ar denotes the string 61... Cl... ey The empty string Abas the property that for any string a, a = or 5.1. Post-systems In clementary algebra a common operation is to replace the string (x - y)(x + y) whenever it occurs by the string (x? —y#). This string ‘manipulation may be denoted by writing SiC — yNixt y)S, -* Siex?-y)S, where Si and S, are arbitrary strings. A more general manipulation of a string, yet still regarded by Post as ‘elementary, takes the form (5.2) g,SignS;... gnt-ISmgm > A QS,> AISA... Sil, where (9, 8)-5 8M, Ayr A ate fixed strings (and may be null, Gi) the subseripts “zigy; all from 1,2... m, and need not be distinct. 5 Systems of Post and Markov 59 Post called an operation of the form (5.2) @ production: it may be applied to any string a that ean be analysed as S,abS\ applies to the string babaabbaab. Productions form the main ingredient of Posts canonical systems 55. Definition A Post-(canonical) system & consists of (@) finite alpaber () a finite subset A of £*, the axioms of — (©) @ finite set O of productions of the form (5.2), whose fixed strings are in J* We say that ist Post-system over S. We write a Bif the string r can be obtained from the string er by @ finite succession of applications of productions in Q | then we writy rif there is an axiom a ¢ A such that a “>r, In this case we say that r is generated by the Post-system; the set of all strings in 2°* generated byis denoted Ta icc. {ae2%I5 a} 3 Other approaches to computability 60 ‘The set T* is also called the set of theorems 6f reflecting the original motivation of Post 5.6. Example Let be the Post-system with alphabet X = fa, (>), axioms 4, a, 6 and productions 5 -»aSa and § -> Ab, Then T, is the set of palindromes - the strings reading the same in cither direction, such as aba, bbabb, abba. Sometimes, in order to generate a particular set of strings in Z* it is necessary to use auxiliary symbols in the generation process. This leads to the following definition: 5.1. Definition Let J be an alphabet and let X ¢ £*, Then X is Post-generable if there is an alphabet Joand a Post-system % over Buch that X is the set of strings in thi are generated by ie. X=9, Tent, Post proved a remarkable theorem showing that really only very simple productions are needed to generate Post-generable sels. A set of produc tions Q (and any system in which they occur) is said to be normal if all the productions have the form eS'-» Sh. Post proved 5.8. Theorem (Posfs normal form theorem) Any Post-generable set can be generated by a normal system. For an excellent proof consult Minsky [1967]. Post-systems having only productions of the kind SlgS2 Sins? ‘give models of grammars and languages. They reflect the way in which complex sentences of a language are built up from certain basic units according to the rules of grammar. Restrictions on the nature of g and h provide the context-sensitive and context-free languages of Chomsky, ‘which provide useful models of languages used in computer program- ming. We cannot pursue this interesting topic here: the reader may consult the books of Arbib [1969] and Manna [1974] for further information, 5 Systems of Post and Markov 61 5.9. Post-systems and other approaches to computability ‘As we have seen, Post-systems give a characterisation of the notion of an effectively generated set. We may compare this with the corresponding notion that emerges from the other approaches to compu- tubility. For URM-computability (or Turing-computability, ete.) effectively generated sets of numbers are called recursively enumerable (re.}; these are the sets that are the range of some URM-computable function, (We shall study ree. sets in chapter 7.) ‘To compare sets of strings with sets of mumbers, we choose an (intui- tively) effective coding function *: * under which the string er e i* is coded by the number d. A convenient method for an alphabet X A fligne ay) i8 by the k-adic coding where 4; 3* > Nis defined by fi = 0; = ro + nfet+ erst" It is easily seen that * is actually a bijection, so if the inverse of is denoted by ; VPwe also have a representation of each number n by a string n, ‘Suppose now that X is a set of strings: let X = (a: aeX}, the set of numbers coding X. We have the equivalence result 5.10, Theorem Xis Post-generable iff Xis re. Proof. We sketch one proof of this result. Let X¢I* and suppose first that is re, Let X= Ran(/), where f is URM-computable, Using earlier ‘equivalences we can design a Turing machine Al whose symbols include the alphabet X, so that when in state q\ and given inital tape nat [ +1 Al halts if and only if m ¢ Domi), and does so in the following configura- tion is the symbols om the non-bank part ofthe tape indicated constitute the string fim) from Z, and M is in a special halting state qw seaming the square marked j. Now devise a Post-systmigto simulate the behaviour of Mf on is tape; the alphabet ofwll include S and the symbols and 4 Other approaches to computability a states of M; will generate strings of the form sus, gisyers 8 to represent any situation T that oceurs during the computation by M from an initial tape of the form, (*). To get things going, will geferate all strings ofthe form, ml — gilll* ++ 1b» which represent such initial tapes. If we include i the production q,S > S, then the strings from JE* generated bySwill be the set 7): m e Dom(/} = (nen e Rani)} = (22° eX} =X. Thus X= Ty", so Xis Post generable. Conversely, if X is Post-generable by @ Postsystem % show that the relation ‘i's generated by <3 using at most m productions’ is decidable; ffom the theory ofr, sts (chaptet 7 it follows easily that S11. Postecomputability ‘We now explain two ways to derive @ concept of computable function from Post-systems.In both eases the concept is defined first for functions on £*, and then extended to M by coding or representation, Suppose that: 2*-# £* is a partial function. Select a symbol «not in J and consider the set of strings G(= WE :aGDom()} from the alphabet 2.u{+}. The set GQ) contains all information about /, and we define: 5.12. Definition f £->£* is Post-compuable if G(f is Post-gencrable 5.13. Example 5 Systems of Post and Markov 6 “The set G(p is generated by the following Post-system: Alphabet (1,*} Axiom» (=A +f) Production Sj +8, -* Sil + 8,SiSil. “The single production of this system applies toa string ofthe form 1. MeL. HL to produce the string Wa MSD WT ILL 4 IL Z*, Post-computability on fig then defined using any effective representation ~:[N->2” in the natural way: S14. Definition Let g: 'V' be partial function, and let & (1*)" > bb the function defined by AO, thy. my = BOAHToorw) (my... m, € N). ‘Then g is Past-computable if g i Post-computable. If we let*denote the class of Post-computable functions of natural numbers, we have the equivalence: S15. Theorem PE =€=FE=A. (We omit a proof When the reader has studied chapters 6 and 7 he should be able to see that this follows from ‘theorem 5.10 and the results of chapters 6 and 7 linking te. sets with URM-computable functions.) 3 Other approaches to computability 6 ‘a sez yo ero 6 anton of copay oom Pot sync Ist smh cxunon by « acho dey This ca to ‘ns Se pre GP ta eo ms praca can apply to any given sng, Sch se andthe toms in which ey sez te called mongei A monogene stem operates suet We a cl! convecet fir he flog 5 wels a8) >> man that a rut no production in’Q applies to." We have the following characterisation of Post-computability 5.16 Theorem Let f. X* > 2* be a partial function, and letX, ¥ be symbols notin X. Then the following are equivalent (@) fis Post-compurable; () there is a monogenic set of productions Q over an alphabet SEU {Xx} suck that for ack* and reX* Xa ~S{t ita e Dom) and ris the string ¥/(). (ote, The symbols X and ¥ are nesded to distinguish “input strings from ‘output’ strings. Otherwise a desired output string f(a) would be regarded as new input string to which further produetions might apply.) Proof. The implication (a) =>(6) may be obtained by first showing that f is computable by @ Turing machine M, and then devising a rmonogenie set of productions to simulate M. Infact tis possible to obtain a normal monogenic set of proetions for this tsk, For (b) > (a) itis quite straightforward to show that te function fs coding fis paral recursive, then apply theorem 5.15 ‘This equivalence extends to functions (2°) + 2° by considering inputs’ of the form Xa\ +a, .. * For a filler discussion of Post’ systems the reader is referred to the ‘excellent chapters in Minsky [1967] 5.17. Markov-computabitity Markov’s notion of computability is very similar to that derived from Post-systems by the second method above, Rather than restrict attention to monogenic systems, however, Markov gave rules to deter- mine uniquely which of the available productions to apply next. Details are, briefly, as follows 6 Domains other than N 68 A Markov normal algorithm over an alphabet 2 is essentially a list O of productions over / withthe following features: () every production in Q has the form S,g8? 5,52? (Gi) certain productions in O are singled out as being terminal Given an input string a, a Markov algorithm applies productions in sequentially, according to the following rules (a) if'more than one production in Q applies to a string a, use the first one inthe list Q, © if & production SigS2-> SiAS, applies to a in more than one ‘way, apply it tothe leftmost occurrence of g in a, (©) the process halts having produced a string r either when a terminal production is used or if no production in O applies to 7. With these rules, the definition of Markov-computable functionf®*> Z* is given in the obvious way. A Markov normal algorithm to compute / ‘may use an alphabet extending X It is quite straightforward to establish: 5.18. Theorem Lotfi 2* +24 Then fis Markov-computable iff fis Post- computable, Markov-computability on M is defined by using some system of representing numbers in the usual way, and thus coincides with the other approaches to computability 6. Computability on domains other than‘) In chapter 1 § 5 we showed how any notion of computability on M can be extended to other domains by the device of coding. By contrast, in the previous scction the definition of Post-computability on the domain of strings on a finite alphabet was given directly in terms of the objects (strings) and their intrinsic structure. A variety of such direct approaches to computability on other domains is possible: we give two examples, 6.1. Example D Tie LIRM idea may be extended to handle integers by ‘making the following modifications: (a) cach register contains an integer, (@) there is an additional instruction S~(n) for each m = 1,233, that has the effect of subiracting I from the contents of register R, 3 Other approaches to computability 66 62. Example D-£%, where S ~ fa, bj. The cla of partial recursive “functions on ise smallest class of partial functions such that (@) the basic functions fl =A Gi) fg ~ aa (ii) fla) ~ ab (iv) the projection fancti are in i%6P, (6) 2” is closed under substitution, (©) £% ° is closed under primitive recursive definitions of the following form: 1 Uta, a) = a», [Alo 4~e) SAG, Fa)=gi(be the meaning, as for example in theorem 1.2(a),) Clearly, a set is denumerable if and only if it can be enumerated without repetitions. For the main result of this section we need the following (recall that‘ denotes the set of all positive natural numbers): 12, Theorem The following sets are effectively denumerable (@) NxN, (@) N'XN'XNY (©) Ut ole set of all finite sequences of natural numbers. Proof (@) A bijection rr: fol x Muibitefined by Tr(a 11) = 28/2 41-1 It is clear from the definition that rr is in fact a computable function; to see that the inverse is effectively computable observe that 7T-1is given by TIMa) = Chi(a), 77300), where 7Ti, 71, are the computable functions defined by may) = (+ Di, 7(4) = (Ge + D2", (CE. exercise 2-4.16@).) (@) An explicit bijection £: fC x foT 82> M is given, using the function rr of (a), by £(m nq) = Tr(Trém-La-).q- 1, Then we have £169) = (TTIOTIGO)* 1, 77,(7T100)* 1, 77,60) * 1). "To say that we should use a notion of computability based on some caing begs the whole question, since a coding isan elective (inthe informal sense) function. 4 Numbering computable functions 74 ‘Since the functions 7, TH, 772 are effectively computable, then so are £ and (©) A bijectionr: Ut>0 N° > I%L is defined by rain onfife)=2 HD AM UY gy ert te, Clearly + is an effectively computable function. To see that 7 is a bijection, and to calculate T {x), we use the fact that each natural number has a unique expression as a binary decimal, ‘Thus, given x, we can effectively find unique mumbers 1 and 0- that maps the four kinds of instruction onto natural numbers of the forms 4u, 4u + 14u + 2, 44w + 3 respectively; we use the functions 77 and £ defined in the proof of thoorem 1.2 BCAA) = 4-0, o(siay) = 4¢0-4, (Tem, 9)=477(972- In) +2, 0m, Hg) = 48(m, 72, ) +3. This explicit definition shows that (3 is effectively computable, To find G-ly), frst find ur such that x =u 4 with Os 28, The value of r indicates which kind of instruction /3-\@2) is, and from uw we can cffetively find the particular instruction of that kind. Specifically x)= Zu dt) ifr 1, then £108) = Stu I); 1 Numbering programs 15 f= 2, then (3 be) = TUTrigy = 1, 772000) + 1); ifrr= 3, then 0-(x) = Jim, M, g), where (m,n, 9) = (6. Hence iSalso effectively computable. ‘Now we can prove: 14. Theorem & is effectively demumerable. Proof. Define an explicit bijection: PN as follows, using the bijections rand (3 of theorems 1.2 and 1.3: if P= 23, Z,,***,Z then YP) = (BZ)! Since r and (3 ate bijestions, so is y; the fact that f| and their inverses ae effeotvely compatable ensures that y and y"! are also effectively computable ‘The bijection y will play an important role in subsequent development. For a program P, the number y(P) is called the code number of P, or the Gadel? number of P, ot just the number of P, We define P,, = the program with (code) number n IWe and say that P, is the ath program. By construction of y, if m * n, then Py differs from "P,, although these programs may compute the same functions, Its of the utmost importance for later results that the functions y and y-! are effectively computable; ie. (@) Given a particular program P, we can effectively find the ‘code number y(P); () given @ number n, we can effectively find the program Pa =y-'(z2), In order to emphasise this we give two simple illustrations 15, Examples (@) Let P be the program Til, 3), S(4), Z(6). We will calculate y@). O(TG,3)) = 4ir(0.2) + 2 = 4@°@x2_+ YD + 13(8(4)) = 4x3 +1= 13, 3(Z(6)) = 4x5 = 20. 2 The term Gadel munber is used ater K. Gel wi fist exploited the idea of ‘coding non-numirial objets by numbers in his famous paper (Gd 1931), 4 Numbering computable functions 16 Hence y(P) 222294 9007203549970431 (b) Let = 4127; we will find P,i27- 4127 = 2° + 2! - 1; thus P4127 is a program with two instructions A.Lywhere O(A)=S= 4x14, og,)= 124 4x1 +2=401(,0) +2, Hence from the definition of /3, A= $(2) and A= "TQ, 1), so P4127 sa) TQ.) ‘There are, of course, many other possible effective bijections fron? t0 'N; our choice in defining the details of y was somewhat arbitrary. What is vital, we again emphasise, is that y and y"" are effectively computable. ‘The particular details of y are not so important. For subsequent theory, any other bijection y’ would suffice, provided thet y’ and its inverse are effectively computable, However, we have to fix on one particular numbering of programs, and we have chosen that given by y. For the rest of this book, y remains fixed, so that for each particular number 0, the ‘meaning of P, does not change. Thus, for instance, P4127 always means the program $(2), TQ, 1) 16. Brercise Find (a) 0034.2), (6) 13-4503), (©) the code number ofthe following program: TG4),8@), 20), @) Pree. 2. Numbering computable functions Using our fixed numbering of programs, we can now number ‘computable functions and their domains and ranges. We introduce some {important notation which is basic tothe rest of the book. 2a. Definition For each a.G N, and n 1= 2 Numbering computable functions nn (a) <1a'= the rz-ary function computed by P, fo" in the notation of chapter 1 § 3, () Wier = domain of AG n)! Py gon SVs Ey =range of <>?" ‘We shall be mainly concemed with unary computable functions in later chapters, so for convenience we omit the superscript (1) when it occurs; thus we write (>, for ¢.), W, for aH, for B4). 22, Example Let a=4127; from the previous section we know that P4127 is 802), T2,1). Hence o41270)=1 all x) and. Shure xl itn>| Thus eaa7=(1y, £6927 ith Suppose that fis a unary computable function. Then there is a program P, say, that computes J, 80 = , where a = y(P). We say then that ais an index for Since there are many different programs that compute a given function, we cannot say that « is the index for /; in fact, each computable funetion has infinitely many indices. We conclude that every unary computable function appears in the ‘enumeration a>0> S2ne0 and that ths is an enumeration with repetitions. Similar remarks apply to n-ary funetions and their enumeration 23. Exercise Prove that every computable function has infinitely many indices, Recall that we denoted the set of all n-ary computable function by 4, 24. ‘Theorem is denumerable 4 Numbering computable functions 8 Proof. We use the enumeration \ 02 OY e+ (which has repeti- tions) to construct one without repetitions. f= Lettlin $1)= 12(8!" + ++ is an enumeration of %, without repetitions. This was proved by Friedberg [1958] 25. Corollary % is denumerable, Proof. Since UN2:1 this follows from the fact that a denumer- able union of denumerable sets is denumerable. Explicitly for each n let f, be the function used in theorem 2.4 to give an enumeration of without repetitions. Let ir be the bijection M x M-» Nof theorem 1.2. Define 6: 9% >N by (em) = Ta(m, 2-1). Clearly 0s a bijection, ‘The next theorem shows that there are functions that are not compu- table, The idea ofthe proof is as important as the result itself 26. Theorem There is a total unary function that is not computable. Proof, We shall construct a total function f that is. simultaneously Gifferent from every function in the enumeration 0, Oi, 02. of “i Explicitly, define [Seln)=1 ifisdesined, 0 if <1>,(n) is undefined. [Notice that we have constructed fso that for each n, / differs from 0,, a i 0,(t is defined, then f differs from 0, in thav/(n) # O(a); if @y) is undefined, then f differs from <>, in that fa) is defined. 3 The diagonal method 9 Since f differs from every unary computable function , f does not appear in the enumeration of and is thus not itself computable, Clearly Fistotl Discussion: the diagonal method ‘The method of constructing the function f in theorem 2.6 is an example of the diagonal method of construction, due to Cantor. Many readers will be familiar with this method as used in proofs of the ‘uncountability of the set of real numbers. The underlying idea is appli- cable in a wide variety of situations, and is central in the proofs of many results concerning computability and decidability To sce why the term diagonal is used, consider again the construction of / in theorem 2.6, Complete details of the functions <£,, i,.. can be represented by the following infinite table: | Gao) $0) 6] 8 40) 6] 60 «@ 6] 6 o ‘We suppose that in this table the word ‘undefined’ is written whenever © {m) is not defined. ‘The function f was constructed by taking the diagonal entries on this table (circled) 400), b4(1), 6212), and systematically changing them, obtaining (DI Q) ou. such thet fin} differs from <£,(n), for each m Note that there was considerable freedom in choosing the value of ffm); we only had to ensure that it differed from ,(n), Thus Ke ,W 27 if-,(«) is defined, or ne if k(,)(y) = y*. Hence, for each fixed n, k(n) is an index forthe function ‘Then fis computable, so let k be @ computable function such that <1>k(y)6) — J, y). Then, for each fixed m 4>k(,)6) is defined iffy is a multiple of n iffy is inthe range of A(n)- the set of all multiples of ») EK(n)- So we have an effective indexing of the sequence of sets (ziM) as (@ the domains of computable functions, (ii) the ranges of computable functions, 4 The s-m-n theorem 3 One obvious way to generalise theorem 4.1 is ‘0 replace the single variables x,y by m- and n-tuples x and y respectively. We can also reflect the fact that the fantion F defined in the prof of theorem 4.1 depended effectively on a particular program for the original function Thus, instead of considering a fixed computable funetion x, y) we consider a general computable function \ there is total computable (m = Vey function fe, x) suck that 1 let Q\i,x) be the subroutine 2ii) sti)) xtimes sw) that replaces the current contents of R, by x. Then for fixed m, m define $i"(¢, x) to be the code number of the following program: Teme) ) This part ofthe program transforms any configuration | Ri R, teaes| oe TO, m a | jm | oe aol ft \ [xi Sel st o . From this explicit definition, and the effectiveness of y and y"!, we get that iF effectively computable, hence computable, by Church's thesis 4 Numbering computable functions 84 ‘The notation fF the funetion given by theorem 4.3 has given rise 10 the standard description of this result as the s-m-n theorem. We will also use this name to deseribe the simpler version given in theorem 4.1 It is not hard to see that the function 5,” as defined above is in fact primitive recursive. With a little thought it is also possible to see that for cach m there is a function s® (also primitive recursive) that suffices in theorem 4.3 forall n, See the exercises 4.4(5) below 40 Exercises ‘Show that there is a total computable function k such that for each M, A(n) is an index of the function («x ‘Show that there i a total computable function & such that for ceach n, Way) the set of perfect nth powers. Lot #1. Show that there is a total computable function S such that we (inn YI YE te =P ‘Show thatthe functions s™ defined in theorem 4.3 are al primitive recursive Show that for each m there is otal (m + D-ary computable funetion sigh that fr all mend V 9) where x,y are m- and M-tuples respectively (Hint. Consider the definition of s,"e, x) given in the proof of theorem 4:3. The only way in which m was used was in determi- ning how many of then, 2+ 0 transfer 10 Roy Ry Now recall that the effect of P, depends only on the’ original contents of Rin RpJ>y) where p i8 the function defined in chapter 2 § 2; p(PJ is independent of n.) Show further that there jssuch a fanetion tis primitive recursive 5 Universal programs Im this chapter we establish the somewhat surprising result that there are universal programs; i.e. programs that in a sense embody all other programs. This result is one of the twin pillars that support computability theory (the other is the s-m-n theorem); both rest on the numbering of programs given in chapter 4, Important among the applications of universal programs isthe construction of specific non-computable functions and undecidable predicates, a topic pursued in chapter 6, We give a foretaste of such applications in § 2 of this chapter; we also use @ universal program to construct @ total computable function that is not primitive recursive, as promised in chapter 3, ‘The final section of this chapter is devoted to some illustrations of the use of the s-m-n theorem in conjunction with universal programs to show that certain operations on the indices of computable functions are effective (a foretaste ofthe topic of chapter 10). 1, Universal funetions and universal programs Consider the function y)lefined by (s y)=My)- There is an obvious sense in which the single function embodies all the unary computable functions <£o,

i, 2» +++, since for any particular m, the function g given by giy, Thus we describg as the universal function for unary computable functions. Generally, we make the following definition, 5 Universal progranis 86 Ll, Definition ‘The universal fimction for n-ary computable functions is the (n *))-ary function 1G,(¢, X)~ 0), and so we "We mean hers the number sich hat the next nstacton is he Mh instruction OF, | we donot mean the code number (2), 5 Universal programs 88 (6) (eA, x PIG (62%. 9 = Oi Thus, if ¢, and j, are computable, so is «AU* (using substitution and ‘minimalisation) and our proof is complete, ‘We now use Church's thesis to show that a, (and hence ¢, and /,) are computable. We have the following informal algorithm for obtaining ta(@, x, /#1) effectively from a,(¢, x, and: “Decode tr,(¢, X, #) to find the numbers c = e,(¢, x, #) and j = /,(e, x, 9. Ij = 0, then afe, x, r+ 1) = 1, the following predicates are decidable. (a) Se. x, 1) = P.)ly in tr fewersteps\ ©) Hfex, ty P{x) in tor fewer steps’ Proof. (a) Sul@, % ¥,i) = Toe, X, 1) = O-and (Cy(6, x, Di = yl (6) Hex) = Alex) =O" 1 Universal functions and universal programs 89 ‘The significance of the next corollary is discussed in the first note below, 14. Corollary (Kleene’s normal form theorem) There is a total computable function Us) and foreach n>\a decidable predicate Tc x, 2) such that (a) <2) is defined ifand onlyifBeT fe, () “J UtneT (eX). Proof. To discover whether 0j."(x) is defined, and the value if it is, we need to search for a pair of numbers y,¢ such that $x, y, 9. We have the ,v-operator that enables us to search effectively for a single number having a given property. To use this in searching fora pair of numbers, we can think of a single number z as coding the pair of numbers (2) and (2, ‘Then, as 2 runs through ftJ, the pair ((2)>, (2),) runs through M x N. So we define Te, 8,2) ~8,(6, Xs @is (2) For (a), suppose that (/>("t) is defined; then there are y, t such that S,(¢, x,y, $0 putting 2 ~ 273" we have T,(e, x, 2). ‘Conversely, if there is z such that 7, (e, x, 2), then from the definition of Ty Pudls Le. 1 5 Universal programs 90 15. Exercises 1. Show that there is a decidable predicate (2x, y, 2) such that (a) eb, ifand only if 32 O¢y. 2), 0) ify 0 By and Qe y, 2, then , is total’ is undecidable. Proof. Letgbe the characteristic function ofthis problem; Le Lif ,. Now, using g and (Au we can write fas follows: uls)1 itgte)=1 fo iets 2 Two applications of the universal program 91 Now suppose that g is computable; sinedois computable, then, by Church's thesis, so is /, which is a contradiction. Hence g is not computable, ‘Our second application here fulfils the promise made in chapter 3 § 3. 22, Theorem There is a total computable function that is not primitive recursive. Proof. We give an informal proof Recall that the primitive recursive functions are those functions that can be built up fiom the basic functions by a sequence of applications of the operations of substitution and recursion. Thus cach primitive recursive function can be specified by a pplan that indicates the basic functions used and the exact sequence of ‘operations performed in its construction, To describe such a plan it is convenient to adopt some notation such as the following: Sub('; gi, e2on gm) denotes the function obtained by substituting Bivon gm into f (assuming that f is In-ary, and ginny Bq are Mary for some n); Reo(/, g) denotes the function obtained from f and g by recursion (assuming that fis M-ary and g is (M1 +2)-ary for some If we write S for the function x-+ 1, then we have, for example, the following plan for the function (x) = x2, We use letters giv. B10 denote intermediate functions. Plan Explanation of the steps Step 1. ,.=Sub(S:U,). * Bi, y, 2) = Uses, 2) D2 HL ad ‘as 82(x, 0) P(x) =x, Step 2. g,= Rec({, gi). lee y +1) = gilx, y, g,(%, y)) 2(0,y) +1 Soy y)=Xty. Step 3.85 Sub(@,iU2U).” gifs ¥,2)~ ay(&,2)-x+z Repasgie 84(8, 0) =, tp 4. gy = Reo (iiesy se ateseede.y x + au). So ag¢t,y) =. Stop 5. = Sub(gy; U}, UD). (0) = Balt, x)=. ‘Thus a plan is somewhat akin to a program, in that it isa finite and explicit specification of a function, ‘We now restrict our attention to plans for unary primitive recursive functions. As with programs, we can number these plans in an effective 5 Universal programs 92 \way, so that we may then define ),= the unary primitive recursive function defined by plan number Then 0p, #i, 02) + © + is an effective enumeration of all unary primitive recursive functions. From chapter 2. we know that every primitive recursive function is computable. Hence there is a total function p such that for each n, p(n) is the number ofa program that computes 6,) i. n= p(n)- Now the crucial point is that we can find such a fimetion p that is computable, We argue informally using Church's thesis, Recall the proofs of theorems 2-3.1 and 2-4.4, There we showed explicitly how to obtain a program for the function Sabi) given programs for J, gij.ngqi and also, how © obtain a program for the funtion Ree(/,g) sven programs for fand g. (In the next section (example 3.1(5)) we use the sn-n theorem to show in detail that for cach m there is @ computable futon such that for any «je, an index for Reo( =f") "is given by (ci, 2); we can do a similar thing for substitution (see exercise 3.2(5a)).) We also have explicit programs for the basic functions. Hence, given & plan for a primitive reeusive function f involving intermediate functions Bisse Be S4Y, we can effectively find programs for g, gy g*. and finally f ‘Thus there is an effectively computable function p such that On=$ 0 ‘By Church's thesis, p is computable. ‘Now for the payoff! From p and the universal function (Au we can define a total computable function g that differs from every primitive recursive function 0,, We use a diagonal construction as follows: £04) = 0,0) +1 , and ,,( el, y)) = y. BBy the s-m-n theorem there is a total computable function k such that g(, y)=-<>kpg(). Then from (a) and (5) we have (@) Way-E.. OB) DBM Gi) tye, then = <>, and E,W, 5. Effectiveness of recursion. Let x= (sry Xy) and consider the (n+3)-ary function /dfined by ‘eg 0) = <0), Kelsey XY + 1) = EEMR, Ys flee C49). ‘Then using the universal functions «Aw! and £ by recursion By the smn theorem there isa total computable function r(e,,€,) such that , is the characteristic function fora decidable predicate M(x) then Oj,» is the characteristic function for ‘not M(x). 2. Show that there is a total computable function ks) such that for every x, Ey = We 3. ‘Show that there is a total computable function s(x, y) such that forall x,y, Exp, = Ei By 4, Suppose that /(x) iS computable: show that there is a total computable function kfs) such that forall x, Waly = FW. Appendix. Computability of a, 95 5. Prove the equivalent of example 5 above for the operations of substitution and minimalisation, namely: (a) Fix AH, 21; there is a total computable funetion (6; Ginny Such that (inthe notation of theorem 2.2) on =Sub(!"’; 6", 6), () Fix n> 1; there is a total computable function k/e) such that for alle, 0, 2, and this occurs a the ‘i instruction ina program, 0 otherwise (The “next instruction for the computation’ here is as defined in chapter 1 § 2,80. =/ +1 of if jis jump instruetion Ini, my, q) we may have Tf these four functions are primitive recursive, then remembering that Te.) where © = TT(er) and / = Tre) we have chbaG), gale, Tr(er)) iF 0, x26 + DLO) = + DH, thus, if ISIC), then B(x) is the 2th index k such that afk, x)= 1. Hence if L<£< (x) andx> 0, lo otherwise (iv) From the definition: alex) =bi.x) (= 0,0) afi +1, x)= 04-1, PA, N11) From the above explicit formulac, using the techniques of chapter 2, ‘these functions ars all primitive recursive. (6) The functions In(e) and gn(e,) are primitive recursive, Proof From the definitions of the coding function y: where / and a are the funetions in (5) (1) There are primitive recursive functions u, ui, Wy vl, Bp v, such that i's = 0(24am), then wee) = m, B(SUm)), then w(z) iOCT(eni, zn,)ythen «i(e) = m, and 2/52) ite = @Cen!, my <2), then ie) =m, v2) = my and 5 Universal programs 98 Proof. From the definition of 0, and writing (2/4) for qt(4, 2), take ula) = (4) +1, UZ) = THIEL, (@= 71/44, Vile) = THC7TICe/4)YH, vs@) = Mri, Vu@)=T4) +1. (8) The following functions are pri ) zero(e, m) = the change inthe configuration c effected by instruction Zm), = quPii™e). (Gi) sue, m) = the change inthe configuration ¢ «effected by instruction Sm), pm. (Gi) transfer(c, m,n) = the change inthe configuration ¢ cffected by instruction Tim, n), = atp%ep."). (©) The function chic, 2) (defined in (3) above) is primitive recursive. Proof. fwofe, we) ifm, 2)=0 (ic. is the code of a 2et0 instruction), sue(e, u@)) ifm, 2)= 1 (lez | is the code of a che, 27 secessor instruction), | transfer(c, ui(z), w,(z)) if m(4, 2) =2 (ie. 2 is the code of a transfer instruction), ¢ otherwise, Appendix. Computability ofa, 99 (10) The function (defined in (4) above) is primitive recursive, Proof. We ha ve (ist ifr, #3 ie. zis the code of an arithmetic instruction), itOvi@ * ew,@) ) item(4,2)=3 } (ie. zis the code of 8 jump instruction), Az) itcewica eno» From this definition by cases, we se that vis primitive recursive ‘We have now shown that the functions (1}—(4) above are primitive recursive, so the proof ofthe theorem is complet. 6 Decidability, undecidability and partial decidability In previous chapters we have noted several decidable problems, but so far ‘we have encountered only one explicit example of undecidability: the problem ‘, is total” (theorem 5-2.1). It is of considerable interest to identify decidable and undecidable problems; the latter, particulary, indicate the limitations of computability, and hence demonstrate the theoretical limits to the power of real world computers In this chapter the emphasis is largely on undecidability. In § 1 we give 1 survey of undecidable problems arising in the theory of computability iself, and discuss some methods for establishing undecidebility. Sections 2-5 are devoted to a sample of decidable and undecidable problems from other areas of mathematics: these sections will not be needed in latef chapters and may be omitted. In the final section we discuss partial decidability, a notion closely related to decidability Let us recall from chapter | that a predicate A/(x) is said to be decidable i ts characteristic function cy given by {1 ifM(x)holds, els) =1 ‘Hf dos mal? {is computable. This is the same as saying that M(x) is recursive (see chapter 3 § 2). The predicate M(x) is undecidable if itis not decidable. In the literature all of the following phrases are used to mean that M(x) is decidable M(x) is recursively decidable, M(x) has recursive decision problem ‘M(x is sohvable, M(x) is recursively solvable, M(s) is computable. ‘An algorithm for computing ey is ealled a decision procedure for M(x) 1 Undecidable problems in computability 101 1. Undecidable problems in computability Most proofs of undecidability rest on a diagonal construction, as in the following important example. LL. Theorem ‘XGVKI (or, equivalently, <>,(x) is define ‘ifiu(x, x) is defined) is undecidable. ‘Proof. The characteristic function fof this problem is given by 1 ike Wy. re={o itt W, Suppose that fis computible; we shall obtain contradiction. Specifically, we make a diagonal construction of a computable function g such that Dom(g)# W,( = Domy(’)) for every x; this i obviously contradictory. ‘The diagonal motto tells us to ensure that Dom(g) differs from W,at x; so,we sim to make PCO, oF XG Dom(g) <=> XE Letus define g, then, by iE W, Gc. 106) = 0), rndefined iG 1, (.640(8)"D, Since fis computable, then so is g (by Church’s thesis); so we have our contradiction, (To see this in detail: since g is computable teke m such that g= (4 then m GW, <*> m G Dom(g) <=> mé Wa contradiction), We conclude that fis not computable, and so the problem “x Wis undecidable gix)= Note that this theorem does nof say that we cannot tell for any articular number a whether , is defined. For some numbers this is quite simple; for instance, if we have written a program P that computes a total function, and P = P, then we know immediately that y) is defined’ (or, equivalently *P,6)l or *y G W,) is undecidable Proof, Arguing informally, if the problem ‘0,(y) is defined’ is deci able then so is the problem ‘<£,(x) is defined’, which is if anything easier. Bu this contradicts theorem 1.1. Giving this argument in full detail, let g be the characteristic fumetion for <£,(y) is defined’; ie. (_. pellit,67 is defined, 87 loif (> 6) isnot defined If g is computable, then so is the function /(x) = g(x, x); but f is the characteristic function of ‘x e W,*, and is not computable by theorem 1.1 Hence g is not computable; so *(y) is defined’ is undecidable. Theorem 1.3 is often described as the Unsolvability of the Halting problem (for URM programs): there is no effective general method for discovering whether & given program running on a given input eventually halts, The implication of this for the theory of computer programming is ‘obvious: there can be no perfectly general method for checking programs to sce if they are free from possible infinite loops, ‘The undecidable problem °xG W,’ of theorem 1.1. is important for several reasons. Among these is the fact that many problems can be shown to be undecidable by showing that they are at least as difficult as this one. We have already done this in a simple way in showing that the Halting problem is undecidable (theorem 1,3): this process is known as ‘reducing one problem to another. I Undecidable problems in computability 103 Speaking generally, consider a problem M(x). Often we can show that @ solution to the general problem M(x) would lead to a solution to the general problem ‘x 6 W,! Then we say that the problem ‘xa 17,’ is reduced to the problem M(x). In other words, we can give a decision procedure for ‘XG W,’ if only we could find one for M(x). In thiscase, the decidability of M(x) implies the decidability of *x G Wi, from which we ‘conclude immediately that M(x) is undecidable. ‘The sm-n theorem is often useful in reducing “XG W,’ to other problems, as illustrated in the proof of the next result 14. Theorem The problem *0. is undecidable. Proof, Consider the function f defined by Kor) ° iBGVk,. Iundefined itxEW,, We have defined f anticipating that we shall use the s-m-n theorem: thus we are thinking of x as a parameter, and are concemed about the functions g, where gy }i(x, y). We have actully designed f 50 that g,-0<>x0M, By Church's thesis (or by substitution using 0 and “u) fis computable; so there #8 a total computable Function &(s) given by the smn theorem such that (x, y) = d>k(,dy)li-e, R() = gx- Thus from the definition of f we see that (xe W, <=>

, = / is undecidable Proof. We can casily sec that this is a harder problem than the problem sk 0" Let c be a number such that <£, = 0; if /(x, y) is the characteristic function of the problem <), = /is undecidable, We use the s-m-n theorem again to reduce the problem ‘x G HW," in the following results. 16. Theorem Let ¢ be any number. The following problems are undecidable. (@ (the Input or Acceptance problem) ‘ce W," (equivalently, P (ol or eG Dom"), (©) (the Output or Printing problem) ‘e 6 F,” (equivalently, Ye G Ran(’,)), Proof, We are able to reduce “XGW,’ to these problems simul- taneously. Consider the function /(x, y) given by Mey itkKGW,. Os cadetined otherwise (With the s-m-n theorem in mind, we are concemed about the functions «2, where g,(y)"V, y}: we have designed fs0 that cGDom(g,)<-> 1 Undecidable problems in computability 105 x6 W, <> ¢ G Ran(g,).) By Church's thesis f is computable, and so the som-n Iheorem provides a total computable function k such that UGs, y) = Wiyy = Ey =N,806 6 Wy, and ce Ey! and = 0,50 ck W, XE HA WV) La) in Thus we have reduced the problem ‘XG W,’ to each of the problems ‘0G Wiand ‘caE!, Completing the proof of (a) in detail, we see that if g is the charac teristic function of ‘e 6 Wi, then iG Wy BOD = Cy ex ew. This funetion is not computable (theorem 1.1), so g cannot be compu- table, Hence ‘ee W, is undecidable. A detailed proof of (b) is similar. andes) ‘We conclude this section with a very general undecidability result, from which theorems 1.4 and 1.6 follow immediately. It is another use of the ‘s-m-n theorem to reduce 'x 6 Wl 17. Theorem (Rice's theorem) Suppose that & £,and 39 4 0,@hen the problem 'eST is undecidable. Proof. From the algebra of decidabiity (theorem 2-4.7) we know that ‘G39" is decidable iff “\G%139" is decidable; so we may assume without any loss of generality that the function fo that is nowhere defined does not belong to (io, prove the result for 39) Choose a funetion g 6 $&. Consider the function (x,y) defined by 0) tow, 10 OF Fandefined ifxeW.. The s-m-n theorem provides a total computable function A(x) such that (s, rd >K() 6) Tous we see that x0, Dy = tiv. d>kd) 0S; XE W,A> dg = hyie. (PM) *B. So we have reduced the problem ‘x G W,'to the problem “ 0 such that all the zeros of p Tie in the interval }-M, Mf. In fact ips) = a, ~ aix +... + a the number sulfices. Then by Sturnfs theorem the number of zeros of p is RO Ops Ri (8) 1EZ, = S(o let be the statement Vin Vii RR Kans Kon > RRs Lyne Xn) (©) 1E2Z,=Tee,n) let, be the statement Vises Vist RO es Rane Non DO ROT 2X, (4) WI,= Wasim, g let 7, be the statement Viki. Vig: ROXjvon Xo i) 2 (ky Xn > Rode A GHX PRIMI Ny DD. Now for any ae M let a, be the statement (TAMIA... AUARO, 0, 0,0) Fri IK, Ron aye SED, Where the statement VaVy((e ) Ax 0). (This ensures that in any interpretation, ifm, ne N and m =n thea m =m) The statement R(, 0.» 0,1) comesponds oa stating state [alo]o next instruction A, and any statement R(xiun Xy s+1) corresponds to a halting state (ince there is no instruction A+i). Thus we shall see that (9 Pal <=> er, isvalid, Suppose first that P\a){, and that we have a structure in whieh Fyn, 7, and R(@, Ov. 0,1) hold, Using the statements Ty, .., T, we find that cach of the statements R(t, fy K) corresponding to the successive states in the computation also holds. Eventually we find that & halting statement R(bn .., by 8 + 1) holds, for some bu.., 6, B.and hence Bi. 3, RO, os Xy 8 1) holds. Thus a, is valid. 6 Decidability, undecidability and partial decidability m2 Conversely, if a, is valid, it holds in particular in the structure N- with the predicete symbol R interpreted by the predicate R, where Ry(ai... a, 8) = Atsome stage in the computation P(a) the registers contain a, fly in, O,.. and the next instruction is /, ‘Then To...» f and R(@, Oy. 0, 1) all hold in this structure, hence so does 3x. 3, ROxjvos X41). Therefore Pra). If we take P to be a program that computes the function xcDom(g), ‘so M{x) is partially decidable by theorem 6.3. For the converse, suppose that M(x) is partially decidable, with partial decision procedure given by a program P. Define a predicate R(x.) by R(x, y) =P(x)I in y steps, By corollary 51,3, 22(x, 9) is decidable. Moreover, MG) <> Poot «Sym y) ‘as required, Note. From the appendix to chapter § it follows that the predicate R in this characterisation may be taken to be primitive recursive (see the note | following corollary 5-1.4). ‘The characterisation given by theorem 6.4 indicates an important way to think of partially decidable predicates. It shows that partial decision procedures can always be cast in the form of an unbounded search for a 6 Partially decidable predicates us umber y having some decidable property R(x, yj. This search is most naturally cartied out by examining successively y = 0,1, 2... to find such a y. The search halts if and when y is found such that R¢s, y) holds: otherwise the search goes on for ever. We can use theorem 6.4 to establish some further properties of partially decidable predicates, that aid usin their recognition 65. Theorem I Mécy) 18 partially decidable, then so is the predicate SyAfts Proof. Take @ decidable predicate R(x, y, 2) such that Méxy) iff 42R(s,y, 7). Then we have SyM(sy) <=> $y SR, 3,3). ‘We can use the standard technique of coding the pair of numbers y, 2 by the single number u = 23*; then the search for a pair y, 2 such that R(cyz) reduces to the search for a single number u such that Rs (Wi), i. Sy Mis) <=> Sub fu) The predicate Sfx) = R(x, (wi, (w);) i8 decidable (by substitution) and so by theorem 6.4 3yM(x,y) is partially decidable. ‘Theorem 6.5 is described by saying that partially decidable predicates are closed under existential quantification. lis tepeated application gives 66. Corollary Mex, y) is partially decidable, where y = (J ime Yq) then s0 is the predicate 39s. 3ygM% Yo. Ya Let us now consider some applications of the above results 67. Examples 1. The following predicates are partially decidable. (@ xe" (n fixed). (The Printing problem: cf. theorem 1.6.) ©) W,*0(CE. exercise 1.8(12)) Proofs (6 By <> Bein ISHPYtivny ZyX int steps), The predicate in the brackets on the right is decidable; apply coro- ary 6.6. (©) W, # 0 <> 3y3xP,Q)1 in f stops); again the predicate in brackets is decidable, so corollary 6.6 applies. 6 Decidability, undecidability and partial decidability 116 2. Provability in the predicate calculus is partially decidable (this is for those who have read § 5). Proof, We proceed informally; in the predicate caleulus a ‘proof is defined as a finite abject (usually a sequence of state- ‘ments) in such 2 way thatthe predicate Prd, a) ="'d's& proof of the statement a” is decidable. Then we have ais provable <=> 3d Pr(eZ, c#), hence ‘ais provable’ is partially decidable. 68. Diophantine predicates (ef. §3) Suppose that p(Xij.. Xp Yio J) 8 a polynomial with integer coelficients. Then the predicate M(x) given by M(x) = 391. 3yg (POX, Yes Yq) =O) is called a diophantine predicate, because of its obvious connection with iophantine equations. (The quantifiers 3y,.., 3Yq are taken as ranging over M.) Example The predicate ‘x is a perfect square’ is diophantine, since it is equivalent to 3y (x -? = 0) From corollary 6.6 we have immediately 69. Theorem Diophantine predicates are partially decidable. Proof: The predicate p(x, y) = 0 is decidable; apply corollary 6.6 Clearly, diophantine predicates are partially decidable predicates that can be cast in a relatively simple form, and for a long time it was not known whether any undecidable diophantine predicates existed. This question is closely connected with Hilberfs tenth problem (§ 3), as we shall sce. It was @ most remarkable achievement, therefore, when Mati- xyasevich proved in 1970: 6.10. Theorem Every partially decidable predicate is diophantine ‘The proof ofthis result by Matiyasevich rested heavily on earlier work ‘of Davis, Robinson and Putnam, and is far too long to present here, Full 6 Partially decidable predicates 7 proofs are given in Davis [1973], Bell & Machover [1977] and Manin [1977], The major part of the proof consists in showing that diophantine predicates are closed under bounded universal quantification; i.e. if M(x, ) is diophantine then so is the predicate Vr By. 39 (POS Yin Y_) =O) (his is possible by Matiyasevich's theorem). Then decision procedure for Hilberfs problem would give the following decision procedure for ‘xeWi: to test whether a e W, sce whether the polynomial <2yin-*, Yu) = PO Views Jy) has a solution in “J. So x © W,'has been reduced to Hilberfs problem; hence the latter is undecidable. We shall mention another (suprising) consequence of Matiyasevich’s theorem in the next chapter. We conclude this chapter with two important results, linking. partially decidable predicates with decidable predicates (theorem 6.11) and ‘computable funetions (theorem 6.13). 6.11, Theorem A predicate M(x) is decidable if and only if both M(x) and ‘not M(x)’ are partially decidable, Proof. If Al(x) is decidable, so is “not Af{x)", so both are partially decidable. Conversely, suppose that partial decision procedures for M (x) and ‘not M(x)’ are given by programs F, G. Then F (oj <=> M(x) holds and G(x)1 <> Snot M(x) "holds. Morcover, for any x, either F(oj or G(x)] but not both. Thus the following is an algorithm for deciding M(x). Given x, run the 6 Decidabilty, undecidabiity and partial decidability 18 computations F(x) and G(x) simultaneously (or carry out alternately one step in each computation), and go on until one of them stops. If itis F(x) ‘that stops, then conclude that A/(x) holds; if it is G(x) that stops, then A(x) does not hold, This theorem gives an altemative proof that the predicate “x W/ is not partially decidable. Similarly we have 6.12. Corollary The predicate “P,(y)f (Ihe Divergence problem: equivalently “ye W,) or “<£,(y) is undefined’ is not partially decidable. Proof. If this problem were partially decidable, then by theorem 6.11 and example 6.2(1) the Halting problem P,(y)I would be decidable. ‘The final result of this chapter gives a useful way to show that a function is computable, 6.13. Theorem Let x) be a partial function. Then fis computable if and onty if the predicate ‘3" is partially decidable ‘Proof Iffis computable by a program P, then we have (0) 3PCsiy in step). ‘The predicate on the right is partially desidable by theorem 64 and corollary 5-13 Conversely, suppose that the predicate ‘/xs) —y *is patally decidable Let Réx. y, 9) be a decidable predicate such that ((x)="y <> 31R( ¥, 9 ‘Then we have the following algorithm for computing (x) Search for a pair of numbers y, ¢ such that R (x, y, #) holds; if and when such apr‘ found, then 3) —y. Hence f is computable. (A formal proof of the computability of /céuld be given by the standard technique of coding @ pair y, ¢ by the single umber = 25, See exercise 6.14(8) below.) Further properties of partially decidable predicates are given in the exercises below (see in particular exercises 6.14(4, 5, 9). Tn the next chapter we will be studying unary partially decidable predicates in greater detail, in the guise of recursively enumerable sets. We 6 Partially decidable predicates 119 shall see in particular why partially decidable predicates are often deseribed as recursively enumerable predicates. 6.14, Exercises ‘Show that the following predicates are partially decidable: (@) B.""#0" (a fixed), (6) &My) isa perfect square’ (©) ‘nis a Fermat number’. (We say that nis @ Fermat number if there are numbers x, y, > 0 such that x" +y* = 24) (6) ‘There is a run of exactly x consecutive 7s in the decimal expansion of i! (For those knowing some group theory) Show that the word problem for any finitely presented group is partially decidable. ‘A finite sot S of 3 x 3 matrices is said to be mortal if there is a finite product of members of S that equals the zero matrix. Show that the predicate $ is mortal’ is partilly decidable. (It has been shown that this problem isnot decidable; see Paterson [1970].) Suppose that M(x) and Njx) are partially decidable; prove that the predicates “M(x) and Nfs)! MCs) or N(x)" are partially decidable. Show that the predicate ‘not M(x)’ is not necessarily partially decidable. . Suppose that M(x, y) is partially decidable, Show that (a) ‘By y)) (©) *VyM(x, y) isnot necessarily partially decidable. Show thatthe following predicates are diophantine (a) ‘xiseven’, (b) “x divides y" (This exercise shows how the technique of reducibility (§ 1) may ‘be used to show that a predicate isnot partially decidable.) (2) Suppose that Af(x) is predicate and k 2 total computable funetion such that x aVitt M(k(s)) does not hold. Prove that (M(x) is not partially decidable (b) Prove that ‘, is not total’ is not partially decidable. (Hint, Consider the function k inthe proof of theorem 1.6.) (©) By considering the Function 1 if (x) docs not converge in y or fey 1 fewest, \defined otherwise, 6 Decidability, undecidability and partial decidability 120 show that “>, is foal” is not partially decidable, (fin, Use the semen theorem and (a)) Give a formal proof of the second half of Theorem 6, “i(a) =y' is partially decidable, then fis computable Suppose that Mxinn, x) is partially decidable and gi... gy are computable partial finetions. Show that the predicate NG) siven by Nig) Mead), 8019) is parally decidable. (We take this to mean that Nf) does not hold if any one of gi(y)... gy) is undefined.) he. if 7 Recursive and recursively enumerable sets ‘The sets mentioned in the title to this chapter are subsets of M cor responding to decidable and partially decidable predicates. We discuss recursive sets briefly in § 1. The major part of this chapter is devoted to the study of recursively emumerable sets, beginning in § 2; many of the basic properties of these sets are derived directly from the results about partially decidable predicates in the previous chapter. The central new result in § 2 is the characterisation of recursively enumerable sets that gives them their name: they are sets that can be enumerated by a recursive (or computable) funetion, In §§ 3 and 4 we introduce creative sets and simple sets: these are special kinds of recursively enumerable sets that are in marked contrast to each other; they give a hint of the great variety existing within this class of sels. 1. Recursive sets ‘There is a close connection between unary predicates of natural numbers and subsets ofvcorresponding 10 any predicate M(x) we have the set {x : M(x) holds}, called the extent of M (which could, of course, be 0); while to @ set A gf there corresponds the predicate "XG A’.! The name recursive is given to sets corresponding in this way to predicates that are decidable. LL. Definition Let A be a subset of ftd. The characteristic function of A is the function ¢, given by L ifxca, ACO 1g itxea. "As mentioned in a foomote 1 § 3 ofthe Prologue, predicates ac often identifed With their extent: that view would not be inconsistent wih our exposition 7 Recursive and recursively enumerable sets 12 Then A is said to be recursive if c, is computable, or equivalently, if “x GA is a decidable predicate. Notes 1. For obvious reasons, recursive sets are also called computable sts 2. Ife, is primitive recursive, the set dis said to be primitive recursive. 3. The idea of a recursive set can be extended in the obvious way to subsets of N’ (n> 1), although in the text we shall (as is common practice) restrict the use of the term to subsets of N, There is no loss of generality in doing this, because recursive subsets of J" can easily be coded as recursive subsets of fU, See exercise 1.4(2) below for details, 1.2. Examples 1. The following sets are recursive, @) N, (@) F (the even numbers), (©) any finite set, (@) the set of prime numbers 2. The following sets are not recursive. (a) {x: , is total} (theorem 5-2.1), @) {x:x€W,)} (theorem 6-1.1), (©) {x: 1; prove that if B is recursive then the predicate Mixi,..., X,,) given by. Meo) 823%... GB is decidable. (b) Let AGN": define A to be recursive if the predicate “XGA’ is decidable. Prove thal is recursive iff (2X32, pi": (xi... X,)G 4} is recursive. 2. Recursively enumerable sets We tum now to the subsets of M that correspond to partially decidable predicates. These constitute an important class, if only because ‘ofthe many situations in which they occur. 21, Definition Let A be a subset of IM. Then 4 is recursively enumerable if the function fgiven by fat ikea, 1°" undefined ifxEA is computable (or, equivalently, if the predicate 'xeA’ is partially decidable). ‘The phrase recursively enumerable is almost universally abbreviated re, Notes 1. The terms semi-recursive sets and semi-computable sets are also used to describe 1. sets; indeed, from the above definition these names would appear moze appropriate than recursively enumerable. We will, neverthe- less, adnere to the standard name recursively enumerable, which stems from the fact that these sets may also be defined as sets that can be enumerated by a recursive (or computable) function. This alternative characterisation is given in theorem 2.7 below. 2. As with recursive sets, the idea of re. sets can be extended in the ‘obvious way to subsets oflYir > 1), but there is no loss of generality in confining attention (as we do in the tex!) to re. subsets of IM. See exercise 2.18(9) below. 22. Examples 1. Let K = fxe Wy); then K is an re, set that is not recursive, (example 6-6.2(1)). Its complement Kis not re. (example 6-6.2(4)) 2. Any recursive set is re. (example 6-6.2(2)). 7 Recursive and recursively enumerable sets 14 3. The sot {x: W, *0} iste. (example 6-6.7( 1 (6). 4. Iffisa computable function, then Ran(/) is rc, (example 6-6:1( 1 a); f. theorem 2.7 below). Note, K is the standard notation for the set {x: x € W,} (example 1 above), which plays a prominent role in the study of re. sets. Most ofthe results for partially decidable predicates in chapter 6 § 6 translate immediately into the language of re. sets. We begin with 23. Theorem Asset is re if and only if it is the domain of a unary computable function. Proof. Theorem 6-6.3, We conclude from this theorem that the enumeration Wo, Ws» is an enumeration (with repetitions) of all re. sets. If A = W, then e is called an index for 4. From theorem 6-6.4 we obtain the next characterisation of re. sets. 24, ‘Theorem The set A is re. ifand only ifhere isa decidable predicate R(x, y) such that HEA Uf YRC 9). (From the note following the proof of theorem 646.4 this predicate R may be taken to be primitive recursive.) We also have the following immediately from theorem 6-6.5. 28, Theorem Suppose that M(s, yy. ¥x) #8 partially decidable; then the set fx:3yin. 3YWMO, Yours Yad} A He ‘The following link between rc. sets and recursive sets is an immediate application of theorem 66.11, 26. Theorem The set Ais recursive ifand only fA and A are re 2 Recursively enumerable sets 1s Proof. This is immediate from theorem 6.6.11, but itis instructive to sive a formal proof of the non-trivial half of the proof. Suppose then that Rand S are decidable predicates such that 6A 0 3yP(x, y) x6A<=> 3yS(x,y) (ove are using theorem 2.4), Now define a function /(x) by (x)= py (x,y) oF Six, 9). By the resuts of chapter 2, fis computable; further, since for every x, cither x ¢ A or xeA,/(x) is always defined, and we have X6A0 Res) ‘Thus 'xeA\ is decidable, so Ais recursive We now tum to the characterisation of re. sets that gives them their 2.7. Theorem Let Ag M. Then the following are equivalent: (a) Aisre. (2) A= or Ais the range of a unary total computable function, (©) isthe range of a (partial) computable function. Proof, We shall prove the chain of implications (a) => (6) => (©) => ©) (a) (2) Suppose that 4 # 0 and that A = Dom(), where f is computed by a program P. Choose an element a e 4. Then A is the range ‘of the following total binary function: ; x if PCa in ¢ steps, BO La otherwise. Clearly g is computable. To complete the proof we construct a unary total ‘computable funetion / having the same range as g. Let (2) = (22) Clearly Ran(ii) = Ran(g) = A (6) > (is trivia, (© > (@) Suppose that A= Ran(i) where his an Mary computable function. Then 6A 3yi62 By lls Yq) =%) ‘The predicate in brackets on the right is partially decidable (theorem 166.13) so applying theorem 2.5 we sce that 4 is r 7 Recursive and recursively enumerable sets 126 (The reader may have noticed that various parts of this theorem have been given, more or less explicitly, in examples and exercises earlier in this and other chapters.) Notice that it is from theorem 2.7(6) particularly that the name recursively enumerable comes: a non-empty re, set is @ set that can be enumerated as A = (A), 6(1), 6(2)...} where A is a recursive (ie. total computable) function. In fact, by using the results of chapter (and appendix) itis easily seen that the enumerating function fin the proof of (@ => (6)is primitive recursive. ‘Note also that theorem 2.7 tells us that the enumeration Fy Bi, E. of the ranges of unary computable funetions is another enumeration (with repetitions) of all re, sets. In informal terms, theorem 2,7 shows that r. sets are the same as effectively generated sels. We would call a set A effectively generated if there is an informal effective procedure for compiling a list of the members of 4. Such a procedure would from time to time (not necessarily at regular intervals) output & number to be added to the list, The procedure may go on ad infinitum (and certainly must if A is infinite). To see that a set A generated in this way is rc, simply put (0) = Ist number listed by the procedure, ‘fn) ~ (n+ Ita murs listed by the procedure, where ffm) is defined iff there is an (m +1 )th number listed. Then clearly f is computable, and 4 = Ran(/ is r. ‘We can illustrate this with an example. 28. Example ‘The sot {xcthere is a run of exactly x consecutive 7s in the decimal expansion of 77} is re. (ef. exereise 6-6,14( 1 d)). The following is ‘an informal procedure that generates this set of numbers, “Run an algorithm that computes successive digits in the decimal expansion of 77, Each time a run of 7s appears, count the number of consecutive 7s in the run and add this number to thelist.” ‘The characterisation of theorem 2.7 gives us a straightforward diagonal ‘proof that total computable functions cannot be recursively enumerate. 29, Theorem The set (x:

, i total} is notre 2 Recursively enumerable sets 127 Proof, (Cf. the suggested proof of this result given in exercise 6- 6.14(76).) Suppose to the contrary that fis @ total unary compu- lable function that enumerates this set; Le, &Ai(iD> <£/Q),.. is a list of all unary computable functions. Then we can easily make a diagonal construction of a total computable function g that differs from every function in this list. The diagonal motto says ‘make g differ fom) at nso we put 0) = 3y7%(xy) (theorem 2.4), (@) For some partially decidable predate AM, yi» oy 6A <> By. WAI Vines Yo) theorem 2.5), (5) If 4/0, A is the range of a fotal unary computable function (laeorem 2.7), (6) Aisthe range ofa computable function (theorem 2.7), (1) Ais diophantin (theorem 2.11), (8) 4 is the sct of non-negative values taken by a polynomial with integer coefficients (theorem 2.12) 2 Recurisvely e nume rabie sets 129 Naturally, when working with re. sets one chooses the characterisation that is most convenient for the purpose in hand, We illustrate this in the proof of the next theorem, 213. Theorem IA and Bare re. then so are Ar>B and AuB. Proof For A n B use characterisation (2). Suppose that A = Dor(/) and B = Dom(g) with fg computable. Then A n B = Doma), and /g is computable. For uB use characterisation (5). If A = 0 or B = 0 there is nothing to prove. So suppose that A = Ran/) and B = Ran(g) where!, gare total computable. Define h by AGNI), AQx+D= 260. ‘Then fis computable and clearly Ran(i) = AB. (itis instructive to find proofs for ths theorem using each ofthe other ‘characterisations ofr. sets) (Our next theorem gives another link between re. sets and recursive sets, 2.14. Theorem An inginite set is recursive if and only if it isthe range of a total increasing computable function, ie. if ican be recursively enumerated in increasing order. Proof Suppose that 4 is recursive and infinite; then 4 is enumerated by the increasing function fgiven by 1O)= we), Nzi +1) =pyly GA and y >ffn). Moreover, f is computable by minimalisation, recursion and the recur siveness of A Conversely, suppose that 4 is the range of the computable total increasing funetion /; i.e. (O)S(Dsi2)<... I is clear that if y = ffm) then n ysHence we have ved <=> yGRan() 320, 6 kay = hence dU. For ifz 6 K, there is ¢ such that P(2) in # steps, Then g(z, #9 —od>(°(1) is undefined for "> 1. Hence <> is finite, On the other hand, if zé K, then (2, M0) forall, $0 <9 : Now (*) means that zeK <=> s(Jed, which implies that Kis rey a contradiction, Hence there must bea finite OOF with esi For the reverse implication, suppose that fis a computable function, such that there is @ finite fumetion esd. with 0%, bul fésd. Define computable fumetion 2, 0 by (no ifrG Dom) or20K, Tundefined otherwise. gz.) 8 ‘The s-m-n theorem provides a total computable s(2) such that g(2, 00), From the definition of g and the fact that 0 / we see that UGK > dyo)= Mbence ,) =|Dom(0) = 0 (hence <>o9(6 £2). But this means that z GK 1(2)GA, again showing that K is rc, a ‘contradiction, Thus /¢.sd as required We leave it as an exercise for the reader to see how the Rice-Shapiro theorem generalises Rice’s theorem (exercise 2.18(12) below), 218, Exercises 1, For any a GN, let “W, = date) a}. Show that *W, is re. (all 4), Doos the enumeration * W,, *VPj, # Wy. include all r sets? Show that the set (x: 1; prove that if B iste. then the predicate Af(ti.. x, given by NG XS = 268% 2G is partially decidable. 3 Productive and creative sets 133, () Let AGN"; define A to be re. if the predicate “leA' is, partially decidable, Prove that iste. i 0X30 ph (xi. x) £] ise (©) Prove that AgNis re, iff = 0 oF there is a total computable function f:Ni-N" such that A = Rant). (By a computable function f fom N tiiwe mean an metuple / = (i, j,) where cach f is a unary computable function and (8) = Gi). Jaf) 10. Suppose that fis a total computable function, A a recursive set and B an re, set. Show that j(A) is recursive and that (A), f1B) ad FB) axe xe, but not necesssrily recursive, What extra information about these sets can be obtained if fsa bijection? 11, Use the Riee-Shapiro theorem to show that the following prob- Jems are not partially decidable: a)“ W, =0', (6! W, i finite’, (6) W, isinfnite’,() °0, ~0, (@) “6. #0. 12, Prove Rice's theorem (theorem 6-1.7) from the Riee-Shapiro theorem (theorem 2,16), Hint. Suppose that *, © is deci able; then both 48 and, | satisfy the conditions of Rice- Shapiro: consider the cases fe ® and 8) 13, (a) Let Kx: d>,(5) = 0) and K, =(x: ,(x) = 1}. Show that Ky and K\ are re, and that they are recursively inseparable, iss K,r> K\ = 0 and there is no recursive set C such that KjQ C and X\ C; in particular neither K, nor Ki is recursive, (Hint Suppose that there is such a set C and let m be an index for its characteristic function; consider whether or not m e C.) (b) Show that two disjoint sets 4, B are recursively inseparable (in the above sense) iff whenever A.c W, BW, and W, W, ~ 0, then there is a number xEW,uWV, (Note. Recursive inseparability for a pair of disjoint sets corresponds to non- recursiveness for a single set; pairs of recursively inseparable sets that are also re, correspond to re. sets that are not recursive.) 3, Productive and creative sets ‘Our chief concer in this section is to discuss a special class of rc. sets called creative sets, These are r.c. sets whose complement fails to be re, in a rather strong way. Thus we begin by considering class of non-re. sets, among whose complements creative sets are to be found, Suppose that 4 is any set that is not re then if 17, is an re. set contained in 4, there must be a number y e A\ W,, This number y is a ‘witness to the fact that 4 * JY, It turns out that for some non-r.. sets its 7 Recursive and recursively enumerable sets 134 possible to find such a witness in an effective way. Consider, for example, thenon-ne, set K = fxixé Wf W. SK, we cannot have xelf, (for then x<=K, 30 WyéK), hence xeKiW, So x itself is a witness that WK The name productive is used to describe none, sets for which a witness ean always be computed inthis way. 3. Definition A set A is productive if there is a total computable function g such that whenever 7, ¢ 4, then g(x) 6.4 | W, The function g is called a productive function for A. This is illustrated by fig. la Example. Th set Kis productive, wth productive function g(x Many examples of productive sets ate obtained from the following theorem, which incorporates the idea of reducibility that was discussed in the previous chapter. 32. Theorem Suppose that A and B are sets such that A is productive, and there is a total computable function f such that xed iff fjeB. Then B is productive. Proof. Let g be a productive function for A. Suppose that W4"B. ‘Then W,)== Ai (Sihoreover, AW, is re, so there is z such that (LOW) = W,, Now W, a.A, and so g(z)e A |W, from which we see Fig. 7a. A productive set. 3 Productive and creative sets 135 that fle(s)eBIW,\ ic. flg(2)) is a witness to the fact that W, / B (Ge, 7. We now need to obtain the witness/(g(2)) effectively from x. A simple application of the s-m-n theorem provides a total computable function fo(x)such that Wye = /"( M) (apply the s-m-n theorem to the function , #0}, () f\c£ W} (ca fixed number), (©) CEE} (ca fixed number) - (For each of these’ sets apply theorem 3.2 using X and the functions obtained in theorem 6-1.4 (for (a)) and theorem 6-1.6 (for (6) and (e).) ‘The above cxamples of productive sets and many more may be ‘obtained from the following general application of theorem 3.2, based on ‘our proof of Rice's theorem, 34, Theorem Suppose that 33 is a set of unary computable functions with feXCO and 33 8 6Then the set B ={x:<> el] is productive. Proof. Choose a computable function gé 33. Proceeding exactly as in the proof of Rice’s theorem (6-1.7) obtain a total computable function 7 Recursive and recursively enumerable sets 136 (Gs) such that k(x) £4)" /0ie/C Le. xeK iff &(x)6 B. By theorem 3.2, B is productive. 35. Example ‘The sot fx:d>, is not total} is productive, immediately from theorem 3.4 (ur chief interest in productive sets is when they occur as the comple- ‘ment of an re, set 3.6. Definition A set A is creative if it is rand its complement A is productive, ‘The simplest example of a creative set is of course K. Using theorem 2.6 we can say that a creative set isan fe, set that fails to be recursive in a very strong way. We will see in chapter 9 that there is a sense in which creative sets are the re. sets having the most difficult decision problem. 31. Examples ‘The following sets ate ereative (a) {X-0G W,} {the complements of these sets were () {x: 0 E,) shown to be productive in examples 3.3). (©) The set A = {x: d>,(x) = 0}. Cleatly A is res to obtain a productive function for A, use the s-m-n theorem to construct @ total computable function g such that <£,u)(y) = 0 <=> <6,6) is defined. Then g(€ A <> g(x)GK: so if W, © Z we must have eve A\W,, Thus g is @ productive function for 4, Many examples of creative sets of indices are provided from the following application of theorem 3.4 38, Theorem Suppose that of < 6, and let A= {x:GA2/}.IfA is re, and 10 oF then A is creative. Proof Suppose that A is re. and A¥O.M. If foe of then Ais productive, by theorem 3.4; this is a contradiction, Thus (0 X so 4 is productive (theorem 3.4) hence A is creative 3 Productive and creative sets 137 The examples 3.7(a), (b) could be obtained by immediate application Of this theorem; similarly we have: 39. Example The set A™~ (x: W, O}is creative; this ets obviously 2. and corresponds tothe setsd= {fe @./H,) Many of the exereses atthe end of the section may be done with the aid of theorem 3.8 Al examples of nonrecursive re. sets that we have encountered so far are creative, (The reader might care 10 prove this for the examples that we have not dealt with explicitly.) The question then arses as to whether all non-ecursive re, sels are creative, The idea tht this might be the case is reinforced by theorem 3.8, and further examples in the exercises below, It tums out, however, that this conjecture is false: by a special constuction we can obtain re. sets that are neither recursive nor creative. Section & willbe devoted to that task ‘The consiction to be made in the next section is inspired by theorem 31 below, which will show that a productive set (and hence the complement of a creative set), although not itself re, does contain an infinite ne. subset. (The secret of constructing an re. set that is neither recursive nor creative will be to ensure that 4 does no! have this propery.) The proof of the theorem will be facilitated by fist isolating the following technical result 3.10. Lemma Suppose tha is «total computable function. Then there i a total ‘computable function k such that for all x, Ugagy~ W, w{g03)}, Proof. Using the somen theorem, take k(x) 10 be a total computable funetion such that gene! Kye W,ory= at). “ie undefined otherwise. 3.11. Theorem A productive set contains an infinite re. subset. Proof. Let A be a productive set with productive function g. The idea is to enumerate without repetition an infinite set B= {Yq yin }8 A in the following way. 7 Recursive and recursively enumerable sets 138 (Q) Take ey such that W,,=0i since W,.0A, then g(e)JeA. Put yo= ale). (2) For n=0, suppose that yp... Yo have been given so that Worn Yel. Find an index ¢,+i such that (yun Yn} = We,AQA Then g(e,tiJ€A\ W.. thus ifwe put y,ti= g(¢,+) we bave y,Hi6 A and y,.i# YO, Yy (Se fig. 70) To’ see that this enumeration of yy, yin. i8 an effective one, we use lemma 3.10. From the above discussion, when looking for the index ei ‘we require that Ww We, Ayn) = We, Ee (en) -W (where kis the function given by lemma 3.10). Thus we may define e,+\ to bbe k(e,)\ then the sequence ey +i given by the recursion equations Co= some index for 0, eat = (40), and is hence computable, Now y, = g(¢,), 50 the sequence yy, yi. is also computable, Thus B = {¥yy Yio}, being the range of a computable function, is re, By construction, Bg and B is infinite. For the record, we state the obvious 3.12, Corollary IAs creative, then d contains an infinite re. subse. 3.13. Exercises 1, Show thatthe following sets are productive (@ (x: W, is finite), Fig. Te, Enumerating an infinite subset of (theorem 3.11). 3 Productive and creative sets 139 () (x:<, is not surjective}, (co) {x: (fx is injective}, {@) [x:<)), 38 nota polynomial function} Prove that the following sets are creative (@) (exeB,J, () (x: EL * D) (n fixed), (©) fe<1>, is not injective}, (@) {x d> fe A}, where Ais any non-empty re. st. (©) {x:0,(8)=x)}, where fis any total computable function, Prove that if B is re. and APB is productive, then 4 is productive Prove that if C is creative and A is an re, sot such that AnC=0, then CoA is creative. Prove that every productive set contains an infinite recursive subset For any sets A, B define the sets A 8 and AWB as in exercise 1L4(1). Suppose that B is 1. Show that (a) if is ereative, then so are AGB and AWB (provided B #0), (@) iB is recursive, then the implications in (a) reverse Let 88 set of unary computable functions, and suppose that 2 issuch that forall finite 4 g, 6¢ 2. Prove that the set (x: <>, @ is productive, (Hint, Follow the frst par of the proof ofthe Rice-Shapiro theorem.) Use the result of question 7 to show that the following sets are productive: (2) fx: (9) = 1} are effectively recursively inseparable. (int, Find a total computable funetion f such that if W, » W, 0, then 1 ifxGw, segues ifXGm, undefined otherwise.) 7 Recursive and recursively enumerable sets 140 Fig. ld. Effectively ecursvely inseparable sets (exercise 3.1309) () Suppose that 4, B are effectively recursively inseparable. Prove that if A, B ate both re, then they are both creative, (Note. Extending the idea of effectiveness to a pair of recursively inseparable sets in this way parallels the step from a non- recursive set to a set having productive complement; the coun- terpart to a single creative set is then a pair of effectively recursively inseparable sets that are both r2.) 4, Simple sets ‘Our task in this section is to show that there are sets satisfying the following definition and hence (in view of theorem 4.2 below) to establish ‘that not ll noz-recursive re. sets are creative. 4a. Definition Aset A is simple if (@) Aiste, (6) Aisinfinite, (©) A contains no infinite re. subset The idea in (b). (6) ofthis definition is t0 pinpoint some features of a set that are not possessed by any recursive or crcatve set. Thus, although as yet we have no examples of simple ses, we can easily see that 42, Theorem A simple set is neither recursive nor creative. 4 Simple sets 141 Proof. Suppose that 4 is a simple set. From (6) and (c) of the definition, 4 is not re., so 4 is not recursive, By theorem 3.11 and (c) of the definition, 4 is not creative. ‘The following construction of a simple set is due to Post 43. Theorem There isa simple set. Proof. We shall define a computable patial function f such that the range of ‘contains atleast one member from every infinite re. set. This is done by arranging that if 4>, is total and E, is infinite, then (xe £.. To sake Ran(’) simple we must at the same time ensure that Ran() is infinite, We shall sce that both conditions arc met by the function f defined informally as follows: To compute fis): compute <£,(0), ,(y + 1) unless and until ,(y) has been computed); stop if and only if number = is found such that <>,(2) > 2x; in that case put (x) =

,2). (Formally we have (x) =* 2%)), demonstrating clearly that fis computable.) Put 4 = Ran(); then dis re, We now verity that is simple. Suppose that B is any infinite re, set. Then there is @ fora! computable funetion ebh such that B = E,, Since B is infinite, the construction ensures that f(b is defined and fib, = B, Hence BZA. To see that is infinite, note that if x) is defined, then /(x)>2. Thus, for any n, the members of A that are in the set {0, 1,2, 21} are among (0,1). This means that 4 contains more’ than clements, for any n. Hence 4 is infinite ‘The construction of a simple st is but the first and one of the easiest of a wide variety of constructions that yield re. sets with all kinds of special properties. These are beyond the scope of this book; the interested reader should consulta text such as Rogers (1967), where he will find re. sets rejoicing in names such © hypersimple, hypethypersimple, pseudocrea- tive, and maximal. (See also exercise 4.4(3) below for an example of an +, set that is neither recursive, exative nor simple.) 44. Exercises 1. Suppose that 4 and B are simple sets, Show thatthe set AGB is simple. (For the definition of © see exercise 1.4(1).) 7 Recursive and recursive ly enutnerable sets 142 Suppose that fi total injective computable function sueh that Ran(/) is not recursive, (Exercise 2.18(7) showed that such funetions abound.) Show that the set A= fecByly >x andy) <*))} is simple. (Hint. To soe that dis infinite, assume the contrary and show that there would then be @ sequence of numbers yo< yi < Yasin. such that fiyo)> Ay)» f52)> + + + To see that A does not contain an infinite re. set B, suppose to the contrary that 8 ¢ A. Then show that the problem z € Ran(/) is decidable as follows. Given z, find neB such that ff) > z; now use the fact that n£A to devise a finite procedure for testing whether 2 G Ran().) Show that if 4 is simple, then A ® N is re, but neither recursive, creative nor simple (see exercise 3.13(6)) Let A, B be simple sets. Prove that AB is not simple but that ABB is simple, 8 Arithmetic and GédeFs incompleteness theorem The celebrated incompleteness theorem of Gédel [1931] is one of many results about formal arithmetic that involve an interplay between computability and logic. Although full proofs in this area are beyond the scope of this book, we are able to outline some of the arguments discovered by Gédel and others, We shall highlight particularly the part played by computability theory, which in many cases can be viewed as an application of the phenomenon of ereative and productive sets Tn §§ 1 and 2 we present some results about formal arithmetic that lead up to the full Gdel incompleteness theorem in § 3. In the final section the question of undecidability in formal arithmetic, already touched upon in § 1, is taken up again. Our presentation in this chapter does not assume any knowledge of formal logic 1, Formal arithmetic ‘The formalisation of arithmetic begins by specifying a formal logical language L that is adequate for making statements of ordinary arithmetic of the natural numbers. The language L has its own alphabet, which includes the symbols 0, 1, ~, x, = (having the obvious meanings), and also symbols for logical notions as follows: -i (‘not’), A (‘and’), v or"), -> (implies?) V (for al’), 3 (there exists") (In this chapter we will reserve the symbols V, 3 for use in L, and write the phrase ‘for all” and “there exists’ when needed in informal contexts.) In addition, has symbols x, y, Z.. for variables, and brackets ( and ), and there may be other symbols besides. ‘The statements (or formulas) of L are defined to be the meaningful finite sequences of symbols from the alphabet of L. For instance, the statement 3yQx(l+1) =x) is the formal counterpart of the informal statement ‘x is even’. Its helpful 8 Arithmetic and GidePs theorem 144 to abbreviate the expression I + I by 2, (1 + 1) + I by 3, and so on for all natural numbers. Then the false informal statement °S is even’ would be expressed formally in by the statement 3y(yx2=5), We can similarly express in L formal counterparts of many informal statements of ordinary arthmeti: for 'x >y" we would write SaCife=0) Aly +2=x) (The statement ~i(2 = 0) is offen abbreviated by z #0.) For ‘x is prime’ we ‘would write (x0) 4 (#1) A Vy Vaix=yxz-* (y= 1v2=1)) Let us denote by y the set of all possible meaningful statements of the language L. Then y divides into two important sets, namely {y= the set ofall statements that are true in the ‘ordinary arithmetic of N, ‘5° the set ofall statements that are false in the ordinary arithmetic of N. “Mathematicians would like to discover as much as possible about the set ATnatural question from the point of view of computability is (1. Dfa) Is & recursive, or even recursively enumerable? Another question, important for the mathematician and philosopher alike is (1. DG) Is there a simple-minded subset of7(a set of axioms) from Which al other statements in canbe proved? We shall discover that the answer to both of these questions is no. Question 1.1 (a) above can be made precise by means of a standard coding procedure. It is quite routine to specify an effective enumeration of the set y, without repetitions, using procedure similar to that used t0 enumerate programs in chapter 4, Let us assume that this has been done, and let us denote by 0, the (n + 1 )ih statement of Jin this enumeration, so that 00, 01, 8 ‘The effectiveness of this enumeration means that given m we can effectively find and write down the statement 0, and conversely, given ‘any statement a in y we can effectively compute the code number m such that 1 Formal arithmetic 145 This coding of statements is now used to code any set of statements X by the set of numbers X= fnO,eX) We sy that is: productive FX productive [crate [ Jesse se fe This gives the question 1.1 (a) above a precise meaning, ‘One of the Key results that makes computability an extremely useful tool when investigating formal arithmetic is the following, due to Gddel; ‘we present it without any proof, 12. Lemma Suppose that M (xi,..X,) is a decidable predicate. Then itis possible to construct a statement <1(Kij..,X,) of that isa formal counterpart of MéE\... i the following Sense: or ANY yay , CM M(diy +. dn) holds HF TCA, on JES. Consider now the creative set K. By theorem 7-2.4 there is a decidable predicate R(x, y) such that eK <= there isy such that R(x, Applying lemma 1.2 to the predicate R(s, y) let us fix on one particular formal counterpart of this predicate, which we denote by ag(x, y). Then for any ne M the statement Bytr(a.y) is a formal counterpart. for ‘neK\ and “iByo7%(a, y) is a formal counterpart of ‘nEK". Let us therefore write nek for 3y nkK niKey (by lemma 1.3). (aye T (by Jemma 1.4). So, since K is not re.» neither isT. In fact, by theorem 7-3.2 we see that T is productive. 16, Exercise Show that & is productive 2. Incompleteness ‘A simple version of GédeF's incompleteness theorem follows casily from theorem 1.5. We must first describe the setting of this famous result Consider the second question (1.1(6)) posed in § 1. This question is made precise by using the idea of a formal system. A formal system (X*) (for the language L) consists of a set sd.c y (the axioms) and an explicit Gefinition 6 the notion of a formal proof of a statement in y from these axioms, satisfying the conditions: Ql) (a) Proofs are finite objects (hence capable of being coded), (@) The explicit definition 2 of proof is such that if sd is recursive ‘then the relation ‘p is a proof of the statement a from the axioms sd” is decidable. ‘We can now interpret the question 1,1(6) as asking whether there is a formal system for L such that (22) a) sd is recursive (60 we are taking wide sense), (6) The provable statements are precisely those in J". 2 Incompleteness 147 “The condition (6) poses a problem for the philosopher who may be trying to define the very notion of arithmetic truth by means of a formal system. Fo" him, this condition is meaningless, and must be replaced by conditions reflecting some of the properties to be expected of truth, such (2.2)(b')Consistency: there is no statement a such that both a and “ier are provable, (2.2)(0")Completeness: for any statement , (6"). In other words, any consistent formal system of arithmetic having a recursive set of axioms is incomplete, This will be proved in § 3. We shall need the following lemma to establish the simplified Gadel theorem, 23. Lemma In any recursively axiomatised formal system the set of provable Statements is r. Proof. Letbe the set of statements in y that are provable, Since proofs are finite they can be effectively numbered; then if sd is a recursive set of axioms the predicate ‘Af(,)) sly is the number of a proof of 6, ftom the axioms sa" is decidable, by (2.1 >). Then 6, is provable <> there is y such that M(x, y) holds Hence, by theorem 7-2.4, is res Now we have 24, Theorem. (The simplified Godel incompleteness theorem) Suppose that (sd, 2) is a recursively axiomatised formal system in which all provable statements are true. Then there is a statement a that is true but not provable (and consequently ~iais not provable either). 8 Arithmetic and GodePs theorem 148 Proof By lemma 23, the set SPr of provable statements is re, and we are given that @5". Now ST is not re, (theorem 1.5) so we immediately. have astatement ae T\P»: icq is true but not provable. Clearly ~la is not provable either (otherwise ~icr would be true). (Using the productiveness of S* (theorem 1.5) we could strengthen this theorem to say that the statement a can be obtained effectively from a specification ofthe formal system (which would yield an index for) To aid an understanding of the proof of the full Godel theorem in § 3 it js useful to examine the inner workings that were hidden when we applied theorem 1.5 inthe above proof to obtain the statement a Let us say that a statement is refigable if its negation is provable. ‘Consider the sets of numbers Pr* and Ref given by P Ref In: 6 K is provable), {mene K isrefitable} (cit nf Kis provable} = {6 052M, (ouhere g isthe computable function given by lemma 1.4 and used in the proof of theorem 1.5). The assumption that provable statements are true ‘means in particular that Pr* ¢ K and Ref* ¢ K’ Now Ref* is r.e, (from the fact that ne Refter>*/,9e,and Were), so there is a number m such that Ret = By the productiveness of K we have immediately that mG J”\Ref*, ie, méK, and m £ K is not provable. Taking a to be the statement m € K. wwe thus see that a is true but not provable (and ntr is not provable, as befor). The argument i illustrated by fig. 8a, For comparison with the 3 GdePs incompleteness theorem 149 proof of the full Gédel theorem in the next section, note that the non-provability of mir can be seen as a consequence of the fact that p.*eK: for m£K (as above), so méPr*, ic. meKis not provable. ‘Then, by the rules of formal proof ~iméK (ic. —ict) is not provable.) Notice now the intended meaning of the statement a thus obtained: a is the formal counterpart of the statement m £ K, ic. mE W,, But we have mE RSD m eRe <=> mE Kis not provable <=> abi Thus a is a formal counterpart of the statement ‘a is not provable’; ie speaking rather loosely, a says ‘I am not provable’. This is reminiscent of the paradox of the liar, involving the informal statement A= "Tam lying’ Informal reasoning about 4 results inthe paradox A istrue iff isnot. If the same informal reasoning is applied to the informal statement ‘I am not provable’ the paradox is avoided by the conclusion that provable is not the same as true. This informal conclusion is rigorously justified by the proof of theorem 2.4, 3. GddeT’s incompleteness theorem We proceed in this seetion to show how the idea behind the proof ‘of theorem 2.4 ean be refined $0 as to avoid any reference to truth For the moment we fix on a particular formal system of arithmetic known as Peano arithmetic. The axioms for this system consist of a recursive subset of y known as Peano's axioms! these reflect the simple properties of the successor operation orivand the recursive definition of addition and multiplication in terms of it, together with an axiom scheme reflecting the principie of induction on N. The notion of a formal proof is taken as that defined for the firstorder predicate calculus, Full details of Peano arithmetic (sometimes called formal number theory) may be found in any textbook on mathematical logic. For our purposes, the important fact we need to know about Peano arithmetic is given by the following Jemma, to which a substantial part of GadePs proof is devoted, 31. Lemma Let, x,) be a decidable predicate, and leta(X\... %,) be the statement of L that is the formal counterpart of M(x\... X,) as 8 Arithmetic and GédePs theorem 150 given by lemma 1.2. Then M is represented in Peano arithmetic in the following sense: for any al... a,eN (@) if Ma, + *»«4) holds, then consistncy implies (by Iemma 3.3) that Prt ¢ K and honos Pr* = K. Thus, with weeansistency, ig. 8 is modified to bovome fig. S5. Thus m&K meas that mE Pry is 1m 6 K is not provable, The rules of the predicate caleulus tll us immediately that nt; (j,c. —im é K) is not provable, Notes I. The statement a produced by GadePs theorem is called an undeci- dable ot an undecided statement of Peano arithmetic, As discussed at the Fig. 8h, Gdel incompleteness (theorem 3.4(a) 8 Arithmetic and GddeP’ theorem 152 Fig. 8c. Godel incompleteness (theorem 3.4 (6). cend of § 2, a has the informal meaning ‘I am not provable’, and is, on an intuitive levei, rue. 2. Clearly GadePs theorem applies to any recursively axiometised formal system in which all decidable relations can be represented (in the sense of Jemma 3.1). In particular, this is true for any such system that is stronger than Peano arithmetic. In consequence, there is no way to avoid the incompleteness phenomenon by adding new axioms: for example a for —ier. The resulting formal system would have a new undecided statement. 3. Note that the undecided statement a can be constructed explicitly from a specification of Peano arithmetic, since from such a specification, ‘we could effectively find an index m for Ref*. This constructive aspect of GédePs theorem is a consequence of the fact that K is creative. An analysis of the proof would show that we can demonstrate the mere existence of an undecided statement using any non-recursive te. set A in place of K. 4, Although not entirely clear from our presentation, the proof of part (a) of GodePs theorem is a finitist proof: that is, it shows explicitly how, given a formal proof of the statement a, to construct a proof of ia (thus ‘demonstrating inconsistency). We cannot make the same remark about (@), beceuse to-consistency isnot a finitist notion. In 1936 J. B, Rosser saw how to eliminate the assumption of a>- consistency in part (b) of GadePs theorem, We shall now see that Rosscr’s refinement of GédePs method can be viewed as an application of the effective recursive inseparabilty of the re, sets K, = (<0 (9) = 0) and Kj = (x there is y such that Rx(n,y). Now clearly Kr (9) mG Ko <> there is y such that () Ryn, y) and (i) for all z) and (€) we have eK’ nko is provable; KicRer* Now Pr** and Ref** are both r.c. (this uses the fact thaf is re.) so the reourive inseparailty of K, and Ki (exercise 7-2.18(13/2) means th there is a number pé Pr** u Ret, The state of afi i ilstrated in i 8d. Now pé Pr** means that pe K, is nt provable, and pE Ref** means Fig. 84. Godel-Rosser incompleteness (theorem 3.7) 4 Undecidabiliy 155 that p & Ko is not provable, so the theorem is established, by taking 7 to be the statement pe K,, Although the proof of the theorem as stated is complete, let us now see how the mumper p (hence the statement r) can be explicitly constructed, From an explicit specification of Peano arithmetic, we can effectively find an index p such that 0 ifitePr*,

/0(,) = 0, ie, we used the function k to transform or reduce each instance of the general problem “x € W,"to an instance of the genetal problem *<£, = 0' In this chapter we consider two ways of making the idea of redueibility precise, and for each we discuss the associated notion of degree (of difficulty) that arises It is more convenient to deal with reducibility between sets rather than between problems, remembering, that any problem is represented by @ set ‘of numbers. The informal idea of a set 4 being reducible to a set B can be expressed in various ways: for instance (@) ‘Given a decision procedure for the problem *xGB’, we can construct one for °x e4’" (b) ‘For someone who knows all about B, there is a mechanical procedure (that uses his knowledge of B) for deciding questions about A.” (©) ‘Questions about A are no harder than questions about B.” (@) “The degree of difficulty of the problem ‘x G 4’ is no greater than that of the problem x GB." It turns out that there are several non-equivalent ways of making this idea precise, The differences between these consist in the manner and extent to which information about B is allowed to be used to settle questions about A. In §§ 1-3 we shall investigate one of the simplest notions of reducibility, called many-one reducibility, which includes all of ‘our earlier uses of the informal idea. Inthe final sections we shall discuss a ‘more general notion known as Turing reduetbility 9 Reducibility and degrees 158 1. Many-one reducibility 1. Definition ‘The set d is many-one reducible (abbreviated m-reducible) to the set B if there is @ total computable function fsuch that for all x HA MT ffeeB. We shall write this A-<,B1 and we shall write f: 4<,B to indicate that f is a total computable function demonstrating that 4 <,, B. Note. The phrase many-one is used to distinguish this kind of reducibility from a related notion called one-one reducibility, for which the function f is required to be injective. We have used m-reduciblity implicitly on many occasions in earlier chapters. The s-m-n theorem is often needed to establish many-one bility, as we see in the following examples. 12. Examples 1. Im chapter VI we showed that Kis m-reducible to each of the following sets (a) (X:<£, =O} (theorem 6-1.4, quoted above), () (x ceW,} (theorem 6-1.6). 2. If we examine the function k given in the proof of theorem 6-1.6 We se thatx K <=> i total. Hence IK , is total} fx: , = 0). Proof. Using the s-mn theorem obtain a total computable function k such that <£,,.,~ 0%", for allx. Then ke { , = 0} ‘The following theorem gives some of the elementary proper- ties of m-redueibility 13. Theorem Let A,B, Ce ses. (a) &y is reflexive (ie. A- g(xleB; hence xedG gtx)e Brhence gA<,B. (©) Suppose that g:B i(x) GM. Then clearly A= 10. (Gin dual 19: A Ne, A , is total}, (x:

, isnot total} is m-reducible 0K Proof. Feom corollary 7-2.17 neither ofthese sets is re; apply theorem 1.30). 9 Reduciblity and degrees 160 ‘The exceptional behaviour of the sets 0, N as given in theorem 1.3(@), (Oe (@) is PF Ihe Pike yew bE Pl Pr simplicity of the notion of m-reducibilty. Another rather unsatisfactory feature is that the sots 4 and 4 are not necessarily inter-reducible (contrary to the intuition that the problems ‘xed’ and 'x£4" should be equally difficult), as we 15. Corollary If A is an re. set that is not recursive, then AA and.AY A. Proof. By theorem 1.3(@) if 4 <, 4, then 4 is re., a contradiction, For A wse.tleorem 1.36) ‘The next result shows again the key role played by the re, set K. 16. Theorem Aset isre. ifand only fA %(K. Proof. If A=théi theorem 1.3(¢) ‘ells us that A is re, Conversely let d be any 1. set. Define a computable function /(x, y) by “il ifxca, ») undefined ifkéA. ‘The smn theorem gives a total computable function 5(s) such that fbs, y) = s(aJeK. Le ASK. ‘This theorem may be interpreted as saying that the problem "x G TC is the most difficult patially decidable problem. 17. Exercises 1. Show that Kis m-reducible to each of the following sets: (a) (x9) 0}, ) bxxeE 2, Show that for any sets 4, B, if B O then A <,AWB. (Recall that ABB = {Tr(fl,b): ae A, be B},) 3. Show that (@) (x:d>x~0}<9{x:, = 0 , PROM L gy i total For any set 4, the equivalence class of A under the relation =, is the class of sets d,(A) given by dn(A) ={B:A ‘This can be thought of as the class of all those sets having the same degree 9 Reducibility and degrees 162 of difficulty (with respect to <,) as the set Al hence d(A) is called the medegree of A 24. Definition ‘An mdegree is an equivalence class of sets under the relation ‘sys ke. it is any class of sets of the form d, (A) for some set. It is conventional to use lower case bold face letters such as a, b, ¢ to denote degrees! It is worth making a strong mental note that although Tower case letters are used, these are sets of sets, Thus it is meaningful to write dea, where a is a degree and A is a set, although at first this may appear a litle odd, ‘The relation <,, on sets induces a partial ordering (see Prologue § 3 for definition) on m-legrees, also denoted <,., as follows 28. Definition Leta, b be m-dogrees. (a) abit there are A e a and Beb such that A <,B, @) a<,bifabatad b. Note. It is immediate from the definition of-that a ) fiom theorem 1.3(0). (@)\ (<2) from theorem 1.3(@); (@ Som theorem 1.3(€); (6) rom theorem 1.3(0); (0) from theorem 1.6 ‘Theorem 2.7 gives us a picture of the m-legrees as shown in fig. 9a. (In this diagram, we position a degree a below a degree b to indicate that a "b,) We shall see later (as this picture suggests) that there are re. ‘m-degrees other than @,, and 0™, ‘The structure of the collection of m-degrees under their partial order- ing has been studied extensively. The following theorem means that this structure is what is known as an upper semi-lattice. Fig, 9a, The m-degrees. \ all madegrees XO othe than | 0.8, 0,0) 9 Reducibility and degrees 164 28 ‘Theorem “Any pair of m-degrees a, b have & least upper bound: ie, there isan imedegree e such that () aye and bexe (© ix am upper bound), (ec 2x GC, $0.4 2x +166, 9 B,C Ths, putting ¢= dg(C) we have that cis an upper bound of a,b Suppose now that d is an m-degree such that a-<, d and =bsd Choose a set D ed, and suppose that /: A <, D and g: BS, D. Then we have 2G C (is even & |x GA) or (x is odd & |(x - 1)G B) O (xis even&/(IxjGDJor (x is odd & gi|(x-bGD) ‘Thus we have h: C,D if we define h by (a) ={itbD fxs even, | edo — Dp ifx is odd. Hencee<,,0)= 0), (d) fexek Ss trercise 1.70) ‘The reader may have realised that m-reducibility appeared implicitly in the statement of theorem 7-3.2, which implies immediately that 34. Theorem Any m-complete set is creative Proof. fA is m-complete, then K <,, A, so K-<,A, and by Theorem 7232 4 is productive. It is very pleasing to find that the converse of this theorem is also true, giving us a precise characterisation of m-complete sets 3.5. Theorem (Mybill) Creative sets are m-complete We must wait until chapter 11 for a new tool - the Second Recursion ‘theorem -with which to prove this result. Note, however, that we have already established it for creative sets of indices in example 3.3(6). 'As an immediate corollary to theorem 3.4 we can use simple sets to show that 0,, and O™ are not the only r.e, degrees: 3.6. Corollary (to theorem 3.4) Simple sets are not m-complete: hence ifa is the m-degree of any simple set, then Op, 1. The instruction O(n) is called an oracle instruction To be able to obey oracle instructions the URMO must be linked to an oracle, which supplies values of some given function x on demand. We say then that the URMO has the function x in its oracle, The fumetion x is not ‘thought of as part of the URMO itself, The response of the URMO to an oracle instruction O(n) is as follows: ifx is in the oracle, then replace r, (the contents of register R,) by x(«)- 9 Reducibitity and degrees 168 ‘This is denoted in flow diagrams by '=x¢rn) oF 2(7,)">Rn ‘The URMO, with x in * oracle and obeying the instruction O(n) may bbe envisaged as shown in fig. 9 ‘A program is, as before, a finite sequence of instructions. The URMO ‘operates under a URMO program P in the same way as the URM, with the following additional stipulation: after obeying an oracle instruction /& in P the next instruction is J,+1 We emphasise that in a URMO program P no particular function x is ‘mentioned. Thus the meaning of P varies according to the function supplied in the oracle. However, @ computation under P can be carried cout only when a particular function x is supplied, so we write P* to denote the program P when used with the function x in the oracle. Thus we write Pain. 5 a) for the computation by P, with x in the oracle, and with initial configura- tioM ai, dap dy 0, 0,5 and we write oe to mean that the computation P*(a) stops with the number b in register Ri We can now make the following definitions (parallel with definition 13.1). Fig. 9. ® RR, R ‘With sling configuration TO fel 4 Relative computability 169 42. Definition Let.x be a unaty total function, and suppose that fis a partial function from ti, (@) Let P be a URMO program. Then P URMO-computes f relative tox (or fis x-“°"pud by P) if, for every ae and N beIMy Pe(ajlb itt fla) — 6, @®) The function f is URMO-computable relative to x (or just X-computable) if there is a URMO program that URMO- ‘computes it relative to x- We write tédenote the class ofall x-computable functions. ‘We are now in a position where we could define Turing,reducibility. However, to aid a better understanding of this concept when we come to it, we shall first outline a little ofthe development ofthe theory of relative computability Most methods and results from unrelativised computability have ‘counterparts in relative computability. Thus in many of the theorems that follow we supply only a sketch proof or a reference to the unrelativised version of the same result. Throughout this section x stands for a total unary function. 43. Theorem @ xee ® se (©) fXis computable, then % = %6\ (@) © is closed under substitution, recursion and minimalisation, (©) ifs a total unary function that is x-computable, then et gc Proof. (a) Use the URMO program 0(1). (b) Any URM program is a URMO program. (©) In view of (B), we need only showéthat® Suppose that/ is x-computable and that x is computable, Proceeding informally, we can compute any value of / as follows: use the X-algorithm for /, and whenever a value of x is requested simply compute it using the algorithm for x- This is an effective pro- cedure, so by Church’s thesis / is computable. (We leave the reader to provide @ formal proof of this result; see exercise 4.10(3).) 9 Redweibility and degrees 170 (@) The proofs are identical to those of theorems 2-3.1, 2-4.4 and 2-5.2 (©) The proof is similar to that for (c) (which is really a special cease of ()). Other approaches to relativised computability Any alternative approach to computability can be modified to provide a corresponding notion of relative computability. A relativised version of the Fundamen- tal result (theorem 3-1.1) can then be proved, and this leads to the formulation of Church’s thesis for relativised computability We mention here only the relativised notion of partial recursive function: 44. Definition The class 3! of x-partial recursive functions is the smallest class (@) the basic fumetions arein 2" ) xR (©) 1%" is closed under substitution, recursion and minimalisa- tion. ‘The phrases partial recwrsive in x or partial recursive relative to x are also used with the same meaning as x-partial recursive. ‘The notions x-recursive (or recursive in, or relative fo,x) and y-primitive recursive (ot primitive recursive in, ot relative (x) are defined in the obvious way. Corresponding to theorem 3-2.2 (and proved in the same way) we have 43. Theorem For any x, < = <2 Numbering programs and functions URMO programs can be effectively numbered or coded by an casy adaptation of the method used in chapter 4 for URM programs. Let us assume that this has been done, s0 that we have a fixed effective enumeration (without repetitions) 00, Qin, 445 of all URMO programs.’ Then we write (12m for the n-ary function *-computed by Qy ach URM program P appears inthis Hist; in most cases, however, is umber here wll be diffrent fon that estigned to it in chapter 4 4 Relative computability m m for <2. Ws, for Dom(1 there is a total computable (m ~ \)-ary function six) such that for any x OP =O enly Note. The function s,here differs, of course, from the function given the same name in theorem 4-4.3, Note, however, that s™ here is. still ‘computable (not merely x-computable) and does not depend on x- Universal programs for relative computability Relativisation of the proof of theorem 5-1.2 gives immediately 41. Theorem For each nthe universal functde"for mary x-computable functions given by Wex)mderts) is x-computable. Remark. A careful examination of the full formal proof of theorem 5-1.2 would show that there is a URMO program Qi\ independent of x, that X-computes (Ati for any x- Xrecursive and x-re. sets The relativised notions of recursive and re. sets are given by: 48. Definition Let d bea set (a) Aisx-recursive (or recursive in) if e, is ;w-computable, (6) Aisx~ (ore. inx) if the partial characteristic function Moat ikea, undefined ifxEA, is x-computable. 9 Reducibilty and degrees Im ‘The following selection of basic results about *-recursive and ;l-re. sets is proved by the addition of the prefix x~ * Ihe appropriate places in the proofs ofthe corresponding unrelativised results in chapter 7; 49. Theorem (@) Forany set A,A isx-recursve fA and d are =" () For any set A, the folowing are equivalent (i) Aisx, (i) A= Whyfor some m, Gi) A= B% for some m, (iv) A= 0 or isthe range ofa total computable function, (9) for some xdecidable predicate R (x3). ayRisy) (Ris x-decidabe fits characteristic function is x-computable). (c) Let K*= {x:x © W?}; then K* is X""-e. but not x-recursive. xed Computability relative to a set For any set 4, we define computability relative to A (or just A-computability) to mean computsbility relative to q the characteristic function of 4, Thus we write P* for Po* (if Pisa URMO programm), * is total. Is #5e necessarily total? ‘Suppose that xi Xz, + + *» Xk are total unary functions. Define 421426 to be the smallest class of functions containing the basic functions and Xi + + *, Xt» and closed under substitutions, recursion and minimalisation. Formulate a definition ofthe set © of functions computable relative to xin + + +» Xk such that 0k=47°**%, Hint, Either define a machine having k ‘oracles, or find a single unary function x "that av any Provide a full formal proof of theorem 4.3(¢): if x is compu- table, then @ = 6° Show that there is a total computable function & (independent of | 2) such that Wao) = IVI, for all indices a,b. Verify theorem 4.9. . Let A be any set, (a) Show that for any re, set B, there is an index e such that B= Ws, () Show that i Ais recursive, then Wis ce. forall e, (© Show that if 4 is recursive, then K* is re. but not Let A, B,C, be sets. Prove that (@ if A is Barcoursive and B is Creoursive, then is C (b) ifs Bore, and B is C-reeursve, then Ais C-re., (©) if A is Baccursive and B is C-re, then A is not necessarily Cre. (Relativisation of theorem 1.6.) Let A be any set. Show that for any setB, Bis Are, <> B<,KA ‘Show that there is a single number d such that KA = fab/all sets A. (@) We say that a set A is X'Simple if () A is Xa (o) infinite, (iii) A contains no infinite X'*- subset. Show that there isaxsimple set (b) Formulate the definition of a x-creative set. Show that a X-simple sot s not creative. 9 Reducibility and degrees 14 5, Turing reducibility and Turing degrees Using relative computability we make the following definitions: SA. Definitions (a) The set 4 is Turing reducible (or just T-redueible) to the set B if A is B-recursive (equivalently, if c, is B-computable). This is writen 4°B. (6) The sets A, B are Turing equivalem (or T-equivalen) it A and B <;A~ (The use of the word equivalent is justified i theorem 5.2(6) below.) We write this A =,B- Let us consider informally the meaning of Turing redueibility. Suppose that A 6856" (by theorem 4.308), (2) and hence SO Uh= 98 5 Turing reducibility and Turing degrees 15 (©) Suppose that f4<,B, and let P be a URM program in standard form that computes £ Then the URMO program P, O(1)is easly seen to B-eompute (@ Since Gj=58° cy dis A-recursive (by substitution); hence AmdA<,4 similaly (©) By theorem 4.366) () By theorem 4.3(c). (g) By (€) above and theorem 1.6 Remarks 1, From (@), (0), () of this theorem we soc that T-reducibility docs not have the defects of m-reducibility; this also shows us that these two notions are distinct. 2. Part (g) of the above theorem shows that K is a T-complete (r..) set, according to the following definition: 53. Definition A set 4 is T-complete if is 10, and B <,A for every 12. set B, ‘The name Turing degree is given to any equivalence class of sets under the relation =: again, we think of a degree as a collection of sets all having the same degree of difficuly. 54, Definitions (a) Let A be a set; the equivalence class 4y(A) = (B:BA} is called the Turing degree of A, abbreviated the T:degre of A © Any Tegree containing a recursive st is called a recursive Tedegree (6) Any T-degree containing an re, sti called an re. Tdegree. ‘The notions of Turing reducibility and Turing degree are widely accepted as the most basic among all other similar notions. Hence the term reducible without qualification is often used to mean Turing reducible; similarly, Turing degrees are often referred to merely as degrees, or degrees of unsolvability. We shall adopt this practice in the remainder of our chapter. As before, the letters a, b. ¢, ete. are used for degrees. ‘The relation <, on sets induces a partial ordering on degrees, as with <3 9 Reducibility and degrees 176 55, Definition Leta, bbe degrees (a) ab if for some (equivalently, for all) 4 G a and Beb, ANB: (0) a) IFAs recursive then Ke (© 46K (@) (IAB thenk*<,K, (i) if 4=1B then Ke =r, 6 Proof. (@ (i is given by theorem 4.9(¢); for (i), 2 straightforward relativisation of theorem 1.6 (using the relativised s-m-n theorem) shows that if B is A-r.. then B <,KA. (®) Clearly K <,K4, since K is Acre, for any 4 | on the other hand, if 4 is recursive then the A-computable partial charac- leristic function of K 4 is actually computable (theorem 4.3(c)); hence K¢ is .¢. Thus K! )), Hence K* ) of the above theorem). This leads to the following definition of the jump operator on degrees. 58. Definition For any degree a, the jump of a, denoted a’, is the degree of K* for any dea. Remarks 1, Theorem 5.7(d) tells us that this is @ valid definition because the degree of K4 is the same for every Aea. 2. By theorem $.7(8) the new definition of 0” here as the jump of 0 accords with our earlier definition of "as the degree of K (theorem 5.5). We can immediately write down the basic properties of the jump operator: 59. Theorem For any degrees a, b 9 Reducibility and degrees 178 (a) axa, (0) ifaxb then ab ©) 0 (@) if B eb, dea and Bis A-re,, then b x andfly) 0, there is an re, degree b such that b | a 5.15. Sacks' Density theorem For any re. degrees a0 there are re. degrees B, © such that b 0 such that there is no degree a with O Oy there is an re. mdegree b such that bhp Proof. Let Ae a’, A is re, so by theorem 5.14 take an re, T-degree uch that d,(A)Je. Let B be an re, set in c, and let b =d,(B). Then if a<,b of bya, by theorem 5.6(c) we have dy(A}sc or e2, then fly:K" <2 (Hint, Find ‘otal computable functions g, ft such that (i) if dP then K= Wi) "yy WE «SK, foralle) For any set A define a Sequence of sets A® by AOma, ATL KAM, and let AM® = ffm, n).-m eB). (@ Show that a Show that A!” 1) the class of all partial functions from 1%4T to M, We use the word aperator to describe afunction 0: | F.->tie letters 0, 0,.. will invariably denote operators in this chapter. We shall confine our atention to totally defined operators 0: Ft & Nive, such that the domain of 0 is the whole of &, The chief problem when trying to formulate the idea of a computable (or effective) operator 0: F, + F;, say, is that both an “input” function f tnd the ‘output’ function 0(/) are likely to be infinite objects, and hence incapable of being given in a finite time. Yet our intuition about effective processes is that in some sense they should be completed within a finite time. To see how this problem can be overcome, consider the following operators from SF\t0 91 1 Recursive opera tors 183 (0,00 =2.. (©) P2() = g, whereg(x) = E,/(9). These operators are certainly down to carth and explicit. Intuitively we might regard them as effective operators: but why? Let /e'i and let gi = #(); notice that any particular value gi(x) (if defined) can be calculated in finite time from the single value (x) of /; if we set g2~ #2), then to calculate 42(x) (if defined) we need to know the finite number of values (O(n (8). Thus in both cases any defined value of the output function (<£>i (/) or 0,(/)) can be effectively calculated in a finite time using only a finite part of the input function f This is «essentially the definition ofa recursive operator given below. One consequence of the definition will be the following: suppose that ‘#()(x) = y is calculated using only a finite part 0 of f; thon if g is any ‘other funetion having 0 as a finite part we must expect that 0(@)(X) = » also. To frame our definition precisely there are some technical considera- tions. First, let us agree that by a “finite part’ of a function f we mean & finite function 0 extended by f (We say that 0 is a finite function if its domain is a finite sct.) For convenience we adopt the convention O always denotes a finite function in this chapter. ‘The above disuston shows that the definition of recursive operator wil involve effective calelations with finite functions. We make this precise by coding each finite fetion 0 by a number 5 and using ordnry Compulabiliy, A suible coding for our purposes is defined as follows suppose that 0 € dy, The H-uple x= (ken) i coded by the number (a) -PP*tPZ"., ps then define the coded for dby 8 bi! Provided Har Domo) # 0, b=0 iDom(0)-0 (inwhich case 0 =f) ‘There is a simple effective procedure to decide for any number z whether 2 = D for some finite function 0\ and if so, to decide whether a given x bbelongs to Dom(0), and calculate 0/x) if it does Now we have our definition: Ll. Definition Let ‘computable function d> + Fa. Then 0 is a recursive operator if there is @ s) such that forall fE, and XGN", yeN 10 Effective operations on partial functions 184 b> (9 (0'y iff there is finite Og/such that > (0,x) —y. (Note that 6 is nét required to be total.) 12. Bvanple The operator 0(/) = 2/ is a recursive operator: to see this define diby (200) if'z= dind x 6 Dom), dlax undefined otherwise ‘By Church's thesis, <> is computable: now for any /, x,y we have (0) y <> x G Dom(/) and y = 2x) O there is 0 ¢ f with x G Dom(0) and y = 20(x) <=> there is Oc/such that <£(0,) Hence <£> is a recursive operator. Further examples will be given in 1.6 below. ‘An important feature of recursive operators is that they are continuous ‘and monotone in the following sense, 13. Definition LetO: Fae an operator (@) 0 i8 continuous if for any ifand all x, » O(){x) = i there is inte 0 OF with (036) — (©) 0 is monotone if whenever |, g%, with fp, then pe) ‘These properties are easily established for recursive operators, and as ‘we shall see they aid the recognition of such operators, 14, Theorem A recursive operator is continuous and monotone. Proof Let Org, be a recursive operator, with computable function d as equized by the definition. Suppose that 0()(x) =* y, and let O0f such that ( (0x) — y. Since 000, it follows immediately that O(0)(x) =* y. Conversely, if 0 ¢ f and 0(0)(x) —y, there is 0| Q 0 such that <£(biax)-y; but then Oi<% so we have that O(\x) —y. Hence 0 is continuous, Monotonicity follows directly fiom continuity: suppose that Pg and O(N) —y. Take O<'f such that 00) ~—y; then O's, so. by continuity, 0(8)x) =. 1 Recursive operators 185 The use of the term continuous to describe the property 1.3(@) is justified informally as follows. Suppose that :F,-» F% satisfies 1.3(8) and fe MI. Then given any xiy. x, for which O()(x) (I (g) is ‘near’ to 0(/) Gin the sense that they agree on the finite set Xi, ...%)- Thus, informally,

()(x) is deter mined (if at all) by a finite amount of positive information about This smeans information asserting that f is defined at certain points and takes certain values there, as opposed to negative information that would indicate points where fis not defined. Using ths idea the term continuous can be rigorously justified as follows. The positive information topologs' onvis defined by taking as base of ‘open neighbourhoods sets ofthe form U, “69 (We By it) Thus fbelongs to U, iff 0 is comect postive information about fis then an easy exercise to see that an operator is continuous with respect tothe positive information topology precisely when it possesses property 13@) The following characterisation of recursive operators using, continuity will make it easy to establish recursiveness of various operators. 15. Theorem Let Bean operator, Then

( x) is undefined for al others, ts compuable Proof. Suppose that

(Oay’y <=> 30 £0 and 010,%) —y); the relation on the right is parially decidable, o 0 is computable by theorem 66.13, Conversely, suppose that conditions (a) and (4) ofthe theorem hold: then Hijet) =" y 3040 gland (0)x) —y) by (a)) <=> 30(0 g/ and 0(0, x) = y) (by (5), whence 0 is @ recursive operator. ‘This theorem enables us o show quit easily thatthe following ‘operators are all recursive: 16, Examples (a) (Tre diagonalisation operator) OUI, 0) UO), is obviously continuous, and 0(0, x) —0(x, x) is computable. 0)

By (x + LOX, O()x4-1, y ADV, Mx 1, yD). To see that

) includes the function that is defined nowhere includes the “undefined constant, which is denoted by w. Thus > NU(e}, and an operator (pdm Fa a recursive functional if there is a computable function <£0) such that fr any fe andy. 00) =y iff 20(0 and= f o(8)~y). We write <>() = w if <£>() is undefined; this emphasises that <2> is stil thought of as being a total operator. ‘We should point out that in some texts the term partial recursive {factional 3%, -> &, i used to describe recursive operators, including the case n= O. In such contexts the word partial describes the kind of object being operated on rather than the domain of definition ofthe operation ‘We shall not discuss here the extension of the ideas of this section to partially defined operators and the corresponding partial recursive opera- tors 0: FF. Te reader is referred to Rogers [1967] for a fll discussion of these and related mates Exercises 1. Show thatthe following operators are recursive. @) O/=P (feFs @) Fyor bY (o ity) =, Otay |G + Ly) +1 if AG, y) is defined and #0, (IG 3%), where g is a fixed computable function in ‘undefined otherwise (The significance of this operator will be seen later) 2. Prove that if @ is a recursive operator and fis computable then so is 01). 3. Decide whether the following operators O:F,>F, are) ‘monotonic, (i) continuous, (ii) recursive. (Kn if Domi) is finite, (undefined if Dom() is infinite, 10 Effective operations on partia! functions 188 if fx) is defined, vy (ldddnca cxberwise {oitpek = 1 iLfeeK undefined otherwise. ZN Iw x (undefined if Dom() is finite, UVa) if Dom(/) is infinite. Suppose that OF, >F, and Wi, >, ate recursive opera: tors. Prove that WW: F,,-» 5, is recursive. Show how to extend the definition of recusive operator to include operators 0: Ay Fak Xu AR, Py and prove appropriate versions of theorems 1.4 and 1.5 for your definition Prove that the following operators ate recursive @) Paixe, +d, given by Ol, g) = Me (ef question le above); 0) ©! Fp. Fur Foor given by | it fx) is defined, {o IFAC y) = 0, &, and -#Szbe continuous operators; prove that Ved: FF, is continuous. Let 12QN) denote the class ofall subsets of formulattis Uefinition of a recursive operator 4>: 0*(N)-> a”(N) are called enumeration ‘operators and are discussed in full in Rogers (1967}.) 2 Effective opera tions on computable functions 189 2. Effective operations on computable functions In chapter 5 § 3 we considered that certain operations on computable functions should be called effective because they can be given by total computable functions acting on indices. For instance, in example 5-3.1(2) we saw that there is a total computable function g such that for all ecfod, (d> J? =

us<. We shall “see in this section that any recursive operator 0, wher restricted 1o computable functions, yields an effective operation of this kkind on indices. This is the first part of a theorem of Myhill and Shepherdson. They proved, moreover, that all such operations on indices of computable functions arise in this way. We shall prove the two parts of the Myhill-Shepherdson result separately, taking the easier part first. 2.1. Theorem (Myhill-Shepherdson, part I) Suppose that VF,» F, is a recursive operator. Then there is a total computable function h such that vie! (ay, Proof. Let be a computable function showing that V7 is a recursive ‘operator according to definition 1.1. Then for any e we have AERA) = y 300!" andt(Xi) is defined and equals y,, then (3) compute i, x) and if defined check whether it equals y IFR (z,€, x,y) holds, this is a mechanical procedure that will tll us so in finite time, as required. 10 Effective operations on partial functions 190 Since R/€ X, y) is partially decidable, so is the relation 3 R(z, x, y) by theorem 6-6.5): but BA Rfa,€, % y) <=> NYMR) —y (Krom the definition of R) <> gle, x) = (fiom the definition of g) ‘Thus g/e, x) — y is partially decidable, so by theorem 6-6.13 g is comput- able, Now the s-m-n theorem provides a total computable function jt such that oy KLE) YR) from which we have 2, = Wid!” Notice that the function # given by this theorem for a recursive ‘operator VF) >; is extensional in te following sense. 22. Definition A total function then , = <1>b ‘Now we can state the other half of Myhill and Shepherdson’s result, 23, Theorem (MyhillShepherdson, part I) Suppose that h is an extensional total computable function. Then there is «unique recursive operator tf such that V9) = efit) forall Proof. At the heart of our proof lies an application of the Rice-Shapiro theorem (theorem 7-21). Leth be an extensional total computable function. Then defies an operator Vy: @ > € by Yolbe)= dn "0 is well defined since h is extensional. We have to show that thete is unique recursive operator: F, » F that extends “y- First note that “0(0) is defined forall finite 3, since finite functions are computable. Thus any recursive operator V7 extendiig, being continuous, must be defined by 24) N(R ¥= 3000 ¢ and * (KR). So such aMif it exists, is unique. To prove the theorem we must now show that © (24) does define an operator, Gi) V’ extends “o» 2 Effective operations on computable functions 191 (il) Wis recursive. We first use the Rice-Shapiro theorem to show théf'is continuous in the following sense: for computable functions f 25) AoldNx) = y <> 30(O5/and *(ONH)-y). To see this, fix x,y andlet= {16 of 2 40N(8) =y). Then the set A= fe: (Pe£ d) = fet.0\X)=y} is rs so by the Riee-Shapito theorem, itis computable then fob & 30(0 gland Derp, hich is precisely (2.5), [Now we establish (i, (i, (ili) above (@ Let f be any partial function; we must show that for any x, (2.4) defines V(x) uniquely (if at all). Suppose then that 0i,0,¢/ and Yo(Gi)(x)— yi and %0(0,)65) = ya. Take a finite fumction 0 2 i, 0, (say, 0 =[Dom(0iju Dom(0,)); by (2.5) vie Wro(Oi)x) = V5(0)) ="0(0,)190 = yp Thus (2.4) defines an operator untbiguously. (i) This is immediate from (2.5) and the definition 2.4). (ii) We show that stisfes the conditions of theorem 1.5. Clearly is continuous, from the definition. For the other condition we must show that the Funetion tA given by (e)- Thus AU.) WX) = F,; knowing that 0° W is continuous (exercise 1.7(7)) use the two parts of the MyhillShepherdson theorem together with the first remark above to show that 0" Vis recursive 2. State and prove a general version of theorem 2.3 for operators from, & 3. Formulate and prove versions of the Myhill-Shepherdson theorem (both parts) appropriate for the operators you have defined (a) in exercise 1.15), (b) in exercise 1.7(8). 3. The first Recursion theorem ‘The first Recursion theorem of Kleene is a fixed point theorem for recursive operators, and is often referred to as the Fixed point ‘theorem (of recursion theory). We sball see later that it is a very useful result 3.1. The first Recursion theorem (Kleene) Suppose that D: Fq. Fn is a recursive operator. Then there is a ‘computable function f=p that is the leas fixed point of

(g) = g, then fipQe. Hence, iff is total, its the only fed point of #> Proof We use the continuity and monotonicity of (p to construct the least fixed point /it as follows. Define a sequence of functions {f,) (m 6 M) by fo =o (the function with empty domain), Mi= <0), Then fo = JOV5; and if feu by monotonicity we have that f+ = (fn)-f2- Hence f,Ofnt fr al n Now let r= UA, by which we mean ‘Fet>(s-9iT Bo such a ‘We shall show that/is a fixed point for 0. Forall n, fn'feP 3 The first Recursion theorem 193 hence Asi (oy 0, tus ecto() Conversely, suppose that (P(M(s) =; then there is finite 0<"f

isthe least fixed point of 0, suppose that Og) ~ a; then clearly fo fog, and by induction we see that. fr all n. Hence i<*> ( g, as required. Moreover, if / is total, then sp = g,s0 fis the only fixed point of 0. Finally we show that /# is computable. Use theorem 2.1 to obtain a total computable funetion fk such that for alle 16.) =o Lote, be an index for /: define & computable function &by *O=6, feln+ DAI), ‘Then f, = fe each n thus Mary <=> 306. NH") ‘The relation on the right hand side is partially decidable, and hence / is computable. Remark. The recursiveness of the operator P was used in this proof only in showing that

(x + 1) = undefined. {f0=1, Vaet)=a, ‘Then the least fixed point is Other fixed points of 0 take the form 10 Effective operations on partial functions 194 2 Recall the definition of the Ackermann function’ in example 255 Oy=yel, + 1.0) thea! is « computable function satisfying these equations, so we have only to show thas total Clearly, isa computable funtion satisfying folx, y)=4 folx+1,y)+1_ if h(x, y) is defined and not 0, lundefined otherwise. But what is this rather strange looking function? We can quite easily check that fex>(x, y)=* Haz (A (x 4-2, 9) = 0) as follows. First suppose that p.zviixd-z, y) = 0) rm; then ‘h(x, y) is defined and not 0 for all z (x, yJ=Me +1, y) #1 =. ple + ay) > 2 @ (x, y) = zn; then from the equations this must be because (x, RAP +L yh = = /8(0-+m, y) +m and h (x + 2, y) is defined and not 0 for 2 < mi; then /*(x +m, y 0, s0-h (x-+m, y) =O. Thus m = pz(hi(r 4 z, y)=0). We can infer fiom this example that the function /*(0y) — -Poli(z, 9) = 0) is computable; of couse, there is no use pretending that Wwe have a new and clever proof of the closure 6f under the “operator, since we have used this property of implicitly in our proof ofthe frst 53 The frst Recursion theorem 19s Recursion theorem. (In Kleene's equation caleulus approach (see chapter 3 § 1), however, the first Recursion theorem is proved without the use of the “operator, so closure under the /x-operator is established by this example.) ‘We can see from the above examples why the first Recursion theorem is, so called, The general idea of recursion is that of defining a function ‘in terms of itselfA simple instance of this is primitive recursion, discussed in chapter 2. We have seen more general forms of recursion in the definitions of Ackerman's function, and the function fS> in example 3.2(3) above, We were able to see quite easily in chapter 2 that primitive recursive definitions are meaningful, but with more complex recursive definitions this is not so obvious; conceivably there are no functions satisfying the proposed definition, This is where the first Recursion theorem comes in, Very general kinds of definition by recursion are represented by an ‘equation of the form G3) 0 where 0 is a recursive operator. The first Recursion theorem shows that such a definition is meaningful; there is even a computable function satisfying it, Since in mathematics we require that definitions define things uniquely, we can say that the recursive definition (3.3) defines the least fixed point of the operator 0. Thus, according to the first Recursion theorem, the class of computable functions is closed under a very general form of definition by recursion, 3.4 Brercises 1. Find the least fixed point ofthe following operators: @ ON=f (feF . 0 itx=0, (eH) POO) = Vox sete ifx>0; ifx-0, OED" Veyigyy if 2. (MeCarthy) Show that the function m(x) given by a io fx < 100, x= 10 otherwise, is the only fixed point of the recursive operator 0 given by Ailx+ 1) ifx FG the sense you have defined in exercise 1.7(5). Show that there is a least pair of functions /,g such that ) ea) and /, gare computable, 4. Suppose that &, be the operator given by 0,(/)= 0, Show that the operator V¥(g) = least fixed point of 0, (43) fle) (We are assuming that in Z we can formulate conditional expressions such as this) Using the equation (4.3) we ean formally evaluate the value /2), for instance, a follows i(3) —2x/(2) —2x2x/(1) = 2x2x2x/(0) —8; ete we have made successive substitions and simplifications using the formal equation (43). Hene iff, s the fanetion deemed to be given by the program (4.3) we would have (3) 8 ‘With more complicated recursive programs there may be more than one way to use the formal equation f(x) = T(/, x) in such an evaluation procedure. Consider, for instance, th reeursive program itx=0 GD TOD Feces, y) i600 Suppose that we try formally to evaluat 0). We have 45) M40+H0,00). But now there is a choice of occurences of f for which to subsite 10 Effective operations on partial functions 198 14/,)- Choosing the leftmast one and simplifying we have (0,0) (0, (1, 0))=1 (singe x= 0), If, on the other hand, we substitute forthe rightmost occurrence of ‘each time, we obtain from (4) Ml, ©0411, 09 10410,1, 09) “HOONOLO.O)> and in this case no “value for (0) emerges ‘A compuration rule is a rule R that specifies how to proceed when confionted with such a choice of possible substitutions during any formal evaluation procedure. Tae computational rules we considered for the recursive program (4.4) were ‘leftmost’ (LM) and ‘rightmost’ (RM). There are many other possible rules. For any computation rule R, and recursive program ix) = 1(, X) we define the Function fog bY: y(t) is the value obtained when f(a) is formally evaluated using the rule R. If no value is thus obtained, fy4/a) is undefined. (Thus for the recursive program (4.4) we have /,§M(1, 0) = 1, and /.RM(1, 0) s undefined.) So we see that each computation rule gives ® meening to any recursive program (and, at the same time, a method of implementing i) ‘The above example demonstrates that different computation rules may tive different meanings fo any particular recursive program, The problem row for the computer scientist who chooses this computational approach is to devide which computation rule to choose. Moreover, for any rule R, there is the question of determining in what sens, if any, the Function fg satisies the equation 1a) =* 1,3). ‘The fixed point approach, using the first Recursion theorem, avoids these problems, and infact sheds light on both of them, as we shall sec The fixed point approach An expression #/, x) of L gives vise to an operator d>: 3>, > & by seting <@)O)"TBA) for any g 6 &. Moreover, in most programming languages the finite and explicit nature of the expression 1(/, x) ensures that 0 is @ recursive ‘operator. The first Recursion theorem now tells us that

1 The second Recursion thearem 201 (If <>x(x) is undefined, we mean the expression on the Iefl of (*) to be ‘undefined; altematively, we can take the left of (*) to denote l\ in theorem 3.1 it is shown that @ fixed point can be calculated effectively from various parameters that may be connected with We continue this section with some corollaries and applications of the second Recusion theorem, LI The second Recursion theorem 202 3 Gol Af fis a total computable function, there is a number n such that Wp = Wy Ady = By Proof. If dir, then W 13. Corollary I f is a total computable function there are arbitrarily large ‘numbers n such that (ftw) ~ ,- Proof. Pick any number k; take a number ¢ such that g(n) ~ k, so ff) = g(n) and nis a fixed point for (dm exercise 1.10(8) we shall indicaté how the proof of theorem 1.1 can bbe modified to obtain an increasing effective enumeration of fixed points for!) ‘The following corollary summarises the way that the second Recursion theorem is often applied, in conjunction with the s-me-n theorem, 14, Corollary Let ffs, y) be any computable function \ then there isan index € such that n(s) = x all x: apply corollary 1.4 with fim, x) =x" 1 The second Recursion theorem 203 @) there is a number m such that 17, = fn}: apply corollary 1.4 ‘with o ity=x, undefined otherwise, obtaining an index » such that 0,(y) is defined iffy ‘The second Recursion theorem reccived its name because, like the first Recursion theorem, it justifies certain very general definitions ‘by recur- sion’. Consider, for example, the following ‘definition’ of a function <1), in terms ofa given total computable function ‘The function <£, is ‘defined’ effectively in terms of an algorithm for computing itself (coded by the number e). In spite of its appearance as a circular definition, we are told by the second Recursion theorem that there are computable functions d>, satisfying such a definition, Tis often useful in advanced computability theory to be able to make ‘an even more general definition of a fimetion d>, “by recursion’ of the kind (0,8). where g is @ given total computable function, Again, think of d=, as “defined? effectively in terms of a code for its own algorithm, Then the second Recursion theorem, in the guise of corollary 1.4, makes this kind of definition meaningful also. We shall use this fact in the Speed-up theorem in the next chapter. ‘We continue this section with some further straightforward, but some- times surprising, consequences of theorem 1.1. First, we show how it ean be used to give a simple proof of Rice's theorem (6-1.7).

/(x}é A.forallx. (On the other hand, by theorem 1.1, there is a mumber 7 such that n, s0 fin) © A <=> ne A, a contradiction. 11 The second Recursion theorem 204 ‘Another application of the second Recursion theorem shows, as prom- ised in chapter 4 § 2, that the ‘natural’ enumeration of computable functions without repetitions is not computable. 12. Theorem Suppose that fis a total increasing fnction such that (a) ifm*n> then dyn) * n (n> whence, by (6) bym% bq (n=K) On the other hand, if f is computable, then by corollary 1.3 there is a number n>k such that yq) =

yq a contradiction Applications of the second Recursion theorem such as the following ‘can be interpreted in anthropomorphic terms. Let P be a program. We can regard the code number y(P) as a description of P. We could regard the program P as capable of self reproduction if for all inpuls x the computation Pfs) gave as output its ‘own description, y(P). At first glance, it would seem difficult to construct, ‘a selfreproducing program P, since to construct P we would need to know y(P), and hence P itself, in advance. Nevertheless, the second Recursion theorem shows that there are such programs. L8, Theorem There is a program P such that for allx, POxIy(P); Le. Pis selfreproducing. Proof. If we write n for y(P), the theorem says that there is a number m such that (n(x) =n (forall x), ‘To establish ths, simply apply corollary 1.4 to the function ffm, x) = We tum now to psychology! Recall the notation and terminology of chapter 5. There we defined a total computable function afe, x, 1) that I The second Recursion theorem 205 codes the state of the computation Pfs} afler ¢ steps; afe, x, 1) contains information about the contents of the registers and the number of the next instruction to be obeyed at stage & It is clear, then, that complete details of the first # steps of the computation Pfs) are encoded by the umber atexzapTiel Let us call the number a*(e, x, 1) the code of the computation P,(s) to steps, Cleatiy a* is computable. Suppose now that we are given a total computable function jp and a program P. By the ij-analysis of the computation P(s) we mean the code of the computation P(x) t &(x) steps. We call a program P &intro- spective at x if P(x) converges and gives as output its own (E-analysis; ‘we call P totally icinirospective if iis (A-introspective at all x. 19. Theorem There is a program P that is totaly i-introspective. Proof. Simply apply corollary 1.4 to the computable funetion /fe, x) = er*(e, x, (Mx)), obtaining a number m such that 0)=fth, x)= the (A-analysis of P(x). ‘We close this section with a tale in which the second Recursion theorem appears in military dress. “We are at war. An operation is mounted to sabotage the enemy's ‘central computer facility. Our special agents have penetrated the enemy defences and found a means of entry to the high security building that houses all the programs Pily Py Pp for the central computer. The mission will be accomplished if our agents can systematically sabotage all of these programs, ensuring that subsequently no program will operate as the enemy thinks it will, Simply to-destroy the programs is not sufficient: the enemy would soon discover this and set about rewriting them. What is needed is a subtle alteration to each program, So that, unknown to the enemy, the computer will give ‘wrong results. Swiflly and silently our men move into action ‘Alas, defeat at the hands of the second Recursion theorem! Whatever systematic plan is devised to modify the programs, it will define an effectively computable funetion fby Ax) = the code of the modification of P, 11 The second Recursion theorem 206 ‘The second Recursion theorem springs into action, producing @ number such that P, and its transform P,,, have the same effect (on unary inputs, atleast), The operation was bound to fail (Sometime later, back at 11Q, our master strategists consider recruiting, a chimpanzee whose mission is to alter the programs in random fashion ..)” 110, Exercises Show that there is a number such that , (2) = [,00)}? Suppose that <2/ aid let A = fx: d>, esd}. Show that A £4. Deduce theorem 1.6 6. Give an example of a total computable function f such that (if (Fis total, then 50 is <"yg, (i) there is no fixed point m for f with a>, lia 7. Prove the second Recursion theorem for fe-ary computable functions: if fis a total compatable function there is @ number ” such that sae 8. Show that theorem 1.1 may be improved to: For any total computable function /, there is an increasing recursive function inf such that for every 6 x for all x (or else show that by adding some redundant instructions to the end of Py, an equally suitable computable function s'fx) can be found, with s(x)>x). Now observe that given any mumiber k we can effectively find an index. m for s(x) with m=>k Then, following the proof of theorem 1.1, we have that n = s(m) is a fixed point for /, and n= sim) m> k It is now a simple matter to construct a function n/t) as required.) 9. Prove that the second Recursion theorem does not depend on the particular effective numbering of programs that is chosen, (Hint, Let 8 be another effective numbering of programs; let ©, ~program given code number m by 5; let ify ~ the unary function computed by Qy. We have to prove that for any total computable fumetion f there is a number m such that iff) = Wn 2 Discussion 207 For this, show that there is a computable bijection r such that P, = Qr(x)I then show that itis sufficient to establish that there is a rnumber m such that yim) = On 10, Suppose that in the tale just before these exercises, our special agents find that the enemy's computer operators have become extremely sophisticated - they have only one program, a uni- versal program, Can our men now completely accomplish their task? 11, Could a chimpanzee succeed where the special agents failed? (A philosophical problem.) 2 Discussion The second Recursion theorem and its proof may seem a litle mysterious at frst, We shall see, however, that it is essentially a simple diagonal argument applied to effective enumerations of computable functions. ‘Suppose that iis @ computable function. If is total, then the ‘enumeration £ given by Exeonion, Snir eager is an effective enumeration of computable functions. If is not total, we ‘can still regard A as enumerating a sequence of computable functions & bby adopting the convention that for any x the expression denotes. the function given by OFiex\(y) = OulFCa), y) {oix)(y) fh (x) is defined, (undefined if h(x) i undefined. ‘Thus if h(x) is undefined, Oy) is the function that is nowhere define. ‘The following lemma shows thatthe sequence F thus enumerated by is an effective enumeration even when h is not total 21, Lemma Suppose that h is a computable function. There is a total compu- table function hf such that h and h’ enumerate the same sequence of ‘computable functions Proof. The s-m-n theorem gives @ foal h such that (RAy"AUMY), 9). ‘We can now explain the idea underlying the proof of the Recursion theorem. For any &; let us denote by B, the sequence of computable 11 The second Recursion theorem 208 functions effectively enumerated by 4! then the list Ey, Ei, By, includes all possible effective enumerations of computable functions. We ‘can display the details ofthese enumerations as follows (ignore the circles): fe: a Gar) com what Bx au Gam) 2 Ex am am Ga — ‘Then the diagonal enumeration, D, citcled on this aray, is given by Dinatnerdi ‘Thus D is an effective enumeration, given by the computable function ifs) = <1>(a). Moreover, D has an entry in common with each effective cemumeration 21 in fact, for each k D and £, have their (k 4-1 jth entry -A<*y(k) in common, Suppose now that f is @ total computable function. ‘Then we can ‘operate’ on D to give an envmeration D* given by D™ ascsaay, tery tect fapens Now D is an effective enumeration of computable functions (given by ‘fh(x)) so here is « number m such that D* = E,, By lemms 2.1 we may assume that étotal, As noted above, D and E., have their (m + 1 )th entry in common, i tee pc Bagster une a aerafenea en ee D. a ! bdim fr Son = <1>,,(m) isa fixed point, Note. This proof can be rephrased to appear similar to standard diagonal arguments as follows. Suppose that fis a total function such that <£%,,# <>, 2 Discussion 209 for all n> then using on the diagonal enumeration D, the enumeration £54 is constructed so as to differ from E; at & (fulfilling the requirements ‘of the diagonal motto). Hence D* is nof an effective enumeration, so / ‘cannot be computable. ‘The second Recursion theorem can thus be viewed as a generalisation ‘of many earlier diagonal arguments To illustrate this, we show how to use ‘the second Recursion theorem to prove that K is not recursive, one of the fundamental diagonal arguments. 22. Theorem Kis not recursive. Proof. Let a, b be indices such that W, = 0 and W, = IM. If K is recursive, then the function g defined by (aifeek, SIL ix. is computable. Notice that g has the property that forall x Wygit W (ince x € Wa) 2 Wyyy N&> g(8) = 6 <-> XE W). This is in contrae diction tothe second Recursion theorem, Remark. We have, of course, used a sledge hammer to erack a nut. The ppoint about this proof is that all diagonalisation is hidden inside the application of the Second Recursion theorem. We ate not suggesting that the earlier proof should be replaced by this one. The relationship between the two Recursion theorems Suppose that ©: F, > F; is a recursive operator, and that h is a total computable function such that (,) = dn.) forall x (as given by the Mybill- ‘Shepherdson theorem). If is a fixed point for A, then (>h, ie. (4) = (>, Thus the second Recursion theorem tells us (as does the first theorem) that Ohas a computable fixed point; it does not tll us, however, that hts a computable feast fixed point, So, for recursive operators the first Recursion theorem gives us mote information, On the other band, the second Recursion theorem applies to non extensional computable functions as well; ie. functions that do not arise from recursive operators. Thus the second theorem has a wider range of application than the fitst theorem, although in the area of overlap it generally gives less information. Thus, these two theorems are best regarded as complementary, although a case is made by Rogers [1967] for the view that the second theorem is the more general of the two. 11 The second Recursion theorem 210 3. Myhills theorem Let us now formulate and prove the generalisation of theorem 11 needed for Myhil’s theorem, Suppose we have a total computable funetion /(x, 2); theorem 1.1 shows that for any particular value of the parameters 2 there is a number n such tha, <>, We now show that can be obtained effectively from = 3.1. Theorem (The second Recursion theorer) Suppose that f(x, 2) is a total computable function. There isa total ‘computable function n(z) such that forall = ‘Proof. We simply introduce the parameter at appropriate points inthe proof of theorem 1.1 By the s-m-n theorem there is total computable fmetion s(x, 2) such that ‘Then, again by using the s-m-n theorem, there isa total computable funetion m/s) such thats, 2)~2!(x)*y is an undecidable predicate. Often in complexity theory a property holds forall suficiently large numbers », though not necessarily for all n, Thus we make the following definition, 13. Definition A predicate M(n) holds for almost all n, or almost everywhere (ae) if Mn) holds for all but finitely many natural numbers m (or, equivalently, if there is a number no such that M(n) holds whenever n>r) We can now state our first theorem, which shows that there are arbitrarily complex computable functions. 12 Complexity of computation 214 1.4, Theorem Let b be a total computable function, There is a total computable function faking only the values 0, 1, suck that fe is any index for fthen V(a)>b(n) ae. Proof. The reader should not be surprised to find that fis obtained by a diagonal construction. The essence of the construction is to ensure that if ti(m)°(m) for infinitely many values m, then f differs from (r>, at one of those values, We define /by recursion as follows. At each stage m in the construction of f we shall either define an index |, oF decide in a finite amount of time that i, isto be undefined. We then censure that ffm) differs from @>, (n) if, is defined. In detail, assuming that AO), .-./\~ T) have been thus defined, we put Difi< n andi differs from all previously ‘defined i, and sn) < bn) if such an i exists, undefined otherwise if is defined and i 10 otherwise. (a) ‘There is a finite procedure that tells us for a given i whether s/n)< in, since Lin) b(n) <=> By4(n). Hence f is a well defined total computable function Suppose now that f By: construction e / J, whenever i, is defined We shall show that if i is any indox such that rifm) bfm) for amos all m. Suppose then that si(m)iip and 4(n}< bn). If/ = i, for some k < n, there is nothing further to prove. Assuming then that # jj for all k -p, we must have i, >4, Hence i,» i, as required 1 Complexity measures 215 We cannot in general improve this theorem to obtain the conchision t(n)>b(n) for all n\ this is because for any f we can always write a program that computes f quickly for some particular value a, simply by specifying the value of f(a) in a preface to the program. For example, suppose that ffa) = 1; let F be a program that computes f/ Then the program £" based on the flow diagram in fig. 12a also computes f. Clearly wwe have (a) = a°3. Thus, if b is a computable function such that bfx) > x +3 for some x, then we cannot obtain the conclusion of theorem 1A with ((n)> b(n) forall. Using a similar idea we ean write @ program that computes f quickly for any given finite number of values: see exercise 1,8(1) below. This shows that f(n)>B(n) ac. is the best possible conclusion in theorem 1.4, Other computational complexity rneasures There are many other natural ways to measure the complexity of a computation, of which the following are a few examples. For simplicity we restrict our discussion (0 ‘mary computations. Fig. 12a 12 Complexity of computation 216 15. Examples 1 (numberof jumps made! in executing P,(), 0.0) iP.) undefined otherwise This measure is closely associated with the number of loops performed when executing P,(s), which is in tum related to the time of computation 6) 2 the maximum number held in any ofthe registers | at any time during the computation P,() ahl=) iPox, undefined otherwise. ‘This measure obviously relates to the amount of storage space needed to cant out te computation Ps) on a real computer. 3. With the Turing machine approach, two natural complexity measures are (i) the number of steps needed to perform a Turing computation and (i) the amount of tape used to perform a computation In general, an abstract computational complexity measure (for unary computations) is defined to be any collection of functions , with the following properties: (a) Domi.) = Dom), for ali; (6) The predicate (pfs) —y’is decidable 1.7. Lemma The functions given in examples 1.5 above are computational complexity measures, Proof. We give sketch proofs for the examples 1.5(1) and 1.5(2), Jeaving 1.5(3) as an exercise (1.8(3) below), In each case it is only part (8) ‘of definition 1.6 that requires any thought (1) To decide “0, (x) — ywhere ,(s) = number of jumps made during P (x). Suppose that P, has 5 instructions; then at most S "We mean here thai jump instruction Jf, mp) is encountered then a jump (0 2,) is made ifr, = ry; but not otherwise 1 Complexity measures 217 consecutive steps of P,(s) ean be performed without making a jump. So run Pf) for up to 1 4- (y 4 Ds steps. If Ps) stops in fewer than this mimber of steps, then count the number of jumps made to see if it is y. Otherwise (ie. if P,(x) has not stopped after 1+ (y+ 1)S steps) P,(x) will have performed at least y 4-1 jumps, so we conchude that 0,(8)# y. (2) To decide “0(x) =) where ,(4) = maximum number bold in any register during P(x). Let u-p(P), and consider all possible nomhalting states under the program P, with Fivcoss MySy. There are s(p 4-1)" such states that are distinct, Run P,(s) for up to 1 4-s(y 4-1)" steps. If P(x) stops after this number of steps or fewer, then find the maximum number that ‘has occurred in any of the registers and see if ti y. Otherwise (i Ps) bas not stopped) one of two possibilities will have occurred ) the computation has been in the seme state on two separate ‘occasions, 80 P(x) is in a loop and 2x 4 3, then the restriction to almost all ‘nin theorem 1.4 cannot be improved, Lot, be the complexity measure given in example 1.5(2). Show that whenever max(x, ) for x eX 2 12 Complexity of computation 218 3. For the complexity measures given in example 1.5(3), verify Jemma 1.6, expressed in the following terms. For any Turing machine M, let fy be the unary function computed by M. Then show that (a) Dom(0,) 1) Gus) = (@ when {the number of steps taken in computing!y(x) wea) =<) USing M, itp (x) is defined, | undefined otherwise. om). is decidable Gi) when (the length of tape actually used? in the epy(s) = computation of f(x) by M, if fy) is defined, undefined otherwise 4. Suppose that (n), Von ¢ i(x) = f(s) forall x, a8 willbe the case in the Speed-up theorem.) Proof. First we must fix a particular total computable function 5 given by the s-m-n theorem, such that d> iu, x) — x, Cyey = 080 s(u.x)-I immediately from the definition. For u gy, then f is certainly total, as required by the theorem, () Fix a number w; we must show that g(0, x) and g(u, x) differ for only finitely many x. It is clear from the construction of the sets C.,, that for any x é = Cox We,» X-1) Since the sets Co.x are all disjoint (by construction) we can find the mumber vy = max{x:C,x contains an index 2 <«}. Then for x>vwe have Cox C {u, w+... x— 1}, and hence Cox =C,,. ‘This means that g(0, x) = g(u, x) for x>v. Thus g0(X) = gy) 2 The Speed-up theorem 21 (©) Suppose that i is an index for /; taking j = s(e, i+ 1) we have that), 1) = gi+i (from above), so isan index for g,.i. We ‘can prove that = n(ij(@aii)()) < iM for all x > If this were not the case, then f would have been cancelled in the definition of g(0, x) for some x>z; i.e. there would have been x > iwith #6 Co.x- But then, by construction of g, we would have ‘2(0, x) #i(x), a contradiction. This completes the proof, ‘Note that the pseudo-Speed-up theorem is effective’. given a program P for f we can effectively find another program that computes f almost everywhere, and is almost everywhere faster than P. We now show how to modify the above proof to obtain 2.2, The Speed-up theorem (Blum) Let r be any total computable function. There is a total computable function f such that, given any program Por f there is another program Py for f such that r(i(3))tH() ae Proof. We may assume without any Toss of generality that r is an increasing function (or else replace r by a larger increasing computable function). First, by a slight modification of the proof of theorem 2.1 we ‘obtain a total computable function ‘such that given any program P, for /, there isa program P, such that (a) v, Let ffm) = by for m . Clearly P, computes f'; moreover, there is a number ¢ such that the extra instructions add at most ¢ steps to any computation; ie. forall x Gr apsE(x) +e. 12 Complexity of computation 22 Fig. ian. Speed-up from pseudo-Speed-up. 1 x () oS + ‘Thus we have 119'(0)"VCii(s) + o) (since ris increasing) -st(u(x) + x)fore>e — e is total and 16) BG) ac.) = (ffs total, computable and has a program P, with r(x)* bac} 12 Complexity of computation 24 Remark. The class thus defined, is the complexity class of b relative to the time measure r(x); for any measure -b(s) for all x, of ‘course By S45 if '¢s)>6(x) forall x, we would naturally expect that G*" ‘contains some new functions not in G/>, especialy if b'¢) is much larger than (3). The next theorem shows that this intuition is false: we ean find », b with b” greater than b by any preassigned computable factor, such that S,- Cin: fact, the theorem shows that 6, ' can be chosen so that there is no rmning time 1) that lies between Bs) and 6's) for more ‘than finitely many x. Thus the theorem is called the Gap theorem. 3.1, The Gap theorem (Borodin) Let r be a total computable fiction such that r(x) > x. Then there is a total computable function 6 such that (a) for any © and x >c, if A(x) is defined and 1(+)> B(x), then 1,69> r(b(s))\ hence © G=Giy. Proof, We define b(x] informally as follows. Define a sequence of numbers ky < ki <..< by fe0= 0, (Ar) +1(@<0, Consider the disjoint intervals? (kj, /+(&2)] for O ‘(x)\ by construction of (x), we have r<(x)BIZ>(%), r(b(s)). Hence t3)> r(b(x). isi "By the interval fe dj we mean these of natural numbers (xx ), we obviously have ©, SC»; now note that iff <&,*bléeb, then fhas a program P, with 1G eHta(N) a0. but 19> bis) infinitely often (otherwise/EGO). This clearly contradicts (a). Hence = Bol. Note. This proof is based on that given by Young [1973]. It is easy to see that the function b in the theorem can be made larger than any pre- assigned computable function c, simply by setting ko = c(s) instead of k, = 0 in the proof. Its also elear from the proof that the Gap theorem is machine independent 4, The elementary functions In this final section we introduce the class of elementary functions as an example of a class of computable functions that can be characterised very neatly in terms of the complexity classes corresponding to time of computation, The elementary functions form a natural and extensive subelass of the primitive recursive functions, as we shall see, They have been studied in some depth, and are of interest in their own right, quite apart from complexity theory. 41. Definition (@) The class £ of elementary functions is the smallest class such that Jeti (@ the functions x 4-1, U7 y) pz< y(t sel(x(z+1)—y)) = 0) Gil) rm. mix, y) = ¥- x gH y). Gv) py Assuming that the fumetion Pr(x) (the characteristic function of “x is prime’) has been proved elementary, we have p,=/zy <2? (x=0 ory isthe sth prime) nys2? (= X Pr(2)) My 82 (x= £ Pr(z)|=0). (The bound p, < 2 is easily proved by induction, using the fact that pti = pop, +++ px 4-1) We leave the proofs for the other functions as an exercise for the reader. 4 The elementary functions 27 We now show thatis even closed under definitions by primitive recursion, provided that we know in advance some elementary bound on the function being defined by the recursion equations. 44. Theorem Let f(s) and g(x, yz) be elementary and let h be the fiction defined from fg by Ins, 0) = 3), Fils, ¥ +1) = 20%, ys heyy). Suppose that there is an elementary function bis, y) such that (xy) ‘6, 9) for all x,y. Then his elementary Proof Fixx, y; then the calculation of 4 (x,y) in the usual way requires the calculation of the sequence of numbers A(X, 0), fi, sn, h( 3) These can be coded by the single number 5 where: ge ATINQU Hel), Mey) P Ti ptii™= etx, yh, say, ‘where (x,y) isan elementary function. The key facts about $ are © (i = i, OMG, G for 26y, Oty = Ws 2 41) = als, % (eid and (i) h(x, ») = (8),*i. Thus we have Hs, y) = Ves " is clementary, we observe that a function that is almost everywhere the same as an elementary function is elemen- tary (see exercise 4.12(46) below). [At this stage the reader might well be wondering whether the clemen- tary functions coincide with the primitive recursive functions. All parti- cular examples of primitive recursive functions from earlier chapters have bbeen shown to be elementary. The only detectable difference between these classes is that for <£ we have only been able to prove closure under limited recursion. Could it be that this is only an apparent distinction? ‘The answer, as we shall sce below, is no. Limited recursion is @ definition principie that is really weaker than primitive recursion, We will find a function that is primitive recursive but not elementary as a consequence of the next theorem te be proved below. Nevertheless, £ is an extremely large class of functions, and contains ‘most of the functions used in practical mathematics. The class £ is @ natural first suggestion for the class of total effectively computable functions, based as it is on the ordinary operations of arithmetic, Indeed, it has been argued (for example, by Brainerd & Landweber [1974)) that £ contains all practically computable functions. They argue that if ffs) is practically computable, then there must be some number & such that ffx) ccan be computed in at most steps for almost all x. After all, for practical purposes, this number of steps quickly becomes very large in comparison with x, even for small values of k. Now, since the function is elementary (for fixed W), this means that fis elementary, by corollary 46. ‘Our goal in the remainder of this section is to show that the clementary functions can be characterised as precisely those functions that are ‘computable in time 12 Complexity of computation 230 for some k AS a first step towards that goal, we have the following, which incidentally will give a non-elementary primitive recursive function, 4.7. Theorem If ffs) is elementary, there is a umber k such that for allx, (C052? Proof. Let us write b(=) for ®, then, explicitly, we have (2) = 2, Z>i(2) = 2\ and bbl) = 2° in eeneral, (Thus, by 2? is meant 22 \ not (22) , ete.). Note that by ifs) = b,@bi(e). We shall use implicitly below the fact that 5, is increasing and that 2°<2? for all = ‘To establish the theorem, we consider each of the clauses whereby a function fcan get into & Referring to definition 4.1 @) x= ax U"@,,(max(x)) (IS), and i(y)s 64(maxty)). Let k~ maxtki,... ky). Then we have is) bila)... 86) 8 Zlimaxt’>*,(mantX))y felimaxly)))) < bi(h, (max(x)) = Z>,.(max(s). Gil) Suppose that g(x, y) = S./lx, 2), and that /aZ)< Mmaxix, 2)). Then we have (8, y)<£ 4 (max(x, 2)) ey ‘sy/>*(max(x, y)) , (max(x)), for some k. Le. @ U Ie Proof. Since for each k, 6Umaxix)) is an elementary function, we have Gtyg Eby corollary 4.6; hence Utise 12 Complexity of computation 234 For the converse inclusion, let /(x) be an elementary function. By ‘theorem 4.9 there is a program F for /such that f, is elementary; now by theorem 4.7 find a number k such that F,(8). <>q(max(x)). ThenieSt,, so our proof is complete. 4.12, Brercises 1. Show that it was not stietly nevessary to include the functions x 4 y and xy in the definition of (Pint. First obtain xy as a bounded sum; then obtain x + y from suitable products, using». 2, Prove lemma 4.2(>) 3. Complete the proof of theorem 43. 4. (a Show that £ is closed under definition by cases, when the funetions and predicates in the definition ae all elementary. (@) Show that if (x) is elementary and g(x) =) ae., then g00) is elementary 5. Check all the details in the proof of corollary 45. Complete the proof of theorem 4.7 by showing that if a(x, y) = W/O) ond Hx, 2)<>y(mants, 2), then BCR IS %,,slmaxx, y). 7. Give an example of a unary primitive recursive funetion that is not elementary, different from that of corollary 43. 8. Prove that iff is computable in elementary time and a, y) = riz,(9)a functions computed by P, 76-77 wom, domain of <18.77 BY) E, range of dsé'77 Chapter 5 , 208 D diagonal enumeration 208 Chapter 12 1p") number of steps taken by P to compute fore) 213 7G) 6°09 213, complet classes of b 223, 233 Notation elementary functions 25 24s index ‘A-computable 172 here. 2 ‘Aercutsive 172 scceptance problem 104 ‘Ackermann function 46, 52, 19.46 addition, program for 17 fdmisible ordinal 237 slgorithm 7-9 arkov 65 almost everywhere (ae) 213 tlphabet ‘of Post system 58 of Turing machine $3 Atbib, MAA. 60,236, 238 ‘rithmetic 143-36 axioms for 144, 149 Statemeats of, ee statements of ‘anthmetic snioms 58,59 for arithmetic 144, 146, 149 sie fanetions 25 107, 117,156,237, bijection 2 Bind, R199, 238 Blur, M 212,219,221, 234 Boles, G. 113,156,287 Boone, W. W. 107 Borodin, A.212, 224 bounded minimsliation 39, 226 bounded -operatar 39,226 bounded product 38,225 hounded quantifers 40, 226 bounded sum 38, 225, Brainerd, W.S. 229,234, 238

You might also like