2
$\begingroup$
D[Probability[Sin[X] < y, 
   Distributed[X, 
    ProbabilityDistribution[
     Piecewise[{{2*x/(Pi^2), 0 < x < Pi}, {0, 
        x <= 0 || x >= Pi}}], {x, -Infinity, Infinity}]]], 
  y] // Simplify

produces $$\left\{\begin{array}{cc} & \begin{array}{cc} \frac{2}{\pi \sqrt{1-y^2}} & 0<y<1 \\ 0 & y>1\lor y<0 \\ \text{Indeterminate} & \text{True} \\ \end{array} \\ \end{array}\right.$$

However,

D[Probability[Sin[X] < y, 
   Distributed[X, 
    ProbabilityDistribution[
     Piecewise[{{2*x/(Pi^2), 0 < x < Pi}}], {x, -Infinity, 
      Infinity}]]], y] // Simplify

produces the same result. I guess in the first example, the Piecewise doesn't work. In the first example, the right answer should be

$$\left\{\begin{array}{cc} & \begin{array}{cc} \frac{2}{\pi \sqrt{1-y^2}} & 0<y<1 \\ 0 & y\ge1\lor y\le0 \\ \end{array} \\ \end{array}\right.$$

$\endgroup$
3
  • 1
    $\begingroup$ Since the default for Piecewise is the value zero, the two Piecewise statements are equivalent, i.e., "Piecewise[{{2*x/(Pi^2), 0 < x < Pi}, {0, x <= 0 || x >= Pi}}] === Piecewise[{{2*x/(Pi^2), 0 < x < Pi}}]` evaluates to True $\endgroup$
    – Bob Hanlon
    Commented Jan 20 at 15:08
  • $\begingroup$ @BobHanlon: Did you pay your attention to my answer submitted before your comment? $\endgroup$
    – user64494
    Commented Jan 20 at 15:34
  • $\begingroup$ @user64494 I think his/her comment is imortant here, but as there is one condition applied, so the default value for Piecewise shouldn't work here. Why does the default value zero does work in this situation? $\endgroup$
    – Y. zeng
    Commented Jan 21 at 3:18

1 Answer 1

5
$\begingroup$

Mathematica is right in both cases, you are not. First,

FullSimplify[ Piecewise[{{2*x/(Pi^2), 0 < x < Pi}, {0, x <= 0 || x >= Pi}}]- 
Piecewise[{{2*x/(Pi^2), 0 < x < Pi}}]]

0

and this explains the identical results (also look in the documentation to Piecewise for info). Second,

Probability[Sin[X] < y,  Distributed[X,  ProbabilityDistribution[ 
Piecewise[{{2*x/(Pi^2), 0 < x < Pi}, {0,  x <= 0 || x >= Pi}}], {x, -Infinity, Infinity}]]]

Piecewise[{{1, y > 1}, {(2*ArcSin[y])/Pi, Inequality[0, Less, y, LessEqual, 1]}}, 0]

and the plot

Plot[Piecewise[{{1, y > 1}, {(2*ArcSin[y])/Pi, 
Inequality[0, Less, y, LessEqual, 1]}}, 0], {y, -1, 2}, 
 WorkingPrecision -> MachinePrecision, PlotPoints -> 200]

enter image description here

clearly shows its non-differentiability at y==0 and y==1 (rigorous proof on demand).

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.