ArticleslgStudy

computer science

LOOP (programming language)

LOOP (programming language) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand LOOP (programming language) rather than just read about it. In short: LOOP is a simple register language designed to precisely capture the primitive recursive functions. The language is derived from the counter-machine model.

Key takeaways

  • LOOP (programming language) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect LOOP (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of LOOP (programming language) from memory before moving on to harder problems.

Reference excerpt

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.

Worked examples

Example 1 — a first encounter with LOOP (programming language)

Start with the simplest possible case. Write down what LOOP (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to LOOP (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about LOOP (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of LOOP (programming language)

In research
LOOP (programming language) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses LOOP (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
LOOP (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computability theory, so understanding it makes those chapters shorter.
In everyday life
Look for LOOP (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study LOOP (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what LOOP (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain LOOP (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is LOOP (programming language) in simple terms?

LOOP is a simple register language designed to precisely capture the primitive recursive functions. The language is derived from the counter-machine model.

Why does LOOP (programming language) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study LOOP (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on LOOP (programming language).

Tags

  • Computability theory

Keep exploring