# Kernel CRASH of NIntegrate with a complicated compiled integrand

When I NIntegrate the integrand with the particular parameter showing below the Kernel crash without any message.

But if I change the "range" parameter a little bit, the Kernel won't crash. The crash problem seems to occur only under certain parameters.

Because I want to make a density plot of the integral as a function of the parameters, this crash problem under certain parameters always breaks the density plot process.

This crash problem happens on both Mac and Win10:

• MacOS Big Sur 11.2.2, Mathematica 12.1.1.0

• Win10, Mathematica 12.1.1.0

(*Integrand*)

expression1 = {{-0.03783737745791316 +
52.07594879537986 (k1^2 + k2^2) -
0.0006566020385220937 \[GothicCapitalB]3, \
-0.00020215783672119025 (\[GothicCapitalB]1 -
I \[GothicCapitalB]2), (0. + 0. I) +
1/2 (273.35324964239567 (k1 - I k2)^3 -
22.668570452264646 (k1 + I k2)^3),
0. + I (k1 - I k2) (-1.0301133331497063 -
370.16816003256605 (k1^2 +
k2^2))}, {-0.00020215783672119025 (\[GothicCapitalB]1 +
I \[GothicCapitalB]2), -0.03783737745791316 +
52.07594879537986 (k1^2 + k2^2) +
0.0006566020385220937 \[GothicCapitalB]3,
0. - I (k1 + I k2) (-1.0301133331497063 -
370.16816003256605 (k1^2 + k2^2)), (0. + 0. I) +
1/2 (22.668570452264646 (k1 - I k2)^3 -
273.35324964239567 (k1 + I k2)^3)}, {(0. + 0. I) +
1/2 (-22.668570452264646 (k1 - I k2)^3 +
273.35324964239567 (k1 + I k2)^3),
0. + I (k1 - I k2) (-1.0301133331497063 -
370.16816003256605 (k1^2 + k2^2)), -0.03304414880767263 +
95.54303239292248 (k1^2 + k2^2) -
0.0015031216532114644 \[GothicCapitalB]3, \
-0.00017807130082869512 (\[GothicCapitalB]1 -
I \[GothicCapitalB]2)}, {0. -
I (k1 + I k2) (-1.0301133331497063 -
370.16816003256605 (k1^2 + k2^2)), (0. + 0. I) +
1/2 (-273.35324964239567 (k1 - I k2)^3 +
22.668570452264646 (k1 +
I k2)^3), -0.00017807130082869512 (\[GothicCapitalB]1 +
I \[GothicCapitalB]2), -0.03304414880767263 +
95.54303239292248 (k1^2 + k2^2) +
0.0015031216532114644 \[GothicCapitalB]3}};
expression2 = {{104.15189759075972 k1s, 0,
1/2 (820.059748927187 (k1s - I k2)^2 -
68.00571135679394 (k1s + I k2)^2), (0. -
740.3363200651321 I) k1s (k1s - I k2) +
I (-1.0301133331497063 -
370.16816003256605 (k1s^2 + k2^2))}, {0,
104.15189759075972 k1s, (0. + 740.3363200651321 I) k1s (k1s +
I k2) - I (-1.0301133331497063 -
370.16816003256605 (k1s^2 + k2^2)),
1/2 (68.00571135679394 (k1s - I k2)^2 -
820.059748927187 (k1s + I k2)^2)}, {1/
2 (-68.00571135679394 (k1s - I k2)^2 +
820.059748927187 (k1s + I k2)^2), (0. -
740.3363200651321 I) k1s (k1s - I k2) +
I (-1.0301133331497063 - 370.16816003256605 (k1s^2 + k2^2)),
191.08606478584497 k1s,
0}, {(0. + 740.3363200651321 I) k1s (k1s + I k2) -
I (-1.0301133331497063 - 370.16816003256605 (k1s^2 + k2^2)),
1/2 (-820.059748927187 (k1s - I k2)^2 +
68.00571135679394 (k1s + I k2)^2), 0,
191.08606478584497 k1s}};
expression3 = {{104.15189759075972 k2s, 0,
1/2 ((0. - 820.059748927187 I) (k1 - I k2s)^2 - (0. +
68.00571135679394 I) (k1 +
I k2s)^2), -1.0301133331497063 - (0. +
740.3363200651321 I) (k1 - I k2s) k2s -
370.16816003256605 (k1^2 + k2s^2)}, {0,
104.15189759075972 k2s, -1.0301133331497063 + (0. +
740.3363200651321 I) (k1 + I k2s) k2s -
370.16816003256605 (k1^2 + k2s^2),
1/2 ((0. - 68.00571135679394 I) (k1 - I k2s)^2 - (0. +
820.059748927187 I) (k1 + I k2s)^2)}, {1/
2 ((0. + 68.00571135679394 I) (k1 - I k2s)^2 + (0. +
820.059748927187 I) (k1 +
I k2s)^2), -1.0301133331497063 - (0. +
740.3363200651321 I) (k1 - I k2s) k2s -
370.16816003256605 (k1^2 + k2s^2), 191.08606478584497 k2s,
0}, {-1.0301133331497063 + (0. + 740.3363200651321 I) (k1 +
I k2s) k2s - 370.16816003256605 (k1^2 + k2s^2),
1/2 ((0. + 820.059748927187 I) (k1 - I k2s)^2 + (0. +
68.00571135679394 I) (k1 + I k2s)^2), 0,
191.08606478584497 k2s}};
HamiltCompiled =
Compile[{{k1, _Real}, {k2, _Real}, {\[GothicCapitalB]1, _Real}, {\
\[GothicCapitalB]2, _Real}, {\[GothicCapitalB]3, _Real}},
Evaluate[expression1],
CompilationOptions -> {"ExpressionOptimization" -> True}];
Dk1HamiltCompiled =
Compile[{{k1s, _Real}, {k2, _Real}, {\[GothicCapitalB]1, _Real}, {\
\[GothicCapitalB]2, _Real}, {\[GothicCapitalB]3, _Real}},
Evaluate[expression2],
CompilationOptions -> {"ExpressionOptimization" -> True}];
Dk2HamiltCompiled =
Compile[{{k1, _Real}, {k2s, _Real}, {\[GothicCapitalB]1, _Real}, {\
\[GothicCapitalB]2, _Real}, {\[GothicCapitalB]3, _Real}},
Evaluate[expression3],
CompilationOptions -> {"ExpressionOptimization" -> True}];
OccupiedCurvatureCompiled[\[Mu]_?NumericQ, k1_?NumericQ,
k2_?NumericQ, \[GothicCapitalB]1_, \[GothicCapitalB]2_, \
\[GothicCapitalB]3_] :=
Block[{Mx1, Mx2, values, vectors, curvaturesList},
{values, vectors} =
Eigensystem@
HamiltCompiled[k1,
k2, \[GothicCapitalB]1, \[GothicCapitalB]2, \
\[GothicCapitalB]3];
{values, vectors} = {values[[#]], vectors[[#]]} &[
Ordering@values];
Mx1 = vectors\[Conjugate].(Dk1HamiltCompiled[k1,
k2, \[GothicCapitalB]1, \[GothicCapitalB]2, \
\[GothicCapitalB]3]).vectors\[Transpose];
Mx2 = vectors\[Conjugate].(Dk2HamiltCompiled[k1,
k2, \[GothicCapitalB]1, \[GothicCapitalB]2, \
\[GothicCapitalB]3]).vectors\[Transpose];
curvaturesList =
Re[I Total[(# - #\[Transpose])]] &[
Mx1*Mx2\[Transpose]*
Table[If[n1 == n2, 0, 1/(values[[n1]] - values[[n2]])^2], {n1,
1, 4}, {n2, 1, 4}]];
];

(*No Crash*)
With[{range =
0.0006 +
0.00025*19., \[Mu] = -0.034637500000000015, \[GothicCapitalB]1 =
0., \[GothicCapitalB]2 = 19., \[GothicCapitalB]3 = 0.},
NIntegrate[
OccupiedCurvatureCompiled[\[Mu], k1,
k2, \[GothicCapitalB]1, \[GothicCapitalB]2, \[GothicCapitalB]3], \
{k1, -range, range}, {k2, -range, range}, MinRecursion -> 2,
PrecisionGoal -> 3, AccuracyGoal -> 3]]

(*Crash*)
With[{range =
0.0005 +
0.00025*19., \[Mu] = -0.034637500000000015, \[GothicCapitalB]1 =
0., \[GothicCapitalB]2 = 19., \[GothicCapitalB]3 = 0.},
NIntegrate[
OccupiedCurvatureCompiled[\[Mu], k1,
k2, \[GothicCapitalB]1, \[GothicCapitalB]2, \[GothicCapitalB]3], \
{k1, -range, range}, {k2, -range, range}, MinRecursion -> 2,
PrecisionGoal -> 3, AccuracyGoal -> 3]]

• I verified the posted code crashes my version of Mathematica, 12.2.0 for Mac OS X x86 (64-bit). I suggest your report this to WRI. Commented Mar 12, 2021 at 8:36
• @AntonAntonov MacOS Big Sur 11.2.2, Mathematica 12.1.1.0; Win10, Mathematica 12.1.1.0 Commented Mar 12, 2021 at 9:20
• @AntonAntonov Could you tell me how to report this to WRI? Thanks Commented Mar 12, 2021 at 9:24
• "Could you tell me how to report this to WRI? " -- Please see wolfram.com/support/contact/email/?topic=Feedback . Also, this MSE discussion: mathematica.meta.stackexchange.com/questions/190/… . Commented Mar 12, 2021 at 9:28