# Approximating an $L^2$ function in the Riemann sense

$\newcommand{\R}{\Bbb R}$ Consider the Lebesgue measure in $\R$ and the following proposition:

P. For each representative of a function class $f\in L^2[0,1]$ there is a sequence of continuous functions $(f_n)_{n\in\Bbb N}$ such that:

1. $|f_n-f|$ is Riemann integrable on $[0,1]$, for all $n\in\Bbb N$.
2. $\lim\limits_{n\to\infty} \int\limits_0^1 |f_n(x)-f(x)|^2\ \mathrm d x=0$.

There is no reason why this proposition should be true, but I cannot find a counterexample.

-
Maybe the Dirichlet function (characteristic function of $\mathbb{Q}$) could provide a counterexample for 1? – Jose27 Aug 1 '12 at 4:04
You require your function to be in $L^2$, but the approximation in 2 is in $L^1$. I guess you have to choose one of them. – Martin Argerami Aug 1 '12 at 5:09
I don't think this matters. As you can see in my answer below, the problem is that leo asks for approximation in the sense of Riemann integral (as $|f_n-f|$ is supposed to be R. integrable). – Stefan Geschke Aug 1 '12 at 5:47
@MartinArgerami I agree with Stefan. There is no problem because $f$ Riemann integrable implies $f^2$ Riemann integrable. However I have edited the question to be consistent. – leo Aug 1 '12 at 5:53

This proposition is not true. Let $f:[0,1]\to\mathbb R$ be defined by $f(x)=1$ iff $x\in\mathbb Q$ and $f(x)=0$ otherwise. $f$ is Lebesgue integrable but not Riemann integrable. Suppose $|f_n-f|$ is Riemann integrable and $\int_0^1|f_n-f|dx<1/4$. Then there is a partition $0=t_0<t_1<\dots<t_n=1$ of the unit interval such that $$\sum_{i=1}^n(t_i-t_{i-1})\sup\{|f_n(x)-f(x)|:x\in[t_{i-1},t_i]\}<1/4.$$ Now there is $i\in\{1,\dots,n\}$ such that $\sup\{|f_n(x)-f(x)|:x\in[t_{i-1},t_i]\}<1/4$. The function $f_n$ is not continuous on $[t_{i-1},t_i]$ since on a dense subset of that interval, $f_n<1/4$ and on a dense set, $f_n>3/4$.
How much close? For example $f_n$ equal to ? – leo Aug 1 '12 at 4:35