Cf. Feynman Lectures I, 39. Suppose we have a box of volume $V$ filled with some gas. The top of the box is closed with some sort of slidable piston. What is the force the gas exerts on the piston? First of all we define the pressure $P$: that`s just the force the gas exerts on the piston per unit area, i.e. $P\colon=F/A$. More precisely: if $e$ denotes the outer unit normal to the surface $A$ of the piston, then
$$
F_e\colon=\la F,e\ra=PA~.
$$
Displacing the piston by $\D x$ in the direction of $e$ (i.e. moving the piston in direction $e$), the volume of the box increases by $A\D x$ and we gain some work, i.e. we need to carry out negative work, which is given by
$$
\D W
=-F_e(\D x)
=-PA\D x
=-P\D V~.
$$
Now we assume that the force only stems from totally elastic collisions of the molecules with the piston, then the force $F_e$ equals the product of the number of molecules hitting the piston and the transferred momentum per time unit. Within a time interval $\D t$ only those molecules can hit the piston, whose distance is smaller than $v_e\D t$ and $v_e > 0$. If $N$ denotes the number of molecules in the box, then $n\colon=N/V$ is the number per unit volume and $nAv_e\D t$ is the number of molecules hitting the piston within a time interval $\D t$. Each time a molecule of mass $m$ hits the piston a momentum $2mv_e$ is transferred and as the force is the momentum per time we get:
$$
F_e=(nAv_e\D t)(2mv_e)/\D t
=2nAmv_e^2
\quad\mbox{i.e.}\quad
P=2nmv_e^2~.
$$
In average one out of two molecules has positive speed in the direction of $e$ and therefore the pressure of the gas exerted on the piston is given by
$$
P=nm\la v_e^2\ra
=\tfrac13nm\la\Vert v\Vert^2\ra
=\tfrac23n\la\tfrac12m\Vert v\Vert^2\ra
$$
where $\la\Vert v\Vert^2\ra$ denotes the average of the squared speed. Hence we get
\begin{equation}\label{pegeq1}\tag{PEG1}
PV=\tfrac23N\la\tfrac12 m\Vert v\Vert^2\ra
=\tfrac23E,
\end{equation}
where $E\colon=N\la\tfrac12 m\Vert v\Vert^2\ra$ denotes the total energy, which in our situation is purely kinetic. If we`d taken photons in place of molecules we`d get:
\begin{equation}\label{pegeq2}\tag{PEG2}
E=Nmc^2
\quad\mbox{and}\quad
PV=\tfrac13Nmc^2
=\tfrac13E~.
\end{equation}
These equations are called equations of state.
So let us assume that for some constant $\g > 1$ we have the equation of state: $PV=(\g-1)E$. In case of a so called adiabatic expansion/compression the only change of the total energy is mechanical: $dE=-P\,dV$. From our first assumption we infer that $(\g-1)dE=P\,dV+V\,dP$ and therefore:
$$
-(\g-1)PdV=P\,dV+V\,dP
\quad\Lrar\quad
\frac{\g}{V}\,dV+\frac1P\,dP=0
\quad\mbox{i.e}\quad
PV^\g=const.
$$
For a gas - in fact an ideal gas - and a photon gas we have by \eqref{pegeq1} and \eqref{pegeq2}, respectively, for adiabatic compression/expansion:
$$
PV^{5/3}=const.
\quad\mbox{and}\quad
PV^{4/3}=const.
$$
Collision of molecules, Temperature
We start with an application of energy-momentum conservation to a so called ideal gas, i.e. a gas whose molecules only interact by collision! First we will investigate the collision of two particles.
$\proof$
Putting $x_i=v_i-v$ and $y_i=u_i-v$ we get three equations:
$$
m_1x_1+m_2x_2=m_1y_1+m_2y_2=0
\quad\mbox{and}\quad
m_1\norm{x_1}^2+m_2\norm{x_2}^2=m_1\norm{y_1}^2+m_2\norm{y_2}^2
$$
Taking the inner product with $x_1,x_2$ and $y_1,y_2$ the first two equations imply:
\begin{eqnarray*}
m_1\norm{x_1}^2=-m_2\la x_1,x_2\ra,\quad&&
m_2\norm{x_2}^2=-m_1\la x_1,x_2\ra,\\
m_1\norm{y_1}^2=-m_2\la y_1,y_2\ra,\quad&&
m_2\norm{y_2}^2=-m_1\la y_1,y_2\ra~.
\end{eqnarray*}
Plugging these into the third equation we get:
\begin{eqnarray*}
0&=&m_1(\norm{x_1}^2-\norm{y_1}^2)+m_2(\norm{x_2}^2-\norm{y_2}^2)
=m_1(\norm{x_1}^2-\norm{y_1}^2)-m_1(\la x_1,x_2\ra-\la y_1,y_2\ra)\\
0&=&m_1(\norm{x_1}^2-\norm{y_1}^2)+m_2(\norm{x_2}^2-\norm{y_2}^2)
=-m_2(\la x_1,x_2\ra-\la y_1,y_2\ra)+m_2(\norm{x_2}^2-\norm{y_2}^2)~.
\end{eqnarray*}
Hence
$$
\norm{x_1}^2-\norm{y_1}^2
=\la x_1,x_2\ra-\la y_1,y_2\ra
=\norm{x_2}^2-\norm{y_2}^2
$$
On the other hand we have by the third equation
$$
m_1(\norm{x_1}^2-\norm{y_1}^2)+m_2(\norm{x_2}^2-\norm{y_2}^2)=0
$$
which is only possible if $\norm{x_1}^2-\norm{y_1}^2=\norm{x_2}^2-\norm{y_2}^2=0$ and thus we also infer that: $\la x_1,x_2\ra-\la y_1,y_2\ra=0$.
$\eofproof$
Suppose $v=0$, then $\la u_1,u_2\ra=\la v_1,v_2\ra$, $\Vert v_1\Vert^2=\Vert u_1\Vert^2$ and $\Vert v_2\Vert^2=\Vert u_2\Vert^2$. Thus the speed of the particles as well as their angle remain unchanged by collision.
Now we model the velocity of the two molecules by random variables $X$ and $Y$ with values in the Euclidean space $E$, whose dimension we don`t specify yet. The random variable $S\colon=(m_1X+m_2Y)/M$ or
$$
S=aX+bY,
\quad\mbox{where}\quad
a\colon=m_1/M,\quad
b\colon=m_2/M,
\quad\mbox{i.e.}\quad
a+b=1,
$$
is said to be the center of mass velocity. Let us just look at the molecules with a specific center of mass velocity. We say that the system of two gases is in a state of thermal equilibrium iff
\begin{equation}\label{pegeq3}\tag{PEG3}
\E(X|S)=S,
\end{equation}
i.e. the mean velocity $X$ conditioned on $S$ equals $S$ - informally: knowing $S$ the `best guess` for $X$ is $S$. As $S=aX+bY$, this readily implies that $\E(Y|S)=S$ as well. But also the converse is true: if $\E(X|S)=\E(Y|S)$, then $\E(X|S)=S$. Indeed, put $Z\colon=\E(X|S)$, then, by assumtion: $Z=\E(Y|S)$ and therefore
$$
S=\E(aX+bY|S)=aZ+bZ=Z~.
$$
$\proof$
This follows easily from
$$
0=\E(\E(X-Y|S)S)
=\E((X-Y)S)
=a\E\norm X^2+(b-a)\E\la X,Y\ra-b\E\norm Y^2~.
$$
$\eofproof$
Thus under the assumption of proposition all ideal gases in thermal equilibrium have the same mean kinetic energy. Temperatur is just another name for this kinetic energy: if temperature $T$ is measured in Kelvin, then it`s defined by
\begin{equation}\label{pegeq4}\tag{PEG4}
E=\tfrac32NkT,
\end{equation}
where $N$ still denotes the total number of molecules and $k$ Boltzmann`s constant - $k\sim1.38\times 10^{-23}$, $[k]=J/K$. Thus $\frac32kT$ is the mean kinetic energy of a molecule. For an ideal gas we have by \eqref{pegeq1}:
\begin{equation}\label{pegeq5}\tag{PEG5}
PV=\tfrac23E=NkT,
\end{equation}
which is also called equations of state. Hence given an ideal gas of volume $V$ at pressure $P$ and Temperature $T$, the number of molecules is fixed an does not depend on other properties of the gas!
In the gaussian case proposition can be reversed.
$\proof$
First we determine $\l\in\R$, such that $(X-Y)-\l(aX+bY)$ is independent from $S\colon=aX+bY$; as $(X,Y)$ are jointly gaussian this holds if and only if $(X-Y)-\l(aX+bY)$ is orthogonal to $S$ in $L_2(\P)$, i.e.
$$
\E((X-Y)-\l(aX+bY))(aX+bY)=0~.
$$
Since $\E X=\E Y=0$, $\E(X_jX_k)=s\d_{jk}$ and $\E(Y_jY_k)=t\d_{jk}$ this amounts to
$$
\l=\frac{as-bt}{a^2s+b^2t}~.
$$
By independence we infer that $\E(X-Y-\l S|S)=\E(X-Y-\l S)=0$ and therefore: $\E(X-Y|S)=\l S$
$\eofproof$
Multi nuclear gas
Let`s look at a gas composed of two nuclei. For each of its nuclei we assume that the mean kinetic energy amounts to $\frac32kT$. The total mass of the molecule is $M=m_1+m_2$ and the velocity of the center of mass is $S=(m_1X+m_2Y)/M$. Hence the center of mass motion of the molecule has kinetic energy:
$$
\tfrac12M\norm S^2
=\frac{m_1\tnorm{X}^2
+2m_1m_2\la X,Y\ra
+m_2\tnorm{Y}^2}{2M}
=\tfrac32kT+m_1m_2\la X,Y\ra/M
$$
If we assume that the distributions $X$ and $Y$ of the velocities satisfy $\E\la X,Y\ra=0$, then the mean kinetic center of mass energy of the molecule considered as a particle of mass $M$ equals $\frac32kT$. We conclude that the internal mean energy of the molecule, which is defined as the difference of the total mean kinetic energy and the mean center of mass energy, amounts to $3kT-\frac32kT=\frac32kT$. Similarly a molecule made up of $r$ nuclei has mean internal energy: $\frac32(r-1)kT$.
In one dimension this comes down to the linear ODE: $-U^\dprime=a+2bU$, where $a\colon=\r_0/\e_0$ and $b\colon=aq/2kT$. Assuming $b^2 < a$ we get
$$
U(x)=e^{-bx}\Big(c_1\cos(\sqrt{a-b^2}\,x)+c_2\sin(\sqrt{a-b^2}\,x)\Big)
\sim e^{-bx}\Big(c_1\cos(\sqrt{a}\,x)+c_2\sin(\sqrt{a}\,x)\Big),
$$
For $f$ we get the equation $-a\exp(2bU)=f^\prime(U)U^\prime=f^\prime(U)f(U)$, i.e. $f(U)^{2\prime}=-2a\exp(2bU)$. Hence $f(U)^2=C-(a/b)\exp(2bU)$ and therefore
$$
U^\prime=\pm\sqrt{C-(a/b)\exp(2bU)}~.
$$
Put $\o=\sum q_j\,dp_j$, then
$$
d\o=\sum d(q_j\,dp_j)=\sum dq_j\wedge dp_j+q_jd^2p_j=\sum dq_j\wedge dp_j
$$
i.e. $\o^2=d\o$ and therefore $d\o^2=d^2\o=0$, i.e. $\o^2$ is closed. It's obviously anti-symmetric and non-singular.
By definition of the exterior product
\begin{eqnarray*}
\vol{}
&=&\sum_{1\leq j_1,\ldots,j_n\leq n}
dq_{j_1}\wedge dp_{j_1}\wedge dq_{j_2}\wedge dp_{j_2}
\wedge\ldots\wedge dq_{j_n}\wedge dp_{j_n}\\
&=&\sum_{1\leq j_1,\ldots,j_n\leq n}(-1)^{1+\cdots+(n-1)}
dq_{j_1}\wedge\ldots\wedge dq_{j_n}
\wedge dp_{j_1}\wedge\ldots\wedge dp_{j_n}
\end{eqnarray*}
and the summands don`t vanish if and only if $(j_1,\ldots,j_n)$ is a permutation of $1,\ldots,n$, i.e.
$$
\vol{}
=(-1)^{\frac{n(n-1)}2}
\sum_{\pi\in S_n}\sign(\pi)^2dq_{1}\wedge\ldots\wedge dq_{n}
\wedge dp_{1}\wedge\ldots\wedge dp_{n}\\
=(-1)^{\frac{n(n-1)}2}n!\,dq_1\wedge\ldots\wedge dp_{n}~.
$$
Every smooth function $H:\O\rar\R$ gives rise to a so called Hamiltonian vector field $X^H$: $X^H\colon=-(dH)^\sharp$ or for any vector field $Y$: $\o^2(X^H,Y)=-dH(Y)$.
Put $X^H=\sum a_j\pa_{q_j}+b_j\pa_{p_j}$, then for $Y=\pa_{q_k}$ we get
$$
-\pa_{q_k}H
=\o^2(X^H,\pa_{q_k})
=dq_k\wedge dp_k(a_k\pa_{q_k}+b_k\pa_{p_k},\pa_{q_k})
=dq_k\wedge dp_k(b_k\pa_{p_k},\pa_{q_k})
=-b_k
$$
and analogously for $Y=\pa_{p_k}$: $-\pa_{p_k}H=a_k$.
A measure $\mu$ with density $\r$ is invariant under the flow $\theta_t(x)$ of $X^H$ if for all $t$ and all Borel subsets $A$: $\mu(\theta_t\in A)=\mu(A)$; this holds iff $\divergence(\r X^H)=0$; as $\divergence(X^H)=0$ this is equivalent to
$$
0=X^H\r-\r\divergence(X^H)
=X^H\r
=\colon(X^H,\r),
$$
i.e. $\r$ must be a first integral of $X^H$, which means that for each $x\in\O$ the function $t\mapsto\r\circ\theta_t(x)$ is constant - this always holds if $\r$ is a function of $H$. If $\mu(\O)=1$, then $\mu$ is a probability measure on $\O$ with density $\r$ (with respect to $v$) and for any Borel subset $A$ of $\O$ the quantity $\mu(A)$ is said to be the probability of finding the system in a state in $A$.
If the measure $v$ is clear from the context we simply drop the subscript $v$! As $u:x\mapsto-x\log x$ is concave on $\R^+$ we infer from Jensen`s inequality that $\Ent(\mu)\leq u(\int f\,dv)=u(1)=0$. Hence if $v$ is itself a probability measure, then $\Ent(\mu)\leq\Ent(v)=0$. In the sequel we`ll show among other things that $v$ is the unique probability measure with maximizes the entropy functional.
$\proof$
2. For all $x\in\R$ and all $y > 0$ we utilize the inequality: $e^x+y\log y-y\geq xy$ (equality holds if and only if $y=e^x$):
$$
\int fg\,dv
\leq-\Ent(f)-1+\int e^g\,dv
\leq-\Ent(f)
$$
and equality holds if and only if $g=\log f$ $v$-almost everywhere.
3. Put $G(p)=\int f^p\,dv$, then $F(1)=G(1)=1$, $G^\prime(1)=-\Ent(f)$ and
$$
F^\prime(p)/F(p)=-p^{-2}\log G(p)+p^{-1}G^\prime(p)/G(p)~.
$$
$\eofproof$
The variational formula implies that the mapping $f\mapsto\Ent(f)$ is concave on the subset of probability densities.
$\proof$
For all $x\geq0$ we have: $3(x-1)^2\leq(4+2x)(x\log x-x+1)$. Taking expectations and applying Cauchy-Schwarz we get
\begin{eqnarray*}
\sqrt3\E|X-1|
&\leq&\E\Big(\sqrt{4+2X}\sqrt{X\log X-X+1}\Big)\\
&\leq&\sqrt{\E(4+2X)}\sqrt{\E(X\log X-X+1)}
=\sqrt6\sqrt{-\Ent_\P(X)}~.
\end{eqnarray*}
$\eofproof$
Now we are ready for the proof of the entropy theorem
$\proof$
Putting $C=\bigcup_j[H_j=\infty]$ we get for $X\in M$: $v(C\cap[X\neq0])=0$; hence we may assume w.l.o.g. that $v(C)=0$. Now define the probability measure $\P$ by $\P(A)\colon=\int_A X_0\,dv$. Hence $\P\ll v\ll\P$ and thus
\begin{eqnarray*}
-\Ent_v(X)+\Ent_v(X_0)
&=&\int X\log X\,dv-\int X_0\log X_0\,dv
=\int X/X_0\log X-\log X_0\,d\P\\
&=&\int X/X_0\log(X/X_0)\,d\P+\int(X/X_0-1)\log X_0\,d\P~.
\end{eqnarray*}
The first term equals $-\Ent_\P(X/X_0)$ and for the second we get by assumption
$$
\int(X-X_0)(\l_0-\sum\l_jH_j)\,dv=0~.
$$
Finally we infer from Pinsker`s inequality:
$$
-\Ent_v(X)+\Ent_v(X_0)
=-\Ent_\P(X/X_0)
\geq\tfrac12\Big(\int|X/X_0-1|\,d\P\Big)^2
=\tfrac12\Big(\int|X-X_0|\,dv\Big)^2~.
$$
$\eofproof$
We have one function, namely $H_1(n)=n$ and thus $\r(n)=e^{-\l_0-\l_1n}$ subjected to $\sum e^{-\l_0-\l_1n}=1$ and $\sum ne^{-\l_0-\l_1n}=M$. As the second sum is just the negative of the partial derivative by $\l_1$ of the first, we get
$$
\frac1{1-e^{-\l_1}}=e^{\l_0},\quad
\frac{e^{-\l_1}}{(1-e^{-\l_1})^2}=Me^{\l_0}
\quad\mbox{i.e.}\quad
e^{-\l_1}=\frac M{1+M}
\quad\mbox{and}\quad
e^{-\l_0}=\frac1{1+M}~.
$$
Again we have just one function $H_1(x)=x$; $\r(x)=e^{-\l_0-\l_1x}$ and two conditions:
$$
\int_0^\infty e^{-\l_0-\l_1x}\,dx=1,\quad
\int_0^\infty xe^{-\l_0-\l_1x}\,dx=M~.
$$
Hence: $e^{-\l_0}=\l_1$ and $e^{-\l_0}=M\l_1^2$, which implies: $\l_1=1/M$ and $e^{-\l_0}=1/M$.
Here we have $H_1(x)=x$ and $H_2(x)=x^2$, hence $\r(x)=e^{-\l_0-\l_1x-\l_2x^2}$ and this density needs to satisfy the following conditions:
$$
\int\r(x)\,dx=1,\quad
\int\r(x)x\,dx=0,\quad
\int\r(x)x^2\,dx=\s~.
$$
These are equivalent to
$$
e^{-\l_0+\l_1^2/4\l_2}=\sqrt{\s/\pi},\quad
\l_1=0,\quad
e^{-\l_0+\l_1^2/4\l_2}=\l_2^2\s/\sqrt{\pi}
$$
i.e. $e^{-\l_0}=\sqrt{\l_2/\pi}$, $\l_1=0$, $\l_2=1/2\s$.
Entropy theorem of classical thermodynamics
Cf. e.g. Landau Lifschitz, Statistical Physics, J. Devriendt. Taking into account chemical reactions the number $n$ of molecules may change. Also the side conditions may depend on some external parameters, for instance on the volume $V$ of the containment. In theorem the parameters $\l_1,\ldots,\l_n$ are uniquely determined by the values of $E_1,\ldots,E_n$ and for different values of $E_1,\ldots,E_n$ we get different values for $\l_1,\ldots,\l_n$. Hence we may and will look at $E_1,\ldots,E_n$ as functions of $\l_1,\ldots,\l_n$. Also in the subsequent theorem we will use different labels for the variables $\l_0,\ldots,\l_n$!
Ising`s model of a ferromagnetic metal
Cf. e.g. Ising Model
Let $A\sbe\Z^3$ be a finite subset, $|A|=N$ and put $\O=\{-1,+1\}^A=\{-1,+1\}^N$. We look at $A$ as being the set of positions of nuclei in a cubic crystal. For any $\o\in\O$ and any $x\in A$ we consider $\o(x)=\pm1$ as the a sort of spin of the nucleus in position $x$. The only parameter is the energy: a state $\o\in\O$ has energy
$$
H(\o)\colon=\a\sum_{x\in A}\o(x)-\tfrac12\b\sum_{(x,y)\in R}\o(x)\o(y),
$$
where $(x,y)\in R$ if and only if for some $j\in\{1,2,3\}$: $|x_j-y_j|=1$. By the entropy theorem the Gibbs probability measure on $\O$ is given by the density (with respect to the counting measure)
$$
\r(\o)=e^{(F-H(\o))/kT}
\quad\mbox{with free energy}\quad
F=-kT\log\Big(\sum_\o e^{-H(\o)/kT}\Big)
$$
Finally, in terms of $T,P$ and $N$ the entropy of an ideal gas is given by
\begin{equation}\label{enteq7}\tag{ENT7}
S_i=N\log\Big(\frac{ekT}{P}\Big)+N\chi^\prime(T)
=-N\log P+N(\log(ekT)+\chi^\prime(T))~.
\end{equation}
By definition and \eqref{enteq7}:
\begin{eqnarray*}
H&\colon=&E+PV=kN(T\chi^\prime(T)-\chi(T)+T)\quad\mbox{and}\\
G&\colon=&H-kTS=kN(T\chi^\prime(T)-\chi(T)+T)+kT(N\log P-N(\log(ekT)-\chi^\prime(T)))\\
&=&kNT\log P-kN(\chi(T)-T+T\log(ekT))
=kN(T\log P-g(T))~.
\end{eqnarray*}
where $g(T)\colon=\chi(T)-T+T\log(ekT)$. Finally we get for the chemical potential $\mu$ by \eqref{enteq4}:
$$
\mu=\pa_NG=kT\log(P)-kg(T)=G/N
$$
i.e. the chemical potential of an ideal gas is just the free enthalpy per molecule! From \eqref{enteq4} we therefore infer that
$$
N\,d\mu+\mu\,dN=-kS\,dT+V\,dP+\mu\,dN
\quad\mbox{i.e.}\quad
d\mu=-ks\,dT+v\,dP,
$$
where $s\colon=S/N$ and $v\colon=V/N$ denote the entropy and volume per molecule.
Suppose we have a mixture of $n$ different ideal gases with number of particles $N_1,\ldots,N_n$, respectively. Let us denote by $N\colon=\sum N_j$ the total number of molecules and by $c_j\colon=N_j/N$ the concentrations of the gases. Given the free enthalpy $G$ as function of $T,P$ and $N_1,\ldots,N_n$, we have by \eqref{enteq4}:
$$
S=-\pa_TG,\quad
V=\pa_PG,\quad
\mu_1=\pa_{N_1}G=\pa_{c_1}G/N,\quad\ldots\quad
\mu_n=\pa_{N_n}G=\pa_{c_n}G/N~.
$$
In analogy to the previous subsection we obtain for the free energy of a mixture of ideal gases;
$$
F(T,V,N_1,\ldots,N_n)
=-k\sum_{j=1}^nN_j\Big(T\log\Big(\frac{eV}{N_j}\Big)-\chi_j(T)\Big)
$$
and similarly:
$$
S=\sum_{j=1}^nN_j\Big(\log\Big(\frac{eV}{N_j}\Big)+\chi_j^\prime(T)\Big),\quad
P=\sum_{j=1}^nN_jkT=NkT/V
$$
In terms of the partial pressures $P_j\colon=c_jP=N_jP/N=N_jkT/V$, i.e. $V/N_j=kT/P_j$:
$$
S=\sum_j-N_j\log P_j+N_j(\log(ekT)+\chi_j^\prime(T))~.
$$
A chemical reaction $\sum_j\nu_jX_j=0$, where $\nu_j\in\Z$, $\gcd(\nu_1,\ldots,\nu_n)=1$, and $X_j$ denote the chemical symbols of the reacting gases, is in equilibrium if one of the thermodynamic potentials $E,F,G$ or $H$ as a function of $N_1,\ldots,N_j$ attains a local minimum at fixed temperature $T$ and fixed pressure $P$. By \eqref{enteq4} we conveniently take $G$. This means that for all $j$: $\pa_{N_j}G=0$. If e.g. $N_1$ changes in equilibrium by $\nu_1$, then each $N_j$ must changes by $\nu_j$ and therefore: $dN_j/dN_1=\nu_j/\nu_1$ for any $j$:
$$
0=\frac{dG}{dN_1}
=\sum_{j=1}^n\pa_{N_j}G\tfrac{dN_j}{dN_1}
=\sum\sum_{j=1}^n\frac{\nu_j}{\nu_1}~.
$$
By \eqref{enteq4} we have $\mu_j=\pa_{N_j}G$ and therefore we infer that in chemical equilibrium:
\begin{equation}\label{enteq8}\tag{ENT8}
\sum_{j=1}^n\mu_j\nu_j=0~.
\end{equation}
Assuming ideal gases we infer from exam:
$$
G=k\sum_{j=1}^n N_j(T\log(P_j)-g(T)),
\quad\mbox{where}\quad
g_j(T)\colon=\chi_j(T)-T+T\log(ekT)
$$
and thus from \eqref{enteq4}:
$$
\mu_j=\pa_{N_j}G=kT\log(P_j)-kg(T)$.
$$
Plugging this into the condition for chemical equilibrium \eqref{enteq8}:
$$
0=\sum_j\nu_j\mu_j
=k\sum_j\nu_j(T\log(P_j)-g_j(T))
$$
i.e. in chemical equilibrium we have the so called law of mass action:
\begin{equation}\label{enteq9}\tag{ENT9}
\prod c_j^{\nu_j}=e^{\sum_j\nu_jg_j(T)/T}P^{-\sum\nu_j}
\end{equation}
which states a chemical reaction at constant temperature and pressure is in equilibrium if product of the concentrations to the power $\nu_j$ is constant.
Putting $a\colon=\g r_0^\a/kT$ and changing variables $x=r^{-\a}$, i.e. $r=x^{-1/\a}$ we get
$$
\int_0^\infty r^2(1-e^{-K(r)/kT})\,dr
=\a^{-1}\int_0^\infty x^{-1-3/\a}(1-e^{-ax})\,dx
$$
which is finite iff $\a > 3$. In this case we use integration by parts:
$$
-\frac{\a^{-1}x^{-3/\a}}{3/\a}(1-e^{-ax})\Big|_0^\infty
+\int_0^\infty\tfrac13x^{-3/\a}ae^{-ax}\,dx
=\tfrac13a^{3/\a}\G(1-3/\a)~.
$$
Thus the free energy of our real gas model is given by
$$
F_r=F_i+CNkT\Big(\frac{\g}{kT}\Big)^{3/\a}\frac{r_0^3}V~.
$$
For the entropy $S_r$, the pressure $P_r$ and the energy $E_r$ we obtain
\begin{eqnarray*}
S_r&=&-\pa_TF_r/k
=-\pa_TF_i/k+(1-3/\a)C(\g/kT)^{3/\a}Nr_0^3/V\\
&=&S_i+(1-\tfrac3{\a})CN\Big(\frac{\g}{kT}\Big)^{3/\a}\frac{r_0^3}V\\
P_r&=&-\pa_VF_r
=-\pa_VF_i+CNkT(\g/kT)^{3/\a}r_0^3/V^2\\
&=&P_i+CP_i\Big(\frac{\g}{kT}\Big)^{3/\a}\frac{r_0^3}{V}\\
E_r&=&kS_rT+F_r
=kS_iT+F_i+(1-3/\a)Ck(\g/kT)^{3/\a}NTr_0^3/V+CNkT(\g/kT)^{3/\a}r_0^3/V\\
&=&E_i+(2-\tfrac3{\a})CNkT\Big(\frac{\g}{kT}\Big)^{3/\a}\frac{r_0^3}V~.
\end{eqnarray*}
Thus pressure, entropy and energy of a real gas are greater than the corresponding quantities of an ideal gas!
Thus the distribution of the states for high energies only depends on the volume of the domain.
Suppose we cram a bunch of $N_0$ bosons into the box, then by Boltzmann`s law at temperature $T$ each state with energy $E$ gets occupied by $n_0\exp(-E/kT)$ particles. To compute $n_0$ we utilize the fact that the total number of particles must satisfy
$$
N_0\sim\frac{Vn_0}{4\pi^2 A^{3/2}}\int_0^\infty e^{-E/kT}E^{1/2}\,dE
=\frac{Vn_0}{8}\Big(\frac{kT}{\pi A}\Big)^{3/2}~.
$$
For the total energy $E_0$ we again get
$$
E_0\sim\frac{Vn_0}{4\pi^2 A^{3/2}}\int_0^\infty e^{-E/kT}E^{3/2}\,dE
=\tfrac32N_0kT
$$
Our next example is the final state of a star: At the end of his `life` when all its thermal energy has been emitted a star remains merely as a gas of electrons, protons and neutrons, all of approximately the same density. We are going to model this final state as a ball comprising $N$ electrons, $N$ protons and $N$ neutrons at very low temperature. All these particles are fermions and thus occupy any state twice. Now an electron has much smaller mass than a proton or a neutron, which exhibit more or less the same mass. As a consequence the density of electrons is much smaller than the density of the protons or neutrons: by theorem the number of this states is proportional to $A^{-3/2}$ and as $A$ equals $\hbar^2/2$ divided by the mass of the particle, this factor is much smaller for electrons. The mass of the star is $(m_e+m_p+m_n)N\sim2m_nN$ and the number of states in a ball of radius $R$ is for electrons, i.e. $A=\hbar^2/2m_e$, by theorem:
$$
N(E,R)\sim\frac{2R^3}{9\pi A^{3/2}}E^{3/2}
\quad\mbox{or}\quad
N(dE,R)\sim\frac{R^3}{3\pi A^{3/2}}E^{1/2}\,dE~.
$$
Thus we get for the energy of this gas of electrons
\begin{eqnarray*}
2\int_0^{E_F} E\,N(dE,R)
&=&\frac{4R^3}{9\pi A^{3/2}}\int_0^{E_F}\frac32 E^{3/2}\,dE
=\frac{4R^3E_F^{3/2}}{9\pi A^{3/2}}\frac35E_F
=\frac35\frac{E_FM}{m_n}
\end{eqnarray*}
where $E_F$ denotes the Fermi-energy defined implicitely by: $2m_nN(E_F,R)=M$, i.e. $E_F$ is the highest energy of an electron in a star of radius $R$ and mass $M$ at temperatures close to zero:
$$
E_F=\Big(\frac{9\pi M}{4m_n}\Big)^{2/3}\frac{A}{R^2}~.
$$
On the other hand we have for the classical gravitational energy of a ball of constant density of radius $R$: $-3GM^2/5R$. The total energy sums up to
$$
\Big(\frac{9\pi M}{4m_n}\Big)^{2/3}\frac{3MA}{5m_nR^2}
-\frac{3GM^2}{5R}=aR^{-2}-bR^{-1}~.
$$
This is minimal for $2a/R^3=b/R^2$, i.e. $R=2a/b$; using $A=\hbar^2/2m_e$ we obtain
$$
R=\Big(\frac{9\pi}{4}\Big)^{2/3}\frac{\hbar^2}{2Gm_em_n^{5/3}M^{1/3}}
$$
As for neutron stars the immense compression somehow merges electrons and protons into neutrons, turning thus the whole mass into a pure gas of neutrons. Replacing $m_e$ by $m_n$ in the above computation gives
$$
R=\Big(\frac{9\pi}{4}\Big)^{2/3}\frac{\hbar^2}{2Gm_n^{7/3}M^{1/3}}
$$
For the sun we have: $M_\odot=1.985\times10^{30} kg$, the gravitational constant: $G=6.6719\times 10^{-11} m^3/kg.s$, the mass of an electron: $m_e=9.10938\times10^{-31} kg$, and the mass of a neutron: $m_n=1.67492\times10^{-27} kg$.
Statistics
Let $(\O,\P)$ be a probability space, $A:\O\rar{\cal P}(\N_0)$ a measurable function, i.e. $A$ is some random subset of $\N_0$ and $f_n,H_n:\O\rar\R$ random variables, wich may depend on some external parameters (e.g. the volume $V$), such that for all $\o$: $\sum_{n\in A(\o)}f_n(\o)=1$ and
$$
E=\E\Big(\sum_{n\in A}H_nf_n\Big)\quad
N=\E\Big(\sum_{n\in A}nf_n\Big)
$$
Given $\o\in\O$ we may regard $f_n(\o),n\in A(\o)$ as a probability distribution on $A(\o)$. Of course, we may extend $f_n$ by putting for $n\notin A(\o)$: $f_n(\o)=0$. Hence, given $E$ and $N$ the functional
$$
\Ent(f_n)\colon=-\E\Big(\sum_{n\in A}f_n\log f_n\Big)
$$
attains its maximal value in exactly one sequence of functions $\r_n$:
$$
\r_n(\o)\colon=e^{(U(\o)+\mu n-H_n(\o))/kT}
\quad\mbox{where}\quad
U(\o)=-kT\log\Big(\sum_{n\in A(\o)}e^{(\mu n-H_n(\o))/kT}\Big)~.
$$
Let $U\colon=\E U$ be the internal energy, $F\colon=U+\mu N$ the free energy , $P\colon=-\pa_VE$ the pressure and $S$ the entropy of the sequence $\r_n$, then we get again (cf. \eqref{enteq2} and \eqref{enteq3}):
\begin{equation}\label{eqmeq1}\tag{EQM1}
kST=-U-\mu N+E,\quad
F\colon=U+\mu N
\quad\mbox{and}\quad
dU=-S\,dT-P\.dV-\mu\,dN
\end{equation}
Bose-Einstein, Fermi-Dirac and Boltzmann statistics
Integration in polar coordinates shows that
$$
U=4\pi\e kTV\int_0^\infty\log\Big(1-\e e^{\mu/kT-r^\a/kT\a}\Big)r^2\,dr
$$
A change of variables $s=r^\a/\a kT$ and integration by parts yields:
$$
U=-\frac{4\pi\e\a^{3/p}V}{3}(kT)^{1+3/\a}
\int_0^\infty\frac{s^{3/\a}}{e^{s-\mu/kT}-\e}\,ds
\sim T^{1+3/\a}\int_0^\infty\frac{s^{3/\a}}{e^{s}-\e}\,ds
\sim T^{1+3/\a}~.
$$
For a non-relativistic gas we have $\a=2$ and therefore the energy is proportional to $T^{5/2}$. For photones $\a=1$ and hence the energy is proportional to $T^4$!