Posterior distribution of the difference of means of two normal distributions. Let $D = \{(y_{E1}, y_{S1}), \cdots, (y_{En}, y_{Sn})\}$, assume that $y_{Ei} \sim N(\mu_E, \sigma^2)$ and $y_{Si} \sim N(\mu_S, \sigma^2)$ with unknown means $\mu_E$ and $\mu_S$ but a known variance $\sigma^2=1$.
Let $\theta = \mu_E- \mu_S$, $\hat{\theta} = \frac{1}{n}\sum_{i=1}^ny_{Ei} - \frac{1}{n}\sum_{i=1}^ny_{Si}$, what's the posterior distribution of $\theta$?
The answer is that
$$\theta|D \sim N\left(\hat{\theta}, \frac{2}{n}\right)$$
However, I am not sure how to derive it.
 A: The question does not state that

*

*$y_{E_1},\ldots,y_{E_n}$ are independent,

*$y_{S_1},\ldots,y_{S_n}$ are independent,

*$(y_{E_1},\ldots,y_{E_n})$ is independent of $$(y_{S_1},\ldots,y_{S_n}).$$
I will assume those here.
You have a likelihood function
\begin{align}
L(\mu_E, \mu_S) & \propto \prod_{i=1}^n \exp\left(-\tfrac 1 2 (y_{E_i}-\mu_E)^2 \right) \cdot \prod_{i=1}^n \exp\left(-\tfrac 1 2 (y_{S_i}-\mu_S)^2 \right) \\[8pt]
& = \exp\left( -\frac 1 2 \left( \sum_{i=1}^n (y_{E_i}-\mu_E)^2 + \sum_{i=1}^n (y_{S_i}-\mu_S)^2. \right) \right) \tag 1
\end{align}
And so to algebra: Let $\overline y= (y_1+\cdots+y_n)/n.$ Then
\begin{align}
\sum_{i=1}^n (y_i-\mu)^2 & = \sum_{i=1}^n \big( (y_i-\overline y) + (\overline y-\mu)^2 \big) \\[8pt]
& = \sum_{i=1}^n \Big( (y_i-\overline y)^2 +{} \underbrace{ 2(y_i-\overline y)(\overline y - \mu)}_\text{middle terms} {} +{} \underbrace{(\overline y-\mu)^2}_\text{no “$i$” here} \,\Big)
\end{align}
The sum of the middle terms is
\begin{align}
& \sum_{i=1}^n \Bigg( 2(y_i-\overline y)(\overline y - \mu) \Bigg) \\[8pt]
= {} & \left( \sum_{i=1}^n (y_i-\overline y) \right) \cdot 2 (\overline y - \mu) \\
& \text{This can be done because no “$i$” appears in “$2 (\overline y - \mu)$”,} \\
& \text{i.e. that factor does not change as $i$ goes from $1$ to $n$.} \\[8pt]
& = 0.
\end{align}
And we have $\sum_{i=1}^n (\overline y-\mu)^2 = n(\overline y-\mu)^2,$ since this sum is one in which all $n$ terms are identical. Thus the sum is
$$
\underbrace{ \left( \sum_{i=1}^n (y_i-\overline y) \right)}_\text{No “$\mu$” appears here!} {} + n(\overline y-\mu)^2.
$$
So line $(1)$ above becomes
\begin{align}
& \exp\Bigg( -\frac 1 2 \Bigg( \,\,\, \underbrace{ \left( \sum_{i=1}^n (y_{E_i}-\overline y_E) \right)}_\text{no “$\mu_E$”} + n(\overline y_E-\mu_E)^2 + {} \underbrace{ \left( \sum_{i=1}^n (y_{S_i}-\overline y_S) \right)}_\text{no “$\mu_S$”}  + n(\overline y_S-\mu_S)^2 \,\,\, \Bigg) \Bigg) \\[8pt]
\propto {} & \exp\Bigg( -\frac 1 2 \Bigg(  n(\overline y_E-\mu_E)^2 + n(\overline y_S-\mu_S)^2 \,\,\, \Bigg) \Bigg). \\
& \text{Here the proportionality is } \underline{\text{as a function of $\mu_E$ and $\mu_S$},} \\
& \text{so the expressions with no “$\mu$” are “constants.”}
\end{align}
Since you have an improper uniform prior, the probability density function of $(\mu_E,\mu_S)$ is proportional to what you see above. This means $\mu_E,\mu_S$ are normally distributed with respective expectations $\overline y_E,\overline y_S$ and variances each equal to $1/n,$ and independent of each other.
