# How to calculate that conditional expectation?

I mean the expectation of x*z under the conditions (y + z == 8) && (z*w == 2) && (w + y == 1), where x,y,z,w are IID having ExponentialDistribition[1]. The command

Expectation[x*z \[Conditioned] (y + z == 8) && (z*w == 2) && (w + y ==
1), {x \[Distributed] ExponentialDistribution[1], y \[Distributed] ExponentialDistribution[1],
z \[Distributed] ExponentialDistribution[1], w \[Distributed] ExponentialDistribution[1]}]


returns the input as well as NExpectation.

If one reduces the conditions (with the implicit condition that $$Z>0$$ given that $$Z$$ has an exponential distribution with mean 1), one finds

Reduce[(y + z == 8) && (z*w == 2) && (w + y == 1) && z > 0] // LogicalExpand
(* w == 4/(7 + Sqrt[57]) && y == 8 + 1/2 (-7 - Sqrt[57]) && z == 1/2 (7 + Sqrt[57]) *)


So the distribution of $$X Z$$ conditioned on $$Z=\frac{1}{2} \left(\sqrt{57}+7\right)$$ is just a multiple of the distribution of $$X$$ given that $$X$$ is independent of all of the other random variables. The expectation of $$\frac{1}{2} \left(\sqrt{57}+7\right) X$$ is $$\frac{1}{2} \left(\sqrt{57}+7\right) E(X)=\frac{1}{2} \left(\sqrt{57}+7\right) * 1=\frac{1}{2} \left(\sqrt{57}+7\right)$$.

Or using Mathematica:

d = ExponentialDistribution[1];
Expectation[x*z \[Conditioned] Reduce[(y + z == 8) && (z*w == 2) && (w + y == 1) && z > 0] //LogicalExpand,
{w \[Distributed] d, x \[Distributed] d, y \[Distributed] d, z \[Distributed] d}]
(* 1/2 (7 + Sqrt[57]) *)


It didn't work the way you did it because without including the condition $$Z>0$$ one obtains:

Reduce[(y + z == 8) && (z*w == 2) && (w + y == 1)] // LogicalExpand
(* (8 - z == y && -7 + z == w && z == 1/2 (7 - Sqrt[57])) ||
(8 - z == y && -7 + z == w && z == 1/2 (7 + Sqrt[57]))


That more complicated expression I guess is more than Mathematica can handle.

• Expectation[ x z \[Conditioned] (y == -2 && z == -4 && w == -(1/2)), {x \[Distributed] ExponentialDistribution[1], y \[Distributed] ExponentialDistribution[1], z \[Distributed] ExponentialDistribution[1], w \[Distributed] ExponentialDistribution[1]}] returns -4. This is a bug. Jan 31 at 4:34
• Is it a bug when you condition on 3 things that are impossible to occur if the distributions are exponential?
– JimB
Jan 31 at 4:43
• The result of the execution -4 is wrong. The command should return the input. I submitted a report. Jan 31 at 4:47
cons = (y + z == 8) && (z*w == 2) && (w + y == 1);


There are three equations with three variables. The variables are all constants.

values = SolveValues[{cons, z > 0}, {w, y, z}]

(* {{4/(7 + Sqrt[57]), 8 + 1/2 (-7 - Sqrt[57]), 1/2 (7 + Sqrt[57])}} *)

Expectation[x*z \[Conditioned] z == values[[1, 3]],
x \[Distributed] ExponentialDistribution[1]]


Which is consistent with

values[[1, 3]]*Mean[ExponentialDistribution[1]] // Simplify

(* 1/2 (7 + Sqrt[57]) *)

• Good answer. You beat me by a minute.
– JimB
Jan 30 at 21:20
• Both answers use the same idea. I prefer @JimB's one as more automated and accurate. How may a conditional expectation be Piecewise? Jan 31 at 4:24
• The Piecewise is an unsimplified result. The "condition" can be assumed to be true so the default value cannot occur and simplification with that assumption would remove the Piecewise. The last statement is equivalent to Assuming[z == values[[1, 3]], Expectation[x*z, x \[Distributed] ExponentialDistribution[1]]] Jan 31 at 6:30