## Generalized Mediant

```Given any two fractions n1/d1 and n2/d2, the mediant is defined
as the fraction

/ n1   n2 \       n1 + n2
M(  -- , --  )  =   -------
\ d1   d2 /       d1 + d2

Graphically, we can regard each fraction n/d as a vector with the
components (d,n), and then the mediant is simply the vector sum of
two given fractions, as shown below

The locus of fractions with a given numerical value q is obviously
the straight line through the origin with slope q, so it's clear
that the value of the mediant is strictly between the values of the
two original fractions.  Also, the mediant has the same value as
the average of the two vectors, since the ratio of (n1+n2)/2 and
(d1+d2)/2 has the same value, (n1+n2)/(d1+d2), as the mediant.  It's
also clear that for any two positive real numbers w1 and w2 the
weighted mediant defined as

/ n1   n2 \       w1 n1 + w2 n2
M_{w1,w2}(  -- , --  )  =   -------------
\ d1   d2 /       w1 d1 + w2 d2

has a value that is strictly between the values of the arguments.

Incidentally, notice that it's important to distinguish between the
concepts of "fraction" and "ratio".  A fraction is an ordered pair
of real numbers, whereas a ratio is a single real number.  We can
regard each ratio as an equivalence class of fractions.  For example,
the ratio 3 includes the fractions 3/1, 4.5/1.5, 12/4, and so on.
However, the various members of an equivalence class yield differents
results under the mediant operation, as shown by the fact that
M(3/1,1/1) = 4/2 whereas M(6/2,1/1) = 7/3.

We can obviously generalize the mediant concept to any number of
fractions n1/d1, n2/d2,..., nk/dk, and define the mediant as

/ n1   n2        nk \       n1 + n2 + ... + nk
M(  -- , -- , ..., --  )  =   ------------------
\ d1   d2        dk /       d1 + d2 + ... + dk

Again we see that the mediant represents the vector sum of the
individual arguments, interpreted as vectors, and again the sum
lies along a line through the origin that also passes through the
geometrical midpoint (center of gravity) of the points (dj,nj),
j=1,2,..,k.  It follows that the value of the mediant is strictly
between the extreme values of the arguments.  (This inequality was
first pointed out by Cauchy.)  Furthermore, the same is true even
if we apply arbitrary positive "weights" w1, w2,...wk to give the
weighted mediant

/ n1   n2        nk \       w1 n1 + w2 n2 + ... + wk nk
M_{wj}(  -- , -- , ..., --  )  =   ---------------------------
\ d1   d2        dk /       w1 d1 + w2 d2 + ... + wk dk

Since the general mediant always yields a result whose value is
strictly within the range of the arguments, we can use mediants to
define a contractive mapping, and iterate this mapping in a way
similar to the celebrated arithmetic-geometric mean, or James
Gregory's geometric-harmonic mean.  (See Iterated Means.)

To give a simple illustration (suggested by D. G. Morin), suppose we
wish to compute rational approximations to the square root of 2.  If
we begin with two numbers whose product is 2, and produce successive
pairs of numbers that are progressively closer to each other AND whose
product remains equal to 2, we will approach values equal to sqrt(2).
To accomplish this, we can apply the mapping

(f1, f2)  ->  (M, 2/M)    where M = M(f1,f2)

Thus, beginning with 1/1 and 2/1, we produce the sequence of pairs

1/1     2/1
3/2     4/3
7/5    10/7
17/12   24/17
41/29   58/41
etc.

The same approach can be applied to roots of any order.  For example,
to compute rational approximations of the cube root of N, we can begin
with the three fractions

a    c    Nb
---  ---  ----
b    a    c

whose product is N, and then map them to the triple of weighted
mediants
a+c+Nb     Na+c+Nb     Na+Nc+Nb
-------- , --------- , ----------
b+a+c       Nb+a+c     Nb+Na+c

whose product is also N, and which has the same form as the original
triple, i.e.,
a'    c'    Nb'
--- , --- , ----
b'    a'    c'

where
c' = c + Na + Nb
a' = c +  a + Nb
b' = c +  a +  b

In matrix notation this can be written as
_         _  _   _       _    _
|  1  N  N  ||  c  |     |  c'  |
|  1  1  N  ||  a  |  =  |  a'  |
|_ 1  1  1 _||_ b _|     |_ b' _|

Letting L denote the coefficient matrix on the left, we see that
L^n approaches a counter-symmetrical matrix whose components
differ by a factor of N^(1/3) in both the vertical and horizontal
directions.  For example, with N=2 we have
_                  _
|  4159  5240  6602  |
L^7 =  |  3301  4159  5240  |
|_ 2620  3301  4159 _|

If we let s = 1/N and

q  =  N^(0/3) + N^(1/3) + N^(2/3)

then the nth power of (L/q) approaches
_                              _
|   s^(3/3)   s^(2/3)   s^(1/3)  |
lim     (L/q)^n =  |   s^(4/3)   s^(3/3)   s^(2/3)  |
n->oo               |_  s^(5/3)   s^(4/3)   s^(3/3) _|

The analagous results apply to higher order system, such as generating
the 4th roots of N by computing the powers of
_            _
|  1  N  N  N  |
|  1  1  N  N  |
|  1  1  1  N  |
|_ 1  1  1  1 _|
```