# Expectation value of energy in a canonical ensemble

Suppose we have a canonical ensemble system of $$N$$ particles, and $$k$$ single-particle-energy levels labeled by $$\epsilon_i$$.

The energy of the different microstates of the entire system is given by $$\sum n_i\epsilon_i$$, such that $$\sum n_i = N.$$

Let us label the total energies of the system using $$E_i$$ as opposed to the single particle energy levels.

The total expectation value of energy is defined as :

$$\langle E\rangle=\sum_{i}^{m}P(E_i)E_i$$

Here $$E_i$$ represents the total energy of a microstate, and $$P(E_i)$$ represents the probability of the $$N$$ particle microstate. The summation goes till $$m$$ which is the total number of $$N$$ particle microstates of the entire system as a whole.

However, I've seen some sources, like this for example, describe the expectation value of energy in a slightly different way.

According to this source, $$\langle E\rangle=\sum_i^k n_i\epsilon_i$$

In this case, $$n_i$$ represents the (expected) number of particles in the $$\epsilon_i$$ energy level. In this case, the summation goes till $$k$$ which is the number of single particle energy states of the system.

These two definitions seem to be equivalent intuitively. For example, in the thermodynamic limit, $$n_i$$ is the exact number of particles occupying the $$\epsilon_i$$ energy level, and so $$\langle E\rangle$$ must be the total energy of the system. In the previous case, we know that as we reach the large number limit, the energy fluctuations die out, and the expected energy takes a particular value.

However, can someone help me show this mathematically that :

$$\langle E\rangle=\sum_i^k n_i\epsilon_i=\sum_{i}^{m}P(E_i)E_i$$

where ,$$n_i = NZ^{-1}e^{-\beta \epsilon_i}$$

In the first definition, the expected total energy is the energy of each microstate of the system multiplied by its probability and summed over. In the second definition, the expected total energy is the sum of the energies of each particle. This is done, by multiplying the energy of a single particle energy level, with all the particles expected to be in that level, and then summed over.

Let's prove the following statement, for a system of two particles. It is straight-forward to generalize to $$N$$ particles via an inductive argument. Assuming that
• we can specify the states of each particle independently by separately specifying the energies $$\epsilon_1$$ and $$\epsilon_2$$ of the two particles, and
• the total energy can be written as the sum of the energies of the two modes, given by \begin{align*} E(\epsilon_1,\epsilon_2)=\epsilon_1+\epsilon_2\,, \end{align*} then we can compute the (thermal) average energy of each mode separately and then add up them up at the end.
Proof: The average energy of the two-atom subsystem is given by \begin{align*} U = \sum_{E} EP(E) = \sum_{\epsilon_1} \sum_{\epsilon_2}E(\epsilon_1,\epsilon_2)P(E(\epsilon_1,\epsilon_2))\,. \end{align*} The probability is \begin{align*} P(E(\epsilon_1,\epsilon_2))&=\frac{1}{Z}e^{-\beta E(\epsilon_1,\epsilon_2)}\,,~~~~~~~~~~ Z = \sum_{\epsilon_1} \sum_{\epsilon_2}e^{-\beta E(\epsilon_1,\epsilon_2)}\,. \end{align*} Now, the exponential factor factorizes as $$e^{-\beta E(\epsilon_1,\epsilon_2)} = e^{-\beta\epsilon_1}e^{-\beta\epsilon_2}$$, which means that the partition function can be written as \begin{align*} Z &= \sum_{\epsilon_1} \sum_{\epsilon_2}e^{-\beta\epsilon_1}e^{-\beta\epsilon_2} =\sum_{\epsilon_1} e^{-\beta\epsilon_1}\sum_{\epsilon_2}e^{-\beta\epsilon_2}=Z_1Z_2. \end{align*} Thus, the probability becomes \begin{align*} P(E(\epsilon_1,\epsilon_2)) = \frac{e^{-\beta\epsilon_1}}{Z_1}\frac{e^{-\beta\epsilon_2}}{Z_2}, \end{align*} and so the internal energy becomes \begin{align*} U &= \sum_{\epsilon_1} \sum_{\epsilon_2}E(\epsilon_1,\epsilon_2)P(E(\epsilon_1,\epsilon_2)) =\sum_{\epsilon_1} \sum_{\epsilon_2}(\epsilon_1+\epsilon_2) \frac{e^{-\beta\epsilon_1}}{Z_1}\frac{e^{\beta\epsilon_2}}{Z_2}\\ &=\sum_{\epsilon_1} \epsilon_1\frac{e^{-\beta\epsilon_1}}{Z_1} \sum_{\epsilon_2}\frac{e^{-\beta\epsilon_2}}{Z_2} +\sum_{\epsilon_1} \frac{e^{-\beta\epsilon_1}}{Z_1} \sum_{\epsilon_2}\epsilon_2\frac{e^{-\beta\epsilon_2}}{Z_2}. \end{align*} Now, we recognize that the sum over the probabilities is 1, e.g. \begin{align*} \sum_{\epsilon}\frac{e^{-\beta\epsilon}}{Z} = 1. \end{align*} Therefore, the energy becomes \begin{align*} U&= \sum_{\epsilon_1} \epsilon_1\frac{e^{-\beta\epsilon_1}}{Z_1} +\sum_{\epsilon_2} \epsilon_2\frac{e^{-\beta\epsilon_2}}{Z_2}\,. \end{align*} Now, the last thing to recognize is that since the collection of energy states available for each particle is the same, this is just \begin{align*} U&= 2\sum_{\epsilon} \epsilon\frac{e^{-\beta\epsilon}}{Z} =\sum_{\epsilon} \frac{2e^{-\beta\epsilon}}{Z}\epsilon =\sum_{\epsilon} n_{\epsilon}\epsilon\,. \end{align*} The generalization to $$N$$ particles is obvious. Note that this derivation requires the particles to be non-interacting, which I think is necessary for this derivation to make sense. Alternatively, we can think of (bosonic) quasi-particles occupying the quasi-particle states, and I think the same derivation goes through, but we need to be careful about symmetrizing the partition function before computing the energy. Those are things I haven't thought carefully about in a long time, though.