Rearrangement inequality

In mathematics, the rearrangement inequality states that for every choice of real numbers $$x_1 \le \cdots \le x_n \quad \text{ and } \quad y_1 \le \cdots \le 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: Note that the rearrangement inequality ($$) makes no assumptions on the signs of the real numbers, unlike inequalities such as the arithmetic-geometric mean inequality.
 * 1)  The upper bound in ($$) is attained only for permutations $$\sigma$$ that keep the order of $$y_1, \ldots, y_n,$$ that is, $$y_{\sigma(1)} \le \cdots \le 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 identiy.
 * 2)  Correspondingly, the lower bound in ($$) is attained only for permutations $$\sigma$$ that reverse the order of $$y_1, \ldots, y_n,$$ meaning that $$y_{\sigma(1)} \ge \cdots \ge 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.

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 \le \cdots \le x_n$$: By applying ($$) with $$y_i := x_i$$ for all $$i = 1,\ldots,n,$$ it follows that $$x_1 x_n + \cdots + x_n x_1 \le x_1 x_{\sigma(1)} + \cdots + x_n x_{\sigma(n)} \le 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\cdot100 + 5\cdot20 + 3\cdot10$$ dollars. This is exactly what the upper bound of the rearrangement inequality ($$) 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 ($$) says that you optimize the total area of your selection by taking the rectangles on the diagonal or the antidiagonal.

Proof by contradiction
The lower bound and the corresponding discussion of equality follow by applying the results for the upper bound to $$- y_n \le \cdots \le - y_1.$$ Therefore, it suffices to prove the upper bound in ($$) 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 ($$) $$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 ($$), 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 ($$). 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 ($$) due to ($$). This contradicts the choice of $$\sigma.$$

If $$x_1 < \cdots < x_n,$$ then we have strict inequalities in ($$), ($$), and ($$), hence the maximum can only be attained by permutations keeping the order of $$y_1 \le \cdots \le y_n,$$ and every other permutation $$\sigma$$ cannot be optimal.

Proof by induction
As above, it suffices to treat the upper bound in ($$). For a proof by mathematical induction, we start with $$n=2.$$ Observe that $$x_1 \le x_2 \quad \text{ and } \quad y_1 \le y_2$$ implies that

which is equivalent to

hence the upper bound in ($$) is true for $$n = 2.$$ If $$x_1 < x_2,$$ then we get strict inequality in ($$) and ($$) 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 ($$) is true for $$n-1$$ with $$n\ge3$$ 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 \le \cdots \le x_n$$ and $$y_1 \le \cdots \le y_n.$$ Take a $$\sigma$$ from the finite number of permutations of $$1,\ldots,n$$ such that the rearrangement in the middle of ($$) gives the maximal result. There are two cases:

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 $$\sigma(n)=n,$$ then $$y_n=y_{\sigma(n)}$$ and, using the induction hypothesis, the upper bound in ($$) 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\},\\
 * 1) 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 ($$) 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.
 * 2) 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.$$

Three or more sequences
A straightforward generalization takes into account more sequences. Assume we have finite ordered sequences of nonnegative real numbers $$0 \le x_1\le\cdots\le x_n\quad\text{and}\quad 0\le y_1\le\cdots\le y_n\quad\text{and}\quad 0\le z_1\le\cdots\le 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)} \le x_1 y_1 z_1 + \cdots + x_n y_n z_n.$$

Note that, unlike the standard rearrangement inequality ($$), 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 \le \cdots \le x_n$$ and every choice of continuously differentiable functions $$f_i: [x_1,x_n] \to \R$$ for $$i = 1, 2, \ldots, n$$ such that their derivatives $$f'_1,\ldots,f'_n$$ satisfy $$f'_1(x) \le f'_2(x) \le \cdots \le 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) \le \sum_{i=1}^n f_{\sigma(i)}(x_i) \le \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 \le \cdots \le y_n$$ and the linear functions $$f_i(x) := x y_i$$ for real $$x$$ and $$i = 1,\ldots,n,$$ the standard rearrangement inequality ($$) is recovered.