12
$\begingroup$

I stumbled across the fact this integral:

Integrate[1/y, {y, 0, 1}, GenerateConditions -> False]

returns

0

Anybody understand why this is zero and not divergent? Is "GenerateConditions" doing something weird?

$\endgroup$
  • 1
    $\begingroup$ We do not put the bugs tag into questions until your observed behavior has been confirmed by others as a bug. $\endgroup$ – J. M. is in limbo Aug 12 '15 at 11:35
  • 1
    $\begingroup$ Anyway: what does Integrate[1/y, {y, 0, x}, GenerateConditions -> False] return? $\endgroup$ – J. M. is in limbo Aug 12 '15 at 11:37
  • 3
    $\begingroup$ Well, that at least explains the $0$ result… $\endgroup$ – J. M. is in limbo Aug 12 '15 at 11:49
  • 1
    $\begingroup$ I don't understand completely, but GenerateConditions turns off some checking. In particular, it turns off the step that checks convergence. What I don't understand is why it throws out the limit at 0 -- it calculates it, gets -Infinity and then seems to remove the singular part. Reminds me of something my roommate in grad school, who was in physics, said about one of his classes: whether the integral came out 0 or Infinity, in both cases the result was negligible. I don't really have a complete answer, but may it will be easier to discuss it in an answer... $\endgroup$ – Michael E2 Aug 12 '15 at 12:30
  • 2
    $\begingroup$ If your goal with GenerateConditions -> False is to get rid of ConditionalExpression, consider using Normal instead. $\endgroup$ – Szabolcs Aug 12 '15 at 17:15
20
$\begingroup$

Summary: Setting GenerateConditions -> False turns off safety checks. In my opinion, when the user does that and the result is erroneous, I would not call that a bug. Now WRI could decide to improve Mathematica in this case, but it might not be such a simple matter. On the other hand, it is entirely up to the user to decide whether or not he or she is satisfied with such limitations. The analysis below shows that Mathematica does "plug in" y == 0 and gets -Infinity: I think it would be an easy matter to be able to emit a message about possible divergence and suggest using the option GenerateConditions -> True. See also When to use GenerateConditions -> True and What exactly does GenerateConditions do?.

From How much time should one give Mathematica for an integral evaluation?, one can monitor the progress of Integrate by setting

Internal`Integrate`debugSwitch = 10

The output is mainly inscrutable and for internal use at WRI, but if you've ever been able to read a mathematical paper in a language you don't understand, you can pick out important points now and then.

In a single integral, GenerateConditions -> Automatic is equivalent to GenerateConditions -> True. One of the differences between

GenerateConditions -> False
GenerateConditions -> True

is that the False setting turns off convergence testing. If we set debugSwitch = 10, we get Print statements in the output at various steps as Integrate figures out the integral. After 11 initialization steps, we see that there is a branch (after the last "start main' statement). The computation with GenerateConditions -> True enters the "exception locus" routine, which ultimately determines the integral diverges. The OP's integral enters "SimpPredicates", which sounds like a simplified check of the integrand; it is followed by a "dispatcher" which calls "Simpdispatcher", which again sounds like a simplified integrator.

Block[{Internal`Integrate`debugSwitch = 10},
 Integrate[1/y, {y, 0, 1}]
 ]

Mathematica graphics

Block[{Internal`Integrate`debugSwitch = 10},
 Integrate[1/y, {y, 0, 1}, GenerateConditions -> False]
 ]

Mathematica graphics

As one scrolls through the output of the GenerateConditions -> False computation, one sees that Log[y] is found to be the antiderivative. Its limit is taken as y -> 1 from below; and then the limit is taken as y -> 0 from above:

Mathematica graphics

After this point, I do not have a clear idea of what happens. Apparently dissatisfied with -Infinity, Integrate essentially computes Series[Log[y], {y, 0, 2}]:

Mathematica graphics

It is not clear from the output what is done with this result. A very few steps after, the Log[y] disappears and the result 0 appears; after several simplification steps, 0 is the answer.

The same thing happens when 1/y^2 is integrated. Different things happen when the integrand is 1/(1 + y^2), which should be expected. Integrate is quite complicated.


If you know that for multivariable integrals, GenerateConditions -> Automatic means that the inner integral(s) will be computed with the setting GenerateConditions -> False and the outer integral is integrated with the setting GenerateConditions -> True, you should be able to predict the difference in these two integrals:

Integrate[1/y, {y, 0, 1}, {x, 0, 1}]
Integrate[1/y, {x, 0, 1}, {y, 0, 1}]

Mathematica graphics

The second result might be considered a bug, I suppose. (I'm not sure who would have predicted the unnecessary second message, although you might infer why.)

If one adds the option GenerateConditions -> True to the last integral, one gets the expected divergence message (and only once):

Integrate[1/y, {x, 0, 1}, {y, 0, 1}, GenerateConditions -> True]

Mathematica graphics

Update: See also Why does Mathematica say $\int_0^1\int_0^1\int_0^1\frac{1.0}{xyz}\,dz\,dy\,dx=0$?.

$\endgroup$
  • 1
    $\begingroup$ "when the user does that and the result is erroneous, I would not call that a bug" - pretty much why I removed the initial bugs tag; I think of it like the safety mechanism on a rifle. Disable it if and only if you know what you're doing. $\endgroup$ – J. M. is in limbo Aug 12 '15 at 13:38
  • $\begingroup$ @J. M. Then should Mathematica not generate a warning that its answer might be wrong? $\endgroup$ – Calchas Aug 12 '15 at 17:08
  • $\begingroup$ @Calchas, it's on by default, which is where the usual warnings come from. Since you've explicitly told Mathematica not to warn you… ;) $\endgroup$ – J. M. is in limbo Aug 12 '15 at 17:11
  • 1
    $\begingroup$ @Szabolcs, I'd concur that the double integral example looks to be a bug, but ever since GenerateConditions became built-in, I was always of the philosophy that it's not something you shut off unless you're absolutely sure of what you're doing. So, if the calculus functions suddenly take wrong limits in that case, I'd say it's a classical case of GIGO. $\endgroup$ – J. M. is in limbo Aug 12 '15 at 17:29
  • 3
    $\begingroup$ GenerateConditions is a seriously overloaded option. Meanings include "check hard for convergence", "check for parameter provisos needed to make the result correct", "check for singular points along the integration path", "explicitly allow (or even assume) cancellation of singular parts of the integral". I'd say it is this last one at work in the example shown here. $\endgroup$ – Daniel Lichtblau Aug 16 '15 at 17:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.