Let $S$ be an open set in $\mathbb{R}^n$, and let $f \colon S \to \mathbb{R}$ be a scalar field such that all the partial derivatives $D_1 f (\mathbf{a}), \ldots, D_n f (\mathbf{a})$ exist for all points $\mathbf{a} \in S$.
If the gradient $\nabla f(\mathbf{a})$ of $f$ is zero for all points $\mathbf{a} \in S$, then we can show that $f$ is constant on $S$. Am I right?
If we know that the gradient of $f$ is zero on $S$, then we can even show that $f$ is constant on the closure of $S$. Am I right?
Now my question is, if we know that the gradient of $f$ is zero on $S$, then can we conclude that $f$ is constant on some set in $\mathbb{R}^n$ that properly contains the closure of $S$?
What is the most general statement of this sort that could be made?
If $f:\>S\to{\mathbb R}$ has zero gradient on the open set $S\subset{\mathbb R}^n$ the function $f$ is constant on the connected components of $S$. If $S$ is connected then $f$ is constant on $S$. This can be proven as follows: A connected open set $S\subset {\mathbb R}^n$is path connected. Given any two points $p$, $q\in S$ there is a smooth curve $$\gamma:\quad t\mapsto x(t)\qquad(a\leq t\leq b)$$ connecting the two points. Consider the auxiliary function $\psi(t):=f\bigl(x(t)\bigr)\quad(a\leq t\leq b)$. Then $$f(q)-f(p)=\psi(b)-\psi(a)=\int_a^b\psi'(t)\>dt=0\ ,$$ since $\psi'(t)=\nabla f\bigl(x(t)\bigr)x'(t)\equiv0$.
If your $S$ consists of two open touching discs in the plane you cannot even extend $f$ continuously to $\bar S$ if $f\restriction S_1\ne f\restriction S_2$