Conditional probability on 3 events. Say you have 3 events $A, B$, and $C$. Then you have to calculate the probability of $B$ given $A$.
The formula that the answer key states:
$$P(B|A)=P(B|A,C)P(C) + P(B|A,C^\complement)P(C^\complement)$$
I understand that for just two events $B$ and $A$ it is:
$$P(B)=P(B|A)P(A) + P(B|A^\complement)P(A^\complement)$$
How do you derive the first formula?
 A: Sometimes it's easier to work with intersections rather than conditionals. The key formula here is that $$ P(A)  = P(A\cap B)+P(A\cap B^c)$$ which follows from the fact that $A = (A\cap B)\cup(A\cap B^c)$ and $(A\cap B)\cap(A\cap B^c) = \emptyset$ and that disjoint unions are additive. The second formula that you write down is just this with the definition of conditional probability $P(A|B) = P(A\cap B)/P(B)$ used on the RHS.
So you can write $$ P(A\cap B) = P(A\cap B\cap C)+P(A\cap B\cap C^c) $$ and by definition of conditional probability, $$ P(B\mid A)P(A) = P(B\mid A\cap C)\,P(A\cap C) + P(B\mid A\cap C^c)\,P(A\cap C^c)$$
and dividing both sides by $P(A)$ and using the definition again. $$ P(B\mid A) = P(B\mid A\cap C)\,P(C\mid A)+P(B\mid A\cap C^c)\,P(C^c\mid A).$$
It appears that your first formula only applies to when $C$ and $A$ are independent so that $P(C\mid A) = P(C)$ and $P(C^c\mid A)=P(C^c).$ So unless that's an assumption of the problem, the formula is wrong.
A: The first formula is true when events $A$ and $C$ are independent, which means
$$p(A \cap B)=p(A)p(B)$$
The RHS of the first formula can be written as (Bayes rule)
$$p(B|A)=\frac{p(B\cap A)}{p(A)}$$
Then, using the second formula
$$\frac{p(B\cap A)}{p(A)}=\frac{p(B\cap A|C)p(C)+p(B\cap A|C^c)p(C^c)}{p(A)}$$
$$=\frac{p(B\cap A \cap C)p(C)}{p(C)p(A)}+\frac{p(B\cap A \cap C^c)p(C^c)}{p(C^c)p(A)}$$
Now, if $A$ and $C$ are independent, we can take the final step as the following
$$=\frac{p(B\cap A \cap C)p(C)}{p(A\cap C)}+\frac{p(B\cap A \cap C^c)p(C^c)}{p(A\cap C^c)}=p(B| A \cap C)p(C)+p(B| A \cap C^c)p(C^c)$$
