Prove that in an optimal code, if the letter frequencies are increasing, the encoding lengths are monotonically decreasing
I have come up with a solution.

To show that the old $B(A)$ is larger than the new $B(A)$, it is necessary to show that

$$\text{f}(x_1)\times\text{c_len}(x_1) + \text{f}(x_2)\times\text{c_len}(x_2) &gt; \text{f}(x_1)\times\text{c_len}(x_2) + \text{f}(x_2)\times\text{c_len}(x_1)$$

($\text{f}(x)$ = frequency of $x$, $\text{c_len}(x)$ = length of $x$'s encoding.)

By moving terms over and using distributive law:

$$\text{f}(x_1)(\text{c_len}(x_1) - \text{c_len}(x_2)) &gt; \text{f}(x_2)(\text{c_len}(x_1) - \text{c_len}(x_2))$$

Since $\text{c_len}(x_1) &lt; \text{c_len}(x_2)$,
$$\text{c_len}(x_1) - \text{c_len}(x_2) &lt; 0$$

Therefore dividing both sides by $\text{c_len}(x_1) - \text{c_len}(x_2)$ leaves:

$$\text{f}(x_1) &lt; \text{f}(x_2)$$

Which is true as it is a premise.

Correct me if I have made a mistake.