Prove this limit (formally) As I was coursing through Spivak's calculus, more like analysis; I found an interesting, questionable example. 
Let $\frac{p}{q}$ be in its lowest terms; $p$ and $q$ are integers with no common factors and $q > 0$
If $f(x) = \begin{cases}0 & \text{$x$ is irrational} \\ \frac{1}{q} & x = \frac{p}{q}, 0 < x < 1 \end{cases}$
Show that $f(x)$ approaches $0$ as $x$ approaches $0$
Using the actual definition, not just the rough idea, we must show this is true. 
Definition: For every $\epsilon > 0$ there is some $\delta > 0$ such that, for all $x$, if $0 < |x - a| < \delta$, then $|f(x) - l| < \epsilon$ This is if $f$ approaches the limit $l$ near $a$. 
So, $a = 0$ and $l = 0$ we dont actually pick a random $\delta$, we just use it analytically. 
$0 < |x| < \delta$ because we can choose a $\delta > |x|$ We need to do, 
$|f(x)| < \epsilon$
Lets consider $g_1(x) = 0$, where $x$ is irrational first.
$0 < |x| < \delta_1$ then prove $|0| < \epsilon$
It is true since $\epsilon > 0$ part one is done then. 
Lets consider $g_2(x) = \frac{1}{q}, x= \frac{p}{q}, 0 < x < 1$
$0 < |x| < \delta_2$ then prove $\frac{1}{q} < \epsilon$
Since $0 < x < 1$, $0 < q < \infty$ and $p < q$ because $0 < x < 1$ 
How do we go about this then?
Any ideas will be appreciated! Thanks!
 A: How about letting $\delta = \epsilon$? Then for $x=\frac{p}{q}$ (assume if x<0 then p<0), $ |f(x)| = \frac{1}{q} \leq \frac{|p|}{q} = |x| < \delta =\epsilon$.
A: The key step in proving $f(x)$ approaches zero for positive $x$ is that for any $\delta < 1$ and $x \neq 0$,
if $0 < x < \delta$ then 
$$
x < \frac{1}{\lfloor \frac{1}{\delta} \rfloor } 
$$
where $\lfloor \frac{1}{\delta} \rfloor $ is an integer, being the least integer less than $\frac{1}{\delta}$. 
This tells us that if $0 < x < \delta$ then 
$ x < \frac{1}{q(x;\delta)}$
with $q(x;\delta)=\lfloor \frac{1}{\delta} \rfloor $.  Then $f(x)$ is either $0$ or $\frac{1}{q(x;\delta)}$ or $\frac{1}{k}$ for some $k > q(x;\delta)$.  Thus
$$
f(x) \leq 1/q(x;\delta)  = \frac{1}{\lfloor \frac{1}{\delta} \rfloor }
$$
So given any $\epsilon > 0$, take 
$$
\delta = \frac{1}{\frac{1}{\epsilon} + 1} = \frac{\epsilon}{1+\epsilon}
$$
Then for all $0 < x < \delta$, 
$$
f(x) \leq \frac{1}{\lfloor \frac{1}{\delta} \rfloor } =
\frac{1}{\lfloor \frac{1}{\frac{\epsilon}{1+\epsilon}} \rfloor } 
$$
Simplifying,
$$f(x) \leq \frac{1}{\lfloor \frac{1+\epsilon}{\epsilon} \rfloor } =
\frac{1}{\lfloor \frac{1}{\epsilon}+1 \rfloor }
< \frac{1}{\frac{1}{\epsilon}} = \epsilon
$$
So for all $0 < x < \delta(\epsilon) = \frac{\epsilon}{1+\epsilon}$, 
$$
0 \leq f(x) < \epsilon
$$
and $f(x)$ approaches zero as $x$ approaches zero from above.
You complete the proof by demonstrating similarly that $f(x)$ approaches zero for negative $x$ .
A: You can prove first a more general statement: if $|f(x)|\le|x|$, for all $x\in(0,1)$, then
$$
\lim_{x\to0}f(x)=0.
$$
Proof. Let $\varepsilon>0$; take $\delta=\varepsilon$ and consider $0<|x|<\delta$; then $|f(x)-0|=|f(x)|\le|x|<\delta$ and, therefore, $|f(x)-0|<\varepsilon$.
Note that a slight variation still holds: if $|f(x)|\le k|x|$, for all $x\in(0,1)$, where $k>0$, then $\lim_{x\to0}f(x)=0$. In the proof consider $\delta=\varepsilon/k$.
Now prove that Spivak's $f$ satisfies the condition: if $x\in(0,1)$ is irrational, then $f(x)=0\le x$; if $x=\frac{p}{q}\in(0,1)$ is rational (with $p$ and $q$ coprime integers, $q>0$), then $f(x)=\frac{1}{q}$ and $|p|\ge1$, so
$$
|x|=\frac{|p|}{q}\ge\frac{1}{q}=f(x)=|f(x)|.
$$
