Magical equations in statistical mechanics Studying ensembles in Statistical Mechanics I have found some formulas such as 
$$ S = k\frac{\partial}{\partial T} (T\ln Z) $$ 
or 
$$ \langle E \rangle = -\frac{\partial}{\partial\beta} \ln Z $$ 
or
 $$ \langle \Delta E ^2 \rangle = - \frac{\partial \langle E \rangle}{\partial \beta}$$ 
among many others. These formulas are mostly derived in the scope of one particular ensemble and, at least in the bibliography I am reading, they give no argument other than "if we do this calculation it just works". But they give no physical reasons for this to be so. Then I see that every one uses this formulas in any other ensemble as if they were a general result with no proof.
Are this kind formulas valid in general for any distribution? If so, why? Or are they valid only for some special distributions?
 A: These three relations are only  valid in the canonical and grand canonical ensemble. Let's analyze them one by one:
Relation n. 1:
$$S = k \frac{\partial{(T \log Z)}}{\partial T}\tag{1}\label{1}$$
Valid in canonical and grand canonical ensemble. Formally valid in the mircocanonical.
From thermodynamics, we know that entropy can be calculated from the Helmholtz free energy $F(N,V,T)$ as
$$S=-\left(\frac{\partial F}{\partial T}\right)_{N,V} \tag{1a}\label{1a}$$
as it follows from the fact that $dF=-SdT-PdV+\mu dN$.
In the canonical ensemble, the partition function $Z_c(N,V,T)$ is connected to  $F(N,V,T)$ by the following relation:
$$F(N,V,T)=-kT\log(Z_c(N,V,T)) \tag{1b}\label{1b}$$
It follows from \ref{1a} and \ref{1b} that
$$S = -\left(\frac{\partial F}{\partial T}\right)_{N,V} = k \frac{\partial{(T \log Z_c)}}{\partial T} \tag{1c}\label{1c}$$
which is just \ref{1c}.
But we also know that entropy can be calculated from the Landau free energy $\Omega (\mu, V, T)= - PV$:
$$S=-\left(\frac{\partial \Omega}{\partial T}\right)_{\mu,v}\tag{1d}\label{1d}$$
as it follows from $d\Omega=-SdT-PdV-N d\mu$.
In the grand canonical ensemble, the partition function $Z_{gc}(\mu,V,T)$ is connected to the Landau free energy by the relation
$$\Omega= -kT \log(Z_{gc}(\mu,V,T))\tag{1e}\label{1e}$$
It readily follows from \ref{1d} and \ref{1e} that 
$$S = -\left(\frac{\partial \Omega}{\partial T}\right)_{\mu,V} = k \frac{\partial{(T \log Z_{gc})}}{\partial T} \tag{1f}\label{1f}$$
which is analogous to \ref{1c}.
In the micro canonical ensemble, we have
$$S=k \log(Z_{mc}(N,V,E))$$
so \ref{1} is formally valid again. However, $T$ is not a parameter in the microcanonical ensemble, so I hesistate to say that \ref{1} is valid. But for sure you can use it.
For the other relations, I will be quicker.
Relation n.2
$$E \equiv \langle \mathcal H\rangle = -\frac{\partial Z}{\partial \beta} \tag{2}\label{2}$$
where $\mathcal H$ is the Hamiltonian.
Valid in canonical and grand canonical. No meaning in the microcanonical
Since the canonical and microcanonical partition functions have the same dependence on $\beta$, \ref{2} applies in both ensemble. However it has no meaning in the microcanonical ensemble, where $E$ is a parameter.
Relation n. 3
$$\Delta E^2 = -\frac{\partial E}{\partial \beta} \tag{3}\label{3}$$
Valid in canonical and grand canonical. No meaning in the microcanonical
This one follows from \ref{2}, together with
$$\Delta E^2 = k T^2 C_V \tag{3a}\label{3a}$$
and
$$C_V = -\frac{\partial E}{\partial T}\tag{3b}\label{3b}$$
and
$$-\frac{\partial}{\partial \beta}=-kT^2 \frac{\partial}{\partial T}\tag{3c}\label{3c}$$ 
From these relations, you get \ref{3}. Once again, this has no meaning in the microcanonical ensemble, where $E$ is fixed and therefore there are no energy fluctuation.
If you are looking for books that deal with these issues properly, I suggest Kerson Huang, Statistical Mechanics or Mark Tuckerman, Statistical Mechanics: Theory and Molecular Simulation. You can find Tuckerman's lecture notes here.
A: The partition function is defined as a sum over microstates at a specific temperature (with $\beta = 1/kT$)
$$Z(\beta) = \sum_s e^{-\beta E_s}$$
where $E_s$ is the energy of the microstate $s$.
Recall that if our system is connected to a large heat bath at temperature $T$, the probability for our system to be in state $s$ is
$$\text{Prob}(s) = \frac{e^{-\beta E_s}}{Z(\beta)}.$$
That means that the expected energy $\langle E \rangle$ is
$$\langle E \rangle = \sum_s E_s \text{Prob}(s) = \frac{\sum_s E_s e^{-\beta E_s}}{Z(\beta)} = \frac{- \frac{\partial}{\partial \beta} Z(\beta)}{Z(\beta)} = - \frac{\partial}{\partial \beta} \ln(Z(\beta)).$$
The other identities can be derived using similar manipulations.
