Solution (source code)

= Solution

For a <nonrelativistic particle>, $E(p)=mc^2+p^2/(2m)$. The <Gaussian integral> yields
$$
\boxed{n=g_s\left(\frac{2\pi m k_BT}{h^2}\right)^{3/2}
\exp\left(\frac{\mu-mc^2}{k_BT}\right).}
$$
Indeed $\int_0^\infty p^2e^{-p^2/(2mk_BT)}dp=\sqrt\pi(2mk_BT)^{3/2}/4$, which combines with $4\pi/h^3$ to give the prefactor. For the two species this gives
$$
\boxed{\frac{n_a}{n_b}=\frac{g_a}{g_b}\left(\frac{m_a}{m_b}\right)^{3/2}
\exp\left(\frac{\mu_a-\mu_b-(m_a-m_b)c^2}{k_BT}\right).}
$$
<Chemical equilibrium> imposes $\mu_a+\mu_\alpha=\mu_b+\mu_\beta$. If the two massless bath species have zero <chemical potentials>, then $\mu_a=\mu_b$; their masses alone do not imply this chemical-potential condition.

Weak reactions such as $n+\nu_e\leftrightarrow p+e^-$, with leptons treated as relativistic, interconvert <neutrons> and <protons>. Negligible lepton <chemical potentials> give approximately $n_n/n_p=\exp[-(m_n-m_p)c^2/(k_BT)]$, since their degeneracies and masses are nearly equal. Equilibrium favors <protons> increasingly as <temperature> falls. But the weak reaction rate decreases faster than the expansion rate and eventually falls below it: <cosmological weak freeze-out> prevents the ratio from following its equilibrium exponential to zero. Free <neutrons> subsequently decay, reducing the frozen ratio further.

In <Big Bang nucleosynthesis>, cooling eventually makes deuterium survive photodissociation. Nuclear reactions then build <helium> through deuterium and the light intermediate nuclei, locking almost all surviving <neutrons> into stable helium-four. Neglecting binding-energy corrections and taking $r=n_n/n_p\le1$, each <helium> nucleus uses two <neutrons> and two <protons>, so $n_{\rm He}=n_n/2$ and
$$
\boxed{Y_{\rm He}=\frac{4n_{\rm He}}{n_n+n_p}=\frac{2r}{1+r}.}
$$
For example $r=1/7$ gives a <helium> mass fraction $1/4$, with the remaining baryons predominantly hydrogen.