The LOOP language was formulated in a 1967 paper by Albert R. Meyer and Dennis M. Ritchie.2 They showed the correspondence between the LOOP language and primitive recursive functions.
The language also was the topic of the unpublished PhD thesis of Ritchie.34
It was also presented by Uwe Schöning, along with GOTO and WHILE.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
Meyer & Ritchie proved that each primitive recursive function is LOOP-computable and vice versa.89
An example of a total computable function that is not LOOP computable is the Ackermann function.10
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, V a r := { x 0 , x 1 , . . . } {\displaystyle Var:=\{x_{0},x_{1},...\}} are variable names and c ∈ N {\displaystyle c\in \mathbb {N} } are constants.
If P is a LOOP program, P is equivalent to a function f : N k → N {\displaystyle f:\mathbb {N} ^{k}\rightarrow \mathbb {N} } . The variables x 1 {\displaystyle x_{1}} through x k {\displaystyle x_{k}} in a LOOP program correspond to the arguments of the function f {\displaystyle f} , and are initialized before program execution with the appropriate values. All other variables are given the initial value zero. The variable x 0 {\displaystyle x_{0}} corresponds to the value that f {\displaystyle f} takes when given the argument values from x 1 {\displaystyle x_{1}} through x k {\displaystyle x_{k}} .
A statement of the form
means the value of the variable x i {\displaystyle x_{i}} is set to 0.
means the value of the variable x i {\displaystyle x_{i}} is incremented by 1.
represents the sequential execution of sub-programs P 1 {\displaystyle P_{1}} and P 2 {\displaystyle P_{2}} , in that order.
means the repeated execution of the partial program P {\displaystyle P} a total of x {\displaystyle x} times, where the value that x {\displaystyle x} has at the beginning of the execution of the statement is used. Even if P {\displaystyle P} changes the value of x {\displaystyle x} , it won't affect how many times P {\displaystyle P} is executed in the loop. If x {\displaystyle x} has the value zero, then P {\displaystyle P} 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.
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'.
The k-ary projection function U i k ( x 1 , . . . , x i , . . . , x k ) = x i {\displaystyle U_{i}^{k}(x_{1},...,x_{i},...,x_{k})=x_{i}} extracts the i-th coordinate from an ordered k-tuple.
In their seminal paper 11 Meyer & Ritchie made the assignment x j := x i {\displaystyle x_{j}:=x_{i}} a basic statement. As the example shows the assignment can be derived from the list of basic statements.
To create the assign {\displaystyle \operatorname {assign} } instruction use the block of code below. x j := assign ( x i ) {\displaystyle x_{j}:=\operatorname {assign} (x_{i})} =equiv
Again, all of this is for convenience only; none of this increases the model's intrinsic power.
Addition is recursively defined as:
Here, S should be read as "successor".
In the hyperoperater sequence it is the function H 1 {\displaystyle \operatorname {H_{1}} }
H 1 ( x 1 , x 2 ) {\displaystyle \operatorname {H_{1}} (x_{1},x_{2})} can be implemented by the LOOP program ADD( x1, x2)
Multiplication is the hyperoperation function H 2 {\displaystyle \operatorname {H_{2}} }
H 2 ( x 1 , x 2 ) {\displaystyle \operatorname {H_{2}} (x_{1},x_{2})} can be implemented by the LOOP program MULT( x1, x2 )
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.
Given a LOOP program for a hyperoperation function H i {\displaystyle \operatorname {H_{i}} } , one can construct a LOOP program for the next level
H 3 ( x 1 , x 2 ) {\displaystyle \operatorname {H_{3}} (x_{1},x_{2})} for instance (which stands for exponentiation) can be implemented by the LOOP program POWER( x1, x2 )
The exponentiation program, expanded, has three nested LOOP instructions.
The predecessor function is defined as
This function can be computed by the following LOOP program, which sets the variable x 0 {\displaystyle x_{0}} to p r e d ( x 1 ) {\displaystyle pred(x_{1})} .
Expanded, this is the program
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:
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.
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 x 1 {\displaystyle x_{1}} and x 2 {\displaystyle x_{2}} .
Like before we can extend the LOOP syntax with the statement:
An if-then-else statement with if x1 > x2 then P1 else P2:
Enderton 2012. - Enderton, Herbert (2012). Computability Theory. Academic Press. doi:10.1145/1555746.1555750. https://doi.org/10.1145%2F1555746.1555750 ↩
Meyer & Ritchie 1967. - 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. https://doi.org/10.1145%2F800196.806014 ↩
Brock 2020. - Brock, David C. (19 June 2020). "Discovering Dennis Ritchie's Lost Dissertation". CHM. Retrieved 14 July 2020. https://computerhistory.org/blog/discovering-dennis-ritchies-lost-dissertation/ ↩
Ritchie 1967. - Ritchie, Dennis MacAlistair (1967). Program structure and computational complexity (draft) (Thesis). Computer History Museum (CHM). p. 181. Retrieved 16 October 2024. https://www.computerhistory.org/collections/catalog/102790971 ↩
Schöning 2008, p. 105. - Schöning, Uwe (2008). Theoretische Informatik-kurz gefasst (5 ed.). London: Oxford University Press. ISBN 978-3-8274-1824-1. DNB 986529222. http://www.dnb.de/EN/Home/home_node.html ↩
Schöning 2008, p. 93. - Schöning, Uwe (2008). Theoretische Informatik-kurz gefasst (5 ed.). London: Oxford University Press. ISBN 978-3-8274-1824-1. DNB 986529222. http://www.dnb.de/EN/Home/home_node.html ↩
Schöning 2001, p. 122. - Schöning, Uwe (2001). Theoretische Informatik-kurz gefasst (4 ed.). London: Oxford University Press. ISBN 3-8274-1099-1. ↩
Schöning 2008, p. 112. - Schöning, Uwe (2008). Theoretische Informatik-kurz gefasst (5 ed.). London: Oxford University Press. ISBN 978-3-8274-1824-1. DNB 986529222. http://www.dnb.de/EN/Home/home_node.html ↩