Solution (source code)

= Solution

<Entropy> is a thermodynamic <state function>. For a reversible <heat> transfer, $dS=\delta Q_{\rm rev}/T$; the <Clausius inequality> generalizes this to irreversible processes. The combined <entropy> of a system and its surroundings does not decrease. A subsystem can lose <entropy> by exporting <heat> or matter, so the second-law statement must specify the whole isolated combination. In a simple compressible system,
$$
dU=T\,dS-P\,dV+\mu\,dN,
$$
which identifies <temperature>, <pressure> and <chemical potential> as derivatives of the <energy> representation of the state function. <Thermodynamic equilibrium> maximizes <entropy> under fixed total <energy>, <volume> and particle number. A <heat> reservoir instead leads to minimizing the <Helmholtz free energy> at fixed $T,V,N$, or the <Gibbs free energy> at fixed $T,P,N$.

Statistical mechanics explains the state count. In a <microcanonical ensemble>, equally probable compatible microstates give <Boltzmann's entropy formula>, $S=k_B\ln\Omega$. With general discrete probabilities, the <Gibbs entropy> is
$$
S=-k_B\sum_jp_j\ln p_j.
$$
The microcanonical formula follows by setting every nonzero probability to $1/\Omega$. For a <canonical ensemble>, $p_j=e^{-\beta E_j}/Z$, so
$$
\boxed{S=k_B\ln Z+\frac UT,\qquad F=U-TS=-k_BT\ln Z.}
$$
This turns microscopic <energy> levels and their populations into a measurable thermodynamic quantity. Classical phase-space counting needs a consistent microscopic normalization and indistinguishability convention; quantum state counting supplies that normalization. Independent systems have multiplicative state counts and therefore additive entropies.

For an <ideal gas> freely expanding from <volume> $V$ to $2V$ in an insulated enclosure, <energy> remains fixed while each particle gains twice the accessible position <volume>. The state count increases by $2^N$, giving $\boxed{\Delta S=Nk_B\ln2}$. The actual irreversible process transfers no <heat>. A reversible isothermal comparison path transfers <heat> $Nk_BT\ln2$ and computes the same <entropy> change because the initial and final <thermodynamic equilibrium> states are the same.

Calorimetry supplies another connection to experiment: at fixed <pressure> and within one phase, $S(T)-S(0)=\int_0^T C_P(T')\,dT'/T'$, with latent-heat contributions $\mathcal L/T$ at first-order transitions. The <third law of thermodynamics> fixes $S(0)=0$ for an ideal perfect crystal with a unique ground state. Degeneracy or frozen disorder can produce <residual entropy>. <Entropy> thus links heat-capacity measurements, phase <thermodynamic equilibrium> and the number of accessible microscopic configurations.