# Adding assumptions changes the result of Integrate

When I try to calculate the following integral:

Integrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{ϕ, 0, 2 π},
{θ, 0, π},
{αp, 0, 2 π},
{αr, 0, 2 π},
{pr, 0, lp},
{r, 0, lr}
]


Mathematica returns:

$$\frac{16}{9} \pi^2 l_p^3 l_r^3$$

which is what I expected. However, if I calculate the same integral but adding some assumptions:

Integrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{ϕ, 0, 2 π},
{θ, 0, π},
{αp, 0, 2 π},
{αr, 0, 2 π},
{pr, 0, lp},
{r, 0, lr},
Assumptions -> Element[{lr, lp}, Reals] && lr > 0 && lp > 0
]


Mathematica returns:

$$\frac{32}{9} \pi^2 l_p^3 l_r^3$$

If I then try and calculate the integral numerically (by setting lr=lp=1):

NIntegrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{ϕ, 0, 2 π},
{θ, 0, π},
{αp, 0, 2 π},
{αr, 0, 2 π},
{pr, 0, 1},
{r, 0, 1}
]


Mathematica returns: 35.0918

Which is close to

N[(32 π^2)/9]


Then I try to calculate the integral part by part using Mathematica:

Integrate[r^2, {r, 0, lr}]
Integrate[pr^2, {pr, 0, lp}]
Integrate[Abs[Cos[θ]], {θ, 0, π}]
Integrate[
Abs[Sin[αr - αp]],
{αp, 0, 2 π},
{αr, 0, 2 π}
]
Integrate[1, {ϕ, 0, 2 π}]


and I get: $\frac{l_r^3}{3}$, $\frac{l_p^3}{3}$, 2, $8 \pi$ and $2 \pi$ respectively, which will multiply to get $\frac{32}{9} \pi^2 l_p^3 l_r^3$.

Edit

I managed to pinpoint closer to the part of the integral which is exhibiting this weird behaviour:

Integrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{αp, 0, 2 π},
{pr, 0, lp},
{αr, 0, 2 π},
{r, 0, lr},
Assumptions -> Element[{lr, lp}, Reals] && lr > 0 && lp > 0
]


Without Assumptions, it gives $\frac{4}{9} \pi l_p^3 l_r^3 |\cos \theta|$, with Assumptions, it gives $\frac{8}{9} \pi l_p^3 l_r^3 |\cos \theta|$. Using NIntegrate, it gives a result close to $\frac{8}{9} \pi l_p^3 l_r^3 |\cos \theta|$.

Here's a related but simpler problem that shows the same effect:

{Integrate[r Abs[Sin[αr - αp]], {αp, 0, 2 π}, {αr, 0, 2 π}, {r, 0, lr},
Assumptions -> lr > 0],
Integrate[r Abs[Sin[αr - αp]], {αp, 0, 2 π}, {αr, 0, 2 π}, {r, 0, lr}]}

{4 lr^2 π, 2 lr^2 π}


Questions: Does adding these assumptions change the true values of the integrals? In the first integral, if both are not correct, which of the two results is correct? Should this question be tagged with "bugs"?

• @MichaelE2 "Is this a bug or is there an explanation for this behavior?" Apr 30, 2015 at 5:37
• @user29165 My version of Mathematica returns the 32/9 value even without assumptions. All I did was copy your very first snippet and evaluate it. The simpler problem also gives me the same results (4 lr^2 pi) in either formulation. I am on MMA 10.1.0 for Windows 7 64-bit. Are you using a previous version? Maybe a bug was fixed. Apr 30, 2015 at 5:54
• @SjoerdC.deVries That is a reasonable presumption based on the on the observations. I may have been tired, but it is an assumption and I've found that people are sometimes more interesting than I assume. It seems to me there are other ones. Having a clearly stated question seemed desirable. I'll just add some myself. Apr 30, 2015 at 11:17
• I think the first result is bug, and occurs in V9.0.1 (possibly earlier), and has been fixed in V10.1 (or earlier). May 31, 2015 at 2:51

In V10.1, I get the same things for both symbolic integrals, with and without the assumptions:

Integrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{ϕ, 0, 2 π}, {θ, 0, π}, {αp, 0, 2 π}, {αr, 0, 2 π}, {pr, 0, lp}, {r, 0, lr}]
(*
32/9 lp^3 lr^3 π^2
*)

Integrate[
r^2 pr^2 Abs[Cos[θ]] Abs[Sin[αr - αp]],
{ϕ, 0, 2 π}, {θ, 0, π}, {αp, 0, 2 π}, {αr, 0, 2 π}, {pr, 0, lp}, {r, 0, lr},
Assumptions -> Element[{lr, lp}, Reals] && lr > 0 && lp > 0]
(*
32/9 lp^3 lr^3 π^2
*)


This is kind of interesting.

Integrate[Abs[Sin[αr - αp]], {αp, 0, 2 π}], Assumptions -> {0 <= αr <= 2 π}]

FullSimplify[Integrate[Abs[Sin[αr - αp]], {αp, 0, 2 π}],
Assumptions -> {0 <= αr <= 2 π}]]


I guess that it doesn't handle all those Booles when it doesn't have your assumptions.