I would like a verification of a solution to the following problem from Stein-Shakarchi 3.
a) Find a positive continuous function $f$ such that $f$ is integrable on $\mathbb{R}$ (in the Lebesgue sense), but $\limsup_{x\to\infty}f(x) = \infty$.
b) Show that if $f$ is a positive uniformly continuous and integrable on $\mathbb{R}$, then $\lim_{\vert x \vert \to \infty}f(x) = 0$.
a) I started by considering the function which is equal to $n$ on $[n,n+2^{-n}]$ and $0$ elsewhere. This is of course integrable, since $\sum_{n=1}^{\infty}n2^{-n}$ converges. To make it positive, I shifted it up by $2^{-n}$ on $[n,n+1]$. Then I removed the discontinuities by joining the breaks with line segments on intervals small enough so as to preserve integrability. For $n \geq 1$ define \begin{equation*} \begin{aligned} I_n &= [n,n+2^{-n}] \\ J_n &= [n+2^{-n},n+2^{-n}+2^{-n-1}] \\ K_n &= [n+2^{-n}+2^{-n-1},n + 1 - 2^{-n-1}] \\ L_n &= [n + 1 - 2^{-n-1}, n + 1]. \end{aligned} \end{equation*} On an interval $[a,b]$, we say $f(x) = L(f(a),f(b))$ to indicate that on $[a,b]$, $f$ is the line segment connecting $(a,f(a))$ and $(b,f(b))$. $$f(x) = \begin{cases} 1 & x \in [0,1] \\ n & x \in I_n \\ L(n,2^{-n}) & x \in J_n\\ 2^{-n} & x \in K_n \\ L(2^{-n},n+1) & x \in L_n. \end{cases}$$ We have \begin{equation*} \begin{aligned} \int_{0}^{1}f(x)dx &= 1 \\ \sum_{n=1}^{\infty}\int_{I_n}f(x)dx &= \sum_{n=1}^{\infty}\frac{1}{2^n} \\ \sum_{n=1}^{\infty}\int_{J_n}f(x)dx &= \sum_{n=1}^{\infty}\left(\frac{n - 2^{-n}}{2^{n+1}} + \frac{1}{2^{2n + 1}}\right) = \frac{1}{2}\sum_{n=1}^{\infty} \frac{n}{2^n} \\ \sum_{n=1}^{\infty}\int_{K_n}f(x)dx &= \sum_{n=1}^{\infty}2^{-n}(1 - 2^{-n + 1}) = 2\sum_{n=1}^{\infty}\frac{2^{n-1} - 1}{2^{2n}} \\ \sum_{n=1}^{\infty}\int_{L_n}f(x)dx &= \sum_{n=1}^{\infty} \left(\frac{n + 1 - 2^{-n}}{2^n} + \frac{1}{2^{2n + 1}}\right) = \sum_{n=1}^{\infty}\left(\frac{n2^n + 2^n - 1}{2^{2n}} + \frac{1}{2^{2n + 1}}\right). \\ \end{aligned} \end{equation*} Now $f$ is continuous since it's piecewise continuous and the components agree at the intersection points. Clearly $f$ is positive and $\limsup_{x\to\infty}f(x) = \infty$. But all of the above sums are finite, so $f$ is integrable on $[0,\infty)$. Then we just let $f(x) = f(-x)$ for $x < 0$. I almost certainly made a error somewhere in the calculations, but hopefully the idea is clear and someone can confirm that it works.
Now for (b). Suppose $f$ is a positive uniformly continuous and integrable on $\mathbb{R}$ but $\limsup_{\vert x \vert\to\infty}f(x) \neq 0$.
I. Since $\limsup_{\vert x \vert\to\infty}f(x) \neq 0$ there exists some $c > 0$ such that there exist arbitrarily large $x$ with $f(x) \geq c$.
II. By uniform continuity, pick $\delta > 0$ such that $\vert x - y \vert < \delta$ implies $\vert f(x) - f(y) \vert < \epsilon$ where $\epsilon < c$. Set $c' = c - \epsilon$.
I and II imply that we can find infinitely many pairwise disjoint intervals $[a,b]$ of length $\delta$ on which $f(x) > c'$. But on such an interval $$\int_a^b f(x)dx \geq \delta c' = K,$$ thus $$\int_{-\infty}^{\infty}f(x)dx \geq \infty \cdot K,$$ contradicting that $f$ is integrable.
Thanks!