Solution (source code)

= Solution

For a comoving region, $E=\rho V$ and $V=a^3V_0$. The work law gives
$$
d(\rho V)=-P\,dV,
$$
so differentiation with respect to time yields
$$
V\dot\rho+(\rho+P)\dot V=0.
$$
Since $\dot V/V=3\dot a/a$, division by $V$ gives the <cosmological perfect-fluid continuity equation>
$$
\boxed{\dot\rho+3\frac{\dot a}{a}(\rho+P)=0}.
$$