Let $L^2((0,1))$ be as usual the Lebesgue space of measurable complex-valued functions $f:(0,1) \rightarrow \mathbb{C}$ such that $\int |f(x)|^2 dx < \infty$.
It is a well known fact (see e.g Lieb and Loss, Analysis) that if $f \in L^2((0,1))$, then for every $\epsilon > 0$ there exists $g \in C_{k}^{\infty}((0,1))$ such that $||f-g||_{2} < \epsilon$ (of course here $C_{k}^{\infty}((0,1))$ denotes the set of smooth functions from $(0,1)$ into $\mathbb{C}$ with compact support, and $|| . ||_{2}$ the norm of $L^2((0,1))$).
Let $f \in L^2((0,1))$ such that $\int f(x) dx = 0$. My question is the following. Does there exist $g \in C_{k}^{\infty}((0,1))$, with $\int g(x) dx = 0$, such that $||f-g||_{2} < \epsilon$?
I suppose the answer is positive, but I can't see how to prove it. Thank you very much for your help.
PS Note that the subset $\{ g \in C_{k}^{\infty}((0,1)) | \int g(x) dx = 0 \}$ is exactly equal to the set $D=\{g \in C_{k}^{\infty}((0,1)) | \exists f \in C_{k}^{\infty}((0,1)) : g=f' \}$, as you can immediately verify. So, if we denote with $K$ the set of all constant functions in $L^2((0,1))$, we can rephrase my question in the following way: is $D$ dense in $K^{\perp}$?
Certainly.
Fix $\psi\in C^\infty_c$ with $\int\psi=1$. Say $||\psi||_2=c$.
Now say $f\in L^2$ and $\int f=0$. Let $\epsilon>0$. Choose $\phi\in C^\infty_c$ with $||f-\phi||_2<\epsilon$. Now $$\left|\int\phi\right| =\left|\int(f-\phi)\right|\le||f-\phi||_2<\epsilon.$$
So if $\alpha=\int\phi$ then $\int(\phi-\alpha\psi)=0$ and $$||f-(\phi-\alpha\psi)||_2\le\epsilon+c|\alpha|\le(1+c)\epsilon.$$