Prove that $\lim\limits_{x\to0}g(x)=0$ where $g(x)=\tiny\begin{cases}x&\text{if }x\in\mathbb{Q}\\-x&\text{if }x\notin\mathbb{Q}\end{cases}$. $g:\Bbb R\to \Bbb R$ is defined by:
$$g(x)= \begin{cases}
x &\text{if $x\in \mathbb{Q}$}\\
-x &\text{if $x\notin \mathbb{Q}$}
\end{cases}
$$

Prove that $\lim\limits_{x\to0} g(x) = 0$ using $\delta/\epsilon$.

I'm not sure how to tackle this question. Usually delta epsilon proofs are done with functions and numbers, but here it is element of rational or not element of rational, and I have no idea how to do this question. Any hints/suggestions would be nice.
 A: This proof is done with functions and numbers, just like other
delta-epsilon proofs. The function is $g(x)$, and every $x$ is a number.
Try writing a complete delta-epsilon proof showing that the function
$f$ defined by $f(x) = x$ satisfies
$\lim_{x\to0} f(x) = 0.$
If you do that proof correctly, it should translate almost$^*$ word-for-word
into a proof for your function $g(x)$.
The trick is to do the first proof correctly, of course.
$^*$ You may end up wanting to use a few extra words to explain why
$\lvert g(x) - 0 \rvert < \epsilon$ for $x\not\in\mathbb Q$
as well as for $x\in\mathbb Q$, depending on how you worded the proof for $f$.
A: Consider $\epsilon>0$ and take $\delta=\epsilon$. It follows that if $|x-0|=|x|<\delta$ then $|g(x)-0|=|x|<\epsilon$. The whole point is that $|g(x)|=|x|$ regardless of the (ir)rationality of $x$.
A: It's still a function.  Not a continuous function  but still a function.
Do it as you normally would.  If $|g(x) - c| < \epsilon$ what does that say about $|x - a|$?  If you can find some way that for all $\epsilon$ there is a $\delta$ so that $|x-a| < \delta \implies |g(x) - c| < \epsilon$ then $\lim\limits_{x\rightarrow a} g(x) = c$.
Just do it the same way.
$|g(x) - c| = |g(x) - 0| = |\pm x - 0| < \epsilon \implies$
$|x| < \epsilon \implies$
$|x - 0| < \epsilon$.
So..... set $\delta = \epsilon$
$|x - 0| < \delta \implies |x| < \delta$
Either $g(x) =x$ or $g(x) = -x$.  Either way $|g(x) - 0| = |g(x)| = |x| $.
So $|g(x) - 0| =|x| < \delta =\epsilon$
.... and we are done!  $\lim\limits_{x\rightarrow 0} g(x) = 0$.
===
If you try to picture this function the graph will be two lines, both "blurry" with disjoint holes, making an X.  As x goes toward 0, g(x) bounces around to x and -x like a flea.  But at $x = 0$ both the $-x$ and $x$ lines "converge" at 0.
===
It's interesting to note $\lim\limits_{x \rightarrow a, a \ne 0} g(x)$ is not defined.  (If $x \in (a-\delta, a+\delta)$ and $x$ is rational then $g(x) \in (a - \delta, a + \delta)$ but if $x$ is not rational $g(x) \in (- a - \delta, - a + \delta)$ so they don't "hone in" on anything.
If you have had the definition of continuous then it's interesting that $g(x)$ is continuous at $x = 0$ but nowhere else.  If you haven't had the definiton of continuous ... well, you have something to look forward to.
A: Hint Try to prove that in general for a function you have $\lim\limits_{x \to a} f(x)=0$ if and only if $\lim\limits_{x \to a} |f(x) |=0$.
