Ordered gamma variables led to an ugly integral Suppose $X_1,X_2,...X_n$ are i. i. d. random variables with p. d. f.
$$f(x)=xe^{-x}I_{(0,\infty)}\!(x)$$
and let $Y_1,...,Y_n$ be the order statistics for these variables.
a) Find the conditional p. d. f. of $Y_1$ given $Y_n=y_n$.
When working with order statistics, one should start with the distribution function:
$$F_{Y_1|Y_n}(y_1\,|\,y_n) = \mathbb P(Y_1\le y_1\,|\,Y_n=y_n) = 1 - \mathbb P(Y_1>y_1\,|\,Y_n=y_n)\quad.$$
Because $Y_1 = \min_iX_i$, I have
$$\begin{align}
\mathbb P(Y_1>y_1\,|\,Y_n=y_n) &= \mathbb P(Y_1,...,Y_n>y_1\,|\,Y_n=y_n) =\\
&= \mathbb P(X_1,...,X_n>y_1\,|\,Y_n=y_n) \quad.
\end{align}$$
By the independence of the $X_i$'s, setting $Y_n\triangleq X_j$,
$$\begin{align}
\mathbb P(X_1,...,X_n>y_1\,|\,Y_n=y_n) &= \prod_{i=1}^n\mathbb P(X_i>y_1\,|\,Y_n=y_n) =\\
&= \prod_{i=1}_{i\neq j}^n[1-\mathbb P(X_i\le y_1\,|\,Y_n=y_n)]\cdot
I_{(-\infty,\,y_n)}\!(y_1)\\
&= [1-F_{|Y_n}(y_1\,|\,y_n)]^{n-1}I_{(-\infty,\,y_n)}\!(y_1)\quad.
\end{align}$$
The conditional p. d. f. for each $X_i$ is
$$f_{|Y_n}(x\,|\,y) = xe^{-x}I_{(0,y)}\!(x)\left[\int_0^y xe^{-x}\;dx\right]^{-1} =
\frac{xe^{-x}}{1 - (y+1)e^{-y}}I_{(0,y)}\!(x)\quad,$$
thus the c. d. f. is
$$\begin{align}
F_{|Y_n}(x\,|\,y) &= \int_{-\infty}^xf_{|Y_n}(t\,|\,y)\;dt =\\
&= \frac1{1 - (y+1)e^{-y}}\left(\int_0^xte^{-t}\;dt\right)I_{(0,y)}\!(x) +
I_{[y,\infty)}\!(x) =\\
&= \frac{1 - (x+1)e^{-x}}{1 - (y+1)e^{-y}}I_{(0,y)}\!(x) + I_{[y,\infty)}\!(x)\quad,
\end{align}$$
and
$$\begin{align}
[1-F_{|Y_n}(y_1\,|\,y_n)]^{n-1} &= 
\left\{1 - \left[\frac{1 - (y_1+1)e^{-y_1}}{1 - (y_n+1)e^{-y_n}}I_{(0,y_n)}\!(y_1) + I_{[y_n,\infty)}\!(y_1)\right]\right\}^{n-1} =\\
&= I_{(-\infty,\,0]}(y_1) +
\left[\frac{(y_1+1)e^{-y_1} - (y_n+1)e^{-y_n}}{1 - (y_n+1)e^{-y_n}}\right]^{n-1}
\!\!\!I_{(0,y_n)}\!(y_1)\quad.
\end{align}$$
Finally, using that $y_n$ has to be positive when it is given,
$$\begin{align}
F_{Y_1|Y_n}(y_1\,|\,y_n) &= 1 - \mathbb P(X_1,...,X_n>y_1\,|\,Y_n=y_n) =\\
&= 1 - [1-F_{|Y_n}(y_1\,|\,y_n)]^{n-1}I_{(-\infty,\,y_n)}\!(y_1) =\\
&= 1 - \left\{I_{(-\infty,\,0]}(y_1) +
\left[\frac{(y_1+1)e^{-y_1} - (y_n+1)e^{-y_n}}{1 - (y_n+1)e^{-y_n}}\right]^{n-1}
\!\!\!I_{(0,\,y_n)}\!(y_1)\right\} =\\
&= \left\{1 - \left[\frac{(y_1+1)e^{-y_1} - (y_n+1)e^{-y_n}}{1 - (y_n+1)e^{-y_n}}\right]^{n-1}\right\}I_{(0,\,y_n)}\!(y_1) +
I_{[y_n,\infty)}\!(y_1)\quad,
\end{align}$$
which implies that its derivative is
$$\begin{align}
f_{Y_1|Y_n}(y_1\,|\,y_n) &= -\frac\partial{\partial y_1}\!
\left\{\left[\frac{(y_1+1)e^{-y_1} - (y_n+1)e^{-y_n}}
{1 - (y_n+1)e^{-y_n}}\right]^{n-1}\right\}I_{(0,\,y_n)}\!(y_1) =\\
&= -\frac{(n-1)[(y_1+1)e^{-y_1} - (y_n+1)e^{-y_n}]^{n-2}}{1 - (y_n+1)e^{-y_n}}\frac\partial{\partial y_1}\![\ldots]\,I_{(0,\,y_n)}\!(y_1) =\\
&= \frac{n-1}{1 - (y_n+1)e^{-y_n}}[(y_1+1)e^{-y_1} - (y_n+1)e^{-y_n}]^{n-2}y_1e^{-y_1}
I_{(0,\,y_n)}\!(y_1) \quad.
\end{align}$$
b) Find the p. d. f. of the amplitude $W\triangleq Y_n\,–Y_1$.
A variable transformation shows that
$$\begin{align}
f_{W,Y_1}(w,y_1) &=
f_{Y_1,Y_n}(y_1,y_n)\left|\frac{\partial(w,y_1)}{\partial(y_1,y_n)}\right|^{-1} =\\
&= \frac{f_{Y_1,Y_n}(y_1,y_n)}{|-1\cdot0 - 1\cdot1|} =\\
&= f_{Y_1,Y_n}(y_1,y_1+w) =\\
&= f_{Y_1|Y_n}(y_1\,|\,y_1+w)f_{Y_n}(y_1+w)\quad.
\end{align}$$
To obtain the marginal density of $Y_n$, I note that its c. d. f. is
$$\begin{align}
F_{Y_n}(y) &= \mathbb P(Y_n\le y) =\\
&= \mathbb P(Y_1,...,Y_n\le y) =\\
&= \mathbb P(X_1,...,X_n\le y) =\\
&= \prod_{i=1}^n\mathbb P(X_i\le y) =\\
&= F(y)^n =\\
&= \left(\int_0^y te^{-t}\;dt\cdot I_{(0,\infty)}(y)\right)^n =\\
&= [1 - (y+1)e^{-y}]^n\,I_{(0,\infty)}\!(y)\quad,
\end{align}$$
therefore,
$$f_{Y_n}(y) = n[1 - (y+1)e^{-y}]^{n-1}ye^{-y}I_{(0,\infty)}\!(y)\quad,$$
and
$$\begin{align}
f_{W,Y_1}(w,y) &= (n-1)
\frac{[(y+1)e^{-y} - (y+w+1)e^{-(y+w)}]^{n-2}ye^{-y}}{1 - (y+w+1)e^{-(y+w)}}
I_{(0,\,y+w)}\!(y) \cdot\\
&\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\cdot\;n[1 - (y+w+1)e^{-(y+w)}]^{n-1}(y+w)e^{-(y+w)}
I_{(0,\infty)}\!(y+w) =\\
&= n(n-1)\frac{[g(y)-g(y+w)]^{n-2}[1 - g(y+w)]^{n-1}g(y+w)ye^{-y}}{1 - g(y+w)}\cdot\\
&\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\cdot\;I_{(0,\infty)}\!(w)I_{(-w,\infty)}\!(y)\quad,
\end{align}$$
where $g(t)\triangleq (t+1)e^{-t}$. Now I'd have to integrate this function with respect to the second variable over $\mathbb R$, which seems insane. There is another way to do it, right?
 A: Given: $X$ has pdf $f(x)$:

(source: tri.org.au)
Then, the joint pdf of the 1st and $n$-th order statistics, in a sample of size $n$, is say $g(x_1,x_n)$:

(source: tri.org.au)
with domain of support:

(source: tri.org.au)
... where I am using the OrderStat function from the mathStatica package for Mathematica to automate the nitty-gritties.

Part (a): the pdf of $X_1|x_n$
Then, the pdf of $X_1|x_n$ can be obtained simply with:

(source: tri.org.au)
[ By the way, the easy way to see that  your solution must be incorrect is to note that the conditional pdf of the first order statistic [GIVEN the sample maximum] should depend on the sample maximum (but your $y_n$ term has effectively disappeared from your solution).]

Part (b): the pdf of the sample range $W = X_n - X_1$
The cdf of the sample range $W = X_n - X_1$ is $P(X_n - X_1 < w)$, calculated wrt to the joint pdf $g(x_1,x_n)$:

(source: tri.org.au)
where mathStatica's Prob function calculates the required probability, and where ExpIntegralE is the exponential integral function described here: http://reference.wolfram.com/mathematica/ref/ExpIntegralE.html
Finally, the pdf of $W$ is just the derivative of the cdf wrt $w$:

(source: tri.org.au)
Here is a plot of the solution:  i.e. the pdf of the sample range, as the sample size $n$ varies:

(source: tri.org.au)

Notes:

*

*I should perhaps add that I am one of the authors of the mathStatica software used above.


*When using computer algebra systems or any sort of automated tool, it is always a good idea to check one's work using Monte Carlo methods. Here is a quick check that compares a Monte Carlo simulation of the pdf of the sample range when $n = 5$ (blue squiggly curve) to the theoretical solution derived above (red dashed) ...

(source: tri.org.au)
... Looks good.
A: I think you are going wrong very early, when you state that 
$$\begin{align}
\mathbb P(Y_1>y_1\,|\,Y_n=y_n) &= \mathbb P(Y_1,...,Y_n>y_1\,|\,Y_n=y_n) =\\
&= \mathbb P(Y_1,...,Y_{n-1}>y_1)I_{(y_1,\infty)}\!(y_n).
\end{align}$$ 
You need to keep the information that all the variables with the exception of $Y_n$ are less than or equal to $y_n$. So (wlog assume $X_n = Y_n$)
 $$\begin{align}
\mathbb P(Y_1>y_1\,|\,Y_n=y_n) &= \mathbb P(Y_1,...,Y_n>y_1\,|\,Y_n=y_n) =\\
&= \mathbb P(y_1 <X_1,...,X_{n-1}\leq y_n)I_{(y_1,\infty)}\!(y_n) = \\
& = [F(y_n) - F(y_1)]^{n-1} I_{(y_1,\infty)}\!(y_n).
\end{align}$$
