# Does $\dfrac{d}{dx} f(x) = 0 \Rightarrow f(x)$ is a constant function?

I've heard this claim many times, that when the derivative of a function is $$0$$ everywhere in its domain, then that function is a constant function.

But what about functions like the following two:

$$f : (4,6)\cup (6,7) \to \mathbb{R}$$

$$f(x) = \begin{cases} 2, \, x \in (4,6) \\ \\ 7, \, x \in (6,7) \end{cases}$$

Here, $$f'(x) = 0, \, \forall x \in D_f$$, where $$D_f$$ stands for domain of $$f$$.

I'm writing this after I read the proof of something similar to it in this question here:

If the derivative of a function is zero, is the function a constant function?

• A similar situation occurs when students try to solve for $f:\mathbb{R}_{\neq 0}\to \mathbb{R}$ satisfying $$f'(x)=\dfrac{1}{x}$$ for all $x\in\mathbb{R}\setminus\{0\}$. They like to say $$f(x)=\ln|x|+\text{constant}\,.$$ In fact, this is false. What is true is $$f(x)=\ln|x|+K(x)\,,$$ where $K:\mathbb{R}_{\neq 0}\to \mathbb{R}$ is constant on $(-\infty,0)$ and on $(0,+\infty)$ (but not necessarily the same constant). That is, $K$ is locally constant in $\mathbb{R}_{\neq 0}$, as Kusma explains. Sep 26, 2018 at 11:08

When the derivative is zero everywhere in an open set $$S$$, the function is locally constant in $$S$$. If the set $$S$$ is connected, that implies the function is constant. If the set is not connected, then there are examples of locally constant functions that are not constant.
The claim you cited is only true if the domain $$D_f$$ is connected. The set $$(4,6)\cup (6,7)$$ is not connected.
No. If $$f'(x)=0$$ on an interval I, then $$f$$ is constant on the interval I.
If $$f'(x)=0$$ on another interval J, then $$f$$ is constant on the interval J, but $$f$$'s value on $$J$$ might not be the same as f's value on $$I$$.