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!

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$ .
