If $\partial_2 f\equiv 0$ on domain, then $f$ is independent of that variable? 
Let $z=f(x,y)$ be a function of class $C^1(G;\mathbb{R})$.
a) If $\frac{\partial f}{\partial y}(x,y)\equiv 0$ in $G$, can one
assert that $f$ is independent of $y$ in $G$?
b) Under what condition on the domain $G$ does the preceding question
have an affirmative answer?

Sorry if this question has been asked many times but my question is a bit different and it is about part b). But I did not find my question in existing topics.
Part a) The answer is NO because one can consider the following function $f:G\to \mathbb{R}$, where $G=\{(x,y)\in \mathbb{R}^2: 1<x^2+y^2<4,\ x>0\}$ and
$$f(x,y) =
\begin{cases}
0, & \text{if }(x,y)\in G, x\in [1,2), \\
(x-1)^2, & \text{if }(x,y)\in G,\ x\in (0,1),\ y>0, \\
-(x-1)^2, & \text{if }(x,y)\in G,\ x\in (0,1),\ y<0.
\end{cases}$$
It is easy to see that $f$ depends on $y$ since $f(\frac{1}{2},1)\neq f(\frac{1}{2},-1)$ and $\frac{\partial f}{\partial y}\equiv 0$ on $G$.
Part b) I can prove that if $G$ is convex open set in $\mathbb{R}^2$ then the answer to part a) is YES. But I believe that it is true for larger family of sets in $\mathbb{R}^2$. More precisely, if $G\subset \mathbb{R}^2$ is an open nonempty set with connected first projections then the answer to part a) is still YES. Here by connected first projections I mean that if $x\in \pi_1(G)$, then for any $y_1, y_2$ such that $z_1:=(x,y_1)\in G$ and $z_2:=(x,y_2)\in G$ the line segment $[z_1,z_2]:=\{(x,\theta y_1+(1-\theta)y_2):\theta\in [0,1]\}\subset G$. This is a larger class of sets since every convex set has this property.
The proof is relatively easy. Indeed, let $x_0\in \pi_1(G)$, then $\exists y_0: (x_0,y_0)\in G$. Let $y$ be such that $(x_0,y)\in G$ and WLOG $y_0<y$. Consider a function $\varphi:[y_0,y]\to \mathbb{R}$ defined as $t\mapsto f(x_0,t)$. One can check that $\varphi$ is continuous and differentiable on $[y_0,y]$ and by MVT, we have: $\varphi(y)-\varphi(y_0)=\varphi'(c)(y-y_0)=\frac{\partial f}{\partial y}(x_0,c)(y-y_0)=0.$ Therefore, $\varphi(y)=\varphi(y_0)$ which is equivalent to $f(x_0,y)=f(x_0,y_0)$. We have shown that for any $(x,y)\in G$, we have $f(x,y)=f(x,F(x))$, where $F:\pi_1(G)\to \mathbb{R}$ which is defined as: $x_0\mapsto y_0$, where $(x_0,y_0)\in G$. For example, this function $F$ can be constructed by Axiom of Choice. We are done since we have shown that $f(x,y)$ is independent of $y$.
So far I do not see any mistake. Thank you!
 A: Your proof is correct.
Concerning notation I think the wording "connected first projections" may be confusing. It sounds as if the sets $\pi_1(M)$ are connected for certain $M \subset G$, but you mean that all $G_x = L_x \cap G$ are convex, where $L_x = \{x\} \times \mathbb R$ is the vertical line through $(x,0)$. So perhaps it perhaps would be better to say that the projection $\pi_1 : G \to \mathbb R $ has connected fibers $\pi_1^{-1}(x) = G_x$.
Actually you have shown that each $f \in C^1(G;\mathbb R)$ is constant on each connected fiber $\pi_1^{-1}(x)$.
Perhaps one can also omit introducing the function $F$; doesn't it suffice to say that $f$ being independent of $y$ in $G$ means that all $f \mid_{\pi_1^{-1}(x)}$ are constant?
Let us prove a generalization of your result.
Let $D = \{ x \in \mathbb R \mid \pi_1^{-1}(x) \text{ is disconnected}\}$. Note that $D \subset \pi_1(G)$ because $\pi_1^{-1}(x) = \emptyset$ (which is connected) for all $x \notin \pi_1(G)$.
Theorem. Let $G$ be a domain such that $D$ does not have an interior point. Then each $f \in C^1(G;\mathbb R)$ with $\frac{\partial f}{\partial y}(x,y) \equiv 0$ on $G$ is independent of $y$.
Proof. We have to show that if $\xi \in D$, then $f$ is constant on $\pi_1^{-1}(\xi)$. Since $\pi_1(G)$ is an open subset of $\mathbb R$ and $D$ does not have an interior point, we find a sequence $(x_n)$ in $\pi_1(G) \setminus D$ which converges to $\xi$. Let $y_1 y_2 \in \mathbb R$ such that $(\xi,y_i) \in G$. Since $G$ is open, we find $\epsilon > 0$ such that $(\xi-\epsilon,\xi+\epsilon) \times \{y_i\} \subset G$ for $i =1,2$. We have $x_n \in (\xi-\epsilon,\xi+\epsilon)$ for $n \ge n_0$ and may therefore assume w.l.o.g. that all $x_n \in (\xi-\epsilon,\xi+\epsilon)$. Hence
$$f(\xi,y_i) = \lim_{n \to \infty} f(x_n,y_i). $$
But $f(x_n,y_1) = f(x_n,y_2)$ since the fibers $\pi_1^{-1}(x_n)$ are connected, hence $f(\xi,y_1) = f(\xi,y_2)$.
We can also generalize your counterexample.
Theorem. Assume that there exists a closed interval $[a,b]$ with $a < b$ such that

*

*$G_{a,b} = G \cap \left( [a,b] \times \mathbb R \right)$ has the form $G_{a,b} = G_1 \cup G_2$ with disjoint $G_i$ which are relatively open in $G_{a,b}$.

*There exist $x_0 \in (a,b)$ and $y_1,y_2 \in \mathbb R$ such that $(x_0,y_i)  \in G_i$.

Then there exists $f \in C^1(G;\mathbb R)$ with $\frac{\partial f}{\partial y}(x,y) \equiv 0$ on $G$ which is not independent of $y$.
Proof. Choose a differentiable function $\phi : \mathbb R \to \mathbb R$ such that $\phi(a) = \phi(b) = 0$, $\phi'(a) = \phi'(b) = 0$ and $\phi(x_0) = 1$. Then
$$f : G \cap\left( [a,b] \times \mathbb R \right) \to \mathbb R,f(x,y) = \begin{cases} \phantom{-}\phi(x) & (x,y) \in G_1 \\ -\phi(x) & (x,y) \in G_2 \\ \phantom{-\phi(}0 & (x,y) \in G \setminus \left( (a,b) \times \mathbb R \right) \end{cases}$$
is a well-defined differentiable function with $\frac{\partial f}{\partial y}(x,y) \equiv 0$ on $G$, but $f(x_0,y_1) > 0$ and $f(x_0,y_2) < 0$.
Remark.
If $f$ is indepedent of $y$, we can define
$$\bar f : \pi_1(G) \to \mathbb R, \bar f (x) = f(x,y) \text{ with any } y \in \pi^{-1}(x) .$$
Note that $\pi_1(G)$ is an open subset of $\mathbb R$ and that $\psi = \bar f$ is the unique function such that $f = \psi \circ \pi_1$.
There is no need to work with a "selection function" $F : \pi_1(G) \to \mathbb R$ having the property $(x,F(x)) \in G$ for all $x \in \pi_1(G)$. Such functions always exist by the Axiom of Choice, but in general there is no continuous selection function (let alone an $F \in  C^1(\pi_1(G),\mathbb R)$). But locally we can of course take constant selection functions. In fact, for each $(x_0,y_0) \in G$  there exist $\epsilon > 0$ such that $(x_0-\epsilon,x_0+\epsilon) \times \{y_0\} \subset G$. Then clearly $(x_0-\epsilon,x_0+\epsilon) \subset \pi_1(G)$ and $F : (x_0-\epsilon,x_0+\epsilon) \to G, F(x) = (x,y_0)$, is well-defined.
Using such a constant local selection, the chain rule shows that $\bar f$ is $C^1$ on $(x_0-\epsilon,x_0+\epsilon)$.
Therefore $\bar f \in C^1(\pi_1(G),\mathbb R)$.
