Assumptions and Conditions in Integrate Function in Mathmatica

I was trying to Integrate the gravitational potential at r = x produced by a uniform sphere positioned at the origin. I wrote the following code:

potentialOfSphere[x_] = Integrate[
Integrate[
Integrate[
-m/(4/3 Pi r^3)*g/Sqrt[(x-r1 Cos[ϕ])^2+(r1 Sin[ϕ])^2]*r1^2 Sin[ϕ],
{ϕ, 0, Pi}],
{θ, 0, 2 Pi}], {r1, 0, r}, Assumptions -> {x > 0, r > 0}]


The output on my computer is:

Based on my understanding, the second solution should only appear when x < r. Why does Mathematica skip that condition? Moreover, in the assumptions in my code, I already specified that x > 0, why does Mathematica still keep the x <= 0 condition in the first solution?

• The second solution does only appear when x<r. Because if that was not so, the condition for the first solution would be satisfied. AFAIK, the option Assumptions does not mean "give solutions restricted to a specific domain", rather it prevents the output of long constructions with ConditionalExpression. I'd be hard pressed to elaborate further though. – LLlAMnYP Mar 13 '15 at 22:02
• @LLlAMnYP Thank you! I understand why won't it work now. Is there any way to let Mathematica to give solutions restricted to a specific domain? – fanmingyu212 Mar 13 '15 at 22:08
• I can direct you to the documentation for Refine, but I'm afraid, I can't test this out myself right now, as I don't have Mathematica at home. – LLlAMnYP Mar 13 '15 at 22:21
• FYI your Assumptions only apply to the outermost Integrate. Try setting \$Assumptions (or better make it one triple integral). (cant test here,,) Also if all else fails you can wrap the whole thing in Simplify with your assumptions as an argument. – george2079 Mar 13 '15 at 23:32
• @LLlAMnYP Thanks! I found Refine function really helpful. – fanmingyu212 Mar 14 '15 at 0:10

potentialOfSphere[x_] = Integrate[
-m/(4/3 Pi r^3)*g/Sqrt[(x - r1 Cos[ϕ])^2 +
(r1 Sin[ϕ])^2]*r1^2 Sin[ϕ],
{r1, 0, r}, {θ, 0, 2 Pi}, {ϕ, 0, Pi},
Assumptions -> {x > 0, r > 0}]


(gm(-2*r^3 + (r - x)^2*(2*r + x)* HeavisideTheta[r - x]))/ (2*r^3*x)

For x > r, this reduces to

potentialOfSphere[x] // Simplify[#, x > r] &


-((g*m)/x)

For x < r, this reduces to

potentialOfSphere[x] // Simplify[#, r > x] &


(gm(-3*r^2 + x^2))/(2*r^3)

For x == r

potentialOfSphere[r]


-((g*m)/r)