Do functions with the same gradient differ by a constant? Let $f,g:\mathbb{R}^n\to\mathbb{R}$ be such that  $\nabla f=\nabla g$.
I believe this implies that $f$ and $g$ only differ by a constant, like in the one-dimensional case. But I'm not sure how to prove it. If it's indeed true, can you give me a hint?
Thanks!
 A: If $\nabla f=\nabla g$, then $\frac{\partial f}{\partial x_k}=\frac{\partial g}{\partial x_k}$ for all $k\in\{1,\ldots,n\}$. Thus there exists $c_k(x_1,\ldots,x_{k-1},x_{k+1},\ldots,x_n)$ such that $f=g+c_k$. And, for $l\neq k$, we have
$$ \frac{\partial c_k}{\partial x_l}=0 $$
and thus $dc_k=0$ and $c_k$ is a constant. The value of $c_k$ then does not depend of $k$ since for all $k,l$, $f-g=c_k=c_l$. Thus there exists a constant $c$ such that $f=g+c$.
A: HINT: Integrate both sides of
$df=\frac{\partial f}{\partial x}dx+\frac{\partial f}{\partial y}dy+\cdots= \vec{\nabla f}\cdot \vec{dl}=\vec{\nabla g}\cdot \vec{dl}=dg$
EDIT: As pointed out by @peek-a-boo, this only works if the functions in question have an integrable derivative (so for example a sufficient condition is for $f$ to be $C^1$; i.e continuously differentiable).
A: [Spoiler warning, this is more than a hint. I wanted to show this method because it avoids working with components.]

First suppose that $h:\mathbb R^n \to \mathbb R$ is differentiable and that $\nabla h(x) = 0$ for all $x \in \mathbb R^n$. I'll prove that $h$ is constant. Suppose (for a contradiction) that there exist points $a$ and $b$ in $\mathbb R^n$ such that $h(a) \neq h(b)$. Let $z:[0,1] \to \mathbb R$ be the function defined by
$$
z(t) = h(a + t(b - a)).
$$
Note that $z$ is continuous on $[0,1]$ and differentiable on $(0,1)$ and that $z(0) \neq z(1)$. By the mean value theorem, there exists a number $c$ such that $0 < c < 1$ and
$$
z'(c) = z(1) - z(0) \neq 0.
$$
But, by the chain rule,
$$
z'(c) = \langle \nabla h(a + c(b -a)), b - a \rangle
$$
which is $0$ because we are assuming that $\nabla h(x) = 0$ for all $x$ in $\mathbb R^n$.
This is a contradiction. Therefore $h$ is constant.

Next, to solve the original problem, let $h = f - g$ and apply the above result.
A: Yes that's correct. Solve each ($1$-dimensional) equation $\partial{f}/\partial{x_i} = \partial{g}/\partial{x_i}$
