Function where changing the order of integration is not allowed Recently on this forum there was a question by a student whether changing the order of integration in the $2D$ or $3D$ case is --in principle-- allowed, and if so under which conditions. In the comments a discussion developed in which an expert stated that changing the order is in most cases not allowed. He supported his claim with the following "easy example" of such a function:
$$f(x,y) = xy(x^2 - y^2)/(x^2 + y^2)^3$$
I was surprised. Obviously in the origin the function displays non-analytic behaviour: its value is both divergent and not uniquely defined. On the other hand, in the rest of the $xy$-plane the function is well-behaved. So let us try to integrate the function over a rectangle, for $x$ from $P$ to $Q$ and for $y$ from $R$ to $S$. The rectangle is not nearby the origin. Performing the double integration over $x$ and $y$ is straightforward, and we obtain the following primitive $F$:
$$F(x,y) = (1/8) * (x^2 - y^2)/(x^2 + y^2)$$
We note that $F$ is also not analytic in the origin, but much milder than $f$. The value of $F$ varies here between $-1/8$ and $+1/8$, depending on the path towards the origin. If we assume that $x$ and $y$ are equivalent coordinates, we may postulate that the appropriate value for $F$ equals zero in the origin. One may now simply assign this value: $F(0,0) = 0$. A physicist will presumably choose a different approach and write:
$$F(x,y) = (1/8) * (x^2 - y^2)/(x^2 + y^2 + a^2)$$
in which $a$ is a small parameter. This method has the advantage that $F$ is smooth in the region directly around the origin. Hence it is well-behaved everywhere. We can differentiate with respect to $x$ and $y$, giving:
$$f(x,y) = xy(x^2 - y^2)/(x^2 + y^2 + a^2)^3$$
This function is analytic everywhere, so we can integrate it without the need to pay attention to the order.
My conclusion is that the function $f$ as it was presented has actually more to do with non-analytic behaviour in the origin, than with the question whether the order of integration can be changed. Furthermore a scientist who works with $f$ can easily identify the problem and apply a cure, after which the (improved) function is analytic and questions about the order of integration vanish.
Is my conclusion correct?
 A: In this case the integrand is continuous on any closed rectangle that does not contain the origin, and as you say the iterated integrals taken in any order will be the same.
Fubini's theorem gives a sufficient condition for
$$\int_a^b \int_c^d f(x,y) \, dx \, dy = \int_a^b \int_c^d f(x,y) \, dy \, dx,$$
even if $f$ is discontinuous or unbounded.  The requisite condition is that $f$ be Lebesgue integrable or that the improper multiple Riemann  integral of $|f|$ converges, that is
$$\tag{*}\int_a^b \int_c^d |f(x,y)| d(x,y) < \infty$$
Bear in mind that the integral in (*) is the integral with respect to the product measure -- which is not the same thing as the iterated integral.
In this case, Fubini's theorem does not apply due to a non-integrable singularity at the origin.   However, the presence of a singularity  is not, in general,  sufficient to preclude changing the order of integration.
The integrand is not absolutely integrable on $[0,1]^2$, as  can be seen by
$$\int_0^1 \int_0^1 \left|\frac{xy(x^2-y^2)}{(x^2+y^2)^3}\right| d(x,y) > \int_0^{\pi/2}\int_0^1 \frac{r^4 |\cos \theta \sin \theta(\cos^2 \theta - \sin^2 \theta)|}{r^6} r\, dr\, d\theta \\= \int_0^1 r^{-1} \, dr \int_0^{\pi/2}|\cos \theta \sin \theta(\cos^2 \theta - \sin^2 \theta)|r\, d\theta= \infty$$
A: The standard way is to invoke Fubini-Tonelli Theorem. Clearly $f:\mathbb{R}^{2}\setminus\{0\}\rightarrow\mathbb{R}$
is measurable. Firstly, we go to check that $\int|f|dm_{2}<\infty$.
Note that by Tonelli Theorem, we always have $\int|f|dm_{2}=\int\left(\int|f(x,y)|dx\right)dy=\int\left(\int|f(x,y)|dy\right)dx$,
regardless whether the integral is finite or not. If the integral
is finite, we say that $f$ is (Lebesgue) integrable. If $f$ is integrable,
Fubini theorem is applicable and we have $\int fdm_{2}=\int\left(\int f(x,y)dx\right)dy=\int\left(\int f(x,y)dy\right)dx$.
Hence, to ensure that the double-integral can be calculated as repeated
integral (and the order of integration can be swapped), one needs
to check that $|f|$ is integrable.
