At the intuitive level, any practicing mathematician or computer scientist —indeed any student of these two fields of study— will have no difficulty at all to recognize a computation or an algorithm , as soon as they see one, the latter defining, in a finite manner , computations for any given input. It is also an expectation that students of computer science (and, increasingly nowadays, of mathematics) will acquire the skill to devise algorithms (normally expressed as computer programs) that solve a variety of problems.

But how does one tackle the questions “is there an algorithm that solves such and such a problem for all possible inputs?” —a question with a potentially “no” answer— and also “is there an algorithm that solves such and such a problem via computations that take no more steps than some (fixed) polynomial function of the input length?” —this, too, being a question with a, potentially, “no” answer.

Typical (and tangible, indeed “interesting” and practically important) examples that fit the above questions, respectively, are

  • “is there an algorithm which can determine whether or not a given computer program (the latter written in, say, the C-language) is correct ?” 1

    and

  • “is there an algorithm that will determine whether or not any given Boolean formula is a tautology, doing so via computations that take no more steps than some (fixed) polynomial function of the input length?”

For the first question we have a definitive “no” answer, 2 while for the second one we simply do not know, at the present state of knowledge and understanding of what “computing” means. 3

But what do we mean when we say that “there is no algorithm that solves a given problem” —with or without restrictions on the algorithm’s computation lengths? This appears to be a much harder statement to validate than “there is an algorithm that solves such and such a problem” —for the latter, all we have to do is to produce such an algorithm and a proof that it works as claimed. By contrast, the former statement implies a, mathematically speaking, provably failed search over the entire set of all algorithms , while we were looking for one that solves our problem.

One evidently needs a precise definition of the concept of algorithm that is neither experiential, nor technology-dependent in order to assert that we encountered such a failed “search”. This directly calls for a mathematical theory whose objects of study include algorithms (and, correspondingly, computations ) in order to construct such sets of (all) algorithms within the theory and be able to reason about the membership problem of such sets. This theory we call the theory of computation . It contains tools which, in principle , can “search” 4 the set of all algorithms to see whether a problem is solvable by one; or, more ambitiously, to see if it can be solved by an algorithm whose computations are “efficient” —under some suitable definition of efficiency.

The theory of computation is the metatheory of computing. In the field of computing one computes: that is, develops programs and large scale software that are well-documented, correct, efficient, reliable and easily maintainable. In the (meta)theory of computing one tackles the fundamental questions of the limitations of computing , limitations that are intrinsic rather than technology-dependent. 5 These limitations may rule out outright the existence of algorithmic solutions for some problems, while for others they rule out efficient solutions.

Our approach is anchored on the concrete (and assumed) practical knowledge about general computer programming attained by the reader in a first year programming course, as well as the knowledge of discrete mathematics at the same level. The next natural step then is to develop the metatheory of general computing , building on the computing experience that we have assumed the reader attained. This will be our chapter on computability, that is, the most general meta theory of computing. We develop this metatheory via the programming formalism known as Shepherdson-Sturgis Unbounded Register Machines (URM) —which is a straightforward abstraction of modern high level programming languages. Within that chapter we will also explore a restriction of the URM programming language, that of the loop programs of A. Meyer and D. Ritchie. We will learn that while these loop programs can only compute a very small subset of “all the computable functions”, nevertheless are significantly more than adequate for programming solutions of any “practical”, computationally solvable, problem. For example, even restricting the nesting of loop instructions to as low as two , we can compute —in principle— enormously large functions, which with input x can produce outputs such as

images

The qualification above, “in principle”, stems from the enormity of the output displayed in (1) —even for the input x = 0— that renders the above function way beyond “practical”.

The chapter —after spending considerable care in developing the technique of reductions — concludes by demonstrating the intimate connection between the unsolvability phenomenon of computing on one hand, and the unprovability phenomenon of proving within first-order logic (cf. Gödel (1931)) on the other, when the latter is called upon to reason about “rich” theories such as (Peano’s) arithmetic —that is, the theory of natural numbers, equipped with: the standard operations (plus, times); relations (less than); as well as with the principle of mathematical induction.

What to include and what not to include in an introductory book on the theory of computation is a challenge that, to some extend, is resolved by the preferences of the author. But I should like to think that the choices of topics made in this volume are more rational than simply being manifestations of “preference”.

The overarching goal is to develop for the reader a “first-order” grounding in the fundamentals, that is, the theoretical limitations of computing in its various models of computation, from the most general model —the URM— down to the finite automaton.

We view the technique of reductions as fundamental in the analysis of limitations of computing, and we spend a good deal of space on this topic, a variant of which (polynomial-time reductions) the student of computer science will encounter in Subsection 5.1.2 and will re-encounter in later studies as well, for example, in a course on algorithms and complexity. On the other hand, we do not hesitate to omit combinatorial topics such as “Post’s correspondence problem”, which only leads to specialized results (e.g., the algorithmic unsolvability of detecting ambiguity in context free languages) that we feel embody a less fundamental technical interest. Our emphasis is on laying the foundational tools and concepts that allow us to carry out a mathematical analysis of, and acquire a thorough understanding of, theoretical limitations of computing in both their absolute manifestation (uncomputability) and also in their relative manifestation (complexity and “intractability”).

Consistent with our stated goal and emphasis, we purposely give short shrift to the area of so-called “positive” results, apart from a few familiarization examples of “programming” with URMs, loop programs, FA, NFA, and PDA. This is not a course about writing algorithms, but mostly about what algorithms cannot do at all and about what they have a lot of trouble doing . For example, results of Chapter 5 immediately imply that, in general, FORTRAN-like programs that allow nesting of the loop instruction equal to just three have highly impractical run times; certainly as high as 6

images

Thus, we leave out “applications” such as lexical scanners via finite automata; automata-minimization; parsing of context free languages using LL, LR, recursive-descend, and other parsers; and defer them to a later course on compiler writing tools —these topics do not belong here. We would rather concentrate on what is foundationally important and omit what is not.

Another challenge is where to start building this metatheory. What should be our abstraction of a computer program? It should be a straightforward observation that since this metatheory, or “theory” as we nickname it, abstracts computing practices —in order to analyze and study said abstractions mathematically— the student must have encountered in the first instance the concrete counterparts of these abstractions for the latter to make any sense.

It is hardly the case that, prior to the second year of study, students have “programmed” scanners or parsers. Rather, students have programmed solutions for less specialized problems, using a high level general purpose language such as C/C++, Java, possibly Pascal, etc. They never programmed an automaton, a push-down automaton, or anything like a Turing machine (unless they have taken up machine language in the first year).

Yet the overwhelming majority of the literature develops the “theory of computation”, in a manner of speaking, backwards —invariably starting with the theory of finite automata, as if automata is precisely what the reader was programming in his 7 first university course on programming. We apply this principle: Before the student studies the (meta)theory, he must have attained a good grasp of the practice that this theory attempts to dissect and discuss. Thus, it is natural to start our story with the (meta)theory of general purpose computer programs .

Because of these considerations, our first chapter is on URMs and computability. The choice of URMs as an abstraction of general-purpose computing —a relative latecomer (cf. Shepherdson and Sturgis (1963)) in the search for a good answer to “what would be a good technology-independent model of computation?”— also connects well with the experience of the student who will come to this course to learn what makes things tick in programming, and why some things do not tick at all. He most likely learned his programming via a high level language like C or Java rather than through machine language . The ubiquitous Turing machine (Turing (1936, 1937)) is more like machine language, indeed, is rather even less user-friendly. 8 It offers no advantage at this level of exposition, and rather presents an obscure and hard-to-use (and hard to “arithmetize” 9 ) model of computation that one need not use as the basis of computability. On the other hand it lends itself well to certain studies in complexity theory and is an eminently usable tool in the proof of Cook’s theorem (cf. Subsection 5.1.3 ). So we will not totally avoid the Turing machine!

We turn to the formulaic topics of a book on Automata and Languages — Chapter 3 — only after we become familiar, to some extent, with the (general) computability theory, including the special computability theory of more “practical” functions, the primitive recursive functions. Automata are introduced as a very restricted programming formalism , and their limitations (in expressivity) and their associated languages are studied.

It is often said, with justification, that a course in theory of computation has as side-effect the firming up of the student’s grasp of (discrete) mathematical techniques and mathematical reasoning, as well as the ability to apply such techniques in computer science and beyond. Of course, it cannot be emphasized enough that the student of a theory of computation course must be equipped already with the knowledge expected to be acquired by the successful completion of a one-semester course on discrete mathematics. This required background knowledge is often encapsulated, retold, and aspects of it are emphasized, in the space of a few pages at the front-end of a book like this. This is the ubiquitous “Chapter 0” of many books on the subject. In the case of the present book I would like, most of all, to retell two stories, logic and induction , that I often found being insufficiently developed in the student’s “toolbox”, notwithstanding earlier courses he may have taken. Thus, in Subsection 1.1.1 we develop the notational and how-to parts of elementary predicate logic in the space of some 20 pages, paying special attention to correctness of exposition. Section 1.4 presents the induction principle on the natural numbers in two steps: One, how to use its various forms, and a proof of their equivalence to the least (positive) integer principle. Two, we argue, at the intuitive level, why induction must be a valid principle after all! 10 We also go over concepts about sets and related notation, as well as relations and functions, very quickly since they do not need much retelling. We will also introduce quickly and in an elementary fashion a topic likely not encountered by the reader in the typical “discrete math” course: the distinction between two infinities — countable and uncountable — so that we can have an excuse to introduce the reader to Cantor’s ingenious (and simple) diagonalization argument, that recurs in one or another shape and form, over and over, in the computability and complexity part of the theory of computation.

On intuitive arguments; “formalization” and why a course in theory cannot be taught exclusively by hand-waving : The main reason that compels us to teach (meta)theory in a computer science curriculum is not so much to prevent the innocent from trying to program a solution for the halting problem (cf. 2.5.0.16 ), just as we do not teach courses in geometry just to prevent circle-squaring “research”. Rather, formal mathematical methods used in a course in the theory of computation, more so than the results themselves, are transferable skills that the student becomes endowed with, which equip him to model and mathematically analyze concrete phenomena that occur in computation, and through a mathematical process of reasoning to be able to recognize, understand, and correlate such phenomena. These formal methods, skills and results, put the “science” keyword into computer science .

Intuition, obtained through experience, is invaluable, of course, and we often argue intuitively before we offer a proof of a fact. But: one cannot have “proof-by-intuition”.

We have included in this volume a good amount of complexity theory that will likely be mostly skipped whenever the book is called upon to serve a second year course on the theory of computation. There are a few “high level complexity” results already in Section 2.7 using diagonalization (cf. 2.7.1.9 and 2.7.1.11 ). Later, quite a bit is developed in Chapter 5 , including the concept of Images -completeness and Cook’s theorem; an account of Cobham’s class of feasibly computable functions (mostly delegated to the Exercises section, 5.3 ); and some elements of the hierarchy theory of the primitive recursive functions culminating in the rather startling fact that we cannot algorithmically solve the correctness problem of FORTRAN-like programs even if we restrict the nesting of loops to just two levels . FORTRAN-like languages have as abstract counterpart the loop programs of Meyer and Ritchie (1967) that we study in the chapters on computability (2nd) and complexity (5th).

Were I to use this book in a second year course in the theory of computation I would skim quickly over the mathematical “prerequisites” chapter, and then cover 2.1 – 2.7 , parts of 2.10 , certainly Gödel’s incompleteness theorem and its relation to uncomputability : 2.11 —but not 2.11.1 . I would then cover only as much as time permits from Chapter 3 on finite automata; certainly the pumping lemma, consistent with my view that this is a “course” about what cannot be done, or cannot be done “easily”, rather than a toolbox for how to do things. The latter is deferred to a course and book on algorithms.

In a more advanced course where one can proceed faster, I would want also to cover the sections on creative sets and the recursion theorem, and also as much complexity theory as possible from Chapter 5 , starting with the material leading to Cook’s theorem.

The reader will forgive the many footnotes, which some will assess as bad style! There is always a story within a story, the “… and another thing …”, that is best delegated to footnotes.

The style of exposition that I prefer is informal and conversational and is expected to serve well not only the readers who who have the guidance of an instructor, but also those readers who wish to learn the elements of the theory of computation on their own. I use several devices to promote understanding, such as frequent “pauses” that anticipate questions and encourage the reader to rethink an issue that might be misunderstood if read but not studied and reflected upon. Additionally, I have included numerous remarks, examples and embedded exercises (the latter in addition to the end-of-chapter exercises) that reflect on a preceding definition or theorem. All pauses are delimited by “ Pause .” and Images

The stylized “winding road ahead” warning, Images , that I first saw in Bourbaki’s books (Bourbaki (1966)) and have used in my other books, delimits a passage that is too important to skim over.

On the other hand, I am using Images to delimit passages that I could not resist including, but, frankly, can be skipped (unless you are curious).

There are over 200 end-of-chapter exercises and 41 embedded ones. Many have hints and thus I refrained from (subjectively) flagging them for level of difficulty. After all, as one of my mentors, Alan Borodin, used to say to us (when I was a graduate student at the University of Toronto), “attempt all exercises; but definitely do the ones you cannot do”.

G EORGE T OURLAKIS

Toronto

November 2011

1 A “correct” program produces, for every input , precisely the output that is expected by an a priori specification.

2 There is some interesting “small print” here! As long as the concept of algorithm is identified with that of, say, the Shepherdson-Sturgis “machines” of this volume —or for that matter with Turing machines—then the answer is definitely a “no”: There is a simple mathematical proof that we will see later on, that no Shepherdson-Sturgis machine (nor a Turing machine) exists that solves the problem. Now, such an identification has been advocated by Alonzo Church as part of his famous belief known as “Church’s Thesis”. If one accepts this identification, then the result about the non-existence of a Shepherdson-Sturgis machine that solves the problem is tantamount to the non-existence of an algorithm that does so. However, Church’s “thesis” is empirical, rather than provable, and is not without detractors; cf. Kalmár (1957). Suffice it to say that this statement is mathematically valid: No program, written in any programming language, which is equivalent in expressive power to that of our Shepherdson-Sturgis machines, exists that solves the problem.

3 There is substantial evidence that the answer, if discovered, will likely be “no”.

4 The quotes are necessary since it is not precisely a search that one performs. For example, the unsolvability —by any algorithm— of the program correctness problem is based on a so-called reduction technique that we will learn in this volume. A reduction basically establishes that a problem A is solvable by algorithmic means if we assume that we have a “black-box” algorithmic solution —that we may “call” just as we call a built-in function— of another problem, B . We say that “ A is reduced (or reducible) to B ”. If we now know (say via a previous mathematical proof of the fact) that A cannot be algorithmically solved, then nor can B ! We will, as a starting point, show the unsolvability by algorithmic means, certainly not by any Shepherdson-Sturgis machine, of a certain “prototype” problem, known as the halting problem , “ x Images K ?”. This will be done by a technique akin to Cantor’s diagonalization . After this, many reduction arguments are effected by showing that K is reducible to a problem A . This renders A unsolvable!

5 However this metatheory is called by most people “theory”. Hence the title of this volume.

6 See 5.2.0.47 and 5.2.0.49 . L 3 programs have run times bounded by Ackermann’s Images , for some κ > 0.

7 Pronouns such as “he”, “his”, “him” are, by definition , gender-neutral in this volume and are used solely for textual convenience.

8 Machine language can manipulate numbers , whereas a Turing machine can only manipulate digits !

9 This verb will make sense later.

10 In so doing I will be sure to let the student know that I am not squaring the circle: Induction is not a provable principle of the arithmetic of Peano, it is an axiom. However, this will not stop us from arguing its plausibility , i.e., why it is a reasonable , “natural” axiom.