I am using Mathematica 12.0 on Windows and I recently tried to evaluate a conditional expectation, namely

Expectation[Conditioned[X, X < 0.5], Distributed[X, UniformDistribution[{0, 1}]]]

However, when running it, I obtain the error message

$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of X<1/2.

paired with

Hold[Expectation[X \[Conditioned] X < 0.5, X \[Distributed] UniformDistribution[{0, 1}]]]

I tried closing Mathemtica and re-opening it and it correctly gave me the answer of 0.25. Does anyone know why the behavior of the first try?

I also tried

Probability[Conditioned[X, X < 0.5], Distributed[X, UniformDistribution[{0, 1}]]]

which remains unevaluated.

Adding the method Trace returns

x*Piecewise[{{0., x < 0}, {2., Inequality[0, LessEqual, x, Less, 0.5]}}, 0], 
{x, 0, 1}, GenerateConditions -> False, Assumptions -> True]
  • $\begingroup$ I cannot seem to reproduce this in the Cloud version. Did you try this on a fresh kernel? $\endgroup$ – J. M.'s ennui Feb 3 '20 at 0:59
  • $\begingroup$ Yes I tried both on a fresh kernel. The first time it gave me the first error, while the second it gave me the correct answer. On both cases the Probability command remains unevaluated. $\endgroup$ – DMH16 Feb 3 '20 at 1:01
  • 1
    $\begingroup$ Can you try adding the option Method -> "Trace" to Expectation[] and see what gets returned? (Also, Probability[] with Conditioned[] expects a relation and not a function, e.g. Probability[Conditioned[0.2 < X < 0.6, X < 0.5], Distributed[X, UniformDistribution[{0, 1}]]].) $\endgroup$ – J. M.'s ennui Feb 3 '20 at 1:02
  • $\begingroup$ added the output $\endgroup$ – DMH16 Feb 3 '20 at 1:13
  • 3
    $\begingroup$ Perhaps you had defined X in the original session. $\endgroup$ – John Doty Feb 3 '20 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.