Solution (source code)

= Solution

Let
$$
\delta=-\left(\frac{\partial\log\rho}{\partial\log T}\right)_{P,\mu},
\qquad
\phi=\left(\frac{\partial\log\rho}{\partial\log\mu}\right)_{P,T},
\qquad
\nabla_\mu=\frac{d\log\mu}{d\log P}.
$$
A displaced fluid element remains in pressure balance, changes temperature adiabatically, and retains its composition. Comparing its density with the environment after an upward displacement gives the <Ledoux criterion> for stability,
$$
\boxed{
\nabla<\nabla_{\rm ad}+\frac{\phi}{\delta}\nabla_\mu}.
$$
The reverse inequality causes convection. For uniform composition, or if composition is ignored, $\nabla_\mu=0$ and this reduces to the <Schwarzschild criterion>
$$
\boxed{\nabla<\nabla_{\rm ad}}
$$
for stability. A molecular weight increasing inward has $\nabla_\mu>0$ and stabilizes the stratification.