# Prove the function below is continuous and differentiable at only $0$

$f(x) = \begin{cases} x & x \in \mathbb{Q} \\ -x & x \in \mathbb{I} \end{cases}$

I wish to show that $f(x)$ is continuous at only $0$. Thus, if it is differentiable, it would only be differentiable at $0$.

$\textbf{My attempt (Continuity)}$

$f(x)$ only continuous at $0$

Choose $\delta = \epsilon$

Then, if $|x-0| = |x| < \delta$

$|f(x) - f(0)| = |f(x)| \leq |x| < \delta = \epsilon$

$f(x)$ discontinuous anywhere else ($c \neq 0)$

Choose $\delta =$ (need help)

Then, if $|x-c| < \delta$

$|f(x) - f(c)| \leq |x+c|$

Unsure of where to go from here.

$\textbf{Differentiable}$

$f(x)$ could only possibly be differentiable at $0$ since it was continuous at $0$

$$\lim_{x\to c} \frac{f(x) - f(c)}{x - c}$$

Set $c = 0$

$$\lim_{x\to 0} \frac{f(x) - f(0)}{x - 0} = \lim_{x\to 0} \frac{f(x)}{x}$$

$$= f(x) = \begin{cases} 1 & x \in \mathbb{Q} \\ -1 & x \in \mathbb{I} \end{cases}$$

Some how?

Any help would be appreciated.

• You must have misreaded the question cause that function is not differentiable at $0$. Maybe the function was the same but with $x^2$ instead of $x$? In that case I would first prove that it is discontinuous everywhere but at $0$ and then that it is differentiable at $0$ (recall that differentiability implies continuity).
– user378947
Nov 7, 2016 at 23:21
• Think of sequential caracterisation of a llmit. Nov 7, 2016 at 23:22
• Consider using cases to your advantage. Check continuity in the cases that $x$ is rational or irrational separately.
– Matt
Nov 7, 2016 at 23:27
• @mathbeing That was sort of my point. I didn't feel I fully understood why the example you brought up works, but this one does not. I didn't know if my steps logically worked (plus I still don't quite see how its not differentiable) Nov 7, 2016 at 23:52
• The reason why your function is not differentiable is the one explained in DougM's answer. If you want to see it graphycally then draw a picture of your function around $x=0$. Which tangent line would you give to $f$ at $x=0$? On the other hand, with the function I proposed you can work out the limit and find that it exists or again draw a picture around $x=0$.
– user378947
Nov 8, 2016 at 0:06

$f(x)$ is continuous at $0.$

Choose $\delta = \epsilon$

$|x|<\delta \implies |f(x)|<\epsilon$

$f(x)$ is not continuous away from $0.$

for any $a\ne 0$ Choose $\epsilon < a$

$\forall \delta>0, \exists x$ such that $|x-a|<\delta$ and $|f(x)-f(a)|>\epsilon$

Your proof for the non-differentaiability of $f(x)$ at $0$ is on the mark.

Since $\frac {f(x) - f(0)}{x-0}$ can equal $1$ or $-1$ in a neighborhood of 0, the limit does not exist.

If you want to be more formal.

Proof by contradiction: Suppose $\lim_\limits{x\to 0} \frac {f(x)}{x} = L$

Let $\epsilon < 1$

$\forall \epsilon>0,\exists \delta>0$ such that $|x|<\delta \implies|\frac {f(x)}{x}-L|<\epsilon$

$x\in \mathbb Q \implies \frac {f(x)}{x} = 1\\ x\in \mathbb I \implies \frac {f(x)}{x} = -1$

$|1-L|<1$ and $|-1-L|<1?$

$|1-L|<1 \implies L\in (0,2)\\ |-1-L|<1\implies L\in (-2,0)$

The intervals are disjoint, giving us a contradiction.

• @Doug_M This makes sense, but I have two questions: Still not seeing how $\epsilon < a$ guarantees $|f(x) - f(a) > \epsilon$ Secondly, if we consider the case that "mathbeing" brought up, would L's intervals be $(x-\epsilon, x+\epsilon), (-x-\epsilon, -x+\epsilon)$? If so, how would that show the limit does exist as x goes to $0$? Nov 7, 2016 at 23:49
• Suppose $a$ is rational, there exists an irrational $x$ that is arbitrarily close to $a.$ In which case $|f(x) - f(a)|$ is arbitrarily close to $-2a,$ and $|2a| > \epsilon$. And if $a$ is irrational, same principle applies. Nov 8, 2016 at 0:05
• Mathbeing's function $f(x) = x^2$ when $x\in\mathbb Q$ else $f(x) = -x^2$ is continuous and differentiable at 0, and discontinuous (and not differentiable) everywhere else. Nov 8, 2016 at 0:10
• Agreed, but was curious on a rigorous proof. Example, I can reach the part of your answer to my question when you talk about L. The difference being $|x-L|<\epsilon$ and $|-x-L|<\epsilon$ when $|x| < \delta$ Was asking what you would do from here. Other than that, thank you for a quick answer to my original question. Nov 8, 2016 at 1:25
• Usually you use a shortcut, and say that $-x\le\frac {f(x)}{x}\le x$ (with the amended function) for all $x.$ Then by the squeeze theorem the limit exists (and equals 0) Nov 8, 2016 at 1:34