# Why can't "TransformedDistribution" give a result but finding the probability first and then the derivative can?

PDF[TransformedDistribution[Sin[X],
Distributed[X, ProbabilityDistribution[2*x/(Pi^2), {x, 0, Pi}]]],
y] // Simplify


produces

PDF[TransformedDistribution[Sin[X],
X \[Distributed]
ProbabilityDistribution[(
2 \[FormalX])/\[Pi]^2, {\[FormalX], 0, \[Pi]}]], y]


But

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


can produce \left\{\eqalign{&0,\,&y<0\cr &\frac{2}{\pi\sqrt{1-y^2}},\,0<&y<1\cr &0,\,&y>1\cr &{\rm Indeterminate,}\,&{\rm True} }\right.

Why doesn't TransformedDistribution work but finding the probability first and then the derivative can give the right result?

• I wish I knew the answer. Note that using Sin[X] <= y rather than Sin[X] < y just returns the Mathematica code. Sometimes using a distribution in Mathematica's repertoire works. But using the equivalent PowerDistribution[1/Pi, 2] doesn't work either.
– JimB
Commented Jan 20 at 19:14
• @JimB So, there is a bug that {x, a, b} always means $a\le x\le b$, so users can't make a $a<x<b$ by {x, a, b} style. Commented Jan 21 at 5:02
• A desired feature not implemented is not a bug. But writing to Wolfram, Inc. with the issue would seem to be the next step (unless someone else here has other suggestions). At least in this case you have a workaround.
– JimB
Commented Jan 21 at 6:18
• @JimB But now, I think it isn't what as you said. Try PDF[TransformedDistribution[Sin[X], Distributed[X, ProbabilityDistribution[2*x/(Pi^2), {0.1, 0, 0.99*Pi}]]], y] // Simplify will return the code too. Commented Jan 21 at 6:22
• It's too late at night for me as I'm not seeing how your example contradicts anything I've written.
– JimB
Commented Jan 21 at 6:30

This is not an answer to your question but rather another alternative to use when TransformedDistribution doesn't work.

The pdf of $$X$$ is

pdfx[x_] := Piecewise[{{2 x/π^2, 0 <= x <= π}}]


The desired transformation ($$Y=\sin(X)$$) is not a 1-to-1 transformation (as for every $$Y$$ value there are two $$X$$ values) but is 1-to-1 in two separate segments. First we find the inverse functions for each of the two segments (meaning $$0\leq X < \pi/2$$ and $$\pi/2 \leq X \leq \pi$$).

sol1 = Simplify[x /. Solve[{Sin[x] == y, 0 <= x < π/2}, x][[1]], Assumptions -> 0 < y < 1]
(* ArcSin[y] *)
sol2 = Simplify[x /. Solve[{Sin[x] == y, π/2 <= x < π}, x][[1]], Assumptions -> 0 < y < 1]
(* π - ArcSin[y] *)


Now we construct the pdf for $$Y=\sin(X)$$:

pdfy = Simplify[pdfx[sol1] Abs[D[sol1, y]] + pdfx[sol2] Abs[D[sol2, y]] // PiecewiseExpand,
Assumptions -> 0 <= y <= 1]
(* 2/(π Sqrt[1 - y^2]) *)


The following link has more details on this approach: https://online.stat.psu.edu/stat414/book/export/html/772.

• PDF[TransformedDistribution[Sin[X] + 2 X, Distributed[X, ProbabilityDistribution[2*x/(Pi^2), {x, 0, Pi}]]], y] // Simplify does not work too, though Sin[X]+2X is one-to-one map. Commented Jan 23 at 18:41
• @user64494 I made no claim that TransformedDistribution should work if the there was a one-to-one map. For example, Cos[X] is a one-to-one map for $0<X<\pi$ but it doesn't work either.
– JimB
Commented Jan 23 at 18:58