Bug in Integrate for Mathematica

9

1

Bug introduced in 8.0.0 and fixed in 9.0.0


Consider the following:

regFunc[x_,y_]:=Boole[-5<4x+3y<5 && -2<3x+2y<2];
Integrate[regFunc[x,y]*((4x+3y)(3x+2y))^4,{x,-100,100},{y,-100,100}]//N
Integrate[regFunc[x,y]*(12x^2+17x*y+6y^2)^4,{x,-100,100},{y,-100,100}]//N

In the first example, Mathematica seems to figure out the correct substitution, and arrives at 16000, which is the correct answer. In the second integration, (integrating the same expression, but expanded), Mathematica gives 5885078144/382725, which is 15376.8. This is clearly a bug, is this well-known?

I am using Mathematica 8.04, 64bit Linux.

EDIT: I got an email from the tech support, and I took the answer as a confirmed bug.

Per Alexandersson

Posted 2012-03-27T12:32:08.790

Reputation: 2 142

In case this is still an issue, I'll mention that this has been filed as a bug and will be investigated as such. – Daniel Lichtblau – 2012-03-29T21:49:39.307

1In Mathematica 9.0.0, I get the same result 16000 from both forms. – murray – 2012-12-13T16:38:07.400

Nice! Only a few more letters... – Per Alexandersson – 2012-12-13T17:37:13.140

did you really mean xy in the second example? (guess not) – acl – 2012-03-27T12:39:44.960

@Paxinum I get the correct answer (and much faster) to the second integral if I do NIntegrate[...] rather than Integrate[...]//N – b.gates.you.know.what – 2012-03-27T12:40:42.467

1Yes, I know that NIntegrate manages to get the answer correct. What I am curious about, is why the two identical integrals give different answers, depending on if the integrand is factorized or not. – Per Alexandersson – 2012-03-27T12:53:11.277

3Since this is clearly a bug, the proper place to send it is support@wolfram.com. – Mark McClure – 2012-03-27T13:22:33.177

Current policy for the 'bugs' tag is to use it for confirmed bugs only. So, if you hear something from Tech support please add the tag, but don't start with it. – Sjoerd C. de Vries – 2012-03-27T15:41:22.753

1Blah, I assumed it meant confirmed by other users @sjoerd – nixeagle – 2012-03-27T15:49:10.650

@nixeagle It does as well, but it is vaguely-termed "community consensus" which =!= to a single user's opinion. Actually, I would like a two-pronged approach for bug tagging: bug-report for the initial tag, and bug-confirmed after confirmation. You might consider adding your view to the meta discussion. – Sjoerd C. de Vries – 2012-03-27T18:07:48.057

Well I believed based on the comments it was determined to be a bug. Look at what mark and artes said. But I'm not arguing with you, just explaining why I tagged as such. – nixeagle – 2012-03-27T19:04:35.347

@nixeagle Please do argue, but preferably in meta, as I feel we haven't had sufficient discussion there. In this case I would be tempted to say that one 'maybe' and one 'clearly' do not make community consensus. – Sjoerd C. de Vries – 2012-03-27T19:28:43.540

Ok, if you insist ;). A two level approach might be nice. A definition of "consensus" even more so. BTW, Should we now add the bug tag after the edit? – nixeagle – 2012-03-27T20:38:12.237

Answers

3

I think it is indeed a bug specific to version 8 of Mathematica. The same integrals in version 7 give the correct result. Compare this issue with this answer. In the both cases one works with assumptions which make Integrate behaving improperly.

Edit 1

It seems that definite integrals are calculated correctly and if we subtract the limits of integration in the way that the boolean formula is slightly neutralized, then the result is correct, e.g. :

Integrate[ regFunc[x, y]*((4 x + 3 y) (3 x + 2 y))^4, {x, -10, 10}, {y, -10, 10}] // N

Integrate[ regFunc[x, y]*(12 x^2 + 17 x*y + 6 y^2)^4, {x, -10, 10}, {y, -10, 10}] // N
7836.43
7836.43
RegionPlot[ {-5 < 4 x + 3 y && 4 x + 3 y < 5 && -2 < 3 x + 2 y && 3 x + 2 y < 2, 
             -10 < x < 10 && -10 < y < 10 },
            {x, -25, 25}, {y, -25, 25}, PlotPoints -> 150, MaxRecursion -> 4]

enter image description here

It should be emphasized that Integrate doesn't work either when we use insted of Boole for example UnitStep :

regFuncUS[x_, y_] := UnitStep[ 5 + 4 x + 3 y, 5 - 4 x - 3 y, 2 + 3 x + 2 y, 2 - 3 x - 2 y]

Edit 2

In Mathematica 9 this bug has been fixed :

Integrate[ regFunc[x,y] (( 4 x + 3 y )( 3 x + 2 y ))^4,{x, -100, 100},{y, -100, 100}] //N
Integrate[ regFunc[x,y] ( 12x^2 + 17 x y + 6 y^2 )^4,{x, -100, 100},{y, -100, 100}] //N
16000.
16000.

Artes

Posted 2012-03-27T12:32:08.790

Reputation: 51 831

@rcollyer it seems to be purely a roundoff error: Map[(Integrate[regFunc[x, y]*#, {x, -100, 100}, {y, -100, 100}] // N[#, 20] &) &, ((4 x + 3 y) (3 x + 2 y))^4 // Expand] gives 160000 while without the 20 precision it does not. – chris – 2012-10-07T19:04:13.323

Ah, but what are the assumptions in this case? I guess the inequalities forces the variables to be real, but the region one integrates over is also a real domain... – Per Alexandersson – 2012-03-27T15:53:25.230

Assumptions are in Boole, or in UnitStep if you want. Did I mention anything about Complexes ??? – Artes – 2012-03-27T16:11:44.020

Well, yes, but the same assumptions are made in both integrals. What surprises me is that factorization of the integrand changes the answer. – Per Alexandersson – 2012-03-27T17:42:57.387

I mean the problem is with the limits of integration, when you impose additionally boolean expression (assumptions or UnitStep) Integrate appears to work improperly. Note for example when you imopse smaller limits e.g. Integrate[...{x, -10, 10}, {y, -10, 10}] it seems to work properly. – Artes – 2012-03-27T17:51:57.610

As an added note, this gives 16000: Integrate[regFunc[x,y] #, {x, -100, 100}, {y, -100, 100}]& /@ Expand[(12 x^2 + 17 x*y + 6 y^2)^4]. So, the problem is not entirely with the limits. – rcollyer – 2012-03-28T01:30:18.513

@rcollyer Thanks your remark. However if you put @ instead of /@ you won't get the correct result. – Artes – 2012-03-28T01:39:49.657

I'm aware of that, per the OPs statements to that effect, and my own double checking. – rcollyer – 2012-03-28T01:46:36.933

1

It seems to me it's a roundoff error problem; indeed

Map[(Integrate[regFunc[x, y]*#, {x, -100, 100}, {y, -100, 100}] // N[#, 20] &) &,
((4 x + 3 y) (3 x + 2 y))^4 // Expand]

gives $160000$ correctly. So does the analytic approach:

Integrate[regFunc[x, y] #, {x, -100, 100}, {y, -100, 100}] & /@ 
Expand[(12 x^2 + 17 x*y + 6 y^2)^4]//N

whereas

Map[(Integrate[regFunc[x, y]*#, {x, -100, 100}, {y, -100, 100}] // N) &,
((4 x + 3 y) (3 x + 2 y))^4 // Expand]

gives the wrong answer.

Beware of numerical cancellations!

chris

Posted 2012-03-27T12:32:08.790

Reputation: 20 653