A basic principle in tame geometry is that there are no pathological definable functions in o-minimal structures. One precise sense in which this principle is true is given by the Monotonicity Theorem.
Monotonicity Theorem : Let $f: R \to R$ be a definable function in some o-minimal structure $\mathfrak{R}$. Then $f$ is piecewise continuous and is piecewise constant or strictly monotone. That is, we can find $-\infty = a_0 < a_1 < \ldots < a_m = \infty$ so that for $0 \leq i < m$ the function $f \upharpoonright (a_i,a_{i+1})$ is continuous and constant, strictly increasing, or strictly decreasing.
We will follow the outline of the proof presented by van den Dries.
Fix for now an o-minimal structure $\mathfrak{R}$ so that “definable” will mean “definable in $\mathfrak{R}$. The Monotonicity Theorem is proven as a consequence of three lemmas.
Lemma 1: If $f:I \to R$ is a definable function with domain an interval $I$, then there is a subinterval $J \subseteq I$ for which either $f \upharpoonright J$ is contant or it is injective.
Lemma 2: If $f:I \to R$ is a definable, injective function with domain an interval $I$, then there is a subinterval $J \subseteq I$ on which $f$ is strictly monotone.
Lemma 3: If $f:I \to R$ is a definable, strictly monotone function with domain an interval $I$, then $f$ is piecewise continuous.
Let us check first that the Monotonicity Theorem follows from Lemmas 1, 2, and 3.
Proof (of the Monotonicity Theorem given Lemmas 1, 2, and 3): Let $f:R \to R$ be a definable function. Let us note that the set $C$ of points at which $f$ is continuous is definable. Indeed, the usual $\epsilon$-$\delta$-definition of continuity (slightly modified as we are not assuming that $\mathfrak{R}$ expands an ordered group) gives a formal definition of $C$:
$$C = \{ x \in R : \forall \epsilon_1 \forall \epsilon_2 (\epsilon_1 < f(x) < \epsilon_2 \to \exists \delta_1 \exists \delta_2 [\delta_1 < x < \delta_2 ~\&~ \forall u (\delta_1 < u < \delta_2 \to \epsilon_1 < f(u) < \epsilon_2)])$$
By o-minimality, if $R \smallsetminus C$ were infinite, then there would be an interval $I \subseteq R \smallsetminus C$. By Lemma 1, there would be some subinterval $J \subseteq I$ on which $f$ is contant or injective. We cannot be in the first case as constant functions are continuous. Thus, $f$ is injective on $J$ which implies by Lemma 2 that there is a subinterval $K \subseteq J$ on which $f$ is strictly monotone from which Lemma 3 gives a subinterval $L \subseteq K$ on which $f$ is continuous, again contradicting the fact that $K \cap C = \varnothing$. Therefore, $f$ is piecewise continuous.
Let $B_0 := \{ x \in R : f $ is locally constant at $x \}$, where to say that $f$ is locally constant at $x$ means $\exists \epsilon_1 \exists \epsilon_2 (\epsilon_1 < x < \epsilon_2 ~\&~ \forall y [\epsilon_1 < y < \epsilon_2 \to f(y) = f(x)])$. Likewise, let $B_+ := \{ x \in R : f $ is locally increasing at $x \}$ and $B_- := \{ x \in R : f $ is locally decreasing at $x \}$. Each of these sets is definable. Arguing as we did for proving piecewise continuity, the complement of $B_0 \cup B_+ \cup B_-$ must be finite, for otherwise it would contain an interval $I$ with by Lemma 1 would have a subinterval on which $f$ is constant (which would contradict $I \cap B_0 = \varnothing$) or on which $f$ is injective, and then by Lemma 2, we would find a subinterval on which $f$ is strictly monotone, now contradicting disjointness from $B_+ \cup B_-$.
Finally, we observe that if $f$ is continuous and locally constant (respectively, locally monotone) on some interval, then it is actually constant (respectively, monotone). That is, we assume that $I$ is an interval, $f$ is continuous on $I$, and $f$ is locally constant, increasing, or decreasing on $I$. Let us write the proof in the case that $f$ is locally constant. The other cases are similar. Let $x \in I$. Let $A := \{ y \in I : y < x $ and $ f(y) \neq f(x) \}$ and $B := \{ z \in I : x < z $ and $ f(z) \neq f(x) \}$. We wish to show that both $A$ and $B$ are empty. Suppose that $A \neq \varnothing$. Let $\alpha := \sup A$. (Recall that in an o-minimal structure each nonempty definable subset has a supremum — possibly $\infty$ — and an infimum —possibly $-\infty$). Since $f$ is locally constant at $x$, there is some $\delta < x$ so that for all $z \in (\delta,x)$ we have $f(z) = f(x)$. Thus, $\alpha \leq \delta$. Since $f$ is locally constant at $\alpha$, there are $\beta < \alpha < \gamma$ so that $f$ is constant on $(\beta,\gamma)$. Consider $u$ and $v$ with $\beta < u \leq \alpha < v < \min \{ \gamma, x \}$. Then $f(v) = f(x)$ as $v > \sup A$ and $v < x$ while $f(u) = f(v)$ as $f$ is constant on $(\beta,\gamma)$. Thus, $(\beta,x) \cap A = \varnothing$ which would imply that $\alpha \leq \beta < \alpha$ which is absurd. $\Box$
Let us now prove the lemmas.
Proof of Lemma 1: If there is some $b \in f(I)$ with $f^{-1} \{ b \}$ infinite, then because $f^{-1} \{ b \}$ is definable, there would be some interval $J \subseteq f^{-1} \{ b \}$ meaning that $f$ would be constant on $J$. So, we may assume that for every $b \in f(I)$ the preimage $f^{-1} \{ b \}$ is finite (and nonempty as $b$ is in the range). Define $g:f(I) \to I$ by $y \mapsto \min f^{-1} \{ y \}$. Being a right inverse of $f$, $g$ is itself injective. The function $g$ is a left inverse to $f \upharpoonright g(f(I))$. Hence, $f \upharpoonright g(f(I))$ is injective. Since $f$ is finite to one and $I$ is infinite, the definable set $g(f(I))$ is also infinite and therefore contains an interval $J$ on which $f$ is injective. $\Box$
Of the three lemmas, Lemma 2 is the most complicated. We intend to show that definable functions are not pathological. We will achieve this by showing using o-minimality to argue that if there are pathologies, then they appear everywhere on an interval and moreover the pathologies feed on themselves. Ultimately, we will produce such a pathological situation that it cannot exist.
Proof of Lemma 2: Since $f$ is injective on $I$, for any point $x \in I$ the definable sets $L_{+}(x) := \{ y \in I : y < x$ and $f(y) > f(x) \}$ and $L_-(x) := \{ y \in I : y < x$ and $f(y) < f(x) \}$ partition the set $I \cap (-\infty,x)$. By o-minimality, each of $L_+(x)$ and $L_-(y)$ is a finite union of points and intervals. Thus, one or the other contains an interval of the form $(z,x)$ for some $z \in I$. Likewise, one or the other of $R_+(x) :-= \{ y \in I : y > x$ and $ f(y) > f(x) \}$ or $R_-(x) := \{ y \in I : y > x$ and $f(y) < f(x) \}$ contains an interval of the form $(x,z)$. From these observations we see that $I$ may be partitioned into the following four definable sets.
$$X_{++} := \{ x \in I : (\exists \alpha < x)(\exists \beta > x)(\forall y)(\forall z)(\alpha < y < x < z < \beta \to [f(y) > f(x) ~\&~ f(z) > f(x)])$$
$$X_{+-} := \{ x \in I : (\exists \alpha < x)(\exists \beta > x)(\forall y)(\forall z)(\alpha < y < x < z < \beta \to [f(y) > f(x) ~\&~ f(z) < f(x)])$$
$$X_{-+} := \{ x \in I : (\exists \alpha < x)(\exists \beta > x)(\forall y)(\forall z)(\alpha < y < x < z < \beta \to [f(y) < f(x) ~\&~ f(z) > f(x)])$$
$$X_{- -} := \{ x \in I : (\exists \alpha < x)(\exists \beta > x)(\forall y)(\forall z)(\alpha < y < x < z < \beta \to [f(y) < f(x) ~\&~ f(z) < f(x)])$$
By o-minimality, we may break $I$ into finitely many subintervals and points so that each such piece is contained in exactly one of these sets. Working with each of these pieces separately, we may assume that $I$ itself is equal to one of the sets $X_{++}$, $X_{+-}$, $X_{-+}$, or $X_{- -}$.
Claim 1: If $I = X_{+-}$, then $f$ is strictly decreasing.
Proof of Claim 1: Let us note that for $x \in I$ the set $B(x) :=\{ y \in I : x < y ~\&~ f(y) \geq f(x) \}$ is always empty. Indeed, suppose that $B(x) \neq \varnothing$. As $x \in X_{+-}$ there is some $b > x$ for which $(x,b) \cap B(x) = \varnothing$. Therefore $\beta := \inf B(x) \geq b > x$. Since $\beta \in I$ there some $\gamma < \beta$ so that for all $y \in (\gamma,\beta)$ we have $f(y) > f(\beta) \geq f(x)$. Hence, $\max \{x,\gamma\},b] \subseteq B(x)$ which implies that $\beta = \inf B(x) \leq \max \{ x, \gamma \} < \beta$, which is impossible.
To say that for every $x \in I$ we have that $B(x) = \varnothing$ says that for $x < y$ from $I$ we have $f(x) < f(y)$. That is, $f$ is strictly decreasing on $I$. $\maltese$
Reversing the inequalities we see dually that if $I = X_{-+}$, then $f$ is strictly increasing.
We are left with showing that $X_{++} = X_{- -} = \varnothing$. Since the arguments for $X_{- -}$ are essentially the same as those for $X_{++}$ with the inequalities reversed, we will write out the details only for $X_{++}$.
Claim 2: For each $x \in I$ there is some $y \in I$ with $x < y$ and $f(y) < f(x)$.
Proof of Claim 2: If not, then, because $f$ is injective on $I$, for $x < y$ in $I$ we have $f(x) < f(y)$. That is, $f$ would be strictly increasing on $I$ contrary to the hypothesis that for $y \in I$ there is $a < y$ so that for $a < x < y$ we have $f(x) > f(y)$. $\maltese$
Define $\beta:I \to I$ by $x \mapsto \inf \{ y \in I : y > x ~\&~ f(y) < f(x) \}$. Since for each $x \in I$ there is some $b > x$ for which $x < y < b$ implies $f(y) > f(x)$, we have $x < b \leq \beta(x)$. Thus, the range of $\beta$ is infinite as for any $x \in I$ it contains the infinite sequence of points $\beta(x) < \beta^2(x) < \ldots < \beta^n(x) < \ldots$. In particular, this shows that for every $x \in I$ the definable set $\{ y \in I : y > x ~\&~ f(y) < f(x) \}$ is infinite, and, hence, contains an interval. Define $H(x) := \{ y \in I : (\exists b)[b > y ~\&~ (\forall t) (y < t < b \to f(t) < f(x) )] \}$ and let $\gamma:I \to I$ be given by $x \mapsto \inf H(x)$. Note that because $I \subseteq X_{++}$, $\gamma(x) \in H(x)$. Since the range of $\beta$ is cofinal in $I$, so is the range of $\gamma$. Hence, the range of $\gamma$ contains an interval $J$ which is cofinal in $I$.
Let us define $$Y_{+-} := \{ y \in I : (\exists z)(\exists a < y)(\exists b > y)(\forall u)(\forall v)(a < u < y < v < b \to [f(u) > z ~\&~ f(v) < z]) \}$$
Claim 3: $J \subseteq Y_{+-}$
Proof of Claim 3: If $y \in J$, then there is some $x \in I$ with $y = \gamma(x)$. Let $z = f(x)$. Let $b > y$ witness the existential quantifier showing that $y \in H(x)$. Since $y = \inf H(x)$ and $f(t) > f(x)$ for $t$ just to the right of $x$, we have $y > x$. Since $y$ is the least point at which there is an interval to the right of $y$ on which $f$ is smaller than $f(x)$, there is some $a < y$ so that for $u \in (a,y)$ we have $f(u) > f(x)$. These choices of $a$ and $b$ witness that $y \in Y_{+-}$. $\maltese$
We now reverse the above analysis. That is, again possibly restricting to a coinitial interval we may assume to for each $x \in J$ there is some $y \in J$ with $y < x$ and $f(y) < f(x)$. As above, it follows that we may define $$G(x) := \{ y \in J : y < x ~\&~ (\exists a < y)(\forall u) [a < u < y \to f(u) < f(x) ] \}$$ always obtaining a nonempty definable set. We set $\alpha(x) := \sup G(x)$ and see that there is a cointial interval $K$ in the range of $K$. As with Claim 3, we see that $K \subseteq Y_{-+}$ where $$Y_{-+} := \{ y \in I : (\exists z)(\exists a < y)(\exists b > y)(\forall u)(\forall v)(a < u < y < v < b \to [f(u) < z ~\&~ f(v) > z]) \}$$
However, $K \subseteq Y_{+-}$ and $Y_{+-} \cap Y_{-+} = \varnothing$. With this contradiction we conclude. $\Box$
To finish the proof of the Monotonicity Theorem we need only prove Lemma 3.
Proof of Lemma 3: Without loss of generality, we may assume that $f$ is strictly increasing. The argument for the case where $f$ is strictly decreasing is essentially the same with the inequalities reverses.
Since $f:I \to R$ is strictly increasing, it is, in particular, injective and its range is definable and infinite, and, thus, contains an interval $J$. Let $x \in f^{-1} J$ and consider $\epsilon_1 < f(x) < \epsilon_2$. Let $\epsilon_1′ \in J$ and $\epsilon_2′ \in J$ with $\epsilon_1 < \epsilon_1′ < f(x) < \epsilon_2′ < \epsilon_2$. Let $\delta_1 := f^{-1} (\epsilon_1′)$ and $\delta_2 := f^{-1} (\epsilon_2′)$. Then for $u \in (\delta_1,\delta_2)$ because $f$ is strictly increasing, we have $\epsilon_1 < \epsilon_1′ = f(\delta_1) < f(u) < f(\delta_2) = \epsilon_2′ < \epsilon_2$. Thus, $f$ is continuous on $f^{-1} J$, which being an infinite definable subset of $R$ contains an interval. (In fact, it is an interval itself.) $\maltese$