Two dependent uniformly distributed continuous variables and Bayes' theorem: a billiard table exercise I am trying to solve the following exercise from Judea Pearl's Probabilistic Reasoning in Intelligent Systems: Networks of Plausible Inference.

2.2. A billiard table has unit length, measured from left to right. A ball is rolled on this table, and when it stops, a partition is placed at its stopping position, a distance $x$ from the left end of the table. A second ball is now rolled between the left end of the table and the partition, and its stopping position, $y$, is measured.
a. Answer qualitatively: How does knowledge of $y$ affect our belief about $x$? Is $x$ more likely to be near $y$ , far from $y$, or near the midpoint between $y$ and 1?
b. Justify your answer for (a) by quantitative analysis. Assume the stopping position is uniformly distributed over the feasible range.

For b., I clearly need to use Bayes' theorem:
$$
P(X|Y) = \dfrac{P(Y|X)P(X)}{P(Y)} 
$$
where I expressed
$$
P(X) \sim U[0,1] =
\begin{cases}
1, \text{where } 0 \leq x \leq 1\\
0, \text{else}
\end{cases}
\\
P(Y|X) \sim U[0,x] = 
\begin{cases}
1/x, \text{where } 0 \leq y \leq x\\
0, \text{else}
\end{cases}
$$
I tried getting $P(Y)$ by integrating the numerator over $X$.
$$
\int_{-\infty}^{\infty} P(Y|X)P(X)dx = \int_{0}^{1}P(Y|X)\cdot 1 dx = \int_{0}^{1}\dfrac{1}{x} dx
$$
But the integral doesn't converge.
I also tried to figure out the numerator itself, but I don't see how $\frac{1}{x}$ can represent $P(X|Y)$.
Where did I go wrong?
 A: In short, you haven't been careful with the bounds of integration in your integral for $p(y)$. Let
$$I_A (x) = \begin{cases}
1, & \text{ if $x \in A$} \\
0, & \text{ if $x \notin A$} \\
\end{cases}
$$
denote the indicator function of the set $A$. We're given in the problem that $X \sim U([0, 1])$ and $Y|X=x \sim U([0, x])$, which means that $p(x) = I_{[0,1]} (x)$ and $p(y | x) = \frac{1}{x} I_{[0,x]} (y)$. The correct computation of $p(y)$ begins with:
$$
\begin{align}
p(y) &= \int p(y | x) p(x) dx \\
&= \int \frac{1}{x} I_{[0, x]} (y) I_{[0, 1]} (x) dx \\
&= \int_0^1 \frac{1}{x} I_{[0, x]} (y) dx \\
\end{align}
$$
but now you have to be careful, because $x$ shows up in the set $[0, x]$ in the indicator function. To make this something which we can integrate, we use a simple trick to swap the variables in an indicator function like so:
$$
\begin{align}
I_{[0, x]} (y) & = \begin{cases}
1, & \text{ if } 0 \le y \le x \\
0, & \text{ otherwise }
\end{cases} \\
& = \begin{cases}
1, & \text{ if } x \ge y \\
0, & \text{ otherwise }
\end{cases} \\
& = I_{[y,\infty)} (x)
\end{align}
$$
which re-expresses the indicator function as a function of $x$ instead of $y$. Now we can finish computing the integral:
$$
\begin{align}
p(y) &= \int_0^1 \frac{1}{x} I_{[0, x]} (y) dx \\
&= \int_0^1 \frac{1}{x} I_{[y, \infty]} (x) dx \\
&= \int_y^1 \frac{1}{x} dx \\
&= [\log(x)]_y^1 \\
&= - \log(y).
\end{align}
$$
To visualize what's going on, we can plot the joint pdf. The joint pdf of $X$ and $Y$ is then the product
$$
f_{X,Y} (x, y) = \frac{1}{x} I_{[0, x]} (y) I_{[0, 1]} (x)
$$
This function has a singularity at $(0, 0)$, because $\lim_{(x,y) \to (0,0)} f_{X, Y}(x, y) = \infty$. The image below shows the graph of the joint pdf $f_{X,Y} (x, y)$ as a surface: notice the clipping near $(0, 0)$ where the height of the graph starts getting larger and larger.

In particular, notice the support of the distribution is the triangle where $x \ge y$ and $x, y \in [0, 1]$.
The pink and cyan slices of the graph are two particular values of $x$, $x = 0.3$ and $x = 0.7$. The slices of this graph for these fixed $x$-values are proportional to the conditional densities $p(y | x)$ for those fixed values of $x$. However, they actually already integrate to 1, so the slices are exactly the density $p(y | x)$, because $\int p(y | x) dy = \int_0^x \frac{1}{x} dy = 1$ for any fixed value of $x \in (0, 1]$ (if $x = 0$, then the conditional distribution of $y$ given $x$ is the singular distribution $p(y | x) = \delta(x)$, where $\delta$ is the Dirac delta function instead), and is shown as $p(x)$.
The red and blue slices of the graph are more interesting. These show two particular values of $y$, $y = 0.1$ and $y = 0.2$. Each of these slices is proportional to the conditional distribution $p(x | y)$ for those fixed values of $y$. This conditional density $p(x | y)$ is not uniform, and is higher for smaller values of $x$. This is the distribution we would like to find, as it represents our knowledge about $x$ after observing a particular value of $y$. Notice in particular the support of the distribution $p(x | y)$ is $[y, 1]$, like we saw in the integral above.
Now using Bayes' theorem, you can compute $p(x | y)$:
$$
\begin{align}
p(x | y) & = \frac{p(y | x) p(x) }{p(y)} \\
& = \frac{ \frac{1}{x} I_{[0, x]} (y) I_{[0,1]} (x)}{-\log(y)}\\
& = \frac{ \frac{1}{x} I_{[y, \infty]} (x) I_{[0,1]} (x)}{-\log(y)}\\
& = \frac{ \frac{1}{x} I_{[y, 1]} (x)}{-\log(y)}\\
& = \frac{I_{[y, 1]} (x)}{-x\log(y)}\\
& = \begin{cases}
\frac{1}{-x\log(y)}, & \text{ if } y \le x \le 1 \\
0, & \text{ otherwise } \\
\end{cases}\\
\end{align}
$$
A: You have overlooked the fact that $x \geq y$, implicit in the constraint on $P(Y|X) = 1/x$ that $0 \leq y \leq x$.  As a consequence of this constraint, the lower bounds of the final two integrals in your next equation should be:
$$\int_{0}^{1} P(Y|X)P(X)dx = \int_{Y}^{1}P(Y|X)\cdot 1 dx = \int_{Y}^{1}\dfrac{1}{x} dx $$
which of course equals $-\ln(Y)$.
Integrating out $Y$ to find the constant of integration results in:
$$-\int_0^1\ln(y)dy = (-y\ln(y)+y)|_0^1$$
and using the fact that $\lim_{y \downarrow 0}y\ln(y) = 0$ makes it easy to see that this integrates to 1, i.e., that the constant of integration equals 1 and $P(Y) = -\ln(Y)$.
The end result is that:
$$P(X|Y) = {-\ln(Y) \over x}1(X \geq Y)$$
where $1(A)$ is the indicator function that takes on the value $1$ if the condition $A$ is true, 0 otherwise (just a notational shorthand for the conditional where-else statements you have in the question.)
