Solution (source code)

= Solution

Insert
$$
\rho=\bar\rho+\epsilon\,\delta\rho,
\qquad
\mathbf v=\epsilon\,\delta\mathbf v
$$
into the continuity equation. Its zeroth-order part is the homogeneous <cosmological continuity equation>
$$
\dot{\bar\rho}+3H\bar\rho=0.
$$
Since $\bar\rho$ is spatially homogeneous, the terms of first order in $\epsilon$ give
$$
\frac{\partial\delta\rho}{\partial t}
+3H\delta\rho
+\frac{\bar\rho}{a}\nabla\cdot\delta\mathbf v=0.
$$
On the other hand, the <quotient rule> and the background equation imply
$$
\frac{\partial}{\partial t}
\left(\frac{\delta\rho}{\bar\rho}\right)
=\frac1{\bar\rho}\frac{\partial\delta\rho}{\partial t}
-\frac{\delta\rho}{\bar\rho^2}\dot{\bar\rho}
=\frac1{\bar\rho}\frac{\partial\delta\rho}{\partial t}
+3H\frac{\delta\rho}{\bar\rho}.
$$
Substitution of the first-order equation yields the <linearized cosmological continuity equation>
$$
\boxed{
\frac{\partial}{\partial t}
\left(\frac{\delta\rho}{\bar\rho}\right)
=-\frac1a\nabla\cdot\delta\mathbf v
}.
$$
The ratio $\delta\rho/\bar\rho$ is the <density contrast>.