Solution (source code)

= Solution

The numerator $P(B\mid A)P(A)$ equals $P(A\cap B)$, while $P(A\mid B)=P(A\cap B)/P(B)$. Thus, wherever the original quotient is defined,
$$
\boxed{\frac{P(B\mid A)P(A)}{P(A\mid B)}=P(B).}
$$
In particular a zero numerator and denominator cannot be cancelled; the original expression requires $P(A\mid B)>0$. This is the rearrangement of <Bayes' theorem>.