# Temperature from the Gibbs entropy

In statistical mechanics, temperature is typically introduced via the Boltzmann entropy as follows. The Boltzmann entropy is $$S=k_B \ln W$$ where $$W$$ is the number of microstates. If the system's energy, $$E$$ is fixed, then $$W$$ is a function of the energy, $$W=W(E)$$. Considering two isolated systems with energy $$E_1$$ and $$E_2$$, their number of microstates are $$W_1(E_1)$$ and $$W_2(E_2)$$. The total entropy of the two systems is then $$S=S_1 + S_2 = k_B \ln [W_1(E_1) W_2(E_2)]$$.

Let us put the two systems in thermal contact with each other. They are allowed to exchange energy. Equilibrium sets in when the total number of microstates with the new distribution of energies is the largest. Equivalently, one can consider the logarithm of microstates to be the largest. Let the equilibrium energies be $$E_1'$$ and $$E_2'$$. The equilibrium condition reads:

$$\left . \frac{\partial \ln W_1(E_1)}{\partial E_1} \right|_{E_1'} = \left . \frac{\partial \ln W_2(E_2)}{\partial E_2} \right|_{E_2'}$$

Since this is the condition for thermal equilibrium, one may identify the temperature as

$$\left . \frac{\partial \ln W_1(E_1)}{\partial E_1} \right|_{E_1'} = \left . \frac{\partial \ln W_2(E_2)}{\partial E_2} \right|_{E_2'} = \frac{1}{T}$$

What confuses me here is that from the moment where the two systems are allowed to exchange energy, they are no longer individually in a microcanonical ensemble. Their energy can fluctuate and their individual microstates are not equally likely. Moreover, since the energy can fluctuate, $$E_1'$$ and $$E_2'$$ are not well defined. My understanding is that, if the energy is not fixed and the microstates are not equally likely, the Boltzmann formula is not valid any more and one should use the Gibbs entropy formula $$S = -k_B \sum P_i \ln P_i$$ where the sum runs over all microstates $$i$$.

I believe the correct statement would be that equilibrium sets in for the most probable allocation of the mean energies $$\langle E_1' \rangle$$ and $$\langle E_2' \rangle$$ between the two systems.

Question: Is it possible to introduce the temperature, similarly to the above, but using the Gibbs entropy, and finding the most probable distribution of mean energies, rather than instantaneous energies? If so, how?

I understand that none of this matters in the thermodynamic limit, as energy fluctuations are small and the Gibbs entropy is close to the Boltzmann entropy due to the sharpness of the $$P_i$$ distributions. I need, however, a rigorous definition of temperature that applies to arbitrarily small systems as well. I want therefore to relax the condition of thermodynamic limit. Indeed, one could formulate problems like single particle or single spin in contact with a heat bath and consider the single particle to have a well defined temperature and apply statistical mechanics concepts.

The starting point is, as you correctly observe, the fact that when the two subsystems (say 1 and 2) are in thermal contact, i.e. they may exchange energy, with the constraint that the total energy $$E=E_1+E_2$$ is kept constant, the number of microstates of the total system can be written as $$\Gamma(E) = \sum_{i=0}^{E/\Delta}\Gamma_1(E_i) \Gamma_2(E-E_i)$$ where $$E_i=i \Delta$$, by introducing a coarse grained energy spacing $$\Delta$$.
Let $$\bar E_1$$ be the energy of the system 1 which maximize the above sum of positive terms and, correspondingly, let $$\bar E_2 = E- \bar E_1$$ be the energy of the subsystem 2. Thus, the whole sum must be larger than its maximum term and smaller than the maximum term multiplied by the number of terms: $$\Gamma_1(\bar E_1) \Gamma_2(\bar E_2) \leq \Gamma(E) \leq \left( \frac{E}{\Delta} +1 \right) \Gamma_1(\bar E_1) \Gamma_2(\bar E_2)$$ which implies that the product $$\Gamma_1(\bar E_1) \Gamma_2(\bar E_2)$$ is a good approximation of $$\Gamma(E)$$ or, passing to the logarithm, the entropy of the compound system is $$S(E)=S_1(\bar E_1) +S_2(\bar E_2)+ O(\log E)$$ i.e. it is well approximated by the first two terms in the right hand side of previous equation, for large systems.