Making a standard theoretical physics argument rigorous In theoretical physics one often encounters the following rationale:
if $f$ and $g$ are functions on $\mathbf{R}^n$, satisfying some technical conditions, and $\displaystyle\int_\Omega f=\int_\Omega g$ for all open sets $\Omega$, then $f=g$. (For instance, one obtains from Gauss law in "integral form" $\displaystyle\int_\Omega\mathrm{div} \ E = \int_\Omega \rho$ and its "differential form" $\mathrm{div} \ E=\rho$.) 
Now my problem is: I want to know these technical conditions. Of course, it is a seemingly obvious statement, but it disturbs me not to know under what conditions this reasoning is legit. Is there some theorem which answers this question? Of course, I am also happy with a good reference.
 A: I would like to provide a more abstract, measure-theoretic explanation. Of course this is overkill for most physics applications, where the simpler explanation provided by Haskell Curry works perfectly nice. 
Let $(\Omega, \mathcal{F}, \mu)$ be a measure space. We can of course assume that one of the given functions is zero, say $g=0$. We therefore want to find conditions on the integrals of $f\colon \Omega \to \mathbb{R}$ that ensure its vanishing up to a set of measure zero. This last remark is unavoidable as we are really working in a category of functions defined up to "almost-everywhere equivalence", that is, up to sets of measure zero. 
The first statement is pretty simple: if all integrals vanish, then the function itself vanishes.

Lemma If $f\colon \Omega \to \mathbb{R}$ is a measurable function such that 
  $$\int_A f\, d\mu=0,\qquad \forall A \in \mathcal{F}, $$
  then $f=0$ almost everywhere. 

Proof. Consider the positive part $f^+$ of $f$, defined as $f^+(x)=\max(f(x), 0)$. This is a measurable function. Since 
$$\int_{\Omega} f^+\, d\mu= \int_{\{f\ge 0\}} f\, d\mu =0, $$
and since $f^+\ge 0$ almost everywhere, we can conclude that $f^+=0$ almost everywhere. Indeed, we can decompose the set 
$$\left\{f^+> 0\right\}=\bigcup_{n=1}^\infty \left\{f^+\ge \frac{1}{n}\right\},$$
and the sets in the right hand side are all null, because 
$$
0=\int_{\left\{f\ge \frac{1}{n}\right\}}f\, d\mu=\int_{\left\{f^+\ge \frac{1}{n}\right\}}f^+\, d\mu\ge\frac{1}{n}\left\lvert \left\{f^+\ge \frac{1}{n}\right\}\right\rvert.$$
So the condition $f^+(x)>0$ can only hold in a measure zero set. Since $f^+$ is nonnegative, this means that is must vanish almost everywhere, as claimed. The proof that the negative part $f^-$ vanishes is analogous.
$\square$
Of course there is no need to check the vanishing of integrals over all measurable sets. One can do with substantially smaller families of integrals. 

Theorem Suppose that $f\in L^1(\Omega)$ and that $\mathcal{A}\subset \mathcal{F}$ is a family of measurable sets such that 
  
  
*
  
*For every $A\in \mathcal{A}$ it holds that $\int_A f\, d\mu=0$.
  
*$\Omega \in \mathcal{A}$ and $\mathcal{A}$ is a $\pi$-system. 
  
*The sigma-algebra generated by $\mathcal{A}$ (which we denote by $\sigma(\mathcal{A})$) is the whole of $\mathcal{F}$.
  
  
  Then $f=0$ almost everywhere. 

Proof. Define 
$$\mathcal{A}'=\left\{ A'\in \mathcal{F}\ :\ \int_{A'} f\, d\mu=0\right\}.$$
By assumption we have $\mathcal{A}\subset \mathcal{A}'$. So, clearly, 
$$\mathcal{F}=\sigma(\mathcal{A})=\sigma(\mathcal{A}').$$
To conclude we need to show that $\mathcal{A}'$ is a sigma-algebra, which implies that $\mathcal{A}'=\mathcal{F}$ and so the desired conclusion by the Lemma above. Since $\mathcal{A}$ is a $\pi$-system, it will be enough to show that $\mathcal{A}'$ is a $\lambda$-system and then apply the $\pi$-$\lambda$ theorem. We proceed to check the $\lambda$-system properties.
By assumption we have $\Omega \in \mathcal{A}'$. Also, it is immediate that if $A'$ and $B'$ are in $\mathcal{A}'$ and $A'\subset B'$, then 
$$\int_{B'\setminus A'} f\, d\mu=0, $$
that is, $B'\setminus A'\in \mathcal{A}'$. Lastly, if $A_1'\subset A_2'\subset \ldots $ is an expanding family in $\mathcal{A}'$, then
$$\int_{\bigcup_n A_n} f\, d\mu= \lim_{n \to \infty} \int_{\Omega} f\chi_{A_n}\, d\mu =0, $$
by the dominated convergence theorem, which is applicable because $\lvert f\chi_{A_n}\rvert \le \lvert f \rvert \in L^1(\Omega)$. $\square$
This theorem applies to the case at hand because the family of all open sets satisfies properties 1, 2 and 3 above when $\mathcal{F}$ is the sigma-algebra of Borel sets of $\mathbb{R}^n$. Actually, there are not many more families that satisfy those properties and are of practical use. The family of all rectangles is one, but the family of all balls (for which the theorem is true) is not, because it fails on property 2. Indeed, the intersection of two balls needs not being a ball. I guess that property 2 can be  substituted with the following weaker one: 
2$_\mathrm{weak}$. $\Omega\in \mathcal{A}$ and for all $A, B\in \mathcal{A}$ there exists $\varnothing \ne C\in \mathcal{A}$ such that $C\subset A\cap B$. 
A: If you are satisfied with $f=g$ except on a set of measure zero, this is true for all integrable real-valued functions:
For $\epsilon>0$, let $A_\epsilon=\{x\in\mathbf{R}^n:f(x)-g(x)\geq\epsilon\}$. Suppose $\lambda(A_\epsilon)> 0$ for some $\epsilon$. Then $A_\epsilon$ contains an open ball $B(y;\delta)$. It follows
$$\int_{B(y;\delta)}(f-g)\geq\epsilon\cdot\lambda(B(y;\delta))>0,$$
which contradicts the assumptions. So $\lambda(A_\epsilon)=0$ for all $\epsilon>0$. The same can be done with $g-f$ instead of $f-g$. Hence the set $\{x\in\mathbf{R}^n:|f(x)-g(x)|\geq\epsilon\}$ has measure $0$ for any $\epsilon$. This implies that $\{x\in\mathbf{R}^n:|f(x)-g(x)|>0\}$ has measure $0$, e.g. by the monotone convergence theorem.
I'm not sure if the statement is true for complex- or vector-valued functions.
A: If $ f $ and $ g $ are continuous $ L^{1} $-functions, then you can certainly conclude that $ f = g $. We need the $ L^{1} $-condition to ensure that the integrals $ \displaystyle \int_{\Omega} f $ and $ \displaystyle \int_{\Omega} g $ are defined at the very least (especially if you let $ \Omega = \mathbb{R}^{n} $).
Now, suppose that $ \displaystyle \int_{\Omega} f = \int_{\Omega} g $ for all open subsets $ \Omega $ of $ \mathbb{R}^{n} $. Assume, for the sake of contradiction, that $ f \neq g $. Without loss of generality, we may suppose that there exists an $ x \in \mathbb{R}^{n} $ such that $ f(x) < g(x) $. Then by the continuity of $ f $ and $ g $, we can find an open neighborhood $ U $ of $ x $ such that $ f(y) < g(y) $ for all $ y \in U $. It follows readily that $ \displaystyle \int_{U} f < \int_{U} g $, which contradicts our initial hypothesis. The assumption is therefore false, so we conclude that $ f = g $.
