Solution (source code)

= Solution

Divide the relevant joint <probability> by the marginal stopping <probability>. By <Bayes' theorem>,
$$
\boxed{P(D\mid x_1)=\frac{(1-p)d_1}{pg_1+(1-p)d_1}.}
$$
The denominator is positive under the stated assumptions.