BlooP and FlooP

Revision as of 11:35, 8 May 2025 by imported>WikiDan61 (BlooP and FlooP are not educational languages (no one is teaching them); they are esoteric languages, created solely to illustrate a point.)
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Template:Short description Template:Abbr and Template:Abbr (Bounded loop and Free loop) are simple programming languages designed by Douglas Hofstadter to illustrate a point in his book Gödel, Escher, Bach.<ref>Douglas Hofstadter (1979), Gödel, Escher, Bach, Basic Books, Chapter XIII.</ref> BlooP is a Turing-incomplete programming language whose main control flow structure is a bounded loop (i.e. recursion is not permittedTemplate:Citation needed). All programs in the language must terminate, and this language can only express primitive recursive functions.<ref>Stanford Encyclopedia of Philosophy: Computability and Complexity</ref>

FlooP is identical to BlooP except that it supports unbounded loops; it is a Turing-complete language and can express all computable functions. For example, it can express the Ackermann function, which (not being primitive recursive) cannot be written in BlooP. Borrowing from standard terminology in mathematical logic,<ref name="Hofstadter424">Hofstadter (1979), p. 424.</ref><ref>Thomas Forster (2003), Logic, Induction and Sets, Cambridge University Press, p. 130.</ref> Hofstadter calls FlooP's unbounded loops MU-loops. Like all Turing-complete programming languages, FlooP suffers from the halting problem: programs might not terminate, and it is not possible, in general, to decide which programs do.

BlooP and FlooP can be regarded as models of computation, and have sometimes been used in teaching computability.<ref>David Mix Barrington (2004), CMPSCI 601: Theory of Computation, University of Massachusetts Amherst, Lecture 27.</ref>

BlooP examplesEdit

The only variables are OUTPUT (the return value of the procedure) and CELL(i) (an unbounded sequence of natural-number variables, indexed by constants, as in the Unlimited Register Machine<ref>Hofstadter refers to these cells as a set of "auxiliary variables."</ref>). The only operators are (assignment), + (addition), × (multiplication), < (less-than), > (greater-than) and = (equals).

Each program uses only a finite number of cells, but the numbers in the cells can be arbitrarily large. Data structures such as lists or stacks can be handled by interpreting the number in a cell in specific ways, that is, by Gödel numbering the possible structures.

Control flow constructs include bounded loops, conditional statements, ABORT jumps out of loops, and QUIT jumps out of blocks. BlooP does not permit recursion, unrestricted jumps, or anything else that would have the same effect as the unbounded loops of FlooP. Named procedures can be defined, but these can call only previously defined procedures.<ref>Hofstadter (1979), p. 413.</ref>

Factorial functionEdit

Template:Pre

Subtraction functionEdit

This is not a built-in operation and (being defined on natural numbers) never gives a negative result (e.g. 2 − 3 := 0). Note that OUTPUT starts at 0, like all the CELLs, and therefore requires no initialization.

Template:Pre

FlooP exampleEdit

The example below, which implements the Ackermann function, relies on simulating a stack using Gödel numbering: that is, on previously defined numerical functions PUSH, POP, and TOP satisfying PUSH [N, S] > 0, TOP [PUSH [N, S]] = N, and POP [PUSH [N, S]] = S. Since an unbounded MU-LOOP is used, this is not a legal BlooP program. The QUIT BLOCK instructions in this case jump to the end of the block and repeat the loop, unlike the ABORT, which exits the loop.<ref name="Hofstadter424"/>

Template:Pre

See alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Douglas Hofstadter