In problem 4, part C in this online probability book, how is the result pictured below found? (Near the bottom of the answer)
https://www.probabilitycourse.com/chapter9/9_1_10_solved_probs.php
Shouldn't it be: $EX^2 - 2E[X*X_M^{\text{^}}] + E[ X_M^{\text{^2}}]$?
They are in fact the same since
$E[X\hat{X}_M]$ $= P(Y=0)E[X\hat{X}_M \mid Y=0] + P(Y=1)E[X\hat{X}_M \mid Y=1]$
$= P(Y=0)E[E[X\mid Y=0] \hat{X}_M \mid Y=0] + P(Y=1)E[E[X\mid Y=1] \hat{X}_M \mid Y=1]$
$= P(Y=0)E[\hat{X}_M^2 \mid Y=0] + P(Y=1)E[\hat{X}_M^2 \mid Y=1]$
$= E[\hat{X}_M^2]$
so $E[X^2] -2E[X\hat{X}_M] + E[\hat{X}_M^2] = E[X^2] -E[\hat{X}_M^2]$
and this is very similarly to the variance calculation $E[(X-E[X])^2] = E[X^2]-(E[X])^2$