Problem with TransformedDistribution

I am trying to use Mathematica to obtain the probability distribution of $$\frac{1}{2}(A + B)$$ where $$A$$ and $$B$$ are independent random variables each distributed according to the uniform distribution, with lower and upper bounds of $$L$$ and $$H$$ respectively.

I suspect the distribution is triangular with lower and upper bounds of $$L$$ and $$H$$ respectively and mode equal to $$\frac{1}{2}(A + B)$$. However, I am having difficulty using TransformedDistribution to show that.

My code is:

\[ScriptCapitalD] = TransformedDistribution[1/2 (A + B), {B \[Distributed] UniformDistribution[{L, H}], A \[Distributed] UniformDistribution[{L, H}]}]

• That was a typo. But I am still not getting what I expect. Mar 23 '19 at 19:16
• Did you try PDF[\[ScriptCapitalD], y]?
– JimB
Mar 23 '19 at 19:18
• Why not check the PDFs? Simplify[PDF[TransformedDistribution[(a + b)/2, {a, b} \[Distributed] UniformDistribution[{{l, h}, {l, h}}]], t] == PDF[TriangularDistribution[{l, h}], t], l < t < h] Mar 23 '19 at 20:04
• I think I have found a bug! Try the following two expressions. The only difference is that I use U in one and H in the other for the upper limit. Simplify[PDF[TransformedDistribution[(A + B)/2, {A, B} \[Distributed] UniformDistribution[{{L, U}, {L, U}}]], t] == PDF[TriangularDistribution[{L, U}], t], L < t < U] and Simplify[PDF[TransformedDistribution[(A + B)/2, {A, B} \[Distributed] UniformDistribution[{{L, H}, {L, H}}]], t] == PDF[TriangularDistribution[{L, H}], t], L < t < H] Mar 23 '19 at 20:35
• @user120911 It does look like a bug to me. I think you should report it to WRI. Mar 24 '19 at 19:35

You get what you expect if you do it it in two steps

\[ScriptCapitalD] =
TransformedDistribution[x/2,
x \[Distributed] TransformedDistribution[(A + B), {
B \[Distributed] UniformDistribution[{L, H}],
A \[Distributed] UniformDistribution[{L, H}]}]]

(* TriangularDistribution[{L, H}] *)

• That is very nice! Mar 23 '19 at 20:24
PDF[\[ScriptCapitalD]][z]


(((-30 + z)Sign[-30 + z])/2 - (-20 + z) Sign[-20 + z] + ((-10 + z)*Sign[-10 + z])/2)/100

For plotting, assign values to L and H:

L = 10; H = 30;
Plot[Evaluate@PDF[\[ScriptCapitalD]][x], {x, 10, 30}]


pdF[l_, h_] := Module[{L = l, H = h}, Evaluate[PDF[\[ScriptCapitalD]]]]
Plot[Evaluate @ Flatten@Table[pdF[l, h][x], {l, {0, 5}}, {h, {10, 15}}], {x, 0, 15},
PlotRange -> All,
PlotLegends -> (Flatten @ Table[ToString@{l, h}, {l, {0, 5}}, {h, {10, 15}}])]


• That confirms my intution, but can you get Mathematica to output the PDF for the triangular distribution? That is what I am having trouble doing. Mar 23 '19 at 19:30