When is the set $A:=\left\{g \in L^{2}(X,\mu): \int_Xf|g|^2 \mathrm{d}\mu <\infty \right\}$ closed in $L^2(X,\mu)$? Let $(X,\mu)$ be a measure space and $f$ a measurable function $f:X\rightarrow [0,\infty)$. I'm trying to figure out whether the set $$A:=\left\{g \in L^{2}(X,\mu): \int_Xf|g|^2 \mathrm{d}\mu <\infty \right\}$$ is closed or not?
Given a Cauchy sequence $\{g_{n}\}_{n =1}^{\infty}$ in $A$. There is a $g\in L^{2}(X,\mu)$ with $g_{n}\rightarrow g$ wrt. $||\cdot||_{L^{2}}$ since $L^{2}(X,\mu)$ is a Hilbert space. I suspect that the convergence wrt. $||\cdot||_{L^{2}}$ implies that $\int_{X}f|g|^{2}\mathrm{d}\mu < \infty$ which proves that $A$ is closed. However I couldn't come up with a proof.
Any suggestions?
 A: I will assume that $X$ is semifinite, meaning that for each $B\subset X$ with $\mu(B)>0$, there exists $C\subset B$ such that $\mu(C)\in (0,\infty)$. Suppose that $f$ is not essentially bounded. That is, for each $M>0$, $\mu(f>M)>0$. We can recursively select $M_1<M_2<\ldots$ such that $\sum_{n=1}^\infty 1/\sqrt{M_n}<\infty$ and such that for all $n\in \mathbb{N}$, $\mu(f\in [M_n, M_{n+1}))>0$.  Let $A_n$ be a subset of $(f\in [M_n, M_{n+1}))$ with positive, finite measure and let $m_n=\mu(A_n)$.
Define $a_n=\frac{1}{m_n^{1/2}M_n^{1/4}}$, so $a_n^2=1/m_n\sqrt{M_n}$. Let $g_n=a_n1_{A_n}$. Then $$\int |g_n|^2 d\mu=m_n \cdot a_n^2=\frac{1}{\sqrt{M_n}}.$$  From this it follows that $\Bigl(\sum_{n=1}^N g_n\Bigr)_{N=1}^\infty$ is Cauchy in $L_2$, since $\sum_{n=1}^\infty g_n$ is absolutely convergent in $L_2(X,\mu)$. It also lies in $A$, since $$\int f|g_n|^2d\mu \leqslant M_{n+1}\int g_n^2d\mu =M_{n+1} m_n|a_n|^2,$$ since $f$ is bounded by $M_{n+1}$ on $A_n$. This shows that $g_n\in A$ for all $n$. Since $A$ is a subspace, $\sum_{n=1}^N g_n\in A$ for all $N$.
Let $g=\sum_{n=1}^\infty g_n$. Here we are again using that $\sum_{n=1}^\infty g_n$ is absolutely convergent in $L_2$. Note that $$\int f|g|^2 d\mu \geqslant \int_{A_n} f|g|^2d\mu=\int f|g_n|^2d\mu \geqslant M_n \int |g_n|^2 d\mu = M_nm_n\cdot \frac{1}{m_n\sqrt{M_n}}=\sqrt{M_n}\to \infty.$$  Therefore $g\notin A$, and $A$ is not closed. Therefore if $f$ is not essentially bounded, $A$ is not closed.
On the other hand, if $f$ is essentially bounded (by $M$, say), then $$\int f|g|^2d\mu \leqslant M \|g\|_2^2$$ for all $g\in L_2$. So $A=L_2$ is closed. This is true without the semifinite assumption.
If $X$ is not semifinite, we could have some set $B\subset X$ such that $\mu(C)=\infty$ for every non-empty, measurable subset $C$ of $B$ and we could have $f=\infty$ on $B$ and $f=0$ on the complement of $B$. Then $f$ is not essentially bounded, but any $g\in L_2$ such that $\int f|g|^2d\mu<\infty$ must satisfy $g=0$ on $B$. In this case, $A$ would be closed, despite the fact that $f$ is not essentially bounded. If $X\setminus B\neq \varnothing$, this could be a non-trivial example. You could also contrive similar examples where $B_1, B_2,\ldots$ are pairwise disjoint sets such that $\mu(C)=\infty$ for any non-empty subset of $\cup_{n=1}^\infty B_n$ and have $f|_{B_n}=n$, if you prefer a finite-valued function. Again, this example would yield cases where $f$ is not essentially bounded, but $A$ is closed.
Last, if $\lim_{M\to \infty}\mu(f>M)=0$ (which would happen if $f\in L_p(X,\mu)$ for some $p>0$), then you can do without the semifinite assumption.
