Getting two different results in Covariance Calculation Let $A=\{(x, y) \in \mathbb{R}^{2}: x^{2}-\frac{1}{2 \sqrt{\pi}}<y<x^{2}+\frac{1}{2 \sqrt{\pi}}\}$ and let the joint probability density function of $(X,Y)$
$f(x, y)=\begin{cases} e^{-(x-1)^{2}}, & (x, y) \in A \\ 0,  \text { otherwise } \end{cases}.$.
I need to compute the covariance between $X$ and $Y$.
I can see after integrating for $X$ and $Y$ that $X$ follows $N(1, \frac{1}{sqrt{2}})$ and $Y$ folows $Unif[-\frac{1}{2\sqrt{\pi}},\frac{1}{2\sqrt{\pi}}]$. I can also observe that the joint can be written as:
$f(x,y) = \sqrt{\pi} (\frac{1}{\sqrt{\pi}}e^{-(x-1)^2}) = f(x)f(y)$.
Hence, X and Y are independent which means the covariance between them will be zero but I am getting answer as 1.
I think that there is something wrong with the way I factorized the joint pdf. I probably also need to take into account the support over which they are defined but I am exactly sure if that is correct.
I also tried another approach in which I observed that $Cov(X,y) = E(XY] - E(X)E(Y) = E(XY)$ as the for the uniform the expectation is zero. Then I solved for $E(xy)$ by setting up the double integrals and that way also I am getting zero as the answer. I can show my calculation if needed but i have skipped it because it would involve lot of typing in latex.
Please let me know if I am doing anything incorrectly.
 A: Although you can do this with mindless application of definitions and skill at integration, the interest (and challenge) is to obtain an answer with as little work (and as much insight) as possible.
Upon reflection, it looks like this problem ultimately requires only the following facts:

*

*By inspection of the exponent $(x-1)^2 = (x-1)^2/(2\sqrt{1/2}),$ $X$ has a Normal distribution with mean $1$ and standard deviation $\sqrt{1/2}.$


*The regression of $Y$ on $X$ is $E[Y\mid X]=X^2.$
To illustrate this generalization, here are simulated data where the distribution of $Y$ conditional on $X$ has been expanded by a factor of $10 X \cos(4X)$ relative to $X$ to demonstrate that only the conditional expectation matters:

The red curve on the histogram of $X$ at the right is the density function for a Normal$(1,\sqrt{1/2})$ distribution.
The covariance in this simulation of ten thousand realizations of $(X,Y)$ was $0.964;$ in a simulation of one million realizations the covariance was $0.999.$  We might guess, then, that the true covariance is $1.$

Let's return to the analysis.  Fact $(2)$ suggests exploiting information about the conditional expectation of $Y,$ which means applying the law of iterated expectations,
$$\begin{aligned}
\operatorname{Cov}(X,Y) &= E[XY] - E[X]E[Y] \\
&= E[E[XY\mid X]] - E[X]E[E[Y\mid X]] \\
&= E[X^3] - E[X] E[X^2].
\end{aligned}.\tag{*}$$
It remains only to find the first three moments of $X,$ which you can compute using the moment generating function, as explained at https://stats.stackexchange.com/a/176814/919, or you can look them up.
You still have to do some algebra.  I find it easiest to express $X$ in terms of a standard normal variable $Z$ as
$$X = Z/\sqrt{2} + 1$$
so that
$$\begin{aligned}
E[X]&=E[Z/\sqrt{2} + 1] = 1,\\
E[X^2] &= E[Z^2/2 + \cdots + 1] = \frac{1}{2}+1,\\
E[X^3] &= E[\cdots + 3Z^2/2 + \cdots + 1] = \frac{5}{2}.
\end{aligned}\tag{**}$$
The omitted terms involve odd powers $Z$ and $Z^3$ which, because $Z$ is symmetric around $0,$ must have vanishing expectations.  This reveals that all we needed to know about $Z$ (apart from its symmetry) is that its mean is $0$ and its expected square is $E[Z^2] = \operatorname{Var}(Z) + E[Z]^2 = 1 + 0^2 = 1.$
Combining $(*)$ and $(**)$ gives the answer
$$\operatorname{Cov}(X,Y) = \frac{5}{2} - (1)\left(\frac{1}{2}+1\right)=1.$$
Note that fact $(1)$ could be weakened to assuming only that $X-1$ has a symmetric distribution around $0$ and a variance of $1/2$ (or even further weakened to supposing only that the expectations of $X-1$ and $(X-1)^3$ are zero).
