When does $\frac{\partial f}{\partial y} =0$ imply $f(x,y)=g(x)$? Let $U\subseteq\mathbb R^2$ be an open subset and $f:U\to\mathbb R$ a continuously differentiable function such that $$\forall (x,y)\in U:\frac{\partial f}{\partial y} =0.$$
Which conditions must $U$ and $f$ fulfill for $f$ to be a function in $x$ only, i. e. $\exists g:\mathbb R\to\mathbb R\forall (x,y)\in U:f(x,y)=g(x)$?
I was thinking about $U$ having to be connected, because elsewise we could have something like $U=\left\lbrace (x,y)\in\mathbb R^2\mid y<1\vee y>2\right\rbrace$ and define $f$ as $$f(x,y)=\begin{cases}x,&y<1\\2x,&y>2\end{cases}$$ which would make the partial derivative with respect to $y$ equal to zero without $f$ being independent of $y$.
However, is $U$ being a connected space a sufficient condition? How could I prove that or what would a counterexample look like?
 A: It's not sufficient :) if $U$ is convex, then the theorem is true. For a counterexample, think about the set $$U=[0,1]\times[2,3] \cup [1,2]\times[0,3]\cup[0,1]\times[0,1]=U_1\cup U_2 \cup U_3,$$ it is something like a horseshoe. Now define $$f(x,y)=\left\{
                \begin{array}{ll}
                  \ (x-1)^2 \ \text{if} \ (x,y)\in U_1\\
                  \ 0 \ \text{if} \ (x,y) \in U_2 \\
\ -(x-1)^2 \ \text{if} \ (x,y) \in U_3
                \end{array}
              \right.$$
Now, $U$ is connected, $\ f:U \to \mathbb{R}$ is differentiable but if you restrict $f$ to $Int(U),$ which is also connected, it follows every hypothesis but doesn't follow the thesis :). 
A: Here I make a proof of the theorem with the hypothesis of convexity.
If you use the "directional mean value theorem", you obtain that $\forall \ z_1=(x,y), \ z_2=(x,y') \in U,$ the line segment $\gamma$ between $z_1$ and $z_2$ is totally contained in $U.$ So, you have that $$f(x,y)-f(x,y')=(y'-y) \ \partial_yf(x,c_{y,y'})=0,$$ where $c_{y,y'} \in (y,y'),$ which means that $f(x,y)=f(x,y')=g(x).$
