Let $\mu$ be a probability measure on $\mathbb R$, and consider the sequence of orthonormal polynomials in $L^2(\mu)$. These polynomials are constructed by applying Gram-Schmidt to the sequence $\{1,x,x^2,\ldots\}$; we thus assume that all monomials belong to $L^1(\mu)$.
I would like to know when any function $f$ in $L^2(\mu)$ can be written as $$ f=\sum_{k=0}^\infty\langle f, p_k\rangle p_k, $$ where the equality is an equality in $L^2(\mu)$.
Is it true for every probability measure $\mu$ ? I know this is true for Hermite, Laguerre (etc) polynomials, but is there any restriction ?
(Unfortunately I don't remember much of the details, and I don't have time to look them up now, so this will be very sketchy, but perhaps it will be of some use until someone else gives a better answer...)
There are indeed restrictions that $\mu$ must satisfy in order for the space of polynomials to be dense in $L^2(\mu)$. It has to do with limit circle/limit point theory, selfadjoint extensions of symmetric operators, the moment problem, and stuff like that. I think a sufficient (but not necessary) condition is that $\mu$ have compact support. Whatever you need to know is probably in Akhiezer's book The classical moment problem and some related questions in analysis (pdf) from 1965. There's also a little about this (but not with all the proofs) in Section 2.4 of Deift's book Orthogonal Polynomials and Random Matrices: A Riemann-Hilbert Approach.