Spivak's Calculus Chapter 13, Problem 40: Help with rigor The problem is as follows:
Suppose $f$ is continuous and $\lim_{x \to \infty} f(x) = a$. Prove that 
$$\lim_{x \to \infty} \frac{1}{x} \int_0^x f(t)\,dt = a.$$
I have made some progress with the problem, and I know intuitively how the proof should work, but am having trouble with rigor-ifying the argument. See below:
We want to show that for all $\epsilon > 0$, there exists $M$ such that if $x \geq M$, then $\left| \frac{1}{x} \int_0^x f(x)\,dx - a \right| < \epsilon,$ or that $$x(a-\epsilon) < \int_0^x f(x)\,dx < x(a+\epsilon).$$ 
Because $\lim_{x \to \infty} f(x) = a$, for all $\epsilon > 0$, there exists $N > 0$ such that if $x \geq N$, then $|f(x) - a| < \epsilon.$ This means that for any $x\geq N$, $a-\epsilon < f(x) < a+\epsilon,$ so $$(a-\epsilon)(x-N) \leq \int_N^xf(t)\,dt \leq (a+\epsilon)(x-N).$$
Hence it follows that, 
$$\int_0^N f(t)\,dt + (a-\epsilon)(x-N) \leq \int_0^x f(t)\,dt \leq \int_0^N f(t)\,dt + (a+\epsilon)(x-N).$$
This is the part that I am having trouble with proving rigorously: As $x$ gets larger and larger, the $x(a-\epsilon) < \int_0^x f < x(a+\epsilon)$ is achieved. Since $\int_0^N f$ is a constant, it will essentially become zero in comparison to $(a+\epsilon)(x-N)$ or $(a-\epsilon)(x-N).$ Similarly, because $N$ is a constant, $(x-N)$ will basically become $x$. 
Thank you for your help! 
 A: Using $g(x) =f(x) - a$ we can reduce the problem to case when $a=0$. So lets prove the result when $a=0$.
Let $\epsilon >0$ and we have a number $M>0$ such that $$-\epsilon<f(x) <\epsilon$$ whenever $x>M$. Integrating this on interval $[M, x] $ we get $$-\epsilon(x-M) <\int_{M}^{x} f(t) \, dt<\epsilon(x-M) $$ or $$-\epsilon\left(1-\frac{M}{x}\right)+\frac{1}{x}\int_{0}^{M}f(t)\,dt<\frac{1}{x}\int_{0}^{x}f(t)\,dt<\epsilon\left(1-\frac{M}{x}\right)+\frac{1}{x}\int_{0}^{M}f(t)\,dt$$ Letting $x\to \infty $ we get $$-\epsilon\leq\liminf_{x\to\infty} \frac{1}{x}\int_{0}^{x}f(t)\,dt\leq\limsup_{x\to\infty} \frac{1}{x}\int_{0}^{x}f(t)\,dt\leq\epsilon $$ Since $\epsilon$ is arbitrary our proof is complete. 
A: It's simpler if you keep the absolute values and use the same idea: $$\left|\frac{1}{x}\int_0^x f(t)dt - a\right| $$ $$= \left|\frac{1}{x}\int_0^N f(t)dt + \frac{1}{x}\int_N^xf(t)dt - a\right|$$
$$\le\left|\frac{1}{x}\int_0^N f(t)dt\right| + \left|\frac{1}{x}\int_N^xf(t)dt - a\right|$$
$$ \le  \left|\frac{1}{x}\int_0^N f(t)dt\right| + \frac{1}{x}\int_N^x|f(t) - a|dt + \left |a\left (\frac{x-N}{x}-1\right)\right|$$
$$\le  \left|\frac{1}{x}\int_0^N f(t)dt\right| +\frac{(x-N)}{x}\epsilon +  \left |a\left (\frac{x-N}{x}-1\right)\right|$$
Now choose $M \gt N$ such that for $x \gt M$ the first term is $\lt \epsilon$ and $\left|\frac{(x-N)}{x} - 1\right|\lt \min(1,\epsilon/|a|)$. Then the sum above is $\lt \epsilon + 2\epsilon+\epsilon$ and the result follows.
A: In fact, you must combine your idea (cut the integral) and that of  Reveillark. Indeed, you begin, as it was suggested by writing 
$$
\left | \frac{1}{x}\int_0^x f(t)\,dt-a\right|=\left | \frac{1}{x}\int_0^x (f(t)-a) \,dt\right|
$$
now, let us exploit the fact that $\lim_{x\to\infty} f(x)=a$ as you did. 
For all $\epsilon_1>0$ (to be adjusted later), it exists $N$ such that $\forall t\geq N$, 
$|f(t)-a|\leq \epsilon_1$, then you make your cut and for all $x\geq N$
$$
\frac{1}{x}\int_0^x (f(t)-a) \,dt=
\frac{1}{x}\Big(\int_0^N (f(t)-a) \,dt+\int_N^x (f(t)-a) \,dt\Big)
$$
Now, as $x$ grows, the contribution of 
$\frac{1}{x}\int_0^N (f(t)-a) \,dt$ is less and less important, in fact 
$$
\lim_{x\to \infty}\frac{1}{x}\int_0^N (f(t)-a) \,dt=0
$$ 
and 
$$
|\frac{1}{x}\int_N^x (f(t)-a) \,dt|=
\frac{x-N}{x}|\frac{1}{x-N}\int_N^x (f(t)-a) \,dt|\leq \frac{x-N}{x}\cdot \epsilon_1\leq \epsilon_1
$$
so, take $\epsilon_1=\epsilon/2$.
Can you finish ? 
A: Here is a more detailed/adapted version of Spivak's proposed solution:
By assumption, we know that there exists an $N \gt 0: \forall t \geq N: \left|f(t)-a\right|\lt \frac{\varepsilon}{3}$. Consider $f$ restricted to the domain $[N,M]$ for some arbitrary $M \gt N$. Denote this as $f|_{[N,M]}$. For all $t \in [N,M]$, we know that $\left|f|_{[N,M]}(t)-a\right| \lt \frac{\varepsilon}{3}$. Next, let $g(t)=\left|f|_{[N,M]}(t)-a\right|$ and be defined on the same domain. Then for all $t \in [N,M]: g(t) \lt \frac{\varepsilon}{3} \quad (\dagger_1)$.
By assumption, we know that for any $x \gt 0: f|_{[0,x]}$ is integrable on $[0,x]$. Then we certainly have that $f|_{[0,M]}$ is integrable on $[0,M]$, which tells us that for $0 \lt N \lt M: f|_{[N,M]}$ is integrable on $[N,M]$.
Because $f|_{[N,M]}$ is integrable on $[N,M]$, we know that $f|_{[N,M]}(t)-a$ is integrable on $[N,M]$, and because $f|_{[N,M]}(t)-a$ is integrable on $[N,M]$, we must have that $\left|f|_{[N,M]}(t)-a\right|$ is integrable on $[N,M]$. Of course, then, we are certain that $g$ is integrable on $[N,M]$, which allows us to deduce from $(\dagger_1)$ that $\displaystyle \int_N^M g(t)dt \lt \int_N^M \frac{\varepsilon}{3}=(M-N)\frac{\varepsilon}{3}$.
We can rewrite this as:
\begin{align}\int_N^M\left(\left|f|_{[N,M]}(t)-a\right|\right)dt \lt(M-N)\frac{\varepsilon}{3}\end{align}
Applying the result from exercise 37 (Chapter 13), we then have that:
$$\left|\int_N^M \left(f|_{[N,M]}(t)-a\right)dt\right| \leq \int_N^M\left(\left|f|_{[N,M]}(t)-a\right|\right)dt \lt(M-N)\frac{\varepsilon}{3} $$
From this, we have that:
$$\left|\int_N^M f|_{[N,M]}(t)dt- \int_N^M adt\right| \lt (M-N)\frac{\varepsilon}{3},$$ which we can further simplify to:
$$\left|\int_N^M f|_{[N,M]}(t)dt- (M-N)a\right|\lt(M-N)\frac{\varepsilon}{3} \quad (\dagger_2)$$
Note that $M,N \gt 0 \implies \frac{M-N}{M} \lt 1$. This implies that we can modify $(\dagger_2)$ as follows:
$$\frac{\left|\int_N^M f|_{[N,M]}(t)dt- (M-N)a\right|}{M}\lt\frac{(M-N)\frac{\varepsilon}{3}}{M}\lt\frac{\varepsilon}{3} \quad (\dagger_3)$$
$0 \lt M=|M|$, so $(\dagger_3)$ can be rewritten as:
$$\left|\frac{1}{M}\int_N^M f|_{[N,M]}(t)dt -\frac{M-N}{M}a\right|\lt \frac{\varepsilon}{3} \quad (\dagger_4)$$
Importantly, note that, by construction, $(\dagger_4)$ is valid for any $M \gt N$.
Recall that we are trying to prove: $\displaystyle \lim_{x \to \infty}\frac{1}{x}\int_0^xf(t)dt=a \iff \forall \varepsilon \gt 0: \exists M \in \mathbb R: \forall x \gt M: \left|\frac{1}{x}\cdot\int_0^xf(t)dt-a \right|\lt \varepsilon$.
We will make use of the following triangle inequality lemma, applied to three terms:
$$|a+b+c|\leq |a+b|+|c| \leq |a|+|b|+|c| \implies |a+b+c|\leq |a|+|b|+|c|$$
Consider the following two inequalities:
$\displaystyle\left| \frac{1}{M}\int_0^N f(t) \right|\lt \frac{\varepsilon}{3}$ and $\displaystyle \left|\frac{M-N}{M}a-a \right| \lt \frac{\varepsilon}{3}$
We must select an $M \gt N$ that satisfies both of these statements simultaneously. Realize that the left side of each inequality, for a sufficiently large $M$, is a strictly decreasing positive function. So if one $M$ satisfies both inequalities simultaneously, any $M' \gt M$ does, too. Finally, we can add these two inequalities to $(\dagger_4)$ and apply our lemma, which gives us:
$$\left |\frac{1}{M}\int_0^N f(t)dt+\frac{1}{M}\int_N^M f|_{[N,M]}(t)dt-\frac{M-N}{M}a+ \frac{M-N}{M}a-a\right| \lt \frac{\varepsilon}{3}+\frac{\varepsilon}{3}+\frac{\varepsilon}{3}=\varepsilon$$
This simplifies to our desired result of:
$$\left|\frac{1}{M}\int_0^M f(t)dt-a\right| \lt \varepsilon$$
From our previous comments, we know that for any $M' \gt M$, this inequality holds, so we are done.
