# Derivation of temperature / entropy relation from statistical mechanics

I use units where $k_\mathrm{B} = 1$.

You are correct up to the point where you obtain $S = \beta E + \log{Z}.$

Probably the most common source of confusion in thermodynamics is forgetting which variables are held fixed in partial derivatives. In particular, $$\beta = \frac{\partial S{\left(E,V,N\right)}}{\partial E}.$$

$T$ is not one of the variables being held fixed in this derivative! Indeed, if we raise $E$ without changing $V$ or $N$, we certainly expect $T$ to also rise! So we would need to apply the product rule to the first term to proceed as you desired: $$\frac{\partial(\beta E)}{\partial E} \neq \beta.$$

But I'd rather do things a bit differently. Since you have been working in the canonical ensemble, let us try to start by deriving the thermodynamics of the canonical ensemble.

Let $F \equiv - T \log{Z} = E - T S$. We calcuate

\begin{align} \frac{\partial{F}}{\partial T} &= - \log{Z} - T \frac{\partial \log{Z}}{\partial T} \\ &= - \log{Z} - T \frac{\partial \beta}{\partial T} \frac{\partial \log{Z}}{\partial \beta} \\ &= - \log{Z} + \beta \frac{\partial \log{Z}}{\partial \beta}. \end{align}

Using the results you derived, we get

\begin{align} \frac{\partial{F}}{\partial T} = \beta F - \beta E = -S. \end{align}

Now we have entered the realm of thermodynamics - how do we relate the derivatives of $S$ to those of $F$? Well, keep in mind we're basically trying to get the first law of thermodynamics. So write the equivalent for the canonical free energy:

\begin{align} \mathrm{d}F &= \left(\frac{\partial F}{\partial T}\right)_{V,N} \mathrm{d}T + \left(\frac{\partial F}{\partial V}\right)_{T,N} \mathrm{d}V + \left(\frac{\partial F}{\partial N}\right)_{T,V} \mathrm{d}N \\ &= - S \,\mathrm{d} T + \left(\frac{\partial F}{\partial V}\right)_{T,N} \mathrm{d}V + \left(\frac{\partial F}{\partial N}\right)_{T,V} \mathrm{d}N . \end{align}

But we also have: \begin{align} F &= E - T S\\ \mathrm{d}F &=\mathrm{d}E - T \,\mathrm{d}S- S \, \mathrm{d}T, \end{align}

whence

\begin{align} \mathrm{d}E &= T \, \mathrm{d}{S} + \left(\frac{\partial F}{\partial V}\right)_{T,N} \mathrm{d}V + \left(\frac{\partial F}{\partial N}\right)_{T,V} \mathrm{d}N \\ \mathrm{d}{S} &= \frac{1}{T} \mathrm{d}E - \frac{1}{T} \left(\frac{\partial F}{\partial V}\right)_{T,N} \mathrm{d}V - \frac{1}{T} \left(\frac{\partial F}{\partial N}\right)_{T,V} \mathrm{d}N. \end{align}

We thus read off the desired result, $$ \frac{1}{T} =\left( \frac{\partial S}{\partial E} \right)_{V, N}.$$