Message Boards Message Boards

1
|
8601 Views
|
9 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Wrong integration result using Assuming?

Posted 8 years ago

Let's consider the following piece of code:

In[2]:= Assuming[j \[Element] Integers \[And] k \[Element] Integers, Integrate[Sin[j x] Sin[k x], {x, 0, 2 Pi}]]

Out[2]= 0

The result is obviously wrong, since those integrals are non-zero for j=k. I had brought this up with Wolfram two years ago, with no success. Somewhere in my interaction with Wolfram support there was a suggestion that the above wrong result is somehow the proper result for Mathematica to show. Out of pure curiosity, is there anyone at all who can present a cogent argument for the correctness of the Mathematica output above? If not, can we have this fixed, please?

POSTED BY: Dietmar Rempfer
9 Replies
Posted 8 years ago

That is quite interesting:

In[1]:= dot = 
 Integrate[Sin[j x] Sin[k x], {x, 0, 2 Pi}, 
  Assumptions -> j \[Element] Integers \[And] k \[Element] Integers]

Out[1]= 1/2 (Sin[2 (j - k) \[Pi]]/(j - k) - Sin[2 (j + k) \[Pi]]/(
   j + k))

In[2]:= Limit[dot, j -> k, Assumptions -> k \[Element] Integers]

Out[2]= \[Pi]
POSTED BY: David Keith

One thing to be aware of is that one gets a different result from

Integrate[Sin[j x] Sin[k x], {x, 0, 2 Pi}, 
 Assumptions -> j \[Element] Integers \[And] k \[Element] Integers]

This issue comes up from time to time. Maybe at some point we will wrangle Assuming assumptions to behave identically to those passed in the Assumptions option. It's not straightforward in this case because Integrate alters its local assumptions specifically to avoid issues with discrete values (so Integers in effect becomes Reals for such computations).

For some discussion of all this, see this Mathematica StackExchange note

Also related: 1 2 3 4

POSTED BY: Daniel Lichtblau

Daniel,

thanks, this is interesting. Looking at the various discussions I have now seen, it seems that a lot (perhaps all) of the issues center around the way Mathematica's Simplify function works. Now, clearly this is a core, and probably quite complex function, but nevertheless, if my hunch is correct then one could consider modifying the way this function works along the lines I suggested above (a global option to modify simplification behavior, or an option that will have Simplify issue Warning messages when potential solutions get dropped). This way, a user may choose to have Mathematica use a "less aggressive" mode of simplification, that is less likely, or ideally cannot, generate the wrong results we are discussing here.

POSTED BY: Dietmar Rempfer
Posted 8 years ago

To an extent, the significance of Mathematica's elimination of special solutions depends on what we are doing with the math. If we are solving y = m x + b for x, then obtaining (y-b)/m, with no warning m != 0 seems fine. If m were zero, the equation reduces to y = b and contains no information about x. We have already excluded that case in our thinking, and discarding it has little risk. The problem with the calculation of Dietmar's integral is that it looks suspiciously like the inner product for a set of orthogonal functions, and the discarded case is in fact critical to function.

POSTED BY: David Keith

I think this is a good point: Having an option (perhaps something like "RigorousMath") could be useful. Another possibility would be to generate a warning message, similar to the ones we get for, e.g., solutions of nonlinear equations, where Mathematica does warn us that some solutions may be missing. In both cases the user can then use his/her additional insight into the problem of interest to reformulate the problem, or provide restrictions such that the problem of a ballooning tree of conditionals can be avoided. Let's not forget that there may be cases where the user actually does want to see all of the possible solutions, too. Like you said, in the simple case of Solve versus Reduce, that option exists, but in many other cases it doesn't.

Finally, admittedly on a slightly different note, I would be curious as to whether there is in fact a rigorous definition, that is grounded in mathematical reasoning rather than convenience of coding or using Mathematica, behind that comforting-sounding adjective in "generic solution". Frankly, the term "generic" is a dangerously over-used term in certain circles, often used to gloss over significant holes in people's mathematical arguments...

POSTED BY: Dietmar Rempfer

When solving the equation a x==0, you can choose between Solve, that gives the generic solution, and Reduce, that breaks down all possible cases, or at least tries to. The command Integrate[x^n, x] gives x^(1 + n)/(1 + n), which is wrong when n=-1. A totally correct answer for this would be a conditional expression. It would be nice to have that as an option, but perhaps not as the default. Keeping track of nested algebraic or non-algebraic conditions, possibly containing multifunctions, can rapidly escalate into intractability.

POSTED BY: Gianluca Gorni

Hmm, alright, that even makes a certain amount of sense. However, it is clear that such behavior is extremely problematic. "Generic answer" may sound kind of benign, and in my original example the generic answer is indeed correct most of the time, but it is clear that it will be possible to construct expressions for which Mathematica will give "generic" answers that are almost always wrong.

More importantly, a computational system that even just sometimes produces wrong results is already fatally flawed. In numerical computation, nobody would accept a floating point unit that sometimes gives the wrong answer, even if only very rarely (see the infamous FDIV bug in the first-generation of Intel Pentium processors). Common judgment of such devices is that they are completely useless. Likewise, if I want to trust Mathematica's answer in a potentially complex set of interdependent calculations that I may not be able to easily check "by hand", I have to be convinced that the results that Mathematica generates are always correct. If that is not the case, how can I trust any result that Mathematica is giving me?

To be very specific, I find the statement that "If the Wolfram Language did not automatically replace 0/x by 0, then few symbolic computations would get very far" to be quite a lame excuse. Why not demand that the user specify x such that an unambiguous answer is possible, or else produce an error message? So, calculations become impractical if we insist that they give correct answers? And our choice is then that we'll just give wrong answers instead? Are we saying that, "well, alright, we're not sure we're giving you the right answer, but at least it's an answer"?

So, no, I do disagree that "The overall goal of symbolic computation is typically to get formulas that are valid for many possible values of the variables that appear in them" (in parentheses I will note the weasel-wording through the insertion of a "typically" in the sentence above). As for myself, I want a correct answer, period, not an answer that is often correct. To be provocative, I will go so far as to say that, just as in my example of numerical computation, a symbolic system that sometimes gives the wrong answer is useless. Feel free to discuss...

P.S.: As a consequence of what I am saying above, in my opinion, the solution of x=0 to the equation a x=0 is wrong; Mathematica should have given the solution as x=0/a. In contrast, the solution x=-b/a that Mathematica generates for the equation a x+b=0 is correct.

POSTED BY: Dietmar Rempfer

Many Wolfram Language functions return generic solutions. See this or this . Therefore, this result is actually what Mathematica is documented to return. Non-generic solutions can be addressed with functions like Assuming as David shows (the second documentation link also shows that there are some functions which are better about keeping non-generic solutions).

The first link gives a brief explanation as to why this happens - calculations become impractical very quickly if Mathematica has to track every non-generic case on every internal calculation it does.

POSTED BY: Karl Isensee
Posted 8 years ago

I do not see how that answer could be considered correct. It should produce a conditional:

In[1]:= Assuming[j \[Element] Integers && k \[Element] Integers, 
 Integrate[Sin[j x] Sin[k x], {x, 0, 2 Pi}]]

Out[1]= 0

In[2]:= Assuming[
 j \[Element] Integers && k \[Element] Integers && j != k, 
 Integrate[Sin[j x] Sin[k x], {x, 0, 2 Pi}]]

Out[2]= 0

In[3]:= Assuming[
 j \[Element] Integers && k \[Element] Integers && j == k, 
 Integrate[Sin[j x] Sin[k x], {x, 0, 2 Pi}]]

Out[3]= \[Pi]
POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract