# PDF of a continuous uniform random variable conditioned on another continuous uniform random variable

Q. Let $$X$$ be a random variable with the probability density function

$$f_{X}(x) = \begin{cases} 1 &\text{ if} \quad 0 < x < 1 \\ 0 &\text{ otherwise} \end{cases}$$

Let $$Y$$ be a random variable with the conditional probability density function

$$f_{Y|X}(y|x) = \begin{cases} 1/x &\text{ if} \quad 0 < y < x \\ 0 &\text{ otherwise} \end{cases}$$

What is the marginal probability density function for $$Y$$?

I see the answer must be $$f_{Y}(y) = 2(1 - y)$$ for $$0 < y < 1$$. (Edit: see below.) However, I am having trouble deriving this result. My approach has been to apply the law of total probability in the form

\begin{align*} f_{Y}(y) &= \int\limits_{-\infty}^{+\infty} f_{Y|X}(y|x) f_{X}(x) \text{ d}x \\ &= \int\limits_{0}^{1} f_{Y|X}(y|x) \text{ d} x \\ &= \int\limits_{0}^{x} \frac{\text{d} x}{x} \end{align*}

But here I run into the difficulty that $$x$$ appears in the limit. Is there another way of going about this problem? There is likely something obvious I am missing. Thanks in advance for your help.

UPDATE. Starting with J.G.'s advice on the limits, I found the easier way to approach the problem is first to write the joint density

$$f_{X,Y}(x,y) = \begin{cases} 1/x &\quad \text{if } 0 < y < x < 1 \\ 0 &\quad \text{otherwise} \end{cases}$$

Then the marginal density for $$Y$$ is \begin{align*} f_{Y}(y) &= \int\limits_{-\infty}^{+\infty} f_{X,Y}(x, y) \text{ d} x \\ &= \int\limits_{y}^{1} \frac{\text{ d} x}{x} \\ &= - \ln (y) \end{align*}

Pretty weird result. Turns out my earlier intuition that $$f_{Y}(y) = 2 (1 - y)$$ was wrong.

The last integral's lower limit should be $$y$$, not $$0$$. Similarly, the upper limit should be $$1$$.