# Which function in the Schwarz class of functions is “closest” to triangle wave in $L^2$ sense?

Would it be possible to calculate which function in the Schwarz class of infinitely differentiable functions with compact support is closest to triangle wave?

Let us measure closeness as $$_{L_2}^2 = \int_{-\infty}^{\infty}(f(x)-g(x))^2dx$$

I don't expect my knowledge in functional analysis to be strong and polished enough to answer this, but maybe one of you guys know how to?

EDIT of course we need to edit triangle wave to have compact support. Say it has compact support on $$x \in [-1-2N,1+2N], N\in \mathbb Z_+$$ In other words, $$2N+1$$ whole periods and it goes down to $$0$$ just at both ends of support.

The class of Schwartz class is not closed with respect to the $$L^2$$ norm, so there isn't necessarily a closest element. Indeed, in this case there isn't, as you can find arbitrarily close functions (take for instance convolutions with an approximate identity), but the triangle wave itself is not in the Schwartz.
In general, there is no "closest" Schwarz function to a given $$L^2$$ function. Since the Schwarz class is dense in $$L^2$$, we can find Schwarz functions arbitrarily close to any $$L^2$$ function. Indeed, let $$f \in L^2(\mathbb R^n) \setminus \mathcal S(\mathbb R^n)$$ and let $$f_0 \in \mathcal S(\mathbb R^n)$$ be any Schwarz function. Then we can always find $$f_* \in \mathcal S(\mathbb R^n)$$ with, for example, $$\|f - f_*\|_{L^2(\mathbb R^n)} < \frac 1 2 \| f - f_{0} \|_{L^2(\mathbb R^n)}.$$ Thus we can iteratively construct a sequence such that each member is "closer" to $$f$$ than the previous.