# Example of a smooth function with zero derivative that is not constant

One of false beliefs in this question on Math Overflow is "If f is a smooth function with df=0, then f is constant". What is a counterexample to this statement? Can it be made correct by adding some restriction, e.g. that f is a function from reals to reals?

-
This is described in the comments; f need only be locally constant, so as a counterexample take f : (0, 1) cup (2, 3) to R which is equal to 0 on the first component and 1 on the second. It is certainly true for functions from R to R, for example by the mean value theorem. – Qiaochu Yuan Dec 9 '10 at 9:46
@Qiaochu - meh, I was thinking that I missed something fundamental, and that the counter example will be more interesting. You should have posted this as an answer. – ripper234 Dec 9 '10 at 10:00
If you're working in the complex numbers, there are many examples of non-holomorphic functions which are nonconstant but have zero derivative (at least in some sense). – Marra Sep 15 '13 at 3:38

This is described in the comments; $f$ need only be locally constant, so as a counterexample take $f : (0, 1) \cup (2, 3) \to \mathbb{R}$ which is equal to $0$ on the first component and $1$ on the second. It is certainly true for functions from $\mathbb{R}$ to $\mathbb{R}$, for example by the mean value theorem.