I found the following question in GRE 1268 practice test. I was wondering if you could tell me how to approach this problem since everytime I encounter a similar problem I have troubles solving it. Thanks for your help!
The function $f:\mathbb{R} \rightarrow \mathbb{R}$ is defined as follows,
$$f(x) = 3x^2 \text{ if } x \in \mathbb{Q}$$ and $$f(x) = -5x^2 \text{ if } x \notin \mathbb{Q}$$
Which of the following is true?
A) f is discontinuous at all $x \in \mathbb{R}$
B)f is continuous only at $x = 0$ and differentiable only at $x = 0$
C) f is continuous only at $x = 0$ and nondifferentiable at all $x \in \mathbb{R}$
D) f is continuous at all $x \in \mathbb{Q}$ and nondifferentiable at all $x \in \mathbb{R}$
E) f is continuous at all $x \notin \mathbb{Q}$ and nondifferentiable at all $x \in \mathbb{R}$.
That's either the definition or a property from the standard $\varepsilon-\delta$ definition.
So consider an irrational sequence $i_n$ and a rational sequence $r_n$ that both converge to some number $a$. Then we have
$$\lim f(i_n) = \lim -5i_n^2 = -5a^2$$
$$\lim f(r_n) = \lim 3r_n^2 = 3a^2$$
We have $-5a^2 = 3a^2 \iff a=0$
Hence the $f(x)$ is continuous at $x=0$ and nowhere else.
So what about differentiability?
$f$ is not differentiable for any $x \ne 0$ since differentiability implies continuity. So let's see if $f$ is differentiable at $x=0$:
$$f'(0) = \lim_{h \to 0} \frac{f(0+h) - f(0)}{h}$$
$$= \lim_{h \to 0} \frac{f(h)}{h} \tag{*}$$
$(*)$ is supposed* to be equal to both of the following:
$$\lim_{n \to \infty} \frac{f(ih_n)}{ih_n} \tag{1}$$
$$\lim_{n \to \infty} \frac{f(rh_n)}{rh_n} \tag{2}$$
where $ih_n$ is an irrational sequence, $rh_n$ is a rational sequence and both converge to $0$
Compute $(1)$:
$$\lim_{ih_n \to 0} \frac{f(ih_n)}{ih_n} = \lim_{ih_n \to 0} \frac{-5ih_n^2}{ih_n} = \lim_{ih_n \to 0} \frac{-5ih_n}{1} = 0$$
Compute $(2)$:
$$\lim_{rh_n \to 0} \frac{f(rh_n)}{rh_n} = \lim_{rh_n \to 0} \frac{3rh_n^2}{rh_n} = \lim_{rh_n \to 0} \frac{3rh_n}{1} = 0$$
Hence, $f'(0)$ exists and namely is zero.
Therefore, $f$ is continuous and differentiable at $x=0$ and nowhere else.
*I think there's some rule like
$$\lim_{x \to a} f(x) = L \iff$$
for all sequences $x_n$ that converge to $a$
$$\lim_{n \to \infty} f(x_n) = L$$