Solution (source code)

= Solution

By the partition and the <law of total probability>, $\mathbb P(A)=\sum_j\mathbb P(A\cap B_j)=\sum_j\mathbb P(A\mid B_j)\mathbb P(B_j)$. Also $\mathbb P(B_i\mid A)=\mathbb P(A\cap B_i)/\mathbb P(A)$. Combining these identities proves <Bayes theorem>:
$$
\boxed{\mathbb P(B_i\mid A)=\frac{\mathbb P(A\mid B_i)\mathbb P(B_i)}{\sum_j\mathbb P(A\mid B_j)\mathbb P(B_j)}}.
$$
The assumed positive probabilities make the conditional expressions well defined.