Solution (source code)

= Solution

The <expected value>[mean] extension in an ensemble of $A$ molecules is
$$
L=\frac1A\sum_i a_i l_i,
$$
with constraints $\sum_i a_i=A$ and $\sum_i a_i l_i=AL$. For occupancies $\{a_i\}$, the number of assignments of the $A$ distinguishable ensemble members to the states is the <multinomial coefficient>
$$
W=\frac{A!}{\prod_i a_i!}.
$$
Thus maximizing the probability at fixed $A$ and $L$ is equivalent to maximizing the stated <Lagrange multiplier> expression.

Because $A\gg1$, the <Stirling formula> gives $\log(a_i!)\simeq a_i\log a_i-a_i$. Differentiating with respect to each $a_i$ gives
$$
-\log a_i+\tau l_i-\alpha=0,
\qquad
a_i=e^{-\alpha}e^{\tau l_i}.
$$
Normalization by $\sum_i a_i=A$ therefore yields the <probability mass function>
$$
\boxed{p_i=\frac{a_i}{A}=\frac{e^{\tau l_i}}{Z}},
\qquad
\boxed{Z=\sum_i e^{\tau l_i}}.
$$
Here $Z$ is the fixed-tension <partition function> that normalizes the probabilities.