0% found this document useful (0 votes)
8 views

Ritchie Dissertation

Phd Thesis Dennis Ritchie

Uploaded by

nks
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
8 views

Ritchie Dissertation

Phd Thesis Dennis Ritchie

Uploaded by

nks
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 181
Program Structure and Computational Complexity Dennis M, Ritchie y |

‘SYNOPSIS The major purpose of this thesis is to show that when the Language in which computations are described is restricted suitably, there can be an effective relationship between the complexity of a progran and that of the computation it describes. We give two examples. ‘The first exanple is that of Loop programs. A Icop program is a finite sequence of instructions for manipulating noz-negative, un- ounded integers stored in registers; the instructions allow incre- menting registers by unity, setting registers to zero, and moving the contents of registers. The only control instructions consist of Toops; there is a kind of Loop for each number n>1. A Loop with n= L causes the execution of a portion of the program to be repeated a predetermined number of times equal to the current contents of a register. Loops may be nested, one inside another, to any fixed depth; ‘out Loops with n> 1 are defined so as to make a Loop of type n+ 1 equivalent to @ varisble depth of nesting of Loops of type n. Bach Loop program is assigned an ordin al @, where O6, ty majorizes fy: of [15,16] and in general is a modification of the function Wy used te definition of f, for finite ordinals & is the same as the f, by Robbin [25] for mich the sane purposes. The major results on Loop prograns can be stated as follows: for each Loop progran P assigned ordinal a there is a number gf’p effectively derived 2rom P such that Pwith inputs x)..0m, requires no more than £P)(naxtay ».--9%,)) steps to halt (Theoren (3.6)). The notation #(P) means f,, composed with itself p times. There are some programs P assigned ordinal a which do in fact require 2{P)(x) steps to halt when given input x (meoren (4.7). A precise definition of the number of steps used by @ program is a by-product of a formalization of Losp prograns pre- sented in §2. Further results on Loop programs, and much of the rest of the thesis, use heavily the notion of computation-time closure. A set of functions is computation-tine closed when both of the following are true: if a function f is in the set, a motion b is in the set where b bounds the tine required to compute f one Turing machines if b is in the set and b bounds the time required to compute fon a Turing machi 2, f is in the set. S2 If {, is the class of functions computable by prograns assigned an ordinal less than or equal to a, each {, for a> 2 is computation- time closed. This allows us to show the following: each class {, for @ > 2 is closed under Limited recursion (Theorem (6.8)); each class £ for a> 2 can be characterized in arithmetic terms, without refer- ence to Turing machines or Loop programs (Theorem (6.5))3 if a pro- gram P assigned ordinal & requires only 2) steps as a function of its inputs where 6 2 (Theoren (2.5))3 42 fe Ry f(x,1-++)%,) can be computed by a Turing mehine in of) CP) maces )+++)%,)) steps for some p which is effectively found from the recursion equations defining f (Theorem (2.1))s fy,q € Ry (Theorem (8.3). These facts alone show: for o> 2, Sy4q = Ry (Theorem (10.1)). 93 The sane kind of techniques are applied to the hierarchies of Axt [2], Grzegorezyk [9] and Robbin [25]. All of these hierarchies are shown to be identical to a portion of the fy and Ry hierarchies, and thus to each other. Specifically, if @, a 4 (Theorem (10.4)); if &, aca, are the Graegorezyk classes, 1, = &,, for 2 2 (Theorem (10.8)). ALL of these results are straightforward ial modification of the Robbin classes, f, = @ o a 1} these are written LOOP(1), 100?(2), ete. Bach kind of LOOP instruction names a register whose contents control the looping. In the case of the instruction "LOOP(1) x", for example, X may be any register name. This instruction causes the portion of the program between itself and its matching END to be re~ peated a munber of times equal to the contents of X at the time the LOOP is encountered; subsequent changes to X do not affect the number of times the repetition occurs. ‘Thus a Loop introduced by LOOP(1) is entirely comparable to the DO loop of FORTRAN and to the most usual cases of the for of Algol and the THROUGH of MAD. TI similarity 4 not accidental, for part of the motivation for the study of Loop pro- grams is to study the power of this construction. ) Loops may contain other Loops; that is, Loops may be nested to any fixed depth. This is the motivation for the existence of L00P(n) the effect of LOOP(n+1) is defined so as to instructions for n > make such @ Loop equivalent to a variable depth of nesting of L00P(n) Loops. In particular, the program LooP(n +1) X a =D where n> 1, X is a register name, and Q is a program, equivalent to the program 10P(n) x : x WooP(n) X where x is the number in X initially; that is, we have a nest of L00P(n) Loops of depth x. There are no constructions real pro- gramming languages comparable to 100P(n) where n > 1. To each Loop program an ordinal O is assigned, where a O and Xa register name, is assigned a= 6+0". Then, for example, oa program which uses only LOOP(1) instructions is as- signed a finite ordinal equal to the greatest depth of nesting of Loops in the program. The ordinal assigned to a program is the measure of complexity of the program. The notion of computation by Loop program can be formalized; a by-product of the formalization is @ precise definition of the running time of a given program as a function of its inputs. The running time measures the number of individual instruction executions required to complete a program and in a sense the justification for introducing the somewhat opaque formalism is to make reasonable the claim that the complexity of @ calculation is measured accurately vy its running time. 5 The basic result on Loop programs is the Bounding Theorem (3.6). We introduce for each ordinal a, a 0. Then Ff) © FB (2) Thus at limit ordinals, f, ‘a 38 defined by diagonalization over a certain sequence (f3,) of functions where By B, f, majorizes (bounds almost everywhere) the function f,. Given the function f,, the Bounding Theorer is: if P is a pro- gram assigned ordinal a, re is a fixed number p, effectively found from P, such that the runnt g tine of P with inputs x))---5%, 1s bounded vy t(°)(naxt om) y “~ By fixing upon one or more registers for input ard a register for output, we associate with a Loop progran a functicn computed by that progran; the class of functions computable by Loop programs assigned ordinals less than or equal toa is called f,. It is an inmediate consequence of the Bounding Theorem that every function fe Sy hes ap so f(x ym) $ APM maxtayse-s%)). Also, for > 2 3 itis im each @ f(x)s it mediate that the classes $, form a hierarchy, for it is easily shom (ce) B several of the goals looked for in the study of Loop programs have that if a>B, £,(x) > £,°7(x) for each ¢ and almost ell x. Already been achieved, for it follows first that every progran assigned or- inal o consumes no more than #(P)(nax(x, )-++5x,)) steps when given input x,,.-.94,, and second thet there are some programs assigned ordinal a waich actually do require this many steps to halt. Thus the ordinal assigned e program is a reasonable measure of the (po- tential) complexity of the computation described by the program. The further study of Loop programs, and in fact mch of the re- mained of the thesis, is heavily concerned with the property of com putation-time closure of a set of functions defined as follows: first, when a function is in the set, it can be computed by # Turing machine in a number of steps which is bounded, as a function of the inputs, by another function in the set; and second, if a bound on the computation time of a function is in the set, the function itself is in the set. Each class {, for a >2 is computation-time closed. ‘The first require- ment is met by combining enonstration that Bounding Theorem w Toe a Turing machine can simlate an arbitrary Loop program vhile con- suming a number of steps which is an {2 function of the running time of the Loop program; the second ty finding a Loop program which simlates a Turing machine calculation carried out for a given number of stepa, and then substituting the known bound on the length of the computation into the simalation program. aces the conputation-tine of fy leads immediately to several theorens; for example, if it is known that a progran assigned or- dinal a actuelly has a running tine bounded ty £{°) vnere 2 2, is closed under the oper- ation of lini ed recursion (see Grzegorczyk [9]; that each class {,, a> 2, can be characterized in purely arithmetic terms, without re-" ference eit to Turing machines or Loop programs; and that every recursive function primi ¢ ordinal a. s in {, for some fi Our second example ia that of the miltiple recursive functions. These are, for our purposes, precisely those functions definable by certain formal systens of equations. We imagine a language contain- ing symbols for constants, variables, function letters, and appropriate punctuation, combined i ch a way as to represent definitions of effectively computable functions. This language is simply a formal version of the informal def of funct: 1s by means of various kinds of recur: neluding, example, primitive recursi Unlike x: 12] however, we place cert resti tions rm of the systems of equations particular, an equation a function in terms of already-defined functions must be an instance of one of several schemata, namely those of substitution and n- recursion for some fixed integer n>1. Substitution simply means obtaining new function by means of explicit transformation or composition of other functions. The schema of n-recursion allows defining a function f(x,,..-)x,) in terms of known functions and values of f itself at arguments z,,...,z, such that the n-tuple 2ys+++52, is lexicographically less than x,,...,x,- Tke very form of the schema of n-recursion is such as to ensure that the set of equations constituting an instance of n-recursion actually does de- fine a function effectively. An ordinal a < i can be effectively attached to each formal system of equations satisfying certain purely syntactic requirements. Letting @, be the class of functions definable by systeus of equations with ordinals less than or equal toa, another hierarchy results which is equivalent to the following: Ry consists of the closure under sub- stitution of the constant and identity functions; @, for every a>0 consists of the closure under substitution of all func ons f for which on there exist 6 and n soa = 6+)" and f is definable by (n +1)-recur: fron functions in @, For each A> 1 the functions in U | @, are called n-recursive; 2 np % a1. Likewise, each class @, for a> 2 is computation-time closed; © @y for this is established by considering the number of steps a Turing machine would require to carry out the evaluation of a function from its defining equations. Then the theoren £ = @, fora >2 is in- mediate. For if f¢ £,\,5 £(x,,++-.,) can be computed on a Turing machine in no more than ¢(P)(max(x,,...,x,)) steps; but the latter function is in By and so by the computation-time closure of Rye fe B® The converse argument is identical. Tt is.here that the concept of computation-time closure is most important. For to show directly thet S,= 8, 1a quite aifriewt. In particular, if a 1 (5) END Here "x" and "y" may be replaced by any names for registers, and the "Oo" of "X = 0" is to be read “zero” (1.2) Definition, The élass L of Loop programs is U ‘gy where & ranges over ordinals < &, and where I, is the smallest class satisfying (i) If@= 0, ly is the class of finite sequences of type (1), (2), ana (3) instructions, (44) If B € Ig and 8 y, 0 otherwise. Suppose now that the interpretation of the effect of a 100P(n) - END pair has been given for some n > 1, and P is a Loop Program. Say that the initial contents of register X are x > 1. Then we interpret the program Loop(n +1) X PB END as being identical to WooP(n) x qooP(n) x - 1W00P(n) x END END END Where the 100P(n) - END pairs are nested to depth x. If x is zero initially, the effect is the same as Woor(1) Xx P END That is, P is not executed at all. (1.4) Example. Suppose we have the Ly program woor(2) x X= Xe END and X contains 2. Then the program is equivalent to Loop(1) x Loor(1) x X= X41 END =ND and execution of the program would leave 8 in register X. Notice that the depth of nesting is not affected by changes to X. (1.5) Example. If the initial contents of register X are 2, the Lg program LooP(3) X x=Xs1 END is equivalent to the program LooP(2) X LooP(2) X X= X41 ‘END END which is in turn equivalent to Toop(1) x LooP(1) x WooP(z) X QyXake1 END END END Now when the program Q indicated above is executed, the contents of X will change to 8, by Example (1.4). But then the next time Q is executed, Q will be equivalent to woor(1) Xx 5 depth 8 Woor(1) x X=xX+1 p depth 8 Thus the expansion of a LO0P(n+1) - END pair in terms of 100P(n) - END depends on the contents of the associated register at the time the LOOP is encountered. Finding the number left in register X by the program of (1.5) is left as an exercise for the persistent reader. §2. Although it would be possible to characterize formally the notion of computation by Loop program directly in terms of the in- formal discussion above, the examples, especially (1.5), should have convinced the reader that such a characterization would tehd to be quite complicated; more seriously, the individual steps in a com putation ty a Loop program would in themselves involve considerable computation. This is undesirable because we will be attempting to measure the computational complexity of a function by the number of steps required to compute it. If the individual steps turn out to be nearly as complicated as the function itself, this measure can hardly be claimed to have much significance. We will circumvent this kind of objection by giving a definition of computation by Loop program whose individual steps are quite ele- mentary. The price that mist be paid for this characterization is that it is no longer clear from the definition that Leop programs be- have as outlined in §1; thus, e theorem must be proved which states in effect that Loop programs operate as desired. The proof, unfor- tunately, is rather tedious; but given the theorem, we can select whichever version of computation is more appropriate to the case at hand. To begin this alternate cheracterization, associate with each Program P not only the registers Reg (P), but also a switch and a pushdown store; the latter are used by LOOP and END instructions. (2.1) Definition. A pushdown store is either the single object (0) or the pair (t,p) where t is an n-tuple of integers and p is a pushdown store. If a push- down store is (0) it is empty. The depth of (0) is (0), and if p is a pushdown store whose depth is m, the depth of (t,p) is m+1. For the remainder of this section, let P be a Loop program with Reg (P) = (K,) and let P consist of the sequence I) ,Ip,...,T, of instructions where e >0. There is of course no loss of general- ity in restricting Reg (P) in this way. (2.2) Definition. A state of P is an (r+3)-tuple (x,,i,4,p) where x, 20 for 1

You might also like