Solution (source code)

= Solution

Consider a species in <thermal equilibrium>, with <energy density> and pressure depending on <temperature> and with vanishing <chemical potential>, as in the supplied thermodynamic relation. Put $U=\rho(T)V$. The <first law of thermodynamics> gives
$$
dS=\frac VT\frac{d\rho}{dT}\,dT+\frac{\rho+P}{T}\,dV.
$$
Since $dP/dT=(\rho+P)/T$,
$$
\frac{d}{dT}\left(\frac{\rho+P}{T}\right)
=\frac1T\frac{d\rho}{dT}.
$$
The differential is therefore exact:
$$
dS=d\left[V\frac{\rho+P}{T}\right].
$$
After fixing the irrelevant additive entropy zero, the <entropy density at zero chemical potential> is
$$
\boxed{s=\frac{S}{V}=\frac{\rho+P}{T}.}
$$
More precisely the first law leaves an additive constant in $S$; extensivity fixes that constant for the usual entropy-density normalization. A nonzero chemical potential would instead require $Ts=\rho+P-\mu n$, so the stated formula is not a universal identity for a decoupled massive species with conserved particle number.

For a <reversible thermodynamic process> that is an <adiabatic process> in a <comoving volume>, $\dot V=3HV$ and the <cosmological perfect-fluid continuity equation> gives $\dot\rho=-3H(\rho+P)$. Differentiating the extensive expression explicitly, or using the exact differential above, gives
$$
\dot S=\frac1T\left[V\dot\rho+(\rho+P)\dot V\right]=0,
\qquad \boxed{a^3s=\text{constant}.}
$$
This is <cosmological entropy conservation> for the closed equilibrium gas with no entropy-producing energy injection.

For <radiation in cosmology>, $P=\rho/3$, so $s=4\rho/(3T)$. Comparing $s=c_1g_\star T^3$ and $\rho=c_2g_\star T^4$ yields the \b[coefficient ratio]
$$
\boxed{c_1=\frac43c_2,\qquad \frac{c_2}{c_1}=\frac34.}
$$
When all relativistic species share the same temperature and count, the familiar normalizations are $c_1=2\pi^2/45$ and $c_2=\pi^2/30$. More generally the energy and entropy effective counts can differ; the common $g_\star$ here uses the assumptions stated in the question.