# Rearrangement inequality

In mathematics, the rearrangement inequality states that for every choice of real numbers $x_{1}\leq \cdots \leq x_{n}\quad {\text{ and }}\quad y_{1}\leq \cdots \leq y_{n}$ and every permutation $\sigma$ of the numbers $1,2,\ldots n$ we have
Informally, this means that in these types of sums, the largest sum is achieved by pairing large $x$ values with large $y$ values, and the smallest sum is achieved by pairing small values with large values. This can be formalised in the case that the $x_{1},\ldots ,x_{n}$ are distinct, meaning that $x_{1}<\cdots <x_{n},$ then:
* The upper bound in (1) is attained only for permutations $\sigma$ that keep the order of $y_{1},\ldots ,y_{n},$ that is, $y_{\sigma (1)}\leq \cdots \leq y_{\sigma (n)},$ or equivalently $(y_{1},\ldots ,y_{n})=(y_{\sigma (1)},\ldots ,y_{\sigma (n)}).$ Such a $\sigma$ can permute the indices of $y$-values that are equal; in the case $y_{1}=\cdots =y_{n}$ every permutation keeps the order of $y_{1},\ldots ,y_{n}.$ If $y_{1}<\cdots <y_{n},$ then the only such $\sigma$ is the identity.
* Correspondingly, the lower bound in (1) is attained only for permutations $\sigma$ that reverse the order of $y_{1},\ldots ,y_{n},$ meaning that $y_{\sigma (1)}\geq \cdots \geq y_{\sigma (n)}.$ If $y_{1}<\cdots <y_{n},$ then $\sigma (i)=n-i+1$ for all $i=1,\ldots ,n,$ is the only permutation to do this.
Note that the rearrangement inequality (1) makes no assumptions on the signs of the real numbers, unlike inequalities such as the arithmetic-geometric mean inequality.

## Applications

Many important inequalities can be proved by the rearrangement inequality, such as the arithmetic mean – geometric mean inequality, the Cauchy–Schwarz inequality, and Chebyshev's sum inequality.
As a simple example, consider real numbers $x_{1}\leq \cdots \leq x_{n}$: By applying (1) with $y_{i}:=x_{i}$ for all $i=1,\ldots ,n,$ it follows that $x_{1}x_{n}+\cdots +x_{n}x_{1}\leq x_{1}x_{\sigma (1)}+\cdots +x_{n}x_{\sigma (n)}\leq x_{1}^{2}+\cdots +x_{n}^{2}$ for every permutation $\sigma$ of $1,\ldots ,n.$

## Intuition

The rearrangement inequality can be regarded as intuitive in the following way. Imagine there is a heap of $10 bills, a heap of $20 bills and one more heap of $100 bills. You are allowed to take 7 bills from a heap of your choice and then the heap disappears. In the second round you are allowed to take 5 bills from another heap and the heap disappears. In the last round you may take 3 bills from the last heap. In what order do you want to choose the heaps to maximize your profit? Obviously, the best you can do is to gain $7\cdot 100+5\cdot 20+3\cdot 10$ dollars. This is exactly what the upper bound of the rearrangement inequality (1) says for the sequences $3<5<7$ and $10<20<100.$ In this sense, it can be considered as an example of a greedy algorithm.

## Geometric interpretation

Assume that $0<x_{1}<\cdots <x_{n}$ and $0<y_{1}<\cdots <y_{n}.$ Consider a rectangle of width $x_{1}+\cdots +x_{n}$ and height $y_{1}+\cdots +y_{n},$ subdivided into $n$ columns of widths $x_{1},\ldots ,x_{n}$ and the same number of rows of heights $y_{1},\ldots ,y_{n},$ so there are $\textstyle n^{2}$ small rectangles. You are supposed to take $n$ of these, one from each column and one from each row. The rearrangement inequality (1) says that you optimize the total area of your selection by taking the rectangles on the diagonal or the antidiagonal.

## Proofs
### Proof by contradiction

The lower bound and the corresponding discussion of equality follow by applying the results for the upper bound to −y$_n$≤⋯≤−y$_1${\textstyle -y_{n}\leq \cdots \leq -y_{1}}, that is, let $\upsilon$ be any permutation of the numbers 1, 2, …n{\textstyle 1, 2, \ldots n} we have x$_1$(−y$_{υ(1)}$)+⋯+x$_n$(−y$_{υ(n)}$)≤x$_1$(−y$_n$)+⋯+x$_n$(−y$_1$){\textstyle x_{1}(-y_{\upsilon (1)})+\cdots +x_{n}(-y_{\upsilon (n)})\leq x_{1}(-y_{n})+\cdots +x_{n}(-y_{1})}. Then, x$_1$y$_n$+⋯+x$_n$y$_1$≤x$_1$y$_{υ(1)}$+⋯+x$_n$y$_{υ(n)}${\textstyle x_{1}y_{n}+\cdots +x_{n}y_{1}\leq x_{1}y_{\upsilon (1)}+\cdots +x_{n}y_{\upsilon (n)}} for every permutation $\upsilon$ of $1,\dots ,n$.
Therefore, it suffices to prove the upper bound in (1) and discuss when equality holds. Since there are only finitely many permutations of $1,\ldots ,n,$ there exists at least one $\sigma$ for which the middle term in (1) $x_{1}y_{\sigma (1)}+\cdots +x_{n}y_{\sigma (n)}$ is maximal. In case there are several permutations with this property, let σ denote one with the highest number of integers $i$ from $\{1,\ldots ,n\}$ satisfying $y_{i}=y_{\sigma (i)}.$
We will now prove by contradiction, that $\sigma$ has to keep the order of $y_{1},\ldots ,y_{n}$ (then we are done with the upper bound in (1), because the identity has that property). Assume that there exists a $j\in \{1,\ldots ,n-1\}$ such that $y_{i}=y_{\sigma (i)}$ for all $i\in \{1,\ldots ,j-1\}$ and $y_{j}\neq y_{\sigma (j)}.$ Hence $y_{j}<y_{\sigma (j)}$ and there has to exist a $k\in \{j+1,\ldots ,n\}$ with $y_{j}=y_{\sigma (k)}$ to fill the gap. Therefore,
which implies that
Expanding this product and rearranging gives
which is equivalent to (3). Hence the permutation $\tau (i):={\begin{cases}\sigma (i)&{\text{for }}i\in \{1,\ldots ,n\}\setminus \{j,k\},\\\sigma (k)&{\text{for }}i=j,\\\sigma (j)&{\text{for }}i=k,\end{cases}}$ which arises from $\sigma$ by exchanging the values $\sigma (j)$ and $\sigma (k),$ has at least one additional point which keeps the order compared to $\sigma ,$ namely at $j$ satisfying $y_{j}=y_{\tau (j)},$ and also attains the maximum in (1) due to (4). This contradicts the choice of $\sigma .$
If $x_{1}<\cdots <x_{n},$ then we have strict inequalities in (2), (3), and (4), hence the maximum can only be attained by permutations keeping the order of $y_{1}\leq \cdots \leq y_{n},$ and every other permutation $\sigma$ cannot be optimal.

### Proof by induction

As above, it suffices to treat the upper bound in (1). For a proof by mathematical induction, we start with $n=2.$ Observe that $x_{1}\leq x_{2}\quad {\text{ and }}\quad y_{1}\leq y_{2}$ implies that
which is equivalent to
hence the upper bound in (1) is true for $n=2.$ If $x_{1}<x_{2},$ then we get strict inequality in (5) and (6) if and only if $y_{1}<y_{2}.$ Hence only the identity, which is the only permutation here keeping the order of $y_{1}<y_{2},$ gives the maximum.
As an induction hypothesis assume that the upper bound in the rearrangement inequality (1) is true for $n-1$ with $n\geq 3$ and that in the case $x_{1}<\cdots <x_{n-1}$ there is equality only when the permutation $\sigma$ of $1,\ldots ,n-1$ keeps the order of $y_{1},\ldots ,y_{n-1}.$
Consider now $x_{1}\leq \cdots \leq x_{n}$ and $y_{1}\leq \cdots \leq y_{n}.$ Take a $\sigma$ from the finite number of permutations of $1,\ldots ,n$ such that the rearrangement in the middle of (1) gives the maximal result. There are two cases:
* If $\sigma (n)=n,$ then $y_{n}=y_{\sigma (n)}$ and, using the induction hypothesis, the upper bound in (1) is true with equality and $\sigma$ keeps the order of $y_{1},\ldots ,y_{n-1},y_{n}$ in the case $x_{1}<\cdots <x_{n}.$
* If $k:=\sigma (n)<n,$ then there is a $j\in \{1,\dots ,n-1\}$ with $\sigma (j)=n.$ Define the permutation $\tau (i)={\begin{cases}\sigma (i)&{\text{for }}i\in \{1,\ldots ,n\}\setminus \{j,n\},\\k&{\text{for }}i=j,\\n&{\text{for }}i=n,\end{cases}}$ which arises from $\sigma$ by exchanging the values of $j$ and $n.$ There are now two subcases:
* If $x_{k}=x_{n}$ or $y_{k}=y_{n},$ then this exchange of values of $\sigma$ has no effect on the middle term in (1) because $\tau$ gives the same sum, and we can proceed by applying the first case to $\tau .$ Note that in the case $x_{1}<\cdots <x_{n},$ the permutation $\tau$ keeps the order of $y_{1},\ldots ,y_{n}$ if and only if $\sigma$ does.
* If $x_{k}<x_{n}$ and $y_{k}<y_{n},$ then $0<(x_{n}-x_{k})(y_{n}-y_{k}),$ which is equivalent to $x_{k}y_{n}+x_{n}y_{k}<x_{k}y_{k}+x_{n}y_{n}$ and shows that $\sigma$ is not optimal, hence this case cannot happen due to the choice of $\sigma .$

## Generalizations
### Three or more sequences

A straightforward generalization takes into account more sequences. Assume we have finite ordered sequences of nonnegative real numbers $0\leq x_{1}\leq \cdots \leq x_{n}\quad {\text{and}}\quad 0\leq y_{1}\leq \cdots \leq y_{n}\quad {\text{and}}\quad 0\leq z_{1}\leq \cdots \leq z_{n}$ and a permutation $y_{\sigma (1)},\ldots ,y_{\sigma (n)}$ of $y_{1},\dots ,y_{n}$ and another permutation $z_{\tau (1)},\dots ,z_{\tau (n)}$ of $z_{1},\dots ,z_{n}.$ Then $x_{1}y_{\sigma (1)}z_{\tau (1)}+\cdots +x_{n}y_{\sigma (n)}z_{\tau (n)}\leq x_{1}y_{1}z_{1}+\cdots +x_{n}y_{n}z_{n}.$
Note that, unlike the standard rearrangement inequality (1), this statement requires the numbers to be nonnegative. A similar statement is true for any number of sequences with all numbers nonnegative.

### Functions instead of factors

Another generalization of the rearrangement inequality states that for all real numbers $x_{1}\leq \cdots \leq x_{n}$ and every choice of continuously differentiable functions $f_{i}:[x_{1},x_{n}]\to \mathbb {R}$ for $i=1,2,\ldots ,n$ such that their derivatives $f'_{1},\ldots ,f'_{n}$ satisfy $f'_{1}(x)\leq f'_{2}(x)\leq \cdots \leq f'_{n}(x)\quad {\text{ for all }}x\in [x_{1},x_{n}],$ the inequality $\sum _{i=1}^{n}f_{n-i+1}(x_{i})\leq \sum _{i=1}^{n}f_{\sigma (i)}(x_{i})\leq \sum _{i=1}^{n}f_{i}(x_{i})$ holds for every permutation $f_{\sigma (1)},\ldots ,f_{\sigma (n)}$ of $f_{1},\ldots ,f_{n}.$ Taking real numbers $y_{1}\leq \cdots \leq y_{n}$ and the linear functions $f_{i}(x):=xy_{i}$ for real $x$ and $i=1,\ldots ,n,$ the standard rearrangement inequality (1) is recovered.