Let $I$ be a (possibly unbounded) open interval in $\mathbb{R}$. Let $r \in L^1_{\text{loc}}(I)$ with $r > 0$ and $r^{-1} \in L^\infty_{\text{loc}}(I)$.
I would like to determine whether $C^\infty_0(I)$ is dense in the weighted $L^2$ space $L^2(I, r(x)dx)$, where $dx$ denotes standard Lebesgue measure on $\mathbb{R}$.
Here is my attempt so far. I simply try to leverage the fact that $C^\infty_0(I)$ is dense in the standard Lebesgue space $L^2(I,dx)$.
If $f \in L^2(I,rdx)$, then $f r^{1/2} \in L^2(I,dx)$, hence for any $\varepsilon > 0$, there exists $\varphi \in C^\infty_0(I)$ so that $$ \|\varphi - fr^{1/2} \|_{L^2(I,dx)}< \frac{\varepsilon}{2}. $$
So then for any $\psi \in C_0^\infty(I)$, $$ \|\psi - f \|_{L^2(I,rdx)} \le \| \psi - \varphi r^{-1/2} \|_{L^2(I,rdx)} + \|\varphi - fr^{1/2} \|_{L^2(I,dx)}< \| \psi - \varphi r^{-1/2} \|_{L^2(I,rdx)} + \frac{\varepsilon}{2}. $$
But now I can't seem to find a suitable way to choose $\psi$ so that I may control the term $\| \psi - \varphi r^{-1/2} \|_{L^2(I,rdx)} = \|r\psi - \varphi\|_{L^2(I,dx)}$.
Hints or solutions are greatly appreciated!
Take $a$ such that $\|f-f_a\|_{L^2(I,r)}$ is small, where $f_a(x)=f(x)1_{|f(x)\le a|}1_{x\in [-a,a]}$ is bounded compactly supported
Take $b$ such that $a\|r-r 1_{r(x)\le b^2}\|_{L^1[-a,a]}$ is small.
Take $\epsilon$ such that $ a \|r\|_{L^1(\pm [a,a+\epsilon])}$ is small
Take $\phi\in C^\infty_c[-a-\epsilon,a+\epsilon] ,|\phi(x)|\le a$ such that $b\|\phi-f_a\|_{L^2[-a,a]}$ is small
Thus $$\|\phi 1_{[-a,a]}-f_a\|_{L^2(I,r1_{r(x)\le b^2})}\le b\|\phi-f_a\|_{L^2[-a,a]}$$
Then $$\|\phi-f\|_{L^2(I,r)}\le \|\phi -f_a\|_{L^2(I,r)}+\|f-f_a\|_{L^2(I,r)}$$
$$\|\phi-f_a\|_{L^2(I,r)}\le \|\phi 1_{[-a,a]}-f_a\|_{L^2(I,r1_{r(x)\le b^2})}+2a\|r-r 1_{r(x)\le b^2}\|_{L^1[-a,a]}+\|\phi (1-1_{x\in [-a,a]})\|_{L^2(r,I)}$$