# Solving for covariance?

In solving the following problem:

Let $X$ be the number of 1's and Y the number of 2's that occur in
$n$ rolls of a fair die. Compute $Cov( X, Y)$.

I cam up with this solution:

$Cov( X, Y) = E[ XY] - E[ X]E[ Y]\\ = -\sum\limits_1^n x p(x) \sum\limits_1^n y p(y)\\ = -\sum\limits_1^n x \frac{ 1}{ 6} \sum\limits_1^n y \frac{ 1}{ 6}\\ = -\frac{ 1}{ 36} \sum\limits_1^n x \sum\limits_1^n y\\ = -\frac{ 1}{ 36} \frac{ 1}{ 4} n^2 (n + 1)^2\\ = -\frac{ 1}{ 144} n^2 (n + 1)^2\\$

However, the answer in the back of the book and a work solution here (Problem 7.36) indicate the solution is $-\frac{ n}{36}$ and I do not understand why?

Specifically, I do not understand why they are treating the problem as the covariance of sequences?

-
They are treating the problem as the covariance of random variables (which are sums of indicator random variables) because that is what $X$ and $Y$ are. What is the first line that you do not understand in the proof given on the page you refer to? (And the answer is $-n/36$, not $-n/35$.) – Did Jul 20 '12 at 8:43
You're calculating the expectation value of the numbers on the die, not of the number of $1$s and the number of $2$s. – joriki Jul 20 '12 at 9:37
@did sorry, $-\frac{n}{35}$ was a typo. – rudolph9 Jul 20 '12 at 11:23
I see it now thanks guys. – rudolph9 Jul 20 '12 at 11:24

For every $k\geqslant1$, consider the random variables $U_k$ and $V_k$ defined by $U_k=1$ if the $k$th roll is $1$, $U_k=0$ otherwise, $V_k=1$ if the $k$th roll is $2$, $V_k=0$ otherwise. Then $\mathrm E(U_k)=\mathrm E(V_k)=x$ with $x=\frac16$ and $X=\sum\limits_{k=1}^nU_k$ and $Y=\sum\limits_{k=1}^nV_k$.
Thus, $\mathrm E(X)=\mathrm E(Y)=nx$ and $\mathrm E(XY)$ is a sum of expectations $\mathrm E(U_iV_j)$ which we now compute. For every $i$, $U_iV_i=0$ hence $\mathrm E(U_iV_i)=0$. For every $i\ne j$, $U_i$ and $V_j$ are independent hence $\mathrm E(U_iV_j)=x^2$ where $x=\mathrm E(U_i)=\mathrm E(V_j)=\frac16$. There are $n(n-1)$ terms with $i\ne j$ in the sum defining $\mathrm E(XY)$ hence $\mathrm E(XY)=n(n-1)x^2$.
Finally, $\mathrm{Cov}(X,Y)=\mathrm E(XY)-\mathrm E(X)\mathrm E(Y)=n(n-1)x^2-(nx)^2=-nx^2=-\frac1{36}n$.