To begin with we take $x_0 = 0$ : we want $f(0) = 0$ and $f'$ defined at $0$, with $f'(0)=1$.
Then you take :
$f$ is continuous only at $0$. Moreover, you can check that $f'(0) = 1$ : indeed we have $f(0) = 0$, so $\mid \frac{f(x) - f(0)}{x} - 1\mid = \mid \frac{f(x)}{x} - 1\mid$. This quantity equals either to $0$ if $x \in \mathbb{Q}$ or to $\mid x \mid$ if $x \notin \mathbb{Q}$. Either way, when $x$ approaches $0$, $\mid \frac{f(x) - f(0)}{x} -1 \mid $ approaches $0$. Although $f$ is almost nowhere continuous, the derivative at $0$ exists and $f'(0) = 1$.
More generally, if you want $g(x_0) = y_0$, $g'(x_0) = a$ and $g$ continuous only at $x_0$, you can take :
$g(x) = y_0 + a\times f(x-x_0)$
A quite equivalent (but slightly different) explicit version would be :
An example of a strictly increasing function with derivative $0$ at rationals is the Minkowski's question mark function, which is defined as follow :
given $x$ whose continued fraction representation is $[a_0, a_1, a_2, ... ]$, let $?(x) = a_0 - 2 \sum \limits_{n=1}^{\infty} \frac{(-1)^n}{2^{a_1+\cdot \cdot \cdot + a_n}}$.
You can prove that this function's derivative is $0$ over the rationals, but yet it is strictly increasing, so there is no interval on which it is constant.
(PS : continued fraction : $x = a_0 + \frac{1}{a_1+\frac{1}{a_2+\frac{1}{...}}} $ where $a_0 \in Z$, and $a_1,a_2 > 0$ integers. You have existence and unicity of this decomposition (and the list $(a_0,a_1,...)$ is finite iff $x$ is rational) )
$ $
Concerning your second question, if $f$ is continuous, differentiable at irrational numbers and with derivative $0$ at irrational numbers, then $f$ is constant.
More generally, if $f$ is continuous and its derivative exists and is $0$ at the complement of a countable set, then you can prove that $f$ is constant.
$ $
To prove this, first fix $\varepsilon > 0$
- if $f'(x) = 0$, then it exists $\delta > 0$ such that $\forall s \in [x-\delta, x+\delta],\ \mid f(s) - f(x) \mid < \varepsilon \mid s - x \mid$.
So the variation of $f$ over any subinterval of $[x - \delta, x+\delta]$ is less than $2\varepsilon$ times the length of the subinterval (*).
- let us note $(x_n)$ the (countable) other points where the derivative is not defined or not $0$. Using continuity, for all $n$, it exists $\delta$ such that $\forall s\in [x_n - \delta, x_n + \delta],\ \mid f(s) - f(x_n) \mid < \frac{\varepsilon}{2^{n}}$
Hence, the variation over all those intervals when $n$ is an integer is less than $2 \sum \limits_{n\in\mathbb{N}} \frac{\varepsilon}{2^n} = 4\varepsilon$
To be clearer, we can define for all $x$, $\delta(x)$ equals the $\delta$ mentioned in the first case or the second depending on $x$
(hence for all $x$, $[x-\delta(x), x+\delta(x)]$ is a neighborhood of $x$ over which the variation of $f$ is tiny).
$ $
Then let us fix $a<b$. We can prove that there exists $a = a_0 < a_1 < \cdot \cdot \cdot < a_r = b$ and $t_1,...,t_r$ such that for all $i \geqslant 1$, $t_i \in [a_{i-1}, a_i]$ and $a_i - a_{i-1} < \delta(t_i)$.
(the proof consists of considering the set of $y \in [a,b]$ such that it exists $a = a_0 < \cdot \cdot \cdot < a_s = y$ with the previous property. This set is non-empty ($a$ is in it), and bounded, so it has a supremum. If this supremum $c$ is $<b$, you can add to your partition $e>c$ such that $e<c+\delta(c)$, and $e$ is in the set, there is a contradiction. So the supremum is $b$, and we have the property we were looking for. )
Using triangular inequality we have : $\mid f(b) - f(a) \mid \leqslant \sum \limits_{k=1}^r \mid f(a_k) - f(a_{k-1}) \mid$.
So $\mid f(b) - f(a) \mid \leqslant 4\varepsilon + \sum \limits_{k=1}^r 2\varepsilon(a_k - a_{k-1})$ : an upper bound is the sum of the variations in the second case and also in the first case mentionned earlier. For the first case, we need to add that if $f'(t_k) = 0$ (that is, if we are in the first case), then $[a_{k-1},a_k]$ is a subset of $[t_k - \delta(t_k), t_k + \delta(t_k)]$ and we can use (*) : $\mid f(a_k) - f(a_{k-1}) \mid \leqslant 2\varepsilon (a_k - a_{k-1})$.
$ $
Hence $\mid f(b) - f(a) \mid \leqslant 4\varepsilon + 2\varepsilon(b-a)$, and this holds for all $\varepsilon$. Thus $f(a) = f(b)$ : $f$ is constant.
Best Answer
Hint: You're on the right track with that function, but you're overthinking it. You have $|f(x)| \le x^2$ for all $x.$ Use the definition of the derivative at $0.$