Solution (source code)

= Solution

The <cosmological perfect-fluid continuity equation> and the constant <barotropic equation of state> $P=w\rho$ give
$$
\dot\rho=-3(1+w)\frac{\dot a}{a}\rho.
$$
On every interval where $a$ is monotone, separation of variables yields
$$
\frac{d\rho}{\rho}=-3(1+w)\frac{da}{a}.
$$
Hence the <constant-equation-of-state density scaling> is
$$
\boxed{\rho=\frac{3\mu}{8\pi}a^{-3(1+w)},}
$$
where $\mu$ is a constant. The same expression extends through a regular <turning point> by continuity.