Bird–Meertens formalism
   HOME

TheInfoList



OR:

The Bird–Meertens formalism (BMF) is a
calculus Calculus, originally called infinitesimal calculus or "the calculus of infinitesimals", is the mathematical study of continuous change, in the same way that geometry is the study of shape, and algebra is the study of generalizations of arithm ...
for deriving programs from
specification A specification often refers to a set of documented requirements to be satisfied by a material, design, product, or service. A specification is often a type of technical standard. There are different types of technical or engineering specificati ...
s (in a functional-programming setting) by a process of equational reasoning. It was devised by Richard Bird and
Lambert Meertens Lambert Guillaume Louis Théodore Meertens or L.G.L.T. Meertens (born 10 May 1944, in Amsterdam) is a Dutch computer scientist and professor. , he is a researcher at the Kestrel Institute, a nonprofit computer science research center in Palo Alt ...
as part of their work within
IFIP Working Group 2.1 IFIP Working Group 2.1 on Algorithmic Languages and Calculi is a working group of the International Federation for Information Processing (IFIP). IFIP WG 2.1 was formed as the body responsible for the continued support and maintenance of the progra ...
. It is sometimes referred to in publications as BMF, as a nod to
Backus–Naur form In computer science, Backus–Naur form () or Backus normal form (BNF) is a metasyntax notation for context-free grammars, often used to describe the syntax of languages used in computing, such as computer programming languages, document formats ...
. Facetiously it is also referred to as ''Squiggol'', as a nod to
ALGOL ALGOL (; short for "Algorithmic Language") is a family of imperative computer programming languages originally developed in 1958. ALGOL heavily influenced many other languages and was the standard method for algorithm description used by the ...
, which was also in the remit of WG 2.1, and because of the "squiggly" symbols it uses. A less-used variant name, but actually the first one suggested, is ''SQUIGOL''.


Basic examples and notations

Map A map is a symbolic depiction emphasizing relationships between elements of some space, such as objects, regions, or themes. Many maps are static, fixed to paper or some other durable medium, while others are dynamic or interactive. Although ...
is a well-known second-order function that applies a given function to every element of a list; in BMF, it is written *: :f* _1,\dots,e_n= \ e_1,\dots,f\ e_n Likewise,
reduce Reduction, reduced, or reduce may refer to: Science and technology Chemistry * Reduction (chemistry), part of a reduction-oxidation (redox) reaction in which atoms have their oxidation state changed. ** Organic redox reaction, a redox react ...
is a function that collapses a list into a single value by repeated application of a binary operator. It is written / in BMF. Taking \oplus as a suitable binary operator with neutral element ''e'', we have :\oplus / _1,\dots,e_n= e \oplus e_1 \oplus \dots \oplus e_n. Using those two operators and the primitives + (as the usual addition), and +\!\!\!+ (for list concatenation), we can easily express the sum of all elements of a list, and the flatten function, as = + / and = +\!\!\!+ /, in point-free style. We have: :\ _1,\dots,e_n= + / _1,\dots,e_n= 0 + e_1 + \dots+ e_n = \sum_k e_k. :\ _1,\dots,l_n=+\!\!\!+ / _1,\dots,l_n= ,+\!\!\!+\; l_1 +\!\!\!+ \dots+\!\!\!+\; l_n = \text l_k. Similarly, writing \cdot for
functional composition In mathematics, function composition is an operation that takes two functions and , and produces a function such that . In this operation, the function is applied to the result of applying the function to . That is, the functions and ...
and \land for
conjunction Conjunction may refer to: * Conjunction (grammar), a part of speech * Logical conjunction, a mathematical operator ** Conjunction introduction, a rule of inference of propositional logic * Conjunction (astronomy), in which two astronomical bodies ...
, it is easy to write a function testing that all elements of a list satisfy a predicate ''p'', simply as \ p = (\land /)\cdot(p*): : \begin \ p\ _1,\dots,e_n &= (\land /)\cdot(p*)\ _1,\dots,e_n \\&= \land /(p* _1,\dots,e_n \\&= \land / \ e_1,\dots,p\ e_n\\&= p\ e_1\land \dots \land p\ e_n \\&= \forall k\ . \ p\ e_k. \end Bird (1989) transforms inefficient easy-to-understand expressions ("specifications") into efficient involved expressions ("programs") by algebraic manipulation. For example, the specification "\mathrm \cdot \mathrm \; \mathrm \cdot \mathrm" is an almost literal translation of the maximum segment sum problem, but running that functional program on a list of size n will take time \mathcal(n^3) in general. From this, Bird computes an equivalent functional program that runs in time \mathcal(n), and is in fact a functional version of
Kadane's algorithm In computer science, the maximum sum subarray problem, also known as the maximum segment sum problem, is the task of finding a contiguous subarray with the largest sum, within a given one-dimensional array A ...nof numbers. Formally, the task is ...
. The derivation is shown in the picture, with computational complexitiesEach expression in a line denotes an executable functional program to compute the maximum segment sum. given in blue, and law applications indicated in red. Example instances of the laws can be opened by clicking on ''
how How may refer to: * How (greeting), a word used in some misrepresentations of Native American/First Nations speech * How, an interrogative word in English grammar Art and entertainment Literature * ''How'' (book), a 2007 book by Dov Seidma ...
'; they use lists of integer numbers, addition, minus, and multiplication. The notation in Bird's paper differs from that used above: \mathrm, \mathrm, and \mathrm correspond to *, \mathrm, and a generalized version of / above, respectively, while \mathrm and \mathrm compute a list of all
prefixes A prefix is an affix which is placed before the Word stem, stem of a word. Adding it to the beginning of one word changes it into another word. For example, when the prefix ''un-'' is added to the word ''happy'', it creates the word ''unhappy'' ...
and
suffixes In linguistics, a suffix is an affix which is placed after the Stem (linguistics), stem of a word. Common examples are case endings, which indicate the grammatical case of nouns, adjectives, and verb endings, which form the Grammatical conjugation ...
of its arguments, respectively. As above, function composition is denoted by "\cdot", which has lowest binding precedence. In the example instances, lists are colored by nesting depth; in some cases, new operations are defined ad hoc (grey boxes).


The homomorphism lemma and its applications to parallel implementations

A function ''h'' on lists is called a list
homomorphism In algebra, a homomorphism is a structure-preserving map between two algebraic structures of the same type (such as two groups, two rings, or two vector spaces). The word ''homomorphism'' comes from the Ancient Greek language: () meaning "same" ...
if there exists an associative binary operator \oplus and neutral element e such that the following holds: : \begin &h\ ,&&=\ e \\ &h\ (l +\!\!\!+\; m) &&=\ h\ l \oplus h\ m. \end The ''homomorphism lemma'' states that ''h'' is a homomorphism if and only if there exists an operator \oplus and a function ''f'' such that h = (\oplus/)\cdot(f*). A point of great interest for this lemma is its application to the derivation of highly
parallel Parallel is a geometric term of location which may refer to: Computing * Parallel algorithm * Parallel computing * Parallel metaheuristic * Parallel (software), a UNIX utility for running programs in parallel * Parallel Sysplex, a cluster of IBM ...
implementations of computations. Indeed, it is trivial to see that f* has a highly parallel implementation, and so does \oplus/ — most obviously as a binary tree. Thus for any list homomorphism ''h'', there exists a parallel implementation. That implementation cuts the list into chunks, which are assigned to different computers; each computes the result on its own chunk. It is those results that transit on the network and are finally combined into one. In any application where the list is enormous and the result is a very simple type – say an integer – the benefits of parallelisation are considerable. This is the basis of the
map-reduce MapReduce is a programming model and an associated implementation for processing and generating big data sets with a parallel, distributed algorithm on a cluster. A MapReduce program is composed of a ''map'' procedure, which performs filtering ...
approach.


See also

*
Catamorphism In category theory, the concept of catamorphism (from the Ancient Greek: "downwards" and "form, shape") denotes the unique homomorphism from an initial algebra into some other algebra. In functional programming, catamorphisms provide generalizat ...
*
Anamorphism In computer programming, an anamorphism is a function that generates a sequence by repeated application of the function to its previous result. You begin with some value A and apply a function f to it to get B. Then you apply f to B to get C, and ...
*
Paramorphism In formal methods of computer science, a paramorphism (from Greek '' παρά'', meaning "close together") is an extension of the concept of catamorphism first introduced by Lambert Meertens to deal with a form which “eats its argument and keep ...
*
Hylomorphism Hylomorphism (also hylemorphism) is a philosophical theory developed by Aristotle, which conceives every physical entity or being (''ousia'') as a compound of matter (potency) and immaterial form (act), with the generic form as immanently real w ...


References

* * * * * * * * * {{DEFAULTSORT:Bird-Meertens Formalism Functional languages Theoretical computer science Program derivation