suppose $X\sim U(0,1), Y \sim U(0,x)$, find k that minimizes $E[(X-k)^2|Y=y]$. My working below: $E(f(x)|Y) = \int f(x)P(X|Y)dx$
$P(X|Y) = P(Y|X)P(X)/P(Y)$
$P(Y|X) = 1/x,P(X) = 1,P(X,Y)=1/x$
$P(Y)=\int_y^1 P(x,y) dx = -ln(y)$
$P(X|Y) = 1/(x\ln(y))$
$E((X-k)^2|y) = \int_y^1 (x-k)^2/(x\ln y)dx = k^2+k(2/\ln y-y/\ln y - 1/(2\ln y)+ y^2/\ln y)$
differentiate to obtain $g = (y-2)/(2 \ln y)$ clearly this is wrong as when I substitute $y =0.5, g > 1$
How do i fix it?
First you missed a sign because
$$f_{X|Y}=-\frac{1}{x\log y}$$
Using the same procedure as yours I find
$$k=\frac{y-1}{\log y}$$