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?
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}]
]
Block[{Internal`Integrate`debugSwitch = 10},
Integrate[1/y, {y, 0, 1}, GenerateConditions -> False]
]
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:
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}]
:
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}]
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]
Update: See also Why does Mathematica say $\int_0^1\int_0^1\int_0^1\frac{1.0}{xyz}\,dz\,dy\,dx=0$?.
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$
Commented
Aug 12, 2015 at 17:29
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$
Commented
Aug 16, 2015 at 17:26
Integrate[1/y, {y, 0, x}, GenerateConditions -> False]
return? $\endgroup$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 at0
-- 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 out0
orInfinity
, 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$GenerateConditions -> False
is to get rid ofConditionalExpression
, consider usingNormal
instead. $\endgroup$