# Does Mathematica have a 'nice' way to evaluate singular double integrals over line segments?

I want to perform a double integration over a line segment in 2D and I am wondering if can it be done in Mathematica. An added difficulty is that the integral is singular.

$$I = \int_{(4,4)}^{(2,8)}\int_{(4,4)}^{(2,8 )} \log|x-y| \,\mathrm{d}y \, \mathrm{d}x.$$

I am not that concerned with efficiency here, I would just like to have a nice way to integrate these types of integrals compared to how I have to do it in Python which involves analytically regularizing them first to deal with the singular integrands and then transformation to reference intervals before finally coding the actual integration.

So can this be done 'nicely' in Mathematica?

Edit My Mathematica code that gives the incorrect answer:

  NIntegrate[
Log[Norm[{x1, x2} - {y1, y2}]],
{x1, x2} ∈ Line[{{4,4},{2,8}}],
{y1, y2} ∈ Line[{{4,4},{2,8}}]
]

• What do the integral limits mean? – Henrik Schumacher Feb 12 '19 at 12:51
• @HenrikSchumacher The limits mean integrate over the straight line segment from the point $[3,3]$ to the point $[2,5]$. – ManUtdBloke Feb 12 '19 at 13:36
• @HenrikSchumacher Actually I just noticed it can be done using the method you used in a previous question I asked here - mathematica.stackexchange.com/questions/190728/… – ManUtdBloke Feb 12 '19 at 13:46
• However it gives me the result: -0.0435146 whereas I get -0.042677 in Python! I get alot of warnings from Mathematica too before it gives me that result and the 'error estimate': 0.008498. – ManUtdBloke Feb 12 '19 at 13:47

Putting the singularities on the boundary of the integration domain makes NIntegrate take care of them. Plus, this utilizes the fact that the integrant is symmetric, so that the work can be reduced by half.

p = {2, 8};
q = {4, 4};
2 Norm[p - q]^2 NIntegrate[
Log[Norm[(p (1 - t) + t q) - (p (1 - s) + s q)]],
{t, 0, 1}, {s, t, 1}]


-0.0426773

If you are in need of integrating this integrant over more general and more complicated domains and if speed is an issue, the fast multipole method and related techniques might be your friends.

• Ok cool, I got the same result in Python! I will edit my original post to show the Mathematica code I used that gave the wrong result. It would be great if you could identify why it is wrong as I would like to able to compute integrals in this form. – ManUtdBloke Feb 12 '19 at 13:53
• I plan to implement the FMM eventually but for the moment I'm just trying to make sure all my singular integral evaluations are correct! – ManUtdBloke Feb 12 '19 at 13:56
• Do you think the edited code I posted in the OP can be 'fixed' to give the correct answer? It would be great if I could evaluate integrals using expressions in Mathematica like that rather than having to transform them first like I have to do with Python. – ManUtdBloke Feb 12 '19 at 13:57
• I'm not sure if this warrants an answer or not but NIntegrate[Log[Norm[{x1, x2} - {y1, y2}]] /. Abs -> Identity, {x1, x2} ∈ Line[{{4, 4}, {2, 8}}], {y1, y2} ∈ Line[{{4, 4}, {2, 8}}]] gets preprocessed to NIntegrate[20 Log[2 Sqrt[5] Sqrt[(x1 - x2)^2]], {x1, 0, 1}, {x2, 0, 1}] internally and this is where it chokes. – Chip Hurst Feb 12 '19 at 14:33
• @ChipHurst Hm. Interesting. From there one could go by NIntegrate[20 Log[2 Sqrt[5] Sqrt[(x1 - x2)^2]], {x1, 0, 1}, {x2, 0, 1}, Exclusions -> {x1 == x2} ]. Unfortunately, NIntegrate with regions refused to accept a setting for Exclusions. – Henrik Schumacher Feb 12 '19 at 14:45