Puneet Varma (Editor)

Bird–Meertens formalism

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

The Bird–Meertens formalism is a calculus for deriving programs from specifications (in a functional-programming 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.

Contents

It is sometimes referred to in publications as BMF, as a nod to Backus–Naur form. Facetiously it is also referred to as Squiggol, as a nod to ALGOL, 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 is a well-known second-order function that applies itself to every element of a list; in BMF, it is written :

f [ e 1 , , e n ] = [ f   e 1 , , f   e n ] .

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

/ [ e 1 , , e n ] = e e 1 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 s u m = + / and f l a t t e n = + + / , in currified notation. We have:

s u m   [ e 1 , , e n ] = + / [ e 1 , , e n ] = 0 + e 1 + + e n = k e k . f l a t t e n   [ l 1 , , l n ] = + + / [ l 1 , , l n ] = [ ] + + l 1 + + + + l n =  the concatenation of all lists  l k .

Similarly, writing for functional composition and for conjunction, it is easy to write a function testing that all elements of a list satisfy a predicate p, simply as a l l   p = ( / ) ( p ) :

a l l   p   [ e 1 , , e n ] = ( / ) ( p )   [ e 1 , , e n ] = / ( p [ e 1 , , e n ] ) = / [ p   e 1 , , p   e n ] = p   e 1 p   e n = k   .   p   e k .

The homomorphism lemma and its applications to parallel implementations

A function h on lists is a list homomorphism if there exists an associative binary operator and neutral element e such that the following holds:

h   [ ] =   e h   ( l + + m ) =   h   l h   m .

The homomorphism lemma states that h is a homomorphism if and only if there exists an operator and a function f such that h = ( / ) ( f ) .

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 f 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.

References

Bird–Meertens formalism Wikipedia