Classes of continuous functions in $\mathbb R$ Each functions are defined on $\Bbb R$.
$C_k = $ the class of continuous functions $f$ each vanishing outside a compact set $K(f)$
$C_0 = $ the class of continuous functions $f$ such that $$\lim_{|x| \to \infty} f(x) = 0$$
Then, $C_k \subset C_0$.
How can I prove that $C_0$ is the closure of $C_k$ with respect to uniform convergence?
This is my proof for showing $C_k \subset C_0$.
Let $f \in C_k$. Compact set in $\Bbb R$ is closed and bounded, so $K(f)$ is bounded. So it is obvious that $\lim_{|x| \to \infty} f(x) = 0 $.
To prove that $C_0$ is the closure of $C_k$, let's fix $f \in C_0$, and need to show that $f$ is the point of closure of $C_k$, so we need to find a sequence $\{f_n\}$ such that $f_n \in C_k$ and $f_n$ converges to $f$ uniformly.
I'm not sure where to start with to find those sequence of functions.
 A: Suppose that $f_n$ is a uniformly convergent sequence of functions in $C_k$. Let $f$ denote the limit. Our goal is to show that $f$ is in $C_0$. So let $\epsilon > 0$, and we will show that $|f(x)| < \epsilon$ when $|x|$ is sufficiently large. By uniform convergence, we know that there is some $N$ such that for all $n \geq N$ We have that $|f(x) - f_n(x)| < \epsilon$.
Since $f_N$ is in $C_k$, there is some $M >0$ such that $|x| > M$ implies that $f_N(x) = 0$. It follows that for all $x$ with $|x| > M$, that $|f(x) - f_N(x)| = |f(x)| < \epsilon$. Hence $f \in C_0$.

Conversely, suppose that $f \in C_0$. We want to show there is a sequence of functions $f_n$ from $C_k$ such that $f_n \rightarrow f$ uniformly. We can find this sequence by truncating $f$ and doing a straight-line interpolation. That is, set:
$$f_n(x) := \begin{cases} 0 & \quad \text{if } x \leq -(n+1) \\
(x + (n+1)) \cdot f(-n) & \quad \text{if } -(n+1)< x < -n \\ 
f(x) & \quad \text{if } |x| \leq n \\
(x-n) \cdot f(n) & \quad \text{if } n < x < n+1 \\
0 & \quad \text{if } x \geq n+1 \\\end{cases}$$
These $f_n$ look like $f$ on the interval $[-n,n]$, they are uniformly $0$ when $|x| \geq n+1$, and we draw straight lines to fill in the gaps on $[-(n+1), -n]$ and $[n, n+1]$.
It is clear that $f_n \rightarrow f$ uniformly, and that $f_n \in C_k$ for each $n$.
A: Let $f \in C_0$ be arbitrary. Let $\varepsilon > 0$ be arbitrary. Since $f \in C_0$, there is a compact set $K \subset \mathbb{R}$ such that $\sup_{x \in K^c}|f(x)| \leq \varepsilon$. Pick $\phi \in C_k$ with $0 \leq \phi(x) \leq 1$ for all $x \in \mathbb{R}$ and $\phi = 1$ on $K$. Then for $x \in K$, $|\phi(x)f(x) - f(x)| = 0$ and for $x \notin K$, $|\phi(x)f(x) - f(x)| = |\phi(x) - 1||f(x)| \leq |f(x)| \leq \varepsilon$. Thus $\|\phi f - f\|_{\infty} \leq \varepsilon$. Since $\phi f \in C_k$, this shows that $C_0 \subset \overline{C_k}$.
A: Take any function $f \in C_0$, and fix any $\varepsilon > 0$. We have to come up with some function $f_\varepsilon \in C_k$ that is within $\varepsilon$ distance of $f$, with respect to the uniform norm. This proves $C_k$ is dense in $C_0$.
The condition that $\lim_{|x| \to \infty} f(x) = 0$ means that $f$ becomes very small for very large $x$ ("large", meaning very positive, or very negative). In particular, for our fixed $\varepsilon > 0$, we can find some $N$ such that:
$$|x| \ge N \implies |f(x) - 0| \le \frac{\varepsilon}{2}.$$
So, let's define:
$$f_\varepsilon(x) = \begin{cases}
f(-N)(N + 1 + x) & \text{if }-N - 1 < x < -N \\
f(x) & \text{if } |x| \le N \\
f(N)(N + 1 - x) & \text{if }N < x < N + 1 \\
0 & \text{if }|x| \ge N + 1.
\end{cases}$$
You should verify that this is continuous. Then,
\begin{align*}
\|f - f_\varepsilon\|_\infty &= \sup_{x \in \Bbb{R}} \left|f(x) - \begin{cases}
f(-N)(N + 1 + x) & \text{if }-N - 1 < x < -N \\
f(x) & \text{if } |x| \le N \\
f(N)(N + 1 - x) & \text{if }N < x < N + 1 \\
0 & \text{if }|x| \ge N + 1
\end{cases}\right| \\
&= \sup_{x \in \Bbb{R}} \begin{cases}
|f(x) - f(-N)(N + 1 + x)| & \text{if }-N - 1 < x < -N \\
|f(x) - f(x)| & \text{if } |x| \le N \\
|f(x) - f(N)(N + 1 - x)| & \text{if }N < x < N + 1 \\
|f(x) - 0| & \text{if }|x| \ge N + 1.
\end{cases}
\end{align*}
Clearly, when $|x| \le N$, we have $|f(x) - f_\varepsilon(x)| = 0$, which means that the interval $[-N, N]$ contributes nothing to the supremum.
Next, consider $x \in [N, N+1]$. In this case,
\begin{align*}
|f(x) - f_\varepsilon(x)| &= |f(x) - f(N)(N + 1 - x)|\\
&\le |f(x)| + |N + 1 - x| \cdot |f(N)| \\
&\le \frac{\varepsilon}{2} + 1 \cdot \frac{\varepsilon}{2} = \varepsilon.
\end{align*}
A similar result can be deduced when $x \in [-N-1, -N]$.
The remaining points, i.e. where $|x| \ge N + 1 \ge N$ satisfy $$|f(x) - f_\varepsilon(x)| = |f(x) - 0| \le \frac{\varepsilon}{2} \le \varepsilon,$$
by construction of $N$. In total, this means that $\|f - f_\varepsilon\| \le \varepsilon$, as required.
