Conditional Expectation of Bernoulli R.V. Let $X_1, X_2,\ldots, X_n$ be iid bernoulli r.v. with parameter $p$. Let $S=X_1+\cdots+X_n$ and $Y=X_1X_2$. Compute $\mathbb{E}(Y\mid S)$.
I know that $\mathbb{E}(X_1\mid S) = S/n$. So If I could split $\mathbb{E}(Y\mid S)$ into two then I would be done. But I don't think that is allowed. How to proceed? 
 A: The expected value of a Bernoulli-distributed random variable is the same as its probability of being equal to $1.$ So you have $\operatorname E(X_1) = \cdots = \operatorname E(X_n) = p.$ Note that $X_1 X_2$ is a Bernoulli-distributed random variable, i.e. it must be either $0$ or $1.$
\begin{align}
& \operatorname E(X_1 X_1 \mid X_1+\cdots+X_n = s) = \Pr(X_1 X_2=1 \mid X_1+\cdots+X_n = s) \\[10pt]
= {} & \frac{\Pr(X_1 X_2=1\ \&\ X_1+\cdots+X_n=s)}{\Pr(X_1+\cdots+X_n=s)} \\[10pt]
= {} & \frac{\Pr(X_1=1\ \&\ X_2=1\ \&\ X_1+\cdots+X_n=s)}{\Pr(X_1+\cdots+X_n=s)} \\[10pt]
= {} & \frac{\Pr(X_1=1\ \&\ X_2=1\ \&\ X_3+\cdots+X_n=s-2)}{\Pr(X_1+\cdots+X_n=s)} \\[10pt]
= {} & \frac{\Pr(X_1=1\ \&\ X_2=1) \cdot \Pr(X_3+\cdots+X_n=s-2)}{\Pr(X_1+\cdots+X_n=s)} \\[10pt]
= {} &\frac{p^2 \cdot \binom {n-2}{s-2} p^{s-2}(1-p)^{n-s}}{\binom n s p^s (1-p)^{n-s}} \\[10pt]
= {} & \frac{\binom{n-2}{s-2}}{\binom n s} = \frac{s(s-1)}{n(n-1)}.
\end{align}
A: Here's another way. Let $a = E[X_1  X_2 \mid S]$. By symmetry, $a=[X_i  X_j \mid S]$ for any $i\ne j$.
Now write
$$S^2= \left(\sum_i X_i \right)^2= \sum_i X_i^2 + \sum_{i\ne j} X_i X_j=\sum_i X_i + \sum_{i\ne j} X_i X_j=S+\sum_{i\ne j} X_i X_j$$
Conditioning on $S$ and taking expectation
$$E[ S^2 \mid S] = S^2 = S+ n(n-1) a$$
Hence
$$a = \frac{S(S-1)}{n(n-1)}$$
A: Note that $Y = 1$ if and only if $X_1 = X_2 = 1$, and $0$ otherwise.  So if $S \le 1$, then $Y = 0$, and if $S \ge 2$, we must find the number of outcomes for which $X_1 = X_2 = 1$ among the total number of outcomes; that is to say $$\Pr[X_1 = X_2 = 1 \mid S = s] = \frac{\binom{n-2}{s-2}}{\binom{n}{s}} = \frac{(n-2)!s!(n-s)!}{(s-2)!(n-s)!n!} = \frac{s(s-1)}{n(n-1)}, \quad s \ge 2,$$ and $0$ otherwise.  Then
$$\operatorname{E}[Y \mid S] = 1 \cdot \Pr[Y = 1 \mid S] = \Pr[X_1 = X_2 = 1 \mid S] = \begin{cases} \frac{S(S-1)}{n(n-1)}, & S \in \{2, 3, \ldots, n\} \\ 0, & \text{otherwise}. \end{cases}$$
It is worth noting that the result does not depend on $p$, so long as $0 < p < 1$.
