@Wes

First question (just a complement to Carl's answer

**Quantile** vs **solve(CDF):**

restart:
with(Statistics): # Here I use the Statistics package
Y := RandomVariable(ChiSquare(2)): # The correct definition of Y with this package
solve(CDF(Y, y)=0.9, y); # a naive way
Quantile(Y, 0.9); # build-in procedure
4.605170186
HFloat(4.605170185988092)

Second point= What does CDF do?

restart:
with(Statistics):
Y := RandomVariable(ChiSquare(2)):
CDF(Y, y); # you can call CDF this way to get the Cumulative Density Function
/ / 1 \\
piecewise|y < 0, 0, 1 - exp|- - y||
\ \ 2 //
CDF(Y, 1); # Personally I don't like this way which is a short of, for instance,
# eval(CDF(Y, y), y=1)
/-1\
1 - exp|--|
\2 /

There exits another package named **Student:-Statistics**, older than Statistics which does the same thing:

restart:
with(Student:-Statistics):
Y := ChiSquareRandomVariable(2): # Here this is the correct syntax
CDF(Y, y);
CDF(Y, 1)
/ / 1 \\
piecewise|y < 0, 0, 1 - exp|- - y||
\ \ 2 //
/-1\
1 - exp|--|
\2 /

What I did with **CDF** (both packages) can be done the same way with **PDF**.

Also note the use of **Quantile** with package **Student:-Statistics**:

Quantile(Y, 0.9);
HFloat(4.605170185988092)

To sum up, there is no difference in your cas in using **Statistics** or **Student:-Statistics**.

But mixing the syntaxes could explain the problem you observed:

restart:
with(Statistics):
Y := ChiSquareRandomVariable(2): # wrong syntax with this package
Quantile(Y, 0.9);
CDF(Y, y);
CDF(Y, 1);
FAIL
piecewise(ChiSquareRandomVariable(2) <= y, 1, 0)
piecewise(ChiSquareRandomVariable(2) <= 1, 1, 0)

Here "Y" is not a random variable for **ChiSquareRandomVariable** is not a function of package **Statistics**.

The result is thus quite logic.

The problem is that this "logic" doesn't hold for any random variable:

restart:
with(Statistics):
Y := Normal(0, 1):
Quantile(Y, 0.9);
CDF(Y, y);
CDF(Y, 1);
HFloat(1.2815515655447307)
1 1 /1 (1/2)\
- + - erf|- y 2 |
2 2 \2 /
1 1 /1 (1/2)\
- + - erf|- 2 |
2 2 \2 /

This is undeed quite disturbing.

Note that the names of the distributions (in both packages) can be "long names" or "short names", for instance:

restart:
with(Student:-Statistics):
Y := NormalRandomVariable(0, 1):
Quantile(Y, 0.9);
HFloat(1.2815515655447307)
X := Normal(0, 1):
Quantile(X, 0.9);
HFloat(1.2815515655447307)
U := ChiSquareRandomVariable(2):
Quantile(U, 0.9);
HFloat(4.605170185988092)
V := ChiSquare(2):
Quantile(U, 0.9);
HFloat(4.605170185988092)

and

restart:
with(Statistics):
Y := RandomVariable(Normal(0, 1)):
Quantile(Y, 0.9);
HFloat(1.2815515655447307)
X := Normal(0, 1):
Quantile(X, 0.9);
HFloat(1.2815515655447307)
U := RandomVariable(ChiSquare(2)):
Quantile(U, 0.9);
HFloat(4.605170185988092)
V := ChiSquare(2):
Quantile(U, 0.9);
HFloat(4.605170185988092)