9
$\begingroup$

In this question there's an example of an integral where using Assuming and Assumptions give different results:

In[1]:= Integrate[Cos[n x], {x, 0, Pi}, Assumptions -> Element[n, Integers]]    
Out[1]= Sin[n π]/n

In[2]:= Assuming[Element[n, Integers], Integrate[Cos[n x], {x, 0, Pi}]]
Out[2]= 0

In[3]:= Integrate[Cos[n x], {x, 0, Pi}, Assumptions -> Element[n, Integers]]    
Out[3]= Sin[n π]/n

Now let's clear the system cache (or restart the kernel if you like) and try again, but now in a different order:

In[4]:= ClearSystemCache[] (* fresh start! *)

In[5]:= Assuming[Element[n, Integers], Integrate[Cos[n x], {x, 0, Pi}]]
Out[5]= 0

In[6]:= Integrate[Cos[n x], {x, 0, Pi}, Assumptions -> Element[n, Integers]]
Out[6]= 0

To make things even more weird, the results are affected by the order these two versions are evaluated (clearly due to caching). In[6] and In[3] are the same but they return different results.

I always assumed that using Assuming or Assumptions with built-in functions should be equivalent. It seems this is not true. I can imagine that Integrate uses something internally (e.g. Refine) that is affected by the global Assuming, but not by Assumptions.

Generally, when are Assuming and Assumptions not equivalent?

Is the result I quoted above a bug?


EDIT: As Artes and Michael noted in the comments, this is explained by Daniel Lichtblau here. My only remaining worry is that the results are cached and effectively depend on the order of evaluation.

$\endgroup$
5
  • $\begingroup$ I remember Daniel Lichtblau answered such a question (or closely related) more or less one year ago. $\endgroup$
    – Artes
    Feb 11, 2014 at 14:00
  • $\begingroup$ @Artes This one? mathematica.stackexchange.com/a/19894 $\endgroup$
    – Michael E2
    Feb 11, 2014 at 14:02
  • $\begingroup$ @MichaelE2 Perheps I remembered this one but not quite sure at the moment. $\endgroup$
    – Artes
    Feb 11, 2014 at 14:04
  • $\begingroup$ @Artes So then both this one and the other one are practically duplicates of that question. Do you agree? $\endgroup$
    – Szabolcs
    Feb 11, 2014 at 14:12
  • 2
    $\begingroup$ @Szabolcs I marked the other question as a duplicate, but I think the problem you pointed out here (dependence on the order of evaluation) is worth of explanation. $\endgroup$
    – Artes
    Feb 11, 2014 at 15:07

0

Browse other questions tagged or ask your own question.