$f$ function with $\nabla f=\bar{0}$ Let $f:D\subset\mathbb{R}^2\rightarrow\mathbb{R}$ be a function with $D$ open and connected set such that $\nabla f=\bar{0}$ for all $x\in D$ Proof that $f$ is a constant function.
Hi! I have some problems with this exercise. I think that I have the proof, but, in this, I never use the fact that $D$ is a  connected  set. Can anyone help me? Please.
My proof:
First, since $\nabla f=\left(\displaystyle\frac{\partial f}{\partial x},\displaystyle\frac{\partial f}{\partial y} \right)=(0,0)$, then, $\displaystyle\frac{\partial f}{\partial x}=0$ and $\displaystyle\frac{\partial f}{\partial y} =0$. Hence, the partial derivatives are bounded, i.e., there exist a $K,M\in\mathbb{R}^{+}$ such that $\left|\displaystyle\frac{\partial f}{\partial y}  \right|\leq K$ and $\left|\displaystyle\frac{\partial f}{\partial x}  \right|\leq M$ (I think that anything $K$ and $M$ it works, because the partial derivatives are $0$).
Now let $a = (a_1,a_2)$ and $b = (b_1,b_2) \in D$. Then we have:
\begin{align*}
f(a) - f(b) &= f(a_1,a_2) - f(b_1,b_2)
\\
f(a)-f(b) &= f(a_1,a_2) - f(a_1,b_2) + f(a_1,b_2) - f(b_1,b_2)
\end{align*}
Then, by the triangle inequality:
$$|f(a)-f(b)| \leq |f(a_1,a_2) - (a_1,b_2)| + |f(a_1,b_2) - f(b_1,b_2)|$$
And since the partial derivatives exist, we can use the one-dimensional Mean Value Theorem to show that there exists some $c$ such that:
$$\frac{f(a_1,a_2)-f(a_1,b_2)}{a_2-b_2} = \displaystyle\frac{\partial f}{\partial y}(a_1,c)$$
And noting how we defined $K$, it follows that
$$|f(a_1,a_2) - f(a_1,b_2)| \leq K|a_2 - b_2|$$
And similarly
$$|f(a_1,b_2) - f(b_1,b_2)| \leq M |a_1-b_1|$$
And using the statement we got from the triangle inequality, we have that
$$|f(a)-f(b)| \leq M|a_1-b_1| + K|a_2 - b_2|$$
And by the Cauchy-Schwarz inequality, we have that
$$M|a_1-b_1| + K|a_2 - b_2|
\leq 
\sqrt{M^2 + K^2}\cdot
\sqrt{(a_1-b_1)^2+(a_2-b_2)^2}
=
\sqrt{M^2 + K^2} \cdot
||a-b||$$
Whereby
$$|f(a)-f(b)| \leq \sqrt{M^2 + K^2} \cdot ||a-b||$$
So $f$ is Lipschitz with $L = \sqrt{K^2 + M^2}$.
Hence, the function is continuous. But, $M=K=0$ works, we can consider $L=0$ and the nex equality $$0\leq|f(a)-f(b)| \leq 0$$Then $|f(b)-f(a)|=0$ and we can conclude that $f(b)=f(a)$ for all $a,b\in D$. Then, the function is constant. But, in the proof, I never used the connected of $D$. Where is the wrong? Can anyone help me? Thanks. 
 A: Suppose $\nabla f=\left(\displaystyle\frac{\partial f}{\partial x},\displaystyle\frac{\partial f}{\partial y} \right)=(0,0)$. 
$$
\frac{\partial f}{\partial x} = 0 \quad \Rightarrow \quad f(x,y)=A+g(y),
$$
where $A\in \mathbb{R}$ and $g:\mathbb{R}\rightarrow \mathbb{R}$. Note that this only holds if $D$ is connected; e.g., if you consider 
$$f:]0,1[\cup ]1,2[\times \mathbb{R}\rightarrow  \mathbb{R} \\(x,y)\mapsto\lfloor x \rfloor$$ it satisfies $\frac{\partial f}{\partial x} = 0$ but is not constant.
Then, we have $\frac{\partial f}{\partial y} =0= g'(y)$, therefore 
$
g(y)=B \in \mathbb{R}
$.
In summary
$$
f(x,y)=A+B\in \mathbb{R}
$$
A: Your application of the mean value theorem is not always valid as there is no reason why all the points on the line between $(a_1,a_2)$ and $(a_1,b_2)$ has to be in $D$. To close this loophole you need to use the missing ingredient. If $a,b\in D$ then since $D$ is connected we know there exists a smooth curve (see e.g. this answer) $\gamma(t):[0,1]\to D$ such that $\gamma(0) = a$ and $\gamma(1) = b$. You can now apply the mean value theorem to the function $g:[0,1]\to\mathbb{R}$ given by $g(t) = f(\gamma(t))$ to get the desired result:
$$f(b) - f(a) = g(1) - g(0) = g'(c) = \nabla f(\gamma(c))\cdot \gamma'(c) = 0$$
Also it's not stated that $f$ is differentiable, but since all partial derivatives $\nabla_i f = 0$ is continuous and $D$ is open this is guaranteed for all points in $D$ (see e.g. this question).
