This article might contain pre-Unicode character-mapped APL code.
See here for details.
The Common Mean and APL
The classical definitions of the mean of two non-negative real numbers are the harmonic mean h(x,y), the geometric mean g(x,y) and the arithmetic mean a(x,y):
with EMBED EQUATION ù?ò. For example, let x=1 and y=99. We obtain respectively:
As we see, there may be a serious gap between the geometric mean g(x,y) and the arithmetic mean a(x,y). This gap may be filled by the concept of common mean  a not very familiar concept from the literature. For convenience, let x0 be the smaller of two non-negative real numbers x0 and y0. The geometric mean x1 and arithmetic mean y1 are:
If this procedure of forming alternatively geometric and arithmetic means is repeated indefinitely:
xi and yi converging to the same value. We define this as the common mean c(x0,y0) of the numbers x0 and y0.
For the example x=1 and y=99 for instance, with an accuracy of 10 digits, we get successively:
9.94987437 and 50.00000000 22.30456721 and 29.97493719 25.85687532 and 26.13975220 25.99792902 and 25.99831376 25.99812139 and 25.99812139
such that c(x,y) = 25.99812139.
Finally, we have:
g(x,y) = 9.94987437 c(x,y) = 25.99812139 a(x,y) = 50.00000000
with 9.94987437 < 25.99812139 < 50.00000000.
In fact the order in which x and y are treated and the order in which the sequences of geometric and arithmetic means are calculated is not relevant and c(x,y) = c(y,x) (commutativity). In addition c(x,x) = x (idempotency). Finally, c(x,y) = 0 if and only if x = 0 or y = 0 (or both).
Programming the algorithm for calculating the common mean can be somewhat complicated in most programming languages. In APL however, it is very simple. A function to do the job is:
× RIX CMEAN Y  RIX,Y  LAB:RI(0.5?+/R),(?/R)*0.5  →(ý/R)/LAB  RI0.5?+/R ×
which for the chosen example gives:
1 CMEAN 99 25.99812139
Accuracy is determined by the current, i.e. the default value of comparison tolerance SYMBOL 140 \f "APL2741"òCT. It may be changed by defining the comparison tolerance as a global or local variable.
Note: a special case is the common mean of the numbers 1 and EMBED EQUATION ù?ò:
1 CMEAN ⍫SYMBOL 246 \f "VectorAPL"ò 2*0.5 0.8472130848
which is known in the literature as the ôubiquitous constant Uö since it turns up all over the place.
Finally, the common mean is very useful in the design of simple and efficient algorithms for calculating the complete elliptic integrals of the first kind K(p) and of the second kind E(p). More details may be found in .
Joseph De Kerf
- J Spanier and K B Oldham: An Atlas of Functions. Hemisphere Publishing Corporation, New York. New York 1987.
(webpage generated: 29 October 2007, 14:07)