Does there exist a smooth vector field which is locally the gradient of a function but not globally. Let $v:\mathbb{R}^n\rightarrow\mathbb{R}^n$ be a smooth vector field such that for any $p\in\mathbb{R}^n$ there exists open set $U_p\ni p$ and $f_p:U\rightarrow \mathbb{R}^n$ such that $\nabla f_p = v|_U$. That is to say, locally the vector field can be expressed as the gradient of a function. Does this imply the existence of a global function $f:\mathbb{R}^n\rightarrow\mathbb{R}^n$ st. $\nabla f = v$? If so I'd like a proof, if not, a counter example, and in either case a pointer to a proof/counter example would suffice. Thanks for the help.
 A: Yes.  Thinking of $v$ as a $1$-form rather than a vector field, the condition that $v$ is locally a gradient implies that the exterior derivative $dv$ is $0$.  The Poincaré lemma then says there is a smooth function $f$ such that $v=df$; going back to thinking of $v$ as a vector field, this says that $v$ is the gradient of $f$.
Note that for more general domains, this is false.  For instance, identify $\mathbb{R}^2\setminus\{(0,0)\}$ with $\mathbb{C}\setminus\{0\}$ and let $v$ be the vector field that is locally the gradient of the argument function (which is only defined mod $2\pi$, but if you pick a branch then it is locally a smooth function).  Then $v$ is locally a gradient, but not globally, since there is no global argument function (of course it takes some work to make this rigorous).  More generally, if $U\subseteq\mathbb{R}^n$ is open, the space of vector fields that are locally a gradient modulo the space of vector fields that are globally a vector field is naturally isomorphic to the first cohomology group $H^1(U,\mathbb{R})$ (by the de Rham theorem).
