Conditions on $f$ to know it is injective only by looking at the derivative?

Consider $f:I \subseteq \mathbb{R} \to \mathbb {R}$. What conditions must be imposed on $f$ in order to have the following implication true?

If $f'(x_0)\neq 0$ for some $x_0 \in I$, then $\exists \,\,r>0 \,\, | \,\, f$ is injective $\forall \, x \in (x_0-r,x_0+r)$

I think that if $f \in C^1 (J)$ for some open interval $J$ containing the point $x_0$ , then surely the previous implication work. But are there less restrictive conditions on $f$ in this case? Must $f'$ be continous around $x_0$ necessarily or not?

• Related question math.stackexchange.com/questions/2173154/… – mfl Oct 23 '17 at 15:14
• Well, there are certainly counterexamples with $f'$ cadlag. – user228113 Oct 23 '17 at 15:34
• Better to say "injective in $(x_0-r,x_0+r)$". Injectivity is a property of functions on sets, not a property holding at a point. – zhw. Oct 23 '17 at 16:23

"Must $f'$ be continous around $x_0$ necessarily or not?" The example $f(x)=2x + x^2\sin(1/x)$ shows the answer is no (look at a small enough interval about $0$ to see this).
Here's a more ambitous example: Let $A$ be the set of algebraic numbers, $B$ the set of transcendental numbers. Then $A,B$ are disjoint, and both $A,B$ are dense in $\mathbb R.$
Define $f(x) = x$ on $A, f(x) = x+x^3$ on $B.$ Then $f$ is injective on $A$ and injective on $B.$ Furthermore $f$ maps $A$ to $A$ and $B$ to $B.$ It follows that $f$ is injective on $\mathbb R.$
It's straightforward to show $f'(0)= 1.$ But $f$ is discontinuous at each $x\in \mathbb R \setminus \{0\}.$ Therfore $f'(x)$ fails to exist for all $x\ne 0.$
• Why is $x+x^3$ transcendental if $x$ is? I agree that both $x$ and $x^3$ are transcendental, but the sum of transcenentals could be algebraic. What am I missing? – Jason DeVito Oct 23 '17 at 17:33
• @JasonDeVito Suppose $x_0$ is transcendental, $p(x)$ is a nonzero polynomial with integer coefficients, and $p(x_0+x_0^3)=0.$. Let $q(x) =p(x+x^3).$ Then $q$ is a nonzero polynomial with integer coefficients, and $q(x_0)=0,$ contradiction – zhw. Oct 23 '17 at 17:48