Current issue

Vol.26 No.4

Vol.26 No.4

Volumes

© 1984-2017
British APL Association
All rights reserved.

Archive articles posted online on request: ask the archivist.

archive/11/3

Volume 11, No.3

This article might contain pre-Unicode character-mapped APL code.
See here for details.

The Common Mean and APL

by Joseph De Kerf

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):

figure_1

with ￾EMBED EQUATION ù?ò. For example, let x=1 and y=99. We obtain respectively:

figure_2

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 [1] ￾ 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:

figure_3

If this procedure of forming alternatively geometric and arithmetic means is repeated indefinitely:

figure_4

one obtains:

figure_5

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             
[1]    RIX,Y                   
[2]   LAB:RI(0.5?+/R),(?/R)*0.5
[3]    →(ý/R)/LAB              
[4]    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 [1].


Joseph De Kerf
Rooienberg 72
B-2570 Duffel
Belgium

Reference

  1. 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)

script began 18:02:01
caching off
debug mode off
cache time 3600 sec
indmtime not found in cache
cached index is fresh
recompiling index.xml
index compiled in 0.2656 secs
read index
read issues/index.xml
identified 26 volumes, 101 issues
array (
  'id' => '10004430',
)
regenerated static HTML
article source is 'HTML'
source file encoding is ''
read as 'Windows-1252'
URL: mailto:-*- => mailto:-*-
URL: mailto:-*- => mailto:-*-
URL: de_kerf113_21-fig1.gif => trad/v113/de_kerf113_21-fig1.gif
URL: de_kerf113_21-fig2.gif => trad/v113/de_kerf113_21-fig2.gif
URL: de_kerf113_21-fig3.gif => trad/v113/de_kerf113_21-fig3.gif
URL: de_kerf113_21-fig4.gif => trad/v113/de_kerf113_21-fig4.gif
URL: de_kerf113_21-fig5.gif => trad/v113/de_kerf113_21-fig5.gif
completed in 0.2924 secs