If the derivative is 0, prove $f$ is constant without connectedness Given a continuous function $f$: U $\to\mathbb{R}$ where U is an open subset of $\mathbb{R}^n $and suppose that $\nabla $$f$ =0, it is well known that if U is connected then $f$ is constant, and connectedness of U is necessary, for example, if U=(0,1)$\cup $(1,2), define $f$ to be 1 on (0,1) and 0 on (1,2), then$ \nabla $$f$=0 on U but $f$ is not constant. My question is that without the connectedness of U and instead if we add another condition that $f$ is 0 on$ \partial$U and that $f$ is continuous on $\bar{U}$, does $f$ constant on U now? I think this is correct and managed to give a proof of this and I want to know if my result and the proof is right. Any comment is appreciated and thank you all in advance!
Here is my proof:
we first suppose U is connected then $f$ is constant on U,say, $f$$\equiv a$. Since $f$ is continuous near $\partial$U, $a$ must be 0. Next observing that U is locally connected, the boundary of a connected component is in fact contained in the boundary of U.Thus $f$ is 0 on the boundary of a connected component of U, so by the first step, $f$ is 0 on a connected component. Finally, if U is not connected, we can write U as a union of its connected components, and since $f$ is 0 on every connected component of U,  $f$ is 0 on U.
One objection could be that if $U$ does not have a boundary. Think of $(0,1) \cup (2,3)$ as a subset of the topological space $(0,1) \cup (2,3)$. Then you counterexample works, but your proof does not. Although
I admit it is a bit pathological.
One objection could be that if $U$ does not have a boundary. Think of $(0,1) \cup (2,3)$ as a subset of the topological space $(0,1) \cup (2,3)$. Then you counterexample works, but your proof does not. Although
I admit it is a bit pathological.