﻿ Vector, the Journal of the British APL Association

## Volumes

British APL Association

Archive articles posted online on request: ask the archivist.

Volume 11, No.3

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:

one obtains:

# 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
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 22:41:28
caching off
debug mode off
cache time 3600 sec
cached index is fresh
recompiling index.xml
index compiled in 0.3168 secs
identified 26 volumes, 101 issues
array (
'id' => '10004430',
)
regenerated static HTML
article source is 'HTML'
source file encoding is ''
{"ft_lang_label":"__label__en","ft_lang_prob":0.86049634,"math_prob":0.9742805,"size":2793,"snap":"2020-34-2020-40","text_gpt3_token_len":824,"char_repetition_ratio":0.12119039,"word_repetition_ratio":0.021598272,"special_character_ratio":0.3290369,"punctuation_ratio":0.15580286,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9986568,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,4,null,4,null,4,null,4,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-09-30T21:41:29Z\",\"WARC-Record-ID\":\"<urn:uuid:08a44f2d-56e2-4732-a957-4eb7a75e9eb4>\",\"Content-Length\":\"10889\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:870c21c4-f4b1-4475-9537-e6a42c4be9df>\",\"WARC-Concurrent-To\":\"<urn:uuid:c1bb78ad-58dd-44ce-8be0-e5e8bd0c0699>\",\"WARC-IP-Address\":\"94.175.234.235\",\"WARC-Target-URI\":\"http://archive.vector.org.uk/art10004430\",\"WARC-Payload-Digest\":\"sha1:PG2VSXCZMGRFIXDW7VVQ6ZER6YAP4CT7\",\"WARC-Block-Digest\":\"sha1:Q5WGH4NQDOLLEQPIHU755JAZGYFXUJEJ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600402128649.98_warc_CC-MAIN-20200930204041-20200930234041-00606.warc.gz\"}"}