# Do square integrable function and its derivative imply the function tends to $0$ for $|x|$ large?

I know a square integrable function does not necessarily tend to $0$ for $|x|$ large. Now suppose $f\colon\mathbb{R}\to\mathbb{R}$ is a smooth function satisfying \begin{equation} f, f' \in L^2(\mathbb{R}). \end{equation} Then is it true that \begin{equation} \lim_{x\to\pm\infty} f(x) = 0 \quad \text{ and } \quad \lim_{x\to\pm\infty} f'(x) = 0 \, ? \end{equation} Is it also true for any derivative of $f$?

It is true that $\lim_{x\to\infty} f(x) = 0$. To see this, let $\chi_R(x)$ be a smooth function with $\chi_R(x) = 0$ when $|x|<R$ and $\chi_R(x) = 1$ for $|x|>2R$. Given an $\epsilon>0$ we can find large enough $R$ so that $$\|\chi_R f\|_{L^2} + \|(\chi_R f)'\|_{L^2} < \epsilon.$$ Together these imply that $\|\chi_R f\|_{L^\infty} < C \epsilon$ (this is a Sobolev embedding, but a simpler case). This implies the first limit is true (at least once you modify $f$ on a set of measure zero).
Let me explain that point a bit more in detail. Let $g \in L^2(\mathbb{R})$ be a square integrable function with $g'\in L^2(\mathbb{R})$. We want a bound on $|g(x)|$. Momentarily assume that $g\in C_c^\infty(\mathbb{R})$ is smooth and compactly supported. Then by the fundamental theorem of calculus, and the Cauchy-Schwarz inequality, \begin{align*} |g(x)^2| &\leq \int_{-\infty}^x |(g(x)^2)'|\,dx \\ &= \int_{-\infty}^x 2|g(x) g'(x)|\,dx \\ &\leq 2 \left(\int_{-\infty}^x |g(x)|^2\right)^{1/2}\left(\int_{-\infty}^x |g'(x)|^2\,dx\right)^{1/2}. \end{align*} Taking square roots we obtain the expression $$|g(x)| \leq \sqrt{2} \|g\|_{L^2} \|g'\|_{L^2}.$$ Now that we know this is true for smooth compactly supported functions, it remains true for functions with $f,f'\in L^2(\mathbb{R})$ by a limiting argument.
The second limit, $\lim_{x\to\infty} f'(x)$ does not need to exist or tend to $0$ because all we know about $f'$ is that $f'\in L^2$. We construct an example here for completeness. Let $h(x)$ be a triangular "hat" function centered at $0$, with support in $[-1,1]$, and with slope $\pm 1$ on either side of the origin. Observe that $2^{-n} h(2^nx-4^{n})$ is centered at $2^n$, has width $2^{1-n}$, and slope $\pm 1$ on either side of its peak at $2^n$. Thus $$f(x) = \sum_{n=0}^\infty 2^{-n} h(2^nx - 4^{n})$$ is square integrable and has square integrable derivative, but the derivative $f'(x)$ does not tend to $0$ as $x\to\infty$.