The Bird–Meertens formalism (BMF) is a
calculus
Calculus is the mathematics, mathematical study of continuous change, in the same way that geometry is the study of shape, and algebra is the study of generalizations of arithmetic operations.
Originally called infinitesimal calculus or "the ...
for
deriving programs from
program specification
In computer science, formal specifications are mathematically based techniques whose purpose is to help with the implementation of systems and software. They are used to describe a system, to analyze its behavior, and to aid in its design by verify ...
s (in a
functional programming
In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declarat ...
setting) by a process of equational reasoning. It was devised by
Richard Bird and
Lambert Meertens as part of their work within
IFIP Working Group 2.1.
It is sometimes referred to in publications as BMF, as a nod to
Backus–Naur form
In computer science, Backus–Naur form (BNF, pronounced ), also known as Backus normal form, is a notation system for defining the Syntax (programming languages), syntax of Programming language, programming languages and other Formal language, for ...
. 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''.
Martin and Nipkow provided automated support for Squiggol development proofs, using the
Larch Prover.
Basic examples and notations
Map
A map is a symbolic depiction of interrelationships, commonly spatial, between things within a space. A map may be annotated with text and graphics. Like any graphic, a map may be fixed to paper or other durable media, or may be displayed on ...
is a well-known second-order function that applies a given function to every element of a list; in BMF, it is written
:
:
Likewise,
reduce is a function that collapses a list into a single value by
repeated application of a binary operator. It is written / in BMF.
Taking
as a suitable binary operator with neutral element ''e'', we have
:
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:
:
:

Similarly, writing
for
functional composition
In mathematics, the composition operator \circ takes two functions, f and g, and returns a new function h(x) := (g \circ f) (x) = g(f(x)). Thus, the function is applied after applying to . (g \circ f) is pronounced "the composition of an ...
and
for
conjunction, it is easy to write a function testing that all elements of a list satisfy a predicate ''p'', simply as
:
:
Bird (1989) transforms inefficient easy-to-understand expressions ("specifications") into efficient involved expressions ("programs") by algebraic manipulation. For example, the specification "
" is an almost literal translation of the
maximum segment sum problem, but running that functional program on a list of size
will take time
in general. From this, Bird computes an equivalent functional program that runs in time
, 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 data structure, array A ...nof number ...
.
The derivation is shown in the picture, with computational complexities
[Each 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'; they use lists of integer numbers, addition, minus, and multiplication. The notation in Bird's paper differs from that used above:
,
, and
correspond to
,
, and a generalized version of
above, respectively, while
and
compute a list of all
prefixes
A prefix is an affix which is placed before the stem of a word. Particularly in the study of languages, a prefix is also called a preformative, because it alters the form of the word to which it is affixed.
Prefixes, like other affixes, can b ...
and
suffixes
In linguistics, a suffix is an affix which is placed after the stem of a word. Common examples are case endings, which indicate the grammatical case of nouns and adjectives, and verb endings, which form the conjugation of verbs. Suffixes can ca ...
of its arguments, respectively. As above, function composition is denoted by "
", 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 morphism, structure-preserving map (mathematics), map between two algebraic structures of the same type (such as two group (mathematics), groups, two ring (mathematics), rings, or two vector spaces). The word ''homo ...
if there exists an associative binary operator
and neutral element
such that the following holds:
:
The ''homomorphism lemma'' states that ''h'' is a homomorphism if and only if there exists an operator
and a function ''f'' such that
.
A point of great interest for this lemma is its application to the derivation of highly
parallel implementations of computations. Indeed, it is trivial to see that
has a highly parallel implementation, and so does
— 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 approach.
See also
*
Catamorphism
*
Anamorphism
*
Paramorphism
*
Hylomorphism
Hylomorphism is a philosophical doctrine developed by the Ancient Greek philosopher Aristotle, which conceives every physical entity or being ('' ousia'') as a compound of matter (potency) and immaterial form (act), with the generic form as imm ...
References
*
*
*
*
*
*
*
*
*
{{DEFAULTSORT:Bird-Meertens Formalism
Functional languages
Theoretical computer science
Program derivation