Varying the Ricci tensor and contracting gives
Substitution of part (i), followed by metric compatibility, reduces the divergence to
Thus the metric variation of scalar curvature is
and consequently