Solution (source code)

= Solution

Use the <instantaneous recycling approximation> and treat the <interstellar medium> as well mixed. If <star formation> initially consumes mass $dM$, returning a fraction $\beta$ leaves locked stellar mass $ds=(1-\beta)dM$. The original metal mass removed from the <interstellar medium> is $Z_i\,dM$. Of this original material, $\beta fZ_i\,dM$ returns and remains in the <galaxy>. In addition, the <stellar yield> produces fresh metal mass $y_i\,ds$, of which the retained part is $fy_i\,ds$. Therefore metal accounting gives
$$
d(gZ_i)=-Z_i\,dM+\beta fZ_i\,dM+fy_i\,ds,
\qquad
\boxed{\frac{d(gZ_i)}{ds}=-\frac{1-\beta f}{1-\beta}Z_i+y_if.}
$$
This is the <retained-ejecta chemical evolution> equation. It assumes that the same retention fraction applies to original and newly synthesized metals. Pristine <galactic gas inflow> can change $g$ without contributing to $d(gZ_i)$; enriched <galactic gas inflow> would require an additional metal source. Here $0\leq\beta<1$, and $0\leq f\leq1$.

A <star> inherits the <gas-phase metallicity> at its birth. Suppose enrichment is monotone and a fixed <initial mass function>, with an appropriate surviving tracer selection, produces $\kappa$ observable <stars> per unit locked mass. For two birth abundances $Z_a<Z_b$, the relative count is
$$
N(Z_a<Z_i<Z_b)=\kappa\,[s(Z_b)-s(Z_a)],
\qquad
\boxed{\frac{dN}{dZ_i}=\kappa\frac{ds}{dZ_i}.}
$$
Thus $s(Z_i)$ is proportional to the cumulative <metallicity distribution function>; its derivative gives the differential <metallicity distribution function>. The normalized distribution after final locked mass $s_\infty$ is $s_\infty^{-1}ds/dZ_i$. For logarithmic abundances, the <logarithmic metallicity distribution> instead has $dN/d\log_{10}Z_i=(\ln10)Z_i\,dN/dZ_i$.

The fixed <initial mass function> and survival selection matter: a mass distribution is not automatically the number distribution of every presently observable <star>. If enrichment is nonmonotone, add the contributions $\kappa|ds/dZ_i|$ from all birth-time branches attaining that abundance, rather than using one inverse.