Powered by Blogger.
Showing posts with label Putnam Training. Show all posts
Showing posts with label Putnam Training. Show all posts

Power Means (AM-GM Part 3)

In the last two posts on the AM-GM inequality (Part 1 and Part 2), I introduced two types of averages: the arithmetic mean and the geometric mean. We saw that the geometric mean was the more appropriate choice for portfolio returns (due to the compounding effect) and that the geometric mean is always less than the arithmetic mean (or equal when all inputs are equal).

In essence, the AM-GM inequality tells us that the GM weights smaller inputs more than the AM would; a loss in one year continues to affect a portfolio in the following years, since next year's percentage gain applies to a smaller portfolio balance. Thus the GM takes into account the relevance of the product of the inputs, while the AM applies when the sum of the inputs is most relevant.

In this post, I will introduce a family of different "average" formulas and show how the AM-GM inequality is a special case of a more general result.


The Harmonic Mean ($p=-1$)


Suppose we take a 3-leg trip where we travel 20 miles in 30 minutes (40 mph) in the first leg, 65 miles in 60 minutes (65 mph) in the second leg, and 90 miles in 90 minutes (60 mph) in the third leg. At the most basic level, our "average speed" for the trip should be the constant speed that one would need to travel for the total time, 180 minutes, to cover the total distance, 175 miles, or $$
\dfrac{175 \text{ miles}}{180 \text{ min}} \times \dfrac{60 \text{ min}}{1 \text{ hour}} = 58.33 \ \dfrac{\text{miles}}{\text{hour}}
$$ This is analogous to the portfolio example, in which the GM (CAGR) was the constant return which would yield the final portfolio value from the initial one by annual compounding (i.e. multiplying instead of adding) over the full time period in question.

In our travel example, the arithmetic mean will give us the correct result if we use a time-weighted AM: $$
\left( 40 \times \dfrac{30}{180} \right) + \left( 65 \times \dfrac{60}{180} \right) + \left( 60 \times \dfrac{90}{180} \right) = 58.33 \ \checkmark
$$ However, if we weight by distance instead, the AM will return 59.57 mph, an overestimation: $$
\left( 40 \times \dfrac{20}{175} \right) + \left( 65 \times \dfrac{65}{175} \right) + \left( 60 \times \dfrac{90}{175} \right) = 59.57 \ ( \text{overestimate})
$$ When taking an average of ratios (speed is the ratio of distance to time) and weighting by the numerator, we need to use a different average, the (weighted) harmonic mean, defined as the reciprocal of the arithmetic mean of the reciprocals: $$
\text{HM}(x_1, x_2, \dotsc, x_n) = \left( \sum_{i=1}^{n}{w_i  x_i^{-1}} \right)^{-1}
$$ where the $w_i$'s are a sequence of weights which add up to 1; the unweighted HM is simply the special case where all weights equal $1/n$. Note that in order to avoid issues with division by zero, we restrict the definition of the HM to positive inputs only.

The below table shows the results of the AM and HM for our travel example:


In addition to confirming that the HM yields the "average" that we sought in the case of numerator-weighting, the table also suggests that the HM and AM satisfy an inequality similar to AM-GM. Indeed they do, as we shall see in the next section.


Power Means


Let $x_1, x_2, \dotsc, x_n$ be positive real numbers and $p$ be a non-zero real number (not necessarily an integer), and let $w_1, w_2, \dotsc, w_n$ be a sequence of positive weights which add up to 1. Then the (weighted) power mean with exponent $p$ of the $x_i$'s is defined as $$
M_{p}(x_1, x_2, \dotsc, x_n) = \left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{1/p} \tag{$\star$}
$$ Note that the unweighted version is obtained by setting all weights equal to $1/n$.

The AM, GM, and HM are each special cases: $M_1$ is the arithmetic mean, and $M_{-1}$ is the harmonic mean. Now, due to the division by $p$ in the exponent, we can't technically define the case of $p=0$ directly from $( \star )$, so instead we define $M_0$ to be the geometric mean, which turns out (proof deferred to the end of this post) to equal $\displaystyle{\lim_{p \rightarrow 0}{M_p}}$.

Similarly, we define $M_{-\infty}(x_1,x_2, \dotsc , x_n)=\min(x_1, x_2, \dotsc, x_n)$ and $M_{\infty}(x_1,x_2, \dotsc , x_n)=\max(x_1, x_2, \dotsc, x_n)$. The two relevant limits also turn out (proof deferred to the end as well) to equal these definitions. All of the power means are "averages" in the sense that they fall between the minimum and maximum values of the inputs, i.e. $$
M_{-\infty}(x_1, x_2, \dotsc, x_n) \leq M_{p}(x_1, x_2, \dotsc, x_n) \leq M_{\infty}(x_1, x_2, \dotsc, x_n)
$$ for all values of $p$. Furthermore, at the end of the post, we'll prove the following result, which implies the above, as well as the AM-GM and AM-HM inequalities.

Power Means Inequality: For $-\infty \leq p < q \leq +\infty$ and positive inputs $x_1, x_2, \dotsc, x_n$, we have $$
M_{p}(x_1, x_2, \dotsc, x_n) \leq M_{q}(x_1, x_2, \dotsc, x_n)
$$ with equality if and only if $x_1 = x_2 = \dotsb = x_n$.
$\square$

Below is a chart of the power means for different values of $p$ with the $x_i$'s being the set of numbers $\{ 1,2,3,4,5,6,7,8,9,10 \}$ and the weights all equal to $1/10$, i.e. unweighted means:


As expected based on the power means inequality, the orange graph of $M_p$ is strictly upward-sloping with increasing $p$. If you want to play around with the input set and weights and see how this affects the chart, you can download my Excel sheet at this link. After clicking the link, make sure to press the download button at the top so that you can open the file in Excel instead of Google docs:


Now, let's look at a few examples of the power means inequality applied.

Example 1: If $p,q,x,y>0$ and $p+q \leq 1$, then we have $(px+qy)^2 \leq px^{2} + qy^{2}$,

Proof: Applying the power means inequality with weights $\frac{p}{p+q}$ and $\frac{q}{p+q}$ to $M_{1}(x,y)$ (the arithmetic mean) and $M_{2}(x,y)$ (called the quadratic mean or root mean square), we obtain:$$
\begin{alignat}{5}
&&\frac{p}{p+q}x &+ \frac{q}{p+q}y \ &
&\stackrel{(1)}{\leq}& \ \ &\left( \frac{p}{p+q}x^{2} + \frac{q}{p+q}y^{2} \right)^{1/2} \\[2mm]

\stackrel{(2)}{\implies} \ &&px&+qy \ & &\leq& \ \ &(p+q)^{1/2} \left( px^{2} + qy^{2} \right)^{1/2} \\[2mm]

\stackrel{(3)}{\implies} \ &&(px&+qy)^{2}\  & &\leq& \ \ &(p+q) \left( px^{2} + qy^{2} \right) \\[2mm]

\stackrel{(4)}{\implies} \ &&(px&+qy)^{2} \  & &\leq& \ \ & px^{2} + qy^{2} \\
\end{alignat}
$$ (1) is the power means inequality. (2) is multiplication by $(p+q)$ on both sides, and (3) is squaring both sides; neither of these operations reverse the direction of the inequality. Finally, (4) is because $p+q \leq 1$.
$\square$

Example 2: If $a,b,c, \geq 0$, then $\sqrt{3(a+b+c)} \geq \sqrt{a} + \sqrt{b} + \sqrt{c}$.

Proof: This one is quite simple with an application of the power means inequality: $$
\underbrace{\frac{a+b+c}{3}}_{M_{1}(a,b,c)} \geq
\underbrace{\left( \frac{\sqrt{a} + \sqrt{b} + \sqrt{c}}{3} \right)^{2}}_{M_{1/2}(a,b,c)}
$$ from which the desired inequality follows immediately by taking the square root and then multiplying by 3 on both sides. Once again, these operations do not reverse the direction of the inequality.
$\square$

Finally, like AM-GM, we can use the power means inequality to verify the minimum value of a function subject to a constraint. Note that in the examples of Part 1, a volume-like constraint on the product of the inputs, along with a suitable function involving a sum, allowed us to use the AM-GM inequality. In this last example, however, the function consists of a sum of reciprocals, symmetric in the inputs, and thus calls for the harmonic mean; the constraint, a symmetric sum of the inputs, calls for the arithmetic mean.

Example 3: Let $x,y,z>0$ with $x+y+z=1$. Find the minimum value of the function $$
f(x,y,z) = \frac{1}{x} + \frac{1}{y} + \frac{1}{z}
$$ Solution: The AM-HM inequality (power means inequality with $p=-1$ and $q=1$) implies that $$
\begin{align}
\frac{1}{f(x,y,z)} =
\underbrace{\frac{1}{\frac{1}{x} + \frac{1}{y} + \frac{1}{z}}}_{\frac{1}{3}M_{-1}(x,y,z)}
&\leq
\underbrace{\frac{1}{3} \cdot \frac{x+y+z}{3}}_{\frac{1}{3}M_{1}(x,y,z)} \\
&= \frac{x+y+z}{9} \\
&= \frac{1}{9} \tag{$x+y+z=1$}
\end{align}
$$ Since $x,y,z>0$, so is $f(x,y,z)$, so we can multiply both sides by $9f(x,y,z)$ without reversing the direction of the inequality, and we obtain $$
9 \leq f(x,y,z)
$$ Since $f(\frac{1}{3},\frac{1}{3},\frac{1}{3})=9$, this must be the minimum value.
$\square$

The main take-away from these examples is that the power means inequality generates all sorts of inequalities as long as we have an expression that looks something like $M_p$ for some $p$. We have the flexibility to choose any $p$ and $q$ that suit our needs for the particular problem.

That concludes the non-proof portion of this post.


Deferred Proofs


Let's start with the proofs (straight from Wikipedia) of the limit cases $\lim_{p \rightarrow 0}{M_p}$ and $\lim_{p \rightarrow \pm \infty}{M_p}$.

Proof that $\lim_{p \rightarrow 0}{M_p} = M_0$ (the GM): To begin, note that $$
\begin{align}

\lim_{p \rightarrow 0}{M_p}

&= \lim_{p \rightarrow 0}{\left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{1/p}} \\[3mm]

&= \lim_{p \rightarrow 0}{\exp \left( \ln \left[ \left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{1/p} \right] \right)} \tag{$\exp(\ln[z])=z$ for $z>0$}\\[3mm]

&= \exp \left( \lim_{p \rightarrow 0}{\ln \left[ \left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{1/p} \right]} \right) \tag{since exp is continuous} \\[3mm]

&\stackrel{( \spadesuit )}{=} \exp \left( \lim_{p \rightarrow 0}{
\frac{\ln \left( \sum_{i=1}^{n}{w_i x_i^p} \right)}{p}
} \right) \tag{properties of logs}

\end{align}
$$ We can use L'Hôpital's rule to evaluate this limit since it is the indeterminate form $\frac{0}{0}$: $$
\begin{align}
\lim_{p \rightarrow 0}{
\frac{\ln \left( \sum_{i=1}^{n}{w_i x_i^p} \right)}{p}
}
&= \lim_{p \rightarrow 0}{
\frac
{ \frac{d}{dp} \ln \left( \sum_{i=1}^{n}{w_i x_i^p} \right)}
{ \frac{d}{dp} p}
} \\[5mm]

&= \lim_{p \rightarrow 0}{
\frac
{ \frac{\sum_{i=1}^{n}{w_i x_i^p \ln(x_i)}}{\sum_{i=1}^{n}{w_i x_i^p}}}
{1}
} \\[3mm]

&= \lim_{p \rightarrow 0}{
\frac{\sum_{i=1}^{n}{w_i x_i^p \ln(x_i)}}{\sum_{i=1}^{n}{w_i x_i^p}}
} \\[3mm]

&= \frac{\sum_{i=1}^{n}{w_i \ln(x_i)}}{\sum_{i=1}^{n}{w_i}} \tag{$\lim \nolimits _{p \rightarrow 0}{x_{i}^{p}}=1$} \\[3mm]

&= \frac{\sum_{i=1}^{n}{w_i \ln(x_i)}}{1} \tag{weights sum to 1} \\[3mm]

&= \ln \left[ \prod_{i=1}^{n}{x_{i}^{w_i}} \right] \tag{properties of logs}

\end{align}
$$ Finally, we can substitute the result of the limit evaluation back into $( \spadesuit )$: $$
\begin{align}
\lim_{p \rightarrow 0}{M_p}
&= \exp \left( \ln \left[ \prod_{i=1}^{n}{x_{i}^{w_i}} \right] \right) \\[2mm]

&= \prod_{i=1}^{n}{x_{i}^{w_i}} \\[2mm]

&= M_{0}(x_1, x_2, \dotsc , x_n) \tag{definition of weighted GM}
\end{align}
$$ $\square$

Note that in the last line, the definition of the weighted GM coincides with the definition of the unweighted GM we saw in Part 1 when we set $w_i = \frac{1}{n}$ for each $i$: $$
\prod_{i=1}^{n}{x_{i}^{1/n}} = \prod_{i=1}^{n}{\sqrt[n]{x_{i}}} = \sqrt[n]{x_1 x_2 \dotsm x_n}
$$
Proof that $\lim \limits_{p \rightarrow \infty}{M_{p}} = M_{\infty}$ (maximum): To begin, assume that $x_1 \geq x_2 \geq \dotsb \geq x_n$. This is without loss of generality because if our original list does not satisfy this condition, we can rearrange the $x_i$'s. Note that we also rearrange the weights $w_i$ so that this does not change the value of the sum in the formula for $M_p$. Thus, we have: $$
\lim_{p \rightarrow \infty}{M_p}

= \lim_{p \rightarrow \infty}{\left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{1/p}}

= x_1 \lim_{p \rightarrow \infty}{
\left( \sum_{i=1}^{n}{w_i \left( \frac{x_i}{x_1} \right)^p} \right)^{1/p}
}

=x_1
$$ where the final equality is because each ratio $x_i / x_1 \leq 1$ due to our ordering of the $x_i$'s. Thus, they don't blow up the sum when raised to the power of $p$, and the entire limit goes to 1 as the exponent $1/p \rightarrow 0$. Furthermore, $x_1 = \max(x_1, x_2, \dotsc, x_n)$ due to the ordering.
$\square$

Proof that $\lim_{p \rightarrow -\infty}{M_p} = M_{-\infty}$ (minimum): This proof piggybacks off of the $+\infty$ case.

Note that for $p>0$, $$
M_{-p}(x_1, x_2, \dotsc, x_n) = \left( \sum_{i=1}^{n}{w_i x_i^{-p}} \right)^{-1/p} = \frac{1}{M_{p}(\frac{1}{x_1}, \frac{1}{x_2}, \dotsc, \frac{1}{x_n})}
$$ Taking the limit as $p \rightarrow \infty$, $$
\begin{align}
\lim_{p \rightarrow \infty}{M_{-p}(x_1, x_2, \dotsc, x_n)}

&= \frac{1}{
\lim_{p \rightarrow \infty}{M_{p}(\frac{1}{x_1}, \frac{1}{x_2}, \dotsc, \frac{1}{x_n})}
} \\[3mm]

&= \frac{1}{
M_{\infty}(\frac{1}{x_1}, \frac{1}{x_2}, \dotsc, \frac{1}{x_n})
} \\[3mm]

&=\frac{1}{
\max(\frac{1}{x_1}, \frac{1}{x_2}, \dotsc, \frac{1}{x_n})
}
\end{align}
$$ Finally, $\max(\frac{1}{x_1}, \frac{1}{x_2}, \dotsc, \frac{1}{x_n}) = \frac{1}{\min(x_1, x_2, \dotsc, x_n)}$, so that $\lim_{p \rightarrow \infty}{M_{-p}(x_1, x_2, \dotsc, x_n)} = M_{-\infty}$.
$\square$

Now to the main event (at least for the nerds who read this far): the proof of the power means inequality. We'll start with two lemmas.

Lemma 1: $M_p \geq M_q \iff M_{-p} \leq M_{-q}$.

Proof: Suppose $M_p = \sqrt[p]{\sum_{i=1}^{n}{w_i x_i^p}} \geq \sqrt[q]{\sum_{i=1}^{n}{w_i x_i^q}} = M_q$. Since this inequality holds for any list of $n$ input values, we can replace each $x_i$ with its reciprocal, so we have $$
\sqrt[p \uproot 3]{\sum_{i=1}^{n}{w_i x_i^{-p}}} \geq \sqrt[q \uproot 3]{\sum_{i=1}^{n}{w_i x_i^{-q}}}
$$ Raising both sides to the power of $-1$ (which replaces the $\sqrt[p]{\ \ }$ with $\sqrt[-p]{\ \ }$) is a strictly decreasing function and thus reverses the sign of the inequality. Thus $$
\sqrt[-p \uproot 3]{\sum_{i=1}^{n}{w_i x_i^{-p}}} \leq \sqrt[-q \uproot 3]{\sum_{i=1}^{n}{w_i x_i^{-q}}}
$$ That is, $M_{-p} \leq M_{-q}$. Since the same arguments all work in reverse, this proves the asserted equivalence.
$\square$

Lemma 2: For any $p>0$, $M_{-p} \leq M_0 \leq M_p$.

Proof: Using properties of logarithms $( \dagger )$ and then Jensen's inequality $( \ddagger )$ (which applies in reverse since the $\ln$ is concave instead of convex), we have: $$
\ln \left( \prod_{i=1}^{n}{x_i^{w_i}} \right)
\stackrel{( \dagger )}{=}
\sum_{i=1}^{n}{w_i \ln(x_i)}
\stackrel{( \ddagger )}{\leq}
\ln \left( \sum_{i=1}^{n}{w_i x_i} \right)
$$ Since the exponential function ($f(z) = e^z$) is a strictly increasing function of the input $z$, we can apply it to both sides without reversing the direction of the inequality. This eliminates the logs and yields $$
\begin{align}
&&   &&\prod_{i=1}^{n}{x_i^{w_i}} &\leq \ \sum_{i=1}^{n}{w_i x_i} \\[2mm]

&&\stackrel{( \clubsuit )}{\implies} &&\prod_{i=1}^{n}{x_i^{p w_i}} &\leq \ \sum_{i=1}^{n}{w_i x_i^p} \\[2mm]

&&\stackrel{( \heartsuit )}{\implies} &&\left( \prod_{i=1}^{n}{x_i^{p w_i}} \right)^{1/p} &\leq \ \left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{1/p} \\[2mm]

&&\iff &&\prod_{i=1}^{n}{x_i^{w_i}} &\leq \ \left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{1/p}

\end{align}
$$ In line $( \clubsuit )$, we replaced each $x_i$ by $x_i^p$, which is valid since the inequality $( \ddagger )$ holds for any choice of inputs. In the next line $( \heartsuit )$, we raised both sides to the power of $1/p$; note that raising an argument to a positive power is a strictly increasing function and thus this does not reverse the direction of the inequality. In the final line, we just simplified the left side.

This completes the proof that $M_0 \leq M_p$ for $p>0$. The proof that $M_{-p} \leq M_0$ is exactly the same, except that we substitute $-p$ everywhere there's a $p$ above. This reverses the inequality in line $( \heartsuit )$ since raising to a negative power is a decreasing function.
$\square$

Proof of the power means inequality: There are 3 cases to be proved:

  1. $0<p<q$
  2. $p<q<0$
  3. $p<0<q$

Lemma 2 tells us that the power mean for any positive (negative) power is always greater (less) than or equal to the geometric mean. This automatically proves the power means inequality for case 3. Furthermore, by Lemma 1, cases 1 and 2 are equivalent, so we actually only need to prove the power means inequality for case 1.

To that end, define the function $f$ which maps a positive real number $x$ to the positive real number $f(x) = x^{q/p}$. The second derivative of this function is $$
f''(x) = \left( \frac{q}{p} \right) \left( \frac{q}{p}-1 \right) x^{q/p-2}
$$ which is positive for $x>0$ since $q/p>1$. Therefore, $f$ is convex, and so by Jensen's inequality, we have $$
f \left( \sum_{i=1}^{n}{w_i x_i^p} \right) \leq \sum_{i=1}^{n}{w_i f(x_i^p)}
$$ that is, $$
\begin{align}
&& &&\left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{q/p} &\leq \sum_{i=1}^{n}{w_i (x_i^p)^{q/p}} \\[2mm]

&&\iff &&\left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{q/p} &\leq \sum_{i=1}^{n}{w_i x_i^q} \\[2mm]

&&\stackrel{( \diamondsuit )}{\implies} &&\left( \sum_{i=1}^{n}{w_i x_i^p} \right)^{1/p} &\leq \left( \sum_{i=1}^{n}{w_i x_i^q} \right)^{1/q}

\end{align}
$$ In line $( \diamondsuit )$, we raised both sides to the power of $1/q$, a positive number, and thus didn't reverse the direction of the inequality. This completes the proof of case 1 and therefore of the power means inequality.
$\square$

Thanks for reading- please post any questions in the comments section.

AM-GM Inequality (Part 2)

In Part 1 of this post, I introduced the AM-GM Inequality and showed a few examples of how to apply it to prove certain inequalities and find the minimum value of certain functions. In Part 2, I will start off with the proof (which I skipped in Part 1) and then proceed to a few more miscellaneous examples of clever applications. If you're not interested in the proof, then you can skip the next section and go straight to the examples below.

Proof of the AM-GM Inequality


AM-GM Inequality: For $x_1, x_2, \dotsc , x_n \geq 0$, $$
\dfrac{x_1 + x_2 + \dotsb + x_n}{n} \geq \sqrt[n]{x_1 x_2 \dotsm x_n}
$$ with equality if and only if $x_1 = x_2 = \dotsb = x_n$.

Proof: The proof is by induction. The base case for induction is $n=1$, for which it's obvious that the inequality holds (in fact, it's an equality).

Now suppose we have $n+1$ non-negative real numbers $x_1, x_2, \dotsc , x_n, x_{n+1}$, and assume that for any $n$ non-negative real numbers, the AM-GM inequality holds. For notational simplicity, define $\alpha$ to be the arithmetic mean of the $n+1$ numbers, $$
\alpha = \dfrac{x_1 + x_2 + \dotsb + x_n + x_{n+1}}{n+1}
$$ which  can be re-arranged as $$
(n+1) \alpha = x_1 + x_2 + \dotsb + x_n + x_{n+1} \tag{$\star$}
$$ If each of the $n+1$ numbers is equal to $\alpha$, then the AM and GM are both $\alpha$, so there is nothing to prove. Otherwise, there must be at least one of the $x_i$'s that is greater than $\alpha$ and at least one that is less than $\alpha$. Let's say $x_n > \alpha$ and $x_{n+1} < \alpha$ (if this isn't the case, rearrange the labels so that it is). So we know that $$
(x_n - \alpha)(\alpha - x_{n+1}) > 0 \tag{$\star \star$}
$$ a fact which we will use later.

Now define $y = x_n + x_{n+1} - \alpha$. Note that $y$ is positive since it is greater than $x_n - \alpha$. Furthermore, the AM of the $n$ numbers $x_1, x_2, \dotsc , x_{n-1}, y$ is $\alpha$: $$
\begin{align}
\dfrac{x_1 + x_2 + \dotsb + x_{n-1} + y}{n} &= \dfrac{x_1 + x_2 + \dotsb + x_{n-1} + (x_n + x_{n+1} - \alpha)}{n} \\[3mm]
&= \dfrac{(x_1 + x_2 + \dotsb + x_{n-1} + x_n + x_{n+1}) - \alpha}{n} \\[3mm]
&= \dfrac{(n+1)\alpha - \alpha}{n} \ \ \  \text{[by $\star$]} \\[3mm]
&= \dfrac{n \alpha}{n} \\[2mm]
&= \alpha
\end{align}
$$ By the induction hypothesis, the AM-GM inequality holds for the $n$ numbers $x_1, x_2, \dotsc , x_{n-1}, y$, i.e. $$
\begin{align}
&&\sqrt[n]{x_1 x_2 \dotsm x_{n-1} y} \ &\leq \ \alpha& \\
\implies &&x_1 x_2 \dotsm x_{n-1} y \ &\leq \ \alpha^n& \\
\implies &&x_1 x_2 \dotsm x_{n-1} y \cdot \alpha \ &\leq \ \alpha^{n+1}& \tag{$\spadesuit$}
\end{align}
$$ The last ingredient is the following: $$
\begin{align}
(x_n - \alpha)(\alpha - x_{n+1})
= \ &\underbrace{(x_n + x_{n+1} - \alpha)}_{y} \alpha  - x_n x_{n+1} \\[2mm]
> \ &0 \ \ \  \text{[by $\star \star$]} \\[2mm]
\implies y \alpha > \ &x_n x_{n+1}
\end{align}
$$ Plugging this into $( \spadesuit )$ yields $$
\begin{align}
\alpha^{n+1} &\geq x_1 x_2 \dotsm x_{n-1} (y \alpha) \\[2mm]
&> x_1 x_2 \dotsm x_{n-1} (x_n x_{n+1}) \\[2mm]
\implies \alpha &> \sqrt[n+1]{x_1 x_2 \dotsm x_{n-1} x_n x_{n+1}}
\end{align}
$$ i.e. the arithmetic mean is greater than the geometric mean. This completes the proof.
$\square$

Some more examples of AM-GM applications


In Part 1, I showed one easy example and two examples where we could apply the AM-GM inequality to find the minimum value of a function subject to a volume-like constraint. In this part, I'll show 3 more examples of clever applications, in order of increasing difficulty.

Example 4: Let $a_1, a_2, \dotsc , a_n$ be a sequence of positive numbers and $b_1, b_2, \dotsc , b_n$ be a permutation of the $a_i$'s. Show that $$
\dfrac{a_1}{b_1} + \dfrac{a_2}{b_2} + \dotsb + \dfrac{a_n}{b_n} \geq n
$$ Proof: The AM-GM inequality implies $$
\dfrac{1}{n} \left[ \dfrac{a_1}{b_1} + \dfrac{a_2}{b_2} + \dotsb + \dfrac{a_n}{b_n} \right]
\geq
\sqrt[n \uproot4]{\dfrac{a_1}{b_1} \dfrac{a_2}{b_2} \dotsm \dfrac{a_n}{b_n}}
= 1
$$ where the last equality is true since the $a_i$'s and $b_i$'s are the same list of numbers, just rearranged. Multiplying both sides by $n$ yields the desired inequality.
$\square$

In Example 4, there was no volume-like constraint on the values of the $a_i$'s, but we were able to produce one on the fractions $\frac{a_i}{b_i}$ by multiplying them all together. In Example 5, we can do something similar- this one is admittedly shamelessly set up for AM-GM application, but I still thought it was cool enough to show.

Example 5: Find the positive solutions to the system of equations: $$
\begin{gather}
x_1 + \dfrac{1}{x_2} = 4 \\[3mm]
x_2 + \dfrac{1}{x_3} = 1 \\[3mm]
\vdots \tag{$\diamondsuit$}\\[3mm]
x_{99} + \dfrac{1}{x_{100}} = 4 \\[3mm]
x_{100} + \dfrac{1}{x_1} = 1
\end{gather}
$$ Solution: The sum $x_1 + \frac{1}{x_2}$ is 2 times the arithmetic mean of the numbers $x_1$ and $\frac{1}{x_2}$, so by the AM-GM inequality, we have (using the same logic on the other 98 variables as well): $$
\begin{gather}
x_1 + \dfrac{1}{x_2} \geq 2 \sqrt{\dfrac{x_1}{x_2}} \\[3mm]
x_2 + \dfrac{1}{x_3} \geq 2 \sqrt{\dfrac{x_2}{x_3}} \\[3mm]
\vdots \tag{$\clubsuit$} \\[3mm]
x_{100} + \dfrac{1}{x_1} \geq 2 \sqrt{\dfrac{x_{100}}{x_1}}
\end{gather}
$$ Note that putting the $x$'s under square roots is valid since we are only considering positive solutions. Now, both sides of $( \clubsuit )$ are positive in each of these inequalities, so we can multiply them together without reversing the direction of the inequality: $$
\begin{align}
\left( x_1 + \dfrac{1}{x_2} \right)
\left( x_2 + \dfrac{1}{x_3} \right)
\dotsm
\left( x_{100} + \dfrac{1}{x_1} \right)
&\geq 2^{100} \sqrt{\dfrac{x_1}{x_2} \dfrac{x_2}{x_3} \dotsm \dfrac{x_{100}}{x_1}} \\[2mm]
&= 2^{100} \cdot 1 \\[2mm]
&= 2^{100}
\end{align}
$$ thus $$
\left( x_1 + \dfrac{1}{x_2} \right)
\left( x_2 + \dfrac{1}{x_3} \right)
\dotsm
\left( x_{100} + \dfrac{1}{x_1} \right)
\geq 2^{100} \tag{$\heartsuit$}
$$ On the other hand, multiplying together the original system of equations $( \diamondsuit )$ shows that the product on the left side of $( \heartsuit )$ is equal to $4^{50} \cdot 1^{50} = 2^{100}$. In other words, the inequality $( \heartsuit )$ is an exact equality. This implies, in turn, that each of the inequalities in $( \clubsuit )$ are exact equalities too, since otherwise $( \heartsuit )$ would not be an exact equality.

Finally, we can solve for the variables: $$
\begin{align}
&& x_1 + \dfrac{1}{x_2} &= 2 \sqrt{\dfrac{x_1}{x_2}} \\[3mm]
&\implies& x_1 - 2 \sqrt{\dfrac{x_1}{x_2}} + \dfrac{1}{x_2} &= 0 \\[3mm]
&\implies& \left( \sqrt{x_1} - \sqrt{\dfrac{1}{x_2}} \right)^2 &= 0 \\[3mm]
&\implies& \sqrt{x_1} &= \sqrt{\dfrac{1}{x_2}} \\[3mm]
&\implies& x_1 &= \dfrac{1}{x_2}
\end{align}
$$ Similarly, $x_2 = \frac{1}{x_3}, \dotsc, x_{100} = \frac{1}{x_1}$. These, combined with the original system of equations $( \diamondsuit )$, show that the solution is $x_1 = 2, x_2 = \frac{1}{2}, x_3 = 2, x_4 = \frac{1}{2}, \dotsc, x_{99} = 2, x_{100} = \frac{1}{2}$.
$\square$

The sixth and final example will require proving a lemma, but I thought this example (and the lemma itself) was so neat that it would be worth the effort.

Lemma: Let $p(x) = a_n x^n + a_{n-1} x^{n-1} + \dotsb + a_1 x + a_0$ be a polynomial in the variable $x$ (could be a real or complex variable and real or complex coefficients), and let $r_1, r_2, \dotsc, r_n$ be the roots of $p(x)$ (in general, these are complex numbers, and there may be repeats). Then the sum of the squares of the roots is related to the coefficients by the following formula: $$
r_1^2 + r_2^2 + \dotsb + r_n^2 = \left( \dfrac{a_{n-1}}{a_n} \right)^2 - 2 \dfrac{a_{n-2}}{a_n}
$$ Proof: The polynomial $p(x)$ can alternatively be written as $$
p(x) = a_n (x-r_1)(x-r_2) \dotsm (x-r_n) \tag{$\dagger$}
$$ When expanding this product, we add terms consisting of $\pm a_n$ times $n$ items, each either an $x$ or one of the $r_i$'s, then combine "like terms," i.e. those with the same power of $x$. For $0 \leq k \leq n$, a term in the expansion contributes to the $x^k$ coefficient when, from the $n$ factors in the product $( \dagger )$, we choose an $x$ from $k$ of them and the $-r_i$ from the other $n-k$. Therefore, the coefficient of $x^k$ in the expansion is $$
a_n (-1)^{n-k} \sum_{1 \leq i_1 < i_2 < \dotsb < i_{n-k} \leq n}{r_{i_1} r_{i_2} \dotsm r_{i_{n-k}}} \tag{$\ddagger$}
$$ Since the product $( \dagger )$ is an equivalent way of writing $p(x)$, the sum $( \ddagger )$ must be equal to the coefficient $a_k$.

On the other hand, the sum of the squares of the roots can be written as $$
\begin{align}
r_1^2 + r_2^2 + \dotsb + r_n^2
&= (r_1 + r_2 + \dotsb + r_n)^2 - 2 \sum_{1 \leq i_1 < i_2 \leq n}{r_{i_1} r_{i_2}} \\[3mm]
&= \left( \dfrac{1}{a_n (-1)^{n-(n-1)}}a_{n-1} \right)^2
-2 \dfrac{1}{a_n (-1)^{n-(n-2)}}a_{n-2} \tag{$\maltese$} \\[3mm]
&= \left( \dfrac{a_{n-1}}{a_n} \right)^2 - 2 \dfrac{a_{n-2}}{a_n}
\end{align}
$$ where the equality $( \maltese )$ was obtained by plugging in $(n-1)$ and $(n-2)$ in for $k$ in $( \ddagger )$. This completes the proof.
$\square$

Note: the result in the lemma is one of Newton's identities (or Newton sums) for polynomials, and the formulas $( \ddagger )$ (one formula for each value of $k$) are called Vieta's formulas. There are similar Newton's identities for the sum of the third, fourth, fifth, etc. powers of the roots. The formulas are recursive, each depending on the lower-degree Newton sums.


With the lemma and a slick AM-GM application, the final example will be a piece of cake.

Example 6: A polynomial with all coefficients equal to $\pm 1$ and only real roots has degree at most 3.

Proof: Suppose we have a polynomial $p(x) = a_n x^n + a_{n-1} x^{n-1} + \dotsb + a_1 x + a_0$ where each of the $a_i$'s is either $1$ or $-1$ and with roots $r_1, r_2, \dotsc, r_n$. We can assume that the leading coefficient $a_n$ is $+1$ since the polynomials with $a_n = -1$ are just the negatives of polynomials with $a_n = +1$.

By the lemma (with $a_n = 1$), the sum of the squares of the roots is $a_{n-1}^2 - 2 a_{n-2}$. Also, plugging in $k=n$ in $( \ddagger )$ tells us that the product of the squares of the roots is $a_0^2$.

By the AM-GM inequality, we have $$
\begin{align}
&&\dfrac{r_1^2 + r_2^2 + \dotsb + r_n^2}{n} &\geq \sqrt[n \uproot2]{r_1^2 r_2^2 \dotsm r_n^2} \\[3mm]
&\implies& \dfrac{a_{n-1}^2 - 2 a_{n-2}}{n} &\geq \sqrt[n]{a_0^2} \\[3mm]
&\implies& \dfrac{1 \pm 2}{n} &\geq 1 \ \ \ [\text{since all coefficients are }\pm 1 ] \\[3mm]
&\implies& 3 &\geq n
\end{align}
$$ $\square$

That will do it for this post. Please post any questions in the comments section. Thanks for reading, and stay tuned for part 3...

AM-GM Inequality (Part 1)

Intro to the geometric mean: portfolio returns


Everyone and their mother knows how to take the average, or arithmetic mean, of $n$ numbers $x_1, x_2, \dotsc , x_n$: $$
\text{AM}(x_1, x_2, \dotsc , x_n) = \dfrac{x_1 + x_2 + \dotsb + x_n}{n}
$$ Less well known is the geometric mean, calculated as the $n$-th root of the product of the numbers: $$
\text{GM}(x_1, x_2, \dotsc , x_n) = \sqrt[n]{x_1 x_2 \dotsm x_n} = (x_1 x_2 \dotsm x_n)^{\frac{1}{n}}
$$ Now, why would someone use such a thing? One application is analyzing returns on an investment portfolio. Let's look at an example (show-out to Max S-G for this one): say we start with a portfolio of 100 million dollars, which gains 20% in the first year, loses 20% in the second year, and gains 5% in the third year. Below is the table of portfolio sizes and returns for the 3 years:


We can see a few things here. First off, we got an error when attempting to calculate the GM of the returns directly. If we go back and look at the formula for GM above, we see that there is a root, and thus a negative input will return an error. To solve this problem, we need to use the multiple- calculated as 1 plus the return for that year- to avoid negative inputs. Then we subtract 1 at the end to get back to a return number- below is the same spreadsheet with the proper formula added:

The geometric mean is apparently the compound annual growth rate (CAGR) of the portfolio for the 3 years (note that the numbers are shown rounded, so if you do this calculation, it will be a bit off): $$
\$ 100 \times (1 + 0.3 \% )^{3} = \$ 100.8
$$ The geometric mean is the more appropriate measure of return due to the fact that returns are compounded. In other words, in year 2, we are not investing 100 million again, but rather the new portfolio value of 120 million, and the year 2 return of -20% applies to that amount. The arithmetic mean of the returns is misleading- the final portfolio value after year 3 is NOT $$
\$ 105.1 = \$ 100 \times (1 + 1.7 \% )^{3}
$$ Finally- and this is the topic of this post- the geometric mean return is less than the arithmetic mean return. It turns out this is always the case.


Inequality of the arithmetic and geometric mean


AM-GM Inequality: For $x_1, x_2, \dotsc , x_n \geq 0$, $$
\dfrac{x_1 + x_2 + \dotsb + x_n}{n} \geq \sqrt[n]{x_1 x_2 \dotsm x_n}
$$ with equality if and only if $x_1 = x_2 = \dotsb = x_n$.

I'll show the proof in part 2 of this post, but for now, let's look at the geometric interpretation and a few applications. It is easiest to start with the case where $n=2$. A point $(x,y)$, where $x$ and $y$ are both positive (there's nothing interesting about the case where one of them is zero, since then the geometric mean is zero), determines a rectangle as in the following diagram:
Here, I'm using an example point of $(3,5)$, and the rectangle is in red. The rectangle's area is $3 \times 5 = 15$, and in blue is a square of the same area. Thus the square has side length $\sqrt{15} \approx 3.87$. Notice that the square's side length is the geometric mean of the rectangle side lengths, while the arithmetic mean of the same numbers is 4, which, unsurprisingly, is greater than 3.87. Choosing a more "extreme" rectangle of the same area, say using $(x,y) = (1,15)$, would yield an even larger arithmetic mean of 8. In fact, we could choose a rectangle of area 15 with arbitrarily large arithmetic mean side lengths like $(x,y) = \left( 1{,}000{,}000 \ , \frac{15}{1{,}000{,}000} \right)$.

The AM-GM inequality tells us that any red rectangle we choose will have a larger average (i.e. arithmetic mean) side length than the side length of the blue square of the same area. Equivalently, the square has the minimum perimeter among all rectangles of equal area. An analogous statement applies to the $n=3$ case, with "square" replaced by "cube" and "area" replaced by "volume," and of course there are also analogs in higher dimensions with hypercubes and hypervolumes.


Application to minimization problems


Given the interpretation of the AM-GM inequality as a statement about the square/cube minimizing the perimeter given a constraint on the value of the area/volume, it shouldn't come as much of a surprise that we can use it to find the minimum value of certain functions that can be made to look like an arithmetic mean subject to a volume-like constraint. Let's look at a few examples- first a simple one, and then two minimization problems.

Example 1: Prove that $n! < \left( \frac{n+1}{2} \right)^{n}$ for $n=2,3,4, \dotsc$.

This is the AM-GM inequality applied to $(x_1, x_2, \dotsc , x_n) = (1,2, \dotsc, n)$: $$
\sqrt[n]{1 \cdot 2 \cdot \dotsm \cdot n} < \dfrac{1+2+ \dotsb + n}{n} = \dfrac{\frac{n(n+1)}{2}}{n} = \dfrac{n+1}{2}
$$ Raising both sides to the $n$-th power proves the original statement.
$\square$

Example 2: Find the minimum value of the function $f(x_1, x_2, \dotsc , x_n) = x_1 + x_2 + \dotsb + x_n$, where $x_1, x_2, \dotsc , x_n$ are positive real numbers with $x_1 x_2 \dotsm x_n = 1 \ ( \star )$. $$
\begin{align}
\dfrac{f(x_1, x_2, \dotsc , x_n)}{n} &= \dfrac{x_1 + x_2 + \dotsb + x_n}{n} \\[2mm]
&\geq \sqrt[n]{x_1 x_2 \dotsm x_n} \tag{AM-GM} \\[2mm]
&= 1 \tag{$\star$}
\end{align}
$$ which implies that $f(x_1, x_2, \dotsc , x_n) \geq n$. Furthermore, since $f(1, 1, \dotsc , 1) = n$, $n$ is indeed the minimum value of $f$.
$\square$

Example 3: Let $x,y,z \geq 0$ with $xyz = 1$. Find the minimum value of $$
S(x,y,z) = \dfrac{x^2}{y+z} + \dfrac{y^2}{z+x} + \dfrac{z^2}{x+y}
$$ Clearly, $S(1,1,1) = \frac{3}{2}$. We will show that this is the minimum value of $S$ by showing that $S \geq \frac{3}{2}$.

For this one, we'll need the Cauchy-Schwarz inequality, which states that for a positive integer $n$ and real numbers $a_1, a_2, \dotsc , a_n , b_1, b_2, \dotsc, b_n$, $$
\left( \sum_{i=1}^{n}{a_{i}^{2}} \right) \left( \sum_{i=1}^{n}{b_{i}^{2}} \right)
\geq \left( \sum_{i=1}^{n}{a_{i} b_{i}} \right)^{2}
$$ Click here for the proof.

Now, note that $$
S = \left( \dfrac{x}{\sqrt{y+z}} \right)^{2}
+ \left( \dfrac{y}{\sqrt{z+x}} \right)^{2}
+ \left( \dfrac{z}{\sqrt{x+y}} \right)^{2}
$$ Using Cauchy-Schwarz with $n=3$, for any numbers $b_1, b_2, b_3$, we obtain: $$
S \cdot (b_{1}^{2} + b_{2}^{2} + b_{3}^{2})
\geq
\left(
\dfrac{xb_1}{\sqrt{y+z}}
+ \dfrac{yb_2}{\sqrt{z+x}}
+ \dfrac{zb_3}{\sqrt{x+y}}
\right) ^{2} \tag{$\spadesuit$}
$$ This works for any values of $(b_1, b_2, b_3)$, so we can choose $(\sqrt{y+z}, \sqrt{z+x}, \sqrt{x+y})$, which makes $( \spadesuit )$ simplify to: $$\begin{align}
S &\geq \dfrac{1}{2}(x+y+z) \tag{from the above equation} \\[3mm]
&\geq \dfrac{1}{2} \cdot 3 \sqrt[3]{xyz} \tag{AM-GM} \\[3mm]
&= \dfrac{3}{2} \tag{since $xyz=1$}
\end{align}
$$ $\square$

That will do it for this post. In part 2, I will show the proof of the AM-GM inequality, along with a few more examples of its use in miscellaneous problems.

Thanks for reading, and post any questions in the comments section.

Solving a Recursion

Prerequisites: Induction

For those of you who have never heard of it, the Putnam exam is a test for college students (mostly math majors) that universities throughout the country compete in. The test is hard- there are 12 questions (in two sets of 6, for which you get three hours per set), and the median score is 0. I've taken it a few times myself, and I think my record was 2 questions correct, which I was pretty pleased with.

Anyway, a lot of schools have a team that prepares for this test (at Dartmouth, this consisted of a bunch of people gathering for free Raymunto's pizza, which is a surefire way to get folks to show up there), and consequently, you can find a lot of the practice problems on the internet. In fact, you can find archives of past Putnam exams and solutions online, for example, here.

Anyway, the reason I mentioned all this is that I found the following problem in a Putnam practice document from Northwestern:

There are $n$ great circles drawn on the surface of a sphere such that no more than 2 intersect at any point. Into how many regions do the circles divide the surface of the sphere?


Now, I'll get to explaining what a great circle is in a second, but first, I'll explain what made me want to write a post about this problem in the first place. Obviously, the solution must be some function of $n$. Ok, great. But what really #GroundMyGears was that in the solutions in this document, they basically looked at the first few cases, $n=1,2,3,4,...$, guessed the answer, and then proved it was correct by induction. Don't get me wrong- this was all correct and everything, but I just felt like guessing the answer and then proving it works by induction was kind of a cop-out in this case. So I worked out the same answer in what I thought was a more satisfying way, and that's what I'm going to show you here. This method works for other recursions as well, so it may actually be useful to you some day.

Ok, first of all, I just said it, and it's in the title of the post, so what is a recursion? A recursion defines an object in terms of itself.

What???

Ok, maybe best to use an example here, and I promise you'll see what I mean: the factorial of a positive integer $n$, denoted $n!$, is defined as the product of the positive integers 1 through $n$. In symbols, $n! = n(n-1)(n-2)...(3)(2)(1)$, or more succinctly, $n! = \prod_{i=1}^{n}{i}$. Here's where it gets interesting: factorials can be defined in terms of themselves as follows: $$
1! = 1 \\
\forall n > 1, n! = n \cdot (n-1)!
$$ Clearly, this gives the same definition as above, but now we've defined the factorial function in terms of itself, but for smaller values of the input variable. This is crucial in computer science, where we can use this method to specify infinitely many (or more precisely, an arbitrarily large number of) objects in a finite number of steps.

Recursion is also very closely related to induction. Properties of recursively defined functions and sets can often be proved by an induction argument that follows the recursive definition (sentence copy/pasted from Wikipedia, thank you very much). A recursive function definition always needs a base case whose value is specified, and then an inductive definition of the function for greater input values, in terms of the values of the function for smaller inputs.

Hopefully the above got the point across (if not, leave a question in the comments section). Let's shift gears now and talk about great circles.

A great circle of a sphere is a circle drawn on the surface of the sphere, whose center coincides with the sphere's center. All great circles have the same radius and diameter as the sphere itself. Another way to put it is that a great circle is the intersection of a sphere and a plane which passes through its center. These are the largest circles that can be drawn on the surface of a sphere. Smaller circles (called small circles) arise when a plane intersects a sphere and does not pass through its center. In the diagram below, the red circle is a great circle, and the blue one is a small circle:

The equator and meridian are examples of great circles on the surface of the earth. While I'm talking about great circles, it's worth mentioning, though we won't need it in this post, that the shortest path between any two points on the surface of a sphere is the great circle arc (i.e. piece of the great circle) connecting them. It's also worth mentioning (and we will need this fact) that any two great circles intersect at two points (can you see why?).

On that note, let's get back to the question about $n$ great circles on the surface of the sphere. Let's call the number of regions on the surface after we've drawn $n$ great circles $R(n)$. With one circle, the sphere is divided into 2 halves, or hemispheres (hemi- is a prefix that means half, as do demi- and semi- by the way, but for some reason, the word turned out to be hemisphere and not semisphere or demisphere...). So $R(1)=2$.

If we add a second circle, it will intersect the first at 2 points, cutting the existing two regions into 4, so $R(2)=4$. Now, a third great circle will intersect the first two at 2 points each. Remember that the question prohibited an intersection at the existing intersection points (if it hit one, it would hit both), so the third circle again cuts the existing regions each in two, implying $R(3)=8$.

Things get trickier on the fourth circle, which is tougher to picture without a diagram. See the green and red circles in the below diagram, which are the fourth and fifth great circles drawn on the surface after the first 3 black ones:
Note first of all that the fourth circle (and each one thereafter) does not intersect every existing region. The fourth circle intersects 6 of the 8 existing regions, and in fact, since each great circle is the intersection of a plane with the sphere, the fact that the fourth circle hits 6 regions is explained in the post The Plane in ${\Bbb R}^3$- I'll leave it to you to explore the connection there (and it actually does not depend on the angles the first three planes make with each other). So the fourth circle adds 6 new regions (one for each of the 6 it intersected and thus cut into two) so that $R(4)=8+6=14$.

In general, we can see by the same logic that the $n^{\scr th}$ circle intersects each of the existing $n-1$ circles twice. Since none of those intersection points existed before drawing the $n^{\scr th}$ circle (because if one had, then we'd have three circles intersecting at one point, which isn't allowed), there must be $2(n-1)$ intersection points of the $n^{\scr th}$ circle with the original $n-1$ circles.

Also, you can see from the diagram that when we draw the $n^{\scr th}$ circle, each set of two new intersection points breaks the $n^{\scr th}$ circle into an arc which cuts one of the existing $R(n-1)$ regions into two new ones. The number of regions the circle intersects (and thus cuts into two) is $2(n-1)$, because if we walk around the $n^{\scr th}$ circle, there is one region after each of the $2(n-1)$ intersection points with the other circles.

The above two paragraphs give us our recursion: $$
\begin{align}
R(n) &= R(n-1) + 2(n-1), n \geq 2 \tag{1}\\[2mm]
R(1) &= 2 \tag{2}
\end{align}
$$ Note that we need only one initial condition because there is only an $R(n-1)$ term in the recursion equation. If there were also an $R(n-2)$ in there, we'd need both $R(1)$ and $R(2)$ to determine the value of $R$ for all values of $n$. So now that we have our recursion, let's solve the thing. For $n \geq 2$, rearranging $(1)$ gives $$R(n) - R(n-1) = 2(n-1) \tag{3}
$$ Since $(3)$ holds for every $n \geq 2$, we have $$
\begin{align}
R(n-1) - R(n-2) &= 2(n-2) \\[3mm]
R(n-2) - R(n-3) &= 2(n-3) \\[3mm]
\vdots \\[3mm]
R(2) - R(1) &= 2(1)
\end{align}
$$ Therefore: $$
\begin{align}
R(n) &= R(n) + 0 \\[3mm]
&= R(n) + (-R(n-1)+R(n-1)) + (-R(n-2)+R(n-2)) + \cdots + (-R(2)+R(2)) + (-R(1)+R(1)) \\[3mm]
&= (R(n)-R(n-1)) + (R(n-1)-R(n-2)) + \cdots + (R(2)-R(1)) + R(1) \\[3mm]
&\overset{(3)}{=} 2(n-1) + 2(n-2) + \cdots + 2(1) + R(1) \\[3mm]
&\overset{(2)}{=} 2(n-1) + 2(n-2) + \cdots + 2(1) + 2 \\[3mm]
&= \left( 2 \sum_{i=1}^{n-1}{i} \right) + 2 \\[3mm]
&= 2 \left( \dfrac{(n-1)(1+(n-1))}{2} \right) + 2 \tag{$\spadesuit$}\\[3mm]
&= (n-1)n+2 \\[3mm]
&= n^2 - n + 2
\end{align}
$$ where the equality $(\spadesuit)$ is because of the fact that an arithmetic series, i.e. a sum of $N$ terms, the first of which is $a_1$, the last of which is $a_N$, and with the difference between successive terms being a constant, has $\dfrac{N(a_1 + a_N)}{2}$ as its sum. Can you prove why?

So now we've solved for $R(n)$ for every value of $n$ using the recursion equation $(1)$ and the initial condition $(2)$.

I hope you found this interesting and maybe even useful. Thanks for reading, and please post any questions or comments in the comments section.