





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















Primitive Rec, Ackermanās Function, Decidable, Undeciable, and Beyond Exposition by William Gasarch
We would like to formally define some notion of ācomputable functions.ā We attempt to define a set of functions that contains only computable functions, and contains all of them. This attempt will fail, but the reasons for this are of interest. In a later section we will succeed. In this attempt to define ācomputable functionsā we try to use only basic operations (e.g. the operation āadd 1ā), and basic ways of putting functions together (e.g. composition). We do this to make the model as simple as possible, and to guarantee that all functions generated are computable.
Def 1.1 A function f (x 1 ,... , xn) is primitive recursive if either:
f (x 1 ,... , xn) = h(g 1 (x 1 ,... , xn),... , gk(x 1 ,... , xn))
is primitive recursive. This rule for deriving a primitive recursive func- tion is called the Composition rule.
f (x 1 ,... , xnā 1 , 0) = g(x 1 ,... , xnā 1 ) f (x 1 ,... , xnā 1 , m + 1) = h(x 1 ,... , xnā 1 , m, f (x 1 ,... , xnā 1 , m))
This rule for deriving a primitive recursive function is called the Re- cursion rule. It is a very powerful rule and is why these functions are called āprimitive recursive.ā
To show some function is primitive recursive you build it up from these rules. Such a proof is called a derivation of that primitive recursive function. We give some examples of primitive recursive functions. These examples will be given both rather formally (more formal than is really needed) and less formally. After these examples we shall always be less formal. The only reason to give the rather formal definition is to show that it can be done. In practice the informal one is just as informative (actually more so) and has the intuition that the formal one sorely lacks. There are two points these examples are making: (1) LOTS of functions are primitive recursive. Most functions that you have dealt with in your lives have been primitive recursive. (2) It isnāt that hard to show that functions are primitive recursive.
Example 1.2 f (x) = x + 5. Very formally we would say:
Now that we have multiplication is primitive recursive, we use it to define powers.
Example 1.5 f (x, y) = xy^ is primitive recursive via
f (x, 0) = 1 f (x, y + 1) = xf (x, y)
Subtraction would be a nice operation to have, but primitive recursive function only go from N to N. We do have a ātruncated subtractionā called āmonusā
Example 1.6 In all the above examples we took a well known function and showed it was primitive recursive. Here we define a function directly. What this function does is, if x > 0 then it subtracts 1, otherwise it just returns 0.
f (0) = 0 f (x + 1) = x
To do this formally, recall that in the recursion rule the function h can depend on x and f (x). Henceforth, call this function M (x).
We now use M to define a version of subtraction.
Example 1.7 x.^ y. This function is x ā y if x ā y ā„ 0, otherwise it is 0.
f (x, 0) = x f (x, y + 1) = M (f (x, y))
Example 1.8 We can now show that |x ā y| is primitive recursive. |x ā y| = (x.^ y) + (y.^ x).
Fact 1.9 Virtually every function you can think of (primality, finding quo- tients and remainders, any polynomial) is primitive recursive.
Exercise Define a notion of primitive recursive function from (Ī£ā)n^ to Ī£ā, where Ī£ = {a, b}. Show that concatenation is primitive recursive. (Although there are many different ways of doing this, some lead to much cleaner defi- nitions of concatenation than others. We would like a clean definition.) Exercise Define a notion of primitive recursive function from the integers to the integers. Show that subtraction is primitive recursive. (Although there are many different ways of doing this, some lead to much cleaner definitions of subtraction than others. We would like a clean definition.) Exercise Show that there is a JAVA program computing the Successor func- tions, Projection functions, and the Zero function. We claim that the set of primitive recursive functions are ācomputable.ā To back this up, we prove the following
Theorem 1.10 Every primitive recursive function can be computed by a JAVA program
Proof: We prove this by induction on the formation of a primitive recur- sive function. More formally, by induction on the number of steps used to derive the primitive recursive function. (WARNING: the name of the thing we will be inducting on is m, NOT n as is customary. n will be the number of arguments of the primitive recursive function being discussed.) BASE CASE:
The only primitive recursive functions that can be derived with only one step are the functions Si(x 1 ,... , xn), Ļi(x 1 ,... , xn), and Z(x 1 ,... , xn). These are all computable by a JAVA program by the Exercise above. INDUCTION
STEP: Let f (x 1 ,... , xn) be a function that is primitive recursive by a deriva- tion of m + 1 steps. If the last rule used in the derivation of f (x 1 ,... , xn) is either the Zero rule, Projection rule, or Successor rule then f (x 1 ,... , xn) is one of those functions, and thus by the exercise f (x 1 ,... , xn) is primitive recursive. If the last rule used was composition then there are functions g 1 (x 1 ,... , xn), g 2 (x 1 ,... , xn),.. ., gk(x 1 ,... , xn), h(x 1 ,... , xk) which are primitive recursive such that each of those function takes ⤠m steps to derive, and
f (x 1 ,... , xn) = h(g 1 (x 1 ,... , xn),... , gk(x 1 ,... , xn))).
In particular, take x = n to get
F (n) = U (n, n).
But by the definition of F via the JAVA program
F (n) = U (n, n) + 1.
This is a contradiction! Hence F is not computed by any primitive recursive function.
How important is Theorem 1.11? The theorem itself seems to just say that PRIMITIVE RECURSIVE is not the notion we need, and perhaps some other notions will suffice. However, the proof of Theorem 1.11 was not particular to primitive recursive functions, or to JAVA. Any formalism that attempts to capture all the functions that are computable is going to run into the same kind of problem (namely, an analog of Theorem 1.11) as primitive recursive functions did. This is formalized in the following exercise. Exercise Let {f 1 , f 2 , f 3 ,.. .} be a set of functions in one variable. Assume that the function g(i, x) = fi(x) is JAVA computable. Show that there is a function h that is JAVA computable, but h is not one of the fi. How to get around this dilemma? We take this point up in the next section. Although the function in Theorem 1.11 is not primitive recursive, it is contrived. It was defined for the sole purpose of not being primitive recursive and would not arise in practice. Are there ānaturalā JAVA computable functions that are not primitive recursive? We define a JAVA-computable function which is not primitive recursive which we consider ānatural.ā Since naturalness is in the eye of the beholder, you should feel free to disagree as to the naturalness of the function.
Def 1.12 Ackermanās function is the function defined by
A(0, y) = y + 1 A(x + 1, 0) = A(x, 1) A(x + 1, y + 1) = A(x, A(x + 1, y))
It is easy to see that Ackermanās function is JAVA computable. We will not prove that it is not primitive recursive, but we give an idea by giving a list of intuitions:
The primitive recursive functions were an attempt to pin down formally what it means for a function to be computable. It failed since we could construct a program that computed a function that was JAVA-computable (hence computable) but, not primitive recursive (this was Theorem 1.11). The proof of Theorem 1.11 was not particular to primitive recursive func- tions, or to JAVA. As noted after the theorem, any formalism that attempts to capture all the functions that are computable is going to run into the same kind of problem (namely, an analog of Theorem 1.11) as primitive recursive functions did. How to get around this dilemma? One is to give up our hope of pinning down the set of functions that are computable and defined everywhere, and instead be content with looking at the partial functions that are computable. This also takes care of the problem that JAVA programs donāt always halt.
Def 2.1 A partial function is a function whose domain is a subset of N. A total function is a function whose domain is N. We denote the domain of a partial function f by domain(f ).
We will add a basic way of generating one function from another which will allow functions to not always be defined, yet is basic and is something that machines can really do. Intuitively, we allow the operation of being
We will now take a different approach to pinning down what is meant by ācomputable.ā This definition is motivated by actual computers and resem- bles a machine. The definition is similar to that of a Deterministic Finite Automaton, or Push Down Automaton, but it can do much much more. Keep in mind that our final goal is to show that this model can compute a lot of functions. We first give the formal definition, and then explain it intuitively.
Def 3.1 A Turing Machine M is a quintuple (Q, Σ, Γ, q 0 , h) where
The machine acts in discrete steps. At any one step it will read the symbol in the ātape squareā, see what state it is in, and do one of the following:
We now formally say how the machine computes a function. This will be followed by intuition.
Def 3.2 Let M be a Turing Machine. An Instantaneous Description (ID) of M is a string of the form α 1 qα 2 where α 1 , α 2 ā Ī£ā, q ā Q, and the last symbol of α 2 is not B. Intuitively, an ID describes the current status of the TM and Tape.
Def 3.3 Let M be a Turing Machine. Let α 1 , α 2 , α 3 , α 4 ā Ī£ā, and q, qā²^ ā Q. Let α 1 = x 1 x 2 Ā· Ā· Ā· xk, and α 2 = xk+1xk+2 Ā· Ā· Ā· xn. The symbol α 1 qα 2 `M α 3 qā²Ī± 4 means that one of the following is true:
Intuitively, the above definition is saying that if the Turing Machine is in ID C, and C `M D, then after one more move the TM will be in D. The next definition is about what will happen after many moves.
Def 3.4 If C and D are IDs then C ā M D means that either C = D or there exist a finite set of IDs C 1 , C 2 ,... , Ck such that C = C 1 , for all i, CiM Ci+1, and Ck = D.
Def 3.5 Let M be a Turing Machine. Recall that the partial function com- puted by Turing Machine M is the following partial function: f (x) is the unique y (if it exists) such that xq 0 `ā M yh. If no such y exists then M (y) is said to diverge.
Intuitively we start out with x laid out on the tape, and the head looking at the rightmost symbol of x. The machine then runs, and if it gets to the halt state with the condition that there are only blanks to the right of the head, then the string to the left of the head is the value f (x). For examples of Turing machines, and exercises on building them to do things, see Lewis and Papadimitriouās text āElements of the Theory of Com- putation.ā, or the Hopcroft-Ullman White book. Other books also contain this material. Note that, just like a computer, the computation of a Turing machine is in discrete steps.
Def 3.6 Let Me be a Turing Machine and s be a number. The partial function computed by Me,s is the function that, on input x, runs Me(x) for s steps and if it has halted by then, outputs whatever Me(x) output, else diverges.
T (n) steps on inputs of length n can be computed by a 2-tape machine in T (n) log T (n). (See Hopcroft-Ullman, the White book.) Other enhancements to a Turing Machine such as extra heads, two- dimensionality, allowing a 2-way infinite tape, do not add power. Note that a Turing Machine with many added features resembles an actual computer. Exercise Discuss informally how to convert various variants of a Turing Machine to a 1-tape 1-head 1-dim Turing Machine. Comment on how runtime and number of states are affected.
By using variations of Turing Machines it would not be hard to show that standard functions such as addition, multiplication, exponentiation, etc. are all computable by Turing Machines. We wish to examine functions that, in some sense, take Turing Machines as their input. In order to do this, we must code machines by numbers. In this subsection we give an explicit coding and its properties. The actual coding is not that interesting or important and can be skipped, but should at least be skimmed to convince yourself that it really can be carried out. The properties of the coding are very important. A more abstract approach to this material would be to DEFINE a numbering system as having those properties. We DO NOT take this approach, but will discuss it at the end of this section.
Def 5.1 A Godelization is an onto mapping from N to the set of all Turing Machines such that given a Turing Machine, one can actually find the number mapped to, and given a number one can actually find the Turing Machine that maps to it.
We define a Godelization. Let M = (Q, Σ, Γ, q 0 , h) be a Turing Machine. We assume the following:
We first show how to encode a rule as a number: Let q 1 , q 2 ā Q and Ļ 1 , Ļ 2 ā Ī£. (By our convention, q 1 , q 2 , Ļ 1 , Ļ 2 are numbers). The rule Ī“(q 1 , Ļ 1 ) = (q 2 , Ļ 2 )
is represented by the number 2q^1 3 Ļ^1 5 q^2 7 Ļ^2. The representations for rules that have L or R in the last component are defined similarly. In any case we denote the rule that says what Ī“(q, Ļ) does by c(q, Ļ). We now code the entire machine M as a number. Let pi denote the ith prime. Let ćā, āć be such that the map (i, j) ā ći, jć is a bijection from N Ć N to N which is computable by a Turing Machine. The Turing Machine M is coded by the number
ā^ n
i=
ā^ m
j=
pc ći,j(i,jć)
With our current coding, although all Turing Machines correspond to numbers, not all numbers correspond to Turing Machines. We alleviate this by convention:
Def 5.2 Turing Machine Mi is the machine corresponding to number i, if such a machine exists, and is the machine ({q}, {a}, Ī“, q, q) where Ī“(q, a) = (q, a), (i.e. the easiest machine that halts on all inputs) otherwise. The function computed by Mi is denoted Ļi We may also say that i is the index of Mi or Ļi.
It is easy to see that a program could be written to, given a Turing Machine M , find x such that M = Mx. (We will later be assuming that a Turing Machine could carry out such a task). It is also easy to see that a program could be written to, given a number x, determine Mx. The number x codes all the information about Mx that one might wish to know. Exercise Informally show that the following functions are computable:
Theorem 5.5 (Universal Turing Machine Theorem, or Enumeration Theo- rem) There is a Turing Machine M such that M (x, y) is the result of running Mx on y. (Note that this might diverge.)
Convention 5.6 We will always denote the Universal Turing Machine by U.
We will be using the s-m-n Theorem and the existence of a Universal Turing Machine, throughout this course (usually implicitly). A more abstract approach would have been to build these two properties into definitions:
Def 5.7 An acceptable programming system (henceforth APS) is a list of all the Turing computable functions Ļ 1 , Ļ 2 ,... such that the s-m-n Theorem, and the enumeration theorem are true relative to that numbering.
One concern might be that if we prove theorems for our particular APS will it be true for all APSās. The following theorem says YES, as it says that all APSās are essentially the same.
Theorem 5.8 (Rogers isomorphism theorem) Let Ļ 1 , Ļ 2 ,... and Ļ 1 , Ļ 2 ,... be two APSās. There exists a bijection f , computable by a Turing Machine, such that Ļi ā” Ļf (i).
Many models of computation have been proposed. All of them have a notion of discrete time steps, as does a Turing Machine.
These models of computation had very different motivations. Now for the surprise: THEY ALL COMPUTE THE SAME CLASS OF (PARTIAL) FUNCTIONS! In addition, the time loss in going from one to the other is (in most cases) only a polynomial e.g. if a Markov algorithm can compute a function f and use T (n) steps on inputs of length n, then there is a Turing Machine that can computes f and takes T (n)k^ steps on inputs of length n. We have been trying to formalize what it means for a function to be āintuitively computable.ā This seems like a hard concept to define rigorously. But several people who tried to formalize this notation came to the SAME class. This leads one to make a leap of faith and conclude that yes indeed, this class of functions suffices: Churchās Thesis: Any (partial) function that is intuitively computable (e.g. we can write down a program for it in some informal language) is computable by a Turing Machine (thus by the Ī»-calculus, etc.). For the remainder of this course we will speak in terms of Turing Ma- chines, but will virtually never have to worry about the formal details of a machine. To show a function is computable we will write an informal program that computes it, and show that it works. We repeat two definitions that we made earlier, noting that in both the term āTuring Machineā can be replaced by any of the above models.
Def 6.1 A function computed by a Turing Machine is a partial computable function. If the function is total then we say it is computable.
We now give examples of computable functions.
Functions that are almost always 0 are very easy to compute: just store a table.
Example 7.1 Let f be the function that is f (0) = 12, f (10) = 20, f (14) = 7, f is zero elsewhere. The function f is easily seen to be computable. Just write a program with a lot of āifā statements in it. It will output 0 on values that are not 0,10, or 14.
In the above example, the function f was given EXPLICITLY so it was easy to write the program. Even if a function is not given to us explicitly, we may be able to show that it is computable.
Example 7.2 Let f be the function that is nonzero on values less than 10, and on those values always outputs the input squared. From the description we can deduce that f (1) = 1, f (2) = 4, f (3) = 9, f (4) = 16, f (5) = 25, f (6) = 36, f (7) = 49, f (8) = 64, f (9) = 81, and f is zero elsewhere.
In the above example, even though we were not given the function ex- plicitly, we could derive an explicit description from what was given. In the next example this is no longer the case, but the function is still computable. INTERESTING EXAMPLE One needs to know what the Goldbach Conjecture to appreciate this example: Goldbachās conjecture is still unknown. It is: every even is the sum of two primes.
Example 7.3 Let f be the function such that if Goldbachās conjecture is true then f is 74 on all numbers less than 4 and zero elsewhere, and if Gold- bachās conjecture is false then f is 17 on all less than 3 and zero elsewhere. Since we donāt know whether or not Goldbackās Conjecture is true, WE DO NOT KNOW what f is. But we DO know that EITHER
So THERE EXISTS a JAVA program for f. In fact, we can write down two programs, and know that one of them computes f , but we donāt know which one. But to show that f is computable WE DO NOT CARE WHICH ONE! The definition of computability only said THERE EXISTS a JAVA program, it didnāt say we could find it.
An even more interesting example:
Example 7.4 Let f be the following function: if Goldbachās conjecture is false then f is 888 on the the smallest even n such that n cannot be written as the sum of two primes, and 0 elsewhere. if Goldbachās conjecture is true then f is always 0. If Goldbachās conjecture is false then f is one of the following.
The fact that this list is infinite should not bother us. It is still the case that f is computable since one of the functions on this list is f , or f is always
These functions are computable EVEN THOUGH WE CANāT FIND CODE FOR THEM. If I asked you what a computable function was you might say f is computable if there exists a TURING MACHINE to compute it. I might say f is computable if THERE EXISTS a Turing machine to compute it. The key thing is that THERE EXISTS a Turing machine, even if I canāt find it. AN EXAMPLE OF āI DO NOT KNOW AND I DO NOT CAREā, that is not related to computer science:
Example 7.5 Do there exists two irrational numbers x and y such that xy is rational? I will show you pairs (a, b), and (c, d) such that either