Solution (source code)

= Solution

An item escapes detection only in phase B, when it is defective and its inspection coin says no. Since the current item's quality and inspection choice are independent of the phase determined by previous items, the long-run fraction of all production that is defective and undetected is
$$
U=p\left(1-\frac1r\right)\pi_K.
$$
Consequently the two interpretations give
$$
\boxed{U_{\rm cumulative}=\frac{p(r-1)q}{Kp+rq},\qquad U_{\rm consecutive}=\frac{p(r-1)q^K}{1+(r-1)q^K}}.
$$
If the denominator population is defective items alone, divide by their long-run fraction $p$: the corresponding missed fractions are $(r-1)q/(Kp+rq)$ and $(r-1)q^K/[1+(r-1)q^K]$. Stating the denominator matters; the phrase “proportion of defective items” can mean either this conditional fraction or the unconditional production fraction. At $p=0$ no defective item exists, so the unconditional fraction is zero and the conditional fraction is undefined; at $p=1$ eventual full inspection gives zero misses.