Use P(B)=∑iP(B∣Ai)P(Ai)P(B) = \sum_i P(B|A_i)P(A_i)P(B)=∑iP(B∣Ai)P(Ai) for a partition {Ai}\{A_i\}{Ai}.