LOOP (programming language)
LOOP is a language that precisely captures primitive recursive functions.[1] The only operations supported in the language are assignment, addition, and looping a number of times that is fixed before loop execution starts.
The LOOP language was introduced in a 1967 paper by Albert R. Meyer and Dennis M. Ritchie.[2] Meyer and Ritchie showed the correspondence between the LOOP language and primitive recursive functions.
Dennis M. Ritchie formulated the LOOP language, which was also the topic of his unpublished Ph.D. thesis. [3][4]
It was also presented by Uwe Schöning, along with GOTO and WHILE.[5]
Features
Each primitive recursive function is LOOP-computable and vice versa.[5]
In contrast to GOTO programs and WHILE programs, LOOP programs always terminate.[6] Therefore, the set of functions computable by LOOP-programs is a proper subset of computable functions (and thus a subset of the computable by WHILE and GOTO program functions).[7]
An example of a total computable function that is not LOOP computable is the Ackermann function.[8]
Formal definition
Syntax
LOOP-programs consist of the symbols LOOP
, DO
, END
, :=
, +
and ;
as well as any number of variables and constants. LOOP-programs have the following syntax in modified Backus–Naur form:
Here, are variable names and are constants.
Semantics
If P is a LOOP program, P is equivalent to a function . The variables through in a LOOP program correspond to the arguments of the function , and are initialized before program execution with the appropriate values. All other variables are given the initial value zero. The variable corresponds to the value that takes when given the argument values from through .
A statement of the form
xi := 0
means the value of the variable is set to 0.
A statement of the form
xi := xi + 1
means the value of the variable is incremented by 1.
A statement of the form
P1; P2
represents the sequential execution of sub-programs and , in that order.
A statement of the form
LOOP x DO P END
means the repeated execution of the partial program a total of times, where the value that has at the beginning of the execution of the statement is used. Even if changes the value of , it won't affect how many times is executed in the loop. If has the value zero, then is not executed inside the LOOP
statement. This allows for branches in LOOP programs, where the conditional execution of a partial program depends on whether a variable has value zero or one.
Creating "convenience instructions"
From the base syntax one create "convenience instructions". These will not be subroutines in the conventional sense but rather LOOP programs created from the base syntax and given a mnemonic. In a formal sense, to use these programs one needs to either (i) "expand" them into the code – they will require the use of temporary or "auxiliary" variables so this must be taken into account, or (ii) design the syntax with the instructions 'built in'.
- Example
The k-ary projection function extracts the i-th coordinate from an ordered k-tuple.
In their seminal paper [2] Meyer & Ritchie made the assignment a basic statement. As the example shows the assignment can be derived from the list of basic statements.
To create the instruction use the block of code below. Observe the use of the hint mentioned above:
=equiv
xj := 0; LOOP xi DO xj := xj + 1 END
Again, all of this is for convenience only; none of this increases the model's intrinsic power.
Example Programs
Addition
Addition is recursively defined as:
Here, S should be read as "successor".
In the hyperoperater sequence it is the function
can be implemented by the LOOP program ADD( x1, x2)
LOOP x1 DO x0 := x0 + 1 END; LOOP x2 DO x0 := x0 + 1 END
Multiplication
Multiplication is the hyperoperation function
can be implemented by the LOOP program MULT( x1, x2 )
x0 := 0; LOOP x2 DO x0 := ADD( x1, x0) END
The program uses the ADD() program as a "convenience instruction". Expanded, the MULT program is a LOOP-program with two nested LOOP instructions. ADD counts for one.
More hyperoperators
Given a LOOP program for a hyperoperation function , one can construct a LOOP program for the next level
for instance (which stands for exponentiation) can be implemented by the LOOP program POWER( x1, x2 )
x0 := 1; LOOP x2 DO x0 := MULT( x1, x0 ) END
The exponentiation program, expanded, has three nested LOOP instructions.
Predecessor
The predecessor function is defined as
- .
This function can be computed by the following LOOP program, which sets the variable to .
/* precondition: x2 = 0 */ LOOP x1 DO x0 := x2; x2 := x2 + 1 END
Expanded, this is the program
/* precondition: x2 = 0 */ LOOP x1 DO x0 := 0; LOOP x2 DO x0 := x0 + 1 END; x2 := x2 + 1 END
This program can be used as a subroutine in other LOOP programs. The LOOP syntax can be extended with the following statement, equivalent to calling the above as a subroutine:
x0 := x1 ∸ 1
Remark: Again one has to mind the side effects. The predecessor program changes the variable x2, which might be in use elsewhere. To expand the statement x0 := x1 ∸ 1, one could initialize the variables xn, xn+1 and xn+2 (for a big enough n) to 0, x1 and 0 respectively, run the code on these variables and copy the result (xn) to x0. A compiler can do this.
Cut-off subtraction
If in the 'addition' program above the second loop decrements x0 instead of incrementing, the program computes the difference (cut off at 0) of the variables and .
x0 := x1 LOOP x2 DO x0 := x0 ∸ 1 END
Like before we can extend the LOOP syntax with the statement:
x0 := x1 ∸ x2
If then else
An if-then-else statement with if x1 > x2 then P1 else P2:
xn1 := x1 ∸ x2; xn2 := 0; xn3 := 1; LOOP xn1 DO xn2 := 1; xn3 := 0 END; LOOP xn2 DO P1 END; LOOP xn3 DO P2 END;
See also
References
- ^ Enderton 2012.
- ^ a b Meyer & Ritchie 1967.
- ^ "Discovering Dennis Ritchie's Lost Dissertation". CHM. 2020-06-19. Retrieved 2020-07-14.
- ^ "Program structure and computational complexity draft | 102790971 | Computer History Museum". www.computerhistory.org. Retrieved 2020-07-14.
- ^ a b Schöning 2008, p. 105.
- ^ Schöning 2008, p. 93.
- ^ Schöning 2001, p. 122.
- ^ Schöning 2008, p. 112.
Bibliography
- Axt, Paul (1966). "Iteration of relative primitive recursion". Mathematische Annalen. 167: 53–55. doi:10.1007/BF01361215.
- Axt, Paul (1970). "Iteration of primitive recursion". Journal of Symbolic Logic. 35 (3): 479. doi:10.1002/malq.19650110310.
- Calude, Cristian (1988). Theories of Computational Complexity. Vol. 35. North Holland Publishing Company. ISBN 9780080867755.
{{cite book}}
:|journal=
ignored (help) - Cherniavsky, John Charles (1976). "Simple Programs Realize Exactly Presburger Formulas". SIAM Journal on Computing. 5 (4): 666–677. doi:10.1137/0205045.
- Cherniavsky, John Charles; Kamin, Samuel Noah (1979). "A Complete and Consistent Hoare Axiomatics for a Simple Programming Language". Association for Computing Machinery. 26 (1): 119–128. doi:10.1145/322108.322120.
- Crolard, Tristan; Lacas, Samuel; Valarcher, Pierre (2006). "On the expressive power of the loop language". Nordic Journal of Computing. 13: 46–57.
- Crolard, Tristan; Polonowski, Emmanuel; Valarcher, Pierre (2009). "Extending the loop language with higher-order procedural variables". ACM Transactions on Computational Logic. 10 (4).
- Enderton, Herbert (2012). Computability Theory. Academic Press. doi:10.1145/1555746.1555750.
- Ibarra, Oscar H.; Leininger, Brian S. (1981). "Characterizations of Presburger Functions". SIAM Journal on Computing. 10 (1): 22–39. doi:10.1137/0210003.
- Ibarra, Oscar H.; Rosier, Louis E. (1983). "Simple Programming Languages and Restricted Classes of Turing Machines". Theoretical Computer Science. 26 (1–2): 197–220. doi:10.1016/0304-3975(83)90085-3.
- Kfoury, A.J.; Moll, Robert N.; Arbib, Michael A. (1982). A Programming Approach to Computability. Springer, New York, NY. doi:10.1007/978-1-4612-5749-3. ISBN 978-1-4612-5751-6.
- Matos, Armando B. (2015). "The efficiency of primitive recursive functions: A programmer's view". Theoretical Computer Science. 594: 65–81. doi:10.1016/j.tcs.2015.04.022.
- Machtey, Michael (1972). "Augmented loop languages and classes of computable functions". Journal of Computer and System Sciences. 6 (6): 603–624. doi:10.1016/S0022-0000(72)80032-1.
- Meyer, Albert R.; Ritchie, Dennis MacAlistair (1967). The complexity of loop programs. ACM '67: Proceedings of the 1967 22nd national conference. doi:10.1145/800196.806014.
- Minsky, Marvin Lee (1967). Computation: finite and infinite machines. Prentice Hall. doi:10.1017/S0008439500029350.
- Ritchie, Dennis MacAlistair (1967). Program structure and computational complexity (draft) (PDF).
- Ritchie, Robert Wells (November 1965). "Classes of recursive functions based on Ackermann's function". Pacific Journal of Mathematics. 15 (3): 1027–1044. doi:10.2140/pjm.1965.15.1027.
- Schöning, Uwe (2001). Theoretische Informatik-kurz gefasst (4 ed.). London: Oxford University Press. ISBN 3-8274-1099-1.
- Schöning, Uwe (2008). Theoretische Informatik-kurz gefasst (5 ed.). London: Oxford University Press. ISBN 978-3-8274-1824-1. DNB 986529222.
- Tsichritzis, Dennis C (1970). "Iteration of relative primitive recursion". Journal of the ACM. 17 (4): 729–738. doi:10.1145/321607.321621.
- Tsichritzis, Dennis C (1971). "A note on comparison of subrecursive hierarchies". Information Processing Letters. 1 (2): 42–44. doi:10.1016/0020-0190(71)90002-0.