2
$\begingroup$

I mean the following integral $$\int\limits _{[0,1]^4}\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\,dx_1dx_2dy_1dy_2 .$$ Its value is the average length of a random interval in the unit square (see, for example, MathWorld). Mathematica finds a multi-dimensional integral as an iterated integral. There are $4!=24$ variants to do it. Let us consider the first four items:

p = Permutations[{{x1, 0, 1}, {x2, 0, 1}, {y1, 0, 1}, {y2, 0, 1}}][[1 ;; 4]]; ParallelTable[Integrate[Sqrt[(x2 - x1)^2 + (y2 - y1)^2],i[[1]], i[[2]], i[[3]], i[[4]]], {i, p}] 

{1/240 (32 + 16 Sqrt[2] + (320 + 15 I) \[Pi] + 230 ArcSinh[1] + 30 ArcTanh[Sqrt[2]] + 30 Log[99 - 70 Sqrt[2]]), 1/240 (32 + 16 Sqrt[2] + (320 + 15 I) \[Pi] + 230 ArcSinh[1] + 30 ArcTanh[Sqrt[2]] + 30 Log[99 - 70 Sqrt[2]]), 1/240 (32 + 16 Sqrt[2] + (120 + 15 I) \[Pi] - 60 ArcCoth[Sqrt[2]] + 260 ArcSinh[1] + 30 ArcTanh[Sqrt[2]] + 25 Log[99 - 70 Sqrt[2]]), 1/240 (32 + 16 Sqrt[2] + (120 + 15 I) \[Pi] - 60 ArcCoth[Sqrt[2]] + 230 ArcSinh[1] + 30 ArcTanh[Sqrt[2]] + 20 Log[99 - 70 Sqrt[2]])}

N[%] 

{4.7102 + 0. I, 4.7102 + 0. I, 2.0922 + 0. I, 2.0922 + 0. I}

The calculation of each integral in 14.1 on Windows takes approximately 15 minutes for me. The rest of the iterated integrals produce similar results, some of those numerically equal 4.7102 + 0. I and some of those numerically equal 2.0922 + 0. I (the executed *.nb file on demand). All the results of the iterated integrations are not correct since the distance between two points in the unit square is less than or equal to $\sqrt 2$ and

NIntegrate[Sqrt[(x2-x1)^2+(y2-y1)^2],{x1,0,1},{x2,0,1},{y1,0,1},{y2,0,1},AccuracyGoal->8,PrecisionGoal->8,Method->"LocalAdaptive"] 

0.521404

and

Mean[TransformedDistribution[Sqrt[(x2 - x1)^2 + (y2 - y1)^2], {x1, y1, x2, y2} \[Distributed] UniformDistribution[{{0, 1}, {0, 1}, {0, 1}, {0, 1}}]]] // ComplexExpand 

2/15 + Sqrt[2]/15 + 5/48 Log[99 - 70 Sqrt[2]] - 11/192 Log[-1 + Sqrt[2]] + 173/192 Log[1 + Sqrt[2]]

confirm it. I am able to correctly calculate the integral under consideration by the change of variables which simplifies the integrand in such a way.

IntegrateChangeVariables[Inactive[Integrate][Sqrt[(x2-x1)^2+(y2-y1)^2],{x1,0,1}, {x2,0,1},{y1,0,1},{y2,0,1}],{p,q,r,s},{p==x1,q==y1,r==x2-x1,s==y2-y1}] 

Inactive[Integrate][Sqrt[r^2 + s^2], {p, 0, 1}, {q, 0, 1}, {r, -p, 1 - p}, {s, -q, 1 - q}]

Activate[ Inactive[Integrate][Sqrt[r^2 + s^2], {p, 0, 1}, {q, 0, 1}, {r, -p, 1 - p}, {s, -q, 1 - q}], Unevaluated[Integrate]] // ComplexExpand 

2/15+Sqrt[2]/15-1/64 Log[1-1/Sqrt[2]]+1/64 Log[1+1/Sqrt[2]]+13/96 Log[99-70 Sqrt[2]]-1/16 Log[-1+Sqrt[2]]+101/96 Log[1+Sqrt[2]]

Are there other ways to correctly find the integral under consideration as an iterated integral? I'd like to notice that the way to find the average length of a random interval in the unit square

in Trott, M. "The Mathematica Guidebooks Additional Material: Average Distance Distribution." http://www.mathematicaguidebooks.org/additions.shtml#S_1_14 does not consist in the calculation of an iterated integral for the integral under consideration.

$\endgroup$
5
  • $\begingroup$ Also I don't find the way in Trott, M. "The Mathematica Guidebooks Additional Material: Average Distance Distribution." mathematicaguidebooks.org/additions.shtml#S_1_14 reliable though the answer is correct: the integration of DiracDelta works by the rule "As much as is necessary". $\endgroup$ Commented Oct 22, 2024 at 10:20
  • $\begingroup$ I got yet another value 2.6158 : Integrate[Sqrt[(x2 - x1)^2 + (y2 - y1)^2], {x1, 0, 1}, {x2, 0, 1}, {y1, 0, 1}, {y2, 0, 1}] produced 1/60 (8 + 4 Sqrt[2] + 40 \[Pi] + 50 ArcSinh[1] + 15/2 Log[99/2 - 35 Sqrt[2]] + 15 Log[2 + Sqrt[2]]). Version 14.1.0 for Mac OS X ARM (64-bit) (July 16, 2024). $\endgroup$ Commented Oct 22, 2024 at 12:44
  • $\begingroup$ @A.Kato: Thank you. How about other iterated integrals? $\endgroup$ Commented Oct 22, 2024 at 14:28
  • $\begingroup$ As you said, the computation takes a lot of time, so I just tried another case, {x1, 0, 1}, {y1, 0, 1}, {y2, 0, 1}, {x2, 0, 1}. Then I got the correct answer. $\endgroup$ Commented Oct 23, 2024 at 0:42
  • $\begingroup$ @A.Kato: It's kind of you. Nice to hear it. $\endgroup$ Commented Oct 23, 2024 at 5:33

1 Answer 1

1
$\begingroup$

My somewhat older Mathematica version v12.2 isn't able to symbollically evaluate the integral.

But numerical evalution gives same result 0.521396 for all 24 cases

permu = Permutations[{{x1, 0, 1}, {x2, 0, 1}, {y1, 0, 1}, {y2, 0,1}}]; Map[Apply[NIntegrate,Join[{Sqrt[(x2 - x1)^2 + (y2 - y1)^2]}, #, {Method ->"LocalAdaptive"}]] &, permu] (*{0.521396, 0.521396, 0.521396, 0.521396, 0.521396, 0.521396, \ 0.521396, 0.521396, 0.521396, 0.521396, 0.521396, 0.521396, 0.521396, \ 0.521396, 0.521396, 0.521396, 0.521396, 0.521396, 0.521396, 0.521396, \ 0.521396, 0.521396, 0.521396, 0.521396}*) 
$\endgroup$
2
  • $\begingroup$ UlrichNeumann (@ does not work.): Thank you for your comment. The true numeric value is 0.521405. On 12.02.22 some symbolic values of those iterated integrals were true [CASE:4903595]. $\endgroup$ Commented Oct 22, 2024 at 16:23
  • 1
    $\begingroup$ @ works just fine. But only if one has the courtesy of using it. $\endgroup$ Commented Oct 23, 2024 at 16:32

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.