Solution (source code)

= Solution

Vary $g^{ac}g_{cb}=\delta^a_b$. The <product rule> gives
$$
(\delta g^{ac})g_{cb}+g^{ac}\delta g_{cb}=0,
$$
and multiplication by $g^{bd}$ yields the <metric variation>
$$
\boxed{\delta g^{ab}=-g^{ac}g^{bd}\delta g_{cd}}.
$$