Skip to content

Instantly share code, notes, and snippets.

@asmaier
Last active November 14, 2023 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmaier/8b1609775a6ccb95c3031c6afb4c47e0 to your computer and use it in GitHub Desktop.
Save asmaier/8b1609775a6ccb95c3031c6afb4c47e0 to your computer and use it in GitHub Desktop.
Derivation of limits of the generalised mean of two numbers

Generalized Mean

The generalized mean $M$ (also called power mean or Hölder mean) of two numbers $a$ and $b$ of degree $p$ is

$$ M_{p}(a,b) = \left(\frac{a^{p} + b^{p}}{2}\right)^{\frac{1}{p}} $$

The following derivations often make use of the trick

$$ a^x = e^{\ln a^x} = e^{x\ln a} $$

and also use the rule of L'Hopital

$$ \lim_{x \to c} \frac{f(x)}{g(x)} = \lim_{x \to c} \frac{f'(x)}{g'(x)} $$

Arithmetic mean

The arithemtic mean follows from the generalized mean for $p=1$:

$$ M_{1}(a,b) = \frac{a + b}{2} $$

Harmonic mean

The harmonic mean is the particular case of $p=-1$:

$$ M_{-1}(a,b) = \left(\frac{\frac{1}{a} + \frac{1}{b}}{2}\right)^{-1} = \frac{2}{\frac{1}{a} + \frac{1}{b}} = \frac{2ab}{a+b} $$

Root mean square

The root mean square follows from the generalized mean for $p=2$:

$$ M_{2}(a,b) = \sqrt{\frac{a^2 + b^2}{2}} $$

Harmonic mean of squares

The rarely used harmonic mean of squares is the special case for $p=-2$:

$$ M_{-2}(a,b) = \left(\frac{\frac{1}{a^2} + \frac{1}{b^2}}{2}\right)^{-1/2} = \sqrt{\frac{2}{\frac{1}{a^2} + \frac{1}{b^2}}} = \sqrt{\frac{2a^2b^2}{a^2+b^2}} $$

Geometric mean

The geometric mean is the generalized mean in the limit $p \to 0$ :

$$ \begin{align} M_0(a,b) &= \lim_{p \to 0} \left(\frac{a^p + b^p}{2}\right)^{\frac{1}{p}} = \lim_{p \to 0} e^{\ln \left(\frac{a^p + b^p}{2}\right)^{\frac{1}{p}} } = \lim_{p \to 0} e^{\frac{\ln (a^p + b^p) -\ln 2}{p}} \\ &= \exp\left(\lim_{p \to 0} \frac{ \frac{d}{dp}\left(\ln (a^p + b^p) -\ln 2\right)}{\frac{d}{dp} p}\right) = \exp\left(\lim_{p \to 0} \frac{ \frac{a^p \ln a + b^p \ln b}{a^p+b^p}}{1}\right) \\ &= e^{\frac{1}{2} (\ln a + \ln b)} = e^{\ln (ab)^\frac{1}{2} } \\ &= \sqrt{ab} \end{align} $$

Maximum

In the limit $p \to \infty$ the generalized mean is actually computing the maximum of two numbers $a$ and $b$. To see this we start from the point after we applied the rule of L'Hopital in the derivation for the geometric mean

$$ \begin{align} M_\infty(a,b) &= \exp\left(\lim_{p \to \infty} \frac{ \frac{a^p \ln a + b^p \ln b}{a^p+b^p}}{1}\right) = \exp\left(\lim_{p \to \infty} \frac{a^p \ln a}{a^p+b^p} + \frac{b^p \ln b}{a^p+b^p}\right) \\ &= \exp\left(\lim_{p \to \infty} \frac{\ln a}{1+\left(\frac{b}{a}\right)^p} + \frac{\ln b}{\left(\frac{a}{b}\right)^p+1}\right) \end{align} $$

Now if $a > b$ it means that $\frac{a}{b} > 1$ and $\frac{b}{a} < 1$. From this it follows that $\left(\frac{a}{b}\right)^\infty = \infty$ and $\left(\frac{b}{a}\right)^\infty = 0$ and vice versa for $b > a$. So we get

$$ M_\infty(a,b) = \left. \begin{cases} \exp\left(\frac{\ln a}{1+0} + \frac{\ln b}{\infty+1}\right) = e^{\ln a} = a & \text{for} & a > b \\ \exp\left(\frac{\ln a}{1+\infty} + \frac{\ln b}{0+1}\right) = e^{\ln b} = b & \text{for} & a < b \end{cases} \right\} = \max(a,b) $$

Minimum

In the limit $p \to -\infty$ the generalized mean is computing the minimum of two numbers $a$ and $b$. The argument follows the derivation for the maximum.

If $a &gt; b$ it means that $\frac{a}{b} &gt; 1$ and $\frac{b}{a} &lt; 1$. From this it follows that $\left(\frac{a}{b}\right)^{-\infty} = \left(\frac{b}{a}\right)^{\infty} = 0$ and $\left(\frac{b}{a}\right)^{-\infty} = \left(\frac{a}{b}\right)^{\infty} = \infty$ and vice versa for $b &gt; a$. So we get

$$ M_{-\infty}(a,b) = \left. \begin{cases} \exp\left(\frac{\ln a}{1+\infty} + \frac{\ln b}{0+1}\right) = e^{\ln b} = b & \text{for} & a > b \\ \exp\left(\frac{\ln a}{1+0} + \frac{\ln b}{0+\infty}\right) = e^{\ln a} = a & \text{for} & a < b \end{cases} \right\} = \min(a,b) $$

Generalized f-Mean

An even more general mean is the generalized f-mean $M$ (also called Kolmogorov mean) of two numbers $a$ and $b$ of degree $p$

$$ M_{f}(a,b) = f^{-1}\left(\frac{f(a) + f(b)}{2}\right) $$

where $f^{-1}(x)$ is the inverse function of $f(x)$ with the property $f^{-1}(f(x)) = x$.1

Using this formulation it is easier to express the harmonic mean and the geometric mean.

Harmonic mean

The harmonic mean follows from the generalized f-mean for $f=\frac{1}{x}$:2

$$ M_{1/x}(a,b) = \left(\frac{\frac{1}{a} + \frac{1}{b}}{2}\right)^{-1} = \frac{2}{\frac{1}{a} + \frac{1}{b}} $$

Geometric mean

The geometric mean is the particular case of $f=\ln x$ of the generalized f-mean

$$ M_{\ln x}(a,b) = e^{\frac{1}{2} (\ln a + \ln b)} = e^{\ln (ab)^\frac{1}{2} } = \sqrt{ab} $$

Power mean

Our familiar power mean/generalized mean as defined above corresponds to the generalized f-mean for $f(x) = x^p$

$$ M_{x^p}(a,b) = \left(\frac{a^{p} + b^{p}}{2}\right)^{\frac{1}{p}} $$


Footnotes

1 That means the inverse function for $f(x) = x$ is $x$ and not $\frac{1}{x}$. The ladder would be the so called multiplicative inverse with the property $(f(x))^{-1} f(x) = 1$. Don't confuse the multiplicative inverse with the inverse function $f^{-1}(x)$ used in the definition of the generalized f-mean.

2 The inverse function of $\frac{1}{x}$ is $f^{-1}(x) = \frac{1}{x}$, because $f^{-1}(f(x)) = \frac{1}{\frac{1}{x}} = x$.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment