LOOP is a simple register language designed to precisely capture the primitive recursive functions. The language is derived from the counter-machine model. Like the Counter machines the LOOP language comprises a set of one or more unbounded registers, each of which can hold a single non-negative integer. A few arithmetic instructions operate on the registers: inc x (increment), dec x (decrement: max ( 0 , x − 1 ) {\displaystyle \operatorname {max} (0,x-1)} ), x = 0 (clear), and x = y (copy). The only control flow instruction is LOOP x: .... It causes the instructions within its scope to be repeated x {\displaystyle x} times. In contrast to GOTO programs and WHILE programs, LOOP programs always terminate. The running time is known in advance. 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). The LOOP language admits several variants, distinguished by their set of basic instructions. Four such variants, L0 – L3, are distinguished in this article. Despite differences in syntactic convenience and loop-nesting depth, all variants compute exactly the primitive recursive functions. At shallow nesting depths, the choice of basic instructions affects which functions are reachable. The simple functions are exactly the functions computable at depth 1 in L1; the Presburger-definable functions are exactly the functions computable at depth 1 in L3; the Kalmár elementary functions are exactly the functions computable at depth 2 in L1, L2, and a fortiori L3. From depth 3 onward all variants agree. An example of a total computable function that is not LOOP-computable is the Ackermann function.
History The LOOP language was formulated in a 1967 paper by Albert R. Meyer and Dennis M. Ritchie. They showed the correspondence between the LOOP language and primitive recursive functions, proving that each primitive recursive function is LOOP-computable and vice versa. The language also was the topic of the unpublished PhD thesis of Ritchie. It was presented by Uwe Schöning, along with GOTO and WHILE.
Definition Several variants of the LOOP programming language have been defined, based on different sets of basic instructions. Despite these variations, they agree on the class of functions they compute: exactly the primitive recursive functions. However, when considering loop nesting depth —that is, the number of nested LOOP constructs allowed— the choice of basic instructions affects the expressive power at shallow depths. Four variants of the LOOP language are distinguished here:
L0: Minsky (1967); L1: Meyer & Ritchie (1967), Tsichritzis (1970), Machtey (1972), Beck (1975), Fachini & Maggiolo-Schettini (1979), Goetze & Nehrlich (1980), Calude (1988), Schöning & Pruim (1998), Tourlakis (2012), Matos (2015); L2: Tsichritzis (1971), Beck (1975), Kfoury & al (1982), Odifreddi (1989), Matos (2014); L3: Cherniavsky (1976), Cherniavsky & Kamin (1979), Kfoury (1980), Ibarra & Rosier (1983), Handley & Wainer (1999). In this presentation, the term "LOOP program" refers collectively to any of L0 – L3.
Syntax A LOOP program consists of a sequence of instructions, which modify a finite number of registers, any of which may contain a non-negative integer. If x and y are registers, define the following sets Bi of basic instructions:
B0 = {x = 0, inc x} B1 = B0 ∪ {x = y} B2 = B0 ∪ { dec x } B3 = B1 ∪ B2 For 0 ≤ i ≤ 3 {\displaystyle 0\leq i\leq 3} we define the loop language Li as the smallest set of programs generated by the following rules: 1. Every instruction s ∈ Bi is a program in Li. 2. If P and Q are in Li, then the sequential composition
is in Li. 3. If P ∈ Li, then
is in Li. Indentation determines block structure in a Python-like notation. A LOOP program may be associated with a signature specifying input and output registers:
Notes The signature is not part of the program. As input and output can be any lists of registers, in general P can compute several functions, depending on the chosen mapping. So, multiple signatures can be associated to one single LOOP program. In this presentation an intended signature is placed before the program.
Semantics Registers range over N = { 0 , 1 , 2 , … } {\displaystyle \mathbb {N} =\{0,1,2,\dots \}} . Execution proceeds sequentially. A loop of the form LOOP x: ... executes its body exactly x {\displaystyle x} times, where x {\displaystyle x} is the value of the register at loop entry. A LOOP program P is said to compute a function f : N m → N n {\displaystyle f\colon \mathbb {N} ^{m}\to \mathbb {N} ^{n}} when:
i n p u t {\displaystyle {\mathtt {input}}} , an m-tuple, specifies m {\displaystyle m} registers which contain the arguments of f ( x 1 , … , x m ) {\displaystyle f(x_{1},\dots ,x_{m})} ; the remaining registers contain 0 {\displaystyle 0} ;
… excerpt ends here. Continue reading the full article.
