Integration by parts in $\mathbb{R}^n$ Let $U \subset \mathbb{R}^n$ be open. Let $f \colon U \to \mathbb{R}$ be a function of class $C^1$, and let $\phi\colon U \to \mathbb{R}$ be a function in $C_c^\infty (U)$.  Is it true that $$\int\limits_U f(x)\partial_i\phi(x)\ dx = -\int\limits_U \partial_i f(x) \phi(x)\ dx$$ for every $i$? 
 A: This is a consequence of Fubini's theorem and the usual integration by parts in $\mathbb R.$ To simplify notation assume $i = n,$ and write $x = (x',x_n) \in \mathbb R^n = \mathbb R^{n-1} \times \mathbb R$ (the general case follows by interchanging coordinates using Fubini).
Observe that as $\varphi \in C^{\infty}_c(U),$ we have $f \partial_{x_n}\varphi \in C^1_c(\mathbb R^n)$ extending by zero (this is okay as $\varphi$ vanishes in a neighbourhood of $\partial U$). Hence we have,
\begin{align*}
  \int_U f(x)\partial_{x_n}\varphi(x) \,\mathrm{d} x &= \int_{\mathbb R^n} f(x)\partial_{x_n}\varphi(x) \,\mathrm{d}x \\
  &= \int_{\mathbb R^{n-1}} \int_{\mathbb R} f(x',x_n) \partial_{x_n}\varphi(x',x_n) \,\mathrm{d}x_n \mathrm{d}x' \\
  &= \int_{\mathbb R^{n-1}} \left( - \int_{\mathbb R} \partial_{x_n}f(x',x_n)\varphi(x',x_n) \,\mathrm{d}x_n\right)\mathrm{d}x' \\
  &= - \int_U \partial_{x_n}f(x) \varphi(x)\,\mathrm{d}x.
\end{align*}
Here we have used Fubini in the second line and the fact that,
$$ \int_{\mathbb R} f(x',x_n) \partial_{x_n}\varphi(x',x_n) \,\mathrm{d}x_n =  - \int_{\mathbb R} \partial_{x_n}f(x',x_n)\varphi(x',x_n) \,\mathrm{d}x_n $$
for all $x' \in \mathbb R^{n-1}$ by integrating by parts, noting the boundary term vanish since $\varphi$ has compact support.
A: You can also apply the divergence theorem to the vector field
$$
u(x)=e_i f(x)\phi(x)
$$
Then, the divergence becomes
$$
\nabla \cdot u(x)=\phi(x) \partial_i f(x)+f(x)\partial_i \phi(x)
$$
Then, for any compact set $K \subset U \subset \mathbb{R}^n$ such that $supp(\phi) \subseteq K$ :
$$
0=\int_{\partial U}u(x)\cdot n\;  dS=\int_U \nabla \cdot u(x)dx=\int_U \phi(x) \partial_i f(x)+f(x)\partial_i \phi(x) dx
$$
Since $u$ has zero boundary values since $\phi$ has 0 boundary values. Rearranging gives the result.
However, you need your boundary to be somewhat smooth. Else the theorem wont hold. I finished this answer before noting this missing requirement; I will just leave it up for now.
