Integral of a real function giving a complex result

Why, when I compute the following integral $$\int_{0}^{\alpha}dx\int_{0}^{\alpha}dy\frac{\ln|x-y|}{\sqrt{(\alpha-x)(\alpha-y)}}$$ for $$\alpha>0$$, by executing the following:

Assuming[α > 0,
FullSimplify[
Integrate[
Log[Abs[x - y]]/Sqrt[(α - x) (α - y)], {x,
0, α}, {y, 0, α}]]]


do I get the complex-valued answer:

4 α (-3 + I π + Log[4] + Log[α])


The integrand is real-valued, so surely the integral must be too?! I believe the answer should be $$4\alpha(\ln(\alpha)+2\ln(2)-3)$$.

Thanks in advance for any help.

• Using the simplification to remove Abs that others have posted, and changing variables with x,y --> alf-x,alf-y converts this to something quite tame from the point of view of symbolic integration: In[186]:= 2*Integrate[Log[x - y]/Sqrt[x*y], {x, 0, alf}, {y, 0, x}, Assumptions -> alf > 0] // Simplify Out[186]= 4 alf (-3 + Log[4] + Log[alf]) Commented Feb 21, 2022 at 18:48

f[x_, y_, α_] = Log[Abs[x - y]]/Sqrt[(α - x) (α - y)];


The singularity at x == y is a difficulty for Integrate.

Plot3D[f[x, y, 3], {x, 0, 3}, {y, 0, 3}]


Since f[x, y, α] == f[y, x, α] // Simplify  is True

Assuming[α > 0,
2*Integrate[
Log[Abs[x - y]]/Sqrt[(α - x) (α - y)], {x,
0, α}, {y, x, α}]]//Timing

(* {0.765, 4 α (-3 + Log[4] + Log[α])}   *)

• The usage of symmetry (by hand) shortens the execution to 7.09958 s from 137.817 s. Commented Feb 21, 2022 at 17:54
• @user64494 0.765 seconds on version 8.0 Commented Feb 21, 2022 at 17:56
• My comp is not strong. Commented Feb 21, 2022 at 17:59
• Mine is i7-4790 not the newest one. Think difference in versions. Commented Feb 21, 2022 at 18:01
• Interestingly, using the lower triangular region (bounds {y,0,x}) gives the erroneous complex result. Commented Feb 22, 2022 at 1:45
$Version (* "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)" *) Clear["Global*"]  With v13.0.1 the integral doesn't evaluate fully f1[x_, y_] = Log[Abs[x - y]]/Sqrt[(α - x) (α - y)]; int1 = Assuming[α > 0, Integrate[f1[x, y], {x, 0, α}, {y, 0, α}]]  However, since the argument of Abs is real, then f2[x_, y_] = Log[Abs[x - y]]/Sqrt[(α - x) (α - y)] /. Abs[t_] :> Sqrt[t^2]; int2 = Assuming[α > 0, Integrate[f2[x, y], {x, 0, α}, {y, 0, α}]] (* 4 α (-3 + Log[4] + Log[α]) *)  Or, f3[x_, y_] = Log[Abs[x - y]]/Sqrt[(α - x) (α - y)] /. Abs :> RealAbs; int3 = Assuming[α > 0, Integrate[f2[x, y], {x, 0, α}, {y, 0, α}]] (* 4 α (-3 + Log[4] + Log[α]) *)  • Looks as a regression in 13.1 comparing with 13.0.0. Commented Feb 21, 2022 at 17:58 In these cases, I sometimes throw in seemingly extraneous assumptions: Integrate[ Log[Abs[x - y]]/Sqrt[(α - x) (α - y)], {x, 0, α}, {y, 0, α}, Assumptions -> α > x > 0 && α > y > 0] (* 4 α (-3 + Log[4] + Log[α]) *)  This is twice as fast (and risky): Integrate[Log[Abs[x - y]]/Sqrt[(α - x) (α - y)], {x, 0, α}, {y, 0, α}, Assumptions -> α > x > 0 && α > y > 0, GenerateConditions -> False]  The difference between the OP's code and my first code is that while α > 0 implies α is real, because inequalities imply the terms are real in Mathematica, {x, 0, α} does not imply x is real. The integration may take a complex path between two numbers that happen to be real, and Integrate tries to deal with that. (GenerateConditions -> False turns off some of the checking, and therefore it shortens the computation.) Now, I don't know the internal workings well enough to know what I've said is actually why the computation works (e.g., whether any component of the computation ever uses the assumption that x is real under α > x > 0 and does not assume x is real under the OP's assumption). This is not a hard-and-fast rule, either: consider Integrate[1/x, {x, -1, I, 1}] with and without the I, and apparently, sometimes x treated to be real. I do know that this trick has worked for me before, and this is how I explain it to myself so that I might remember to use the trick when I get an unexpected complex result. It could be that some component of the calculation fails to add the condition that x as real, but adding thus, Assumptions -> α > 0 && {x, y} \[Element] Reals, fixes the problem (this works, too, but I like the more stringent version, just in case). All I know, as I just said, is that this works sometimes and is worth trying. In 13.0.0 on Windows 10 FullSimplify[Integrate[Log[Abs[x - y]]/Sqrt[(\[Alpha] - x) (\[Alpha] - y)], {x, 0, \[Alpha]}, {y, 0, \[Alpha]}, Assumptions -> \[Alpha] > 0]]  4 \[Alpha] (-3 + Log[4] + Log[\[Alpha]]) It takes a few minutes. The same result without FullSimplify. • It should be noticed the integral under consideration exists for$\alpha<0\$ too. The command Integrate[ Log[RealAbs[x - y]]/Sqrt[(\[Alpha] - x) (\[Alpha] - y)], {x, 0, \[Alpha]}, {y, 0, \[Alpha]}, Assumptions -> \[Alpha] > -Infinity, GenerateConditions -> True] results in $$\begin{array}{cc} \{ & \begin{array}{cc} -4 \alpha (\log (-4 \alpha )-3) & \alpha <0 \\ 4 \alpha (\log (\alpha )-3+\log (4)) & \alpha >0 \\ \end{array} \\ \end{array} .$$ Commented Feb 21, 2022 at 17:12
• I use version 12.0. Is this therefore a bug that has since been fixed? Commented Feb 21, 2022 at 17:13
• @Chris: As you see. I prefer Assumptions over Assuming and RealAbs over Abs. Commented Feb 21, 2022 at 17:16
• but why should that make any difference to the answer? Commented Feb 21, 2022 at 17:20
• @Chris: In 13.0.0 Assuming[\[Alpha] > 0, Integrate[ Log[Abs[x - y]]/Sqrt[(\[Alpha] - x) (\[Alpha] - y)], {x, 0, \[Alpha]}, {y, 0, \[Alpha]}]] produces 4 \[Alpha] (-3 + Log[4] + Log[\[Alpha]])` too. Commented Feb 21, 2022 at 17:34