# What is technically wrong with this obviously false derivation?

Let's say we have a random variable $X$ and $Y$, and $Z=X+Y$

Now assume we have a probability density distribution over $Z$: $p(Z)$.

Then the expectation of $Z$ is: $$E(Z)=\int Z p(Z)\,dZ=\int (X+Y)p(Z)\,dZ=(X+Y)\int p(Z)\,dZ = X+Y$$

I obviously understand that we cannot do this, because $X+Y$ are random variables, so we have to do a change of variables instead, and we'll end up with a double integral. We could only do the derivation as I just did if we took the conditional expectation $E(Z\mid ,Y)$ instead. I know that $Z$ "depends on" $X$ and $Y$.

But I am not entirely sure where the technical mistake was. That is, if you would explain to me in the most technically detailed and pedantic way possible what is wrong with this obviously wrong argument, what would you say?

• This isn't a question about random variables. It comes down to something very simple: you are manipulating an integral incorrectly. The question should be turned back to you: please tell us what theorem or axiom you are applying that you think allows you to manipulate the integral in this way. In attempting to do this, it is likely the error will become obvious to you. (This circumstance is no different than, say, asserting that for all real numbers $a,b,c$, $(a+b)c=a+bc$ and asking for a rigorous demonstration that your assertion is incorrect.) – whuber Dec 31 '17 at 16:25

$\int a. f(x) dx = a \int f(x) dx$ only if $a$ is constant with changing $x$ (within the range of the integral). X+Y clearly is not a constant with changing Z
You're conflating $X:\Omega\to\mathbb R$, a function from the sample space to numbers, and $X(\omega)$, a particular number.