Solution (source code)

= Solution

The variables $(m-1)S_X^2/\sigma^2$ and $(n-1)S_Y^2/\sigma^2$ are <independent> chi-squared variables with $m-1$ and $n-1$ <degrees of freedom>. <Independence> follows because the two whole samples are <independent>. Their sum is chi-squared with the sum of the <degrees of freedom>, so
$$
\boxed{\frac{(m+n-2)S^2}{\sigma^2}\sim\chi^2_{m+n-2},\qquad d=\frac{m+n-2}{\sigma^2}.}
$$
Within each normal sample the <sample mean> is <independent> of its <sample variance>, and <independence> of the samples makes the pair of means jointly <independent> of the pair of <variances>. Hence this pooled chi-squared variable is <independent> of the standardized mean difference, which is the <independence> required for the Student pivot.