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.