In developing a large set of functions and definitions, I sometimes got zero unexpectedly. In trying to identify the problem via Trace, the fact that Integrate doesn't give much insight in its inner workings turned out unhelpful.
Eventually I realized that the issue can be formulated as a minimal working example as follows (neither x nor f[x] are defined in the below; so this is purely symbolic):
Integrate[f[x] x^2, x] - Integrate[f[x], x] x^2
Integrate[Integrate[f[x] x^2, x] - Integrate[f[x], x] x^2, x]
Integrate[Integrate[f[x] x^2, x], x] - Integrate[Integrate[f[x], x] x^2, x]
(*
Out[1]= Integrate[f[x] x^2, x] - Integrate[f[x], x] x^2
Out[2]= 0
Out[3]= Integrate[Integrate[f[x] x^2, x], x] - Integrate[Integrate[f[x], x] x^2, x]
*)
So, the first line is not zero of itself. Using it as integrand in another integration over x, however, does yield zero. In fact, it does so when replacing x^2 with x^n for all n>1.
From Integration by Parts by hand, however, I reckon that the correct answer is
-n Integrate[Integrate[f[x],x] x^(n-1), x]
integrated once more over x, which is non-zero in general. Moreover, given the linearity of Integration, I was surprised that the second and third input line do not give rise to the same result, according to Mathematica.
I suspect that source of confusion may be the multiple use of x. Indeed, for specified functions, or when the Integrals are given appropriate limits, the issue disappears. As I am interested in the Indefinite integrals, this does not solve my problem. Am I missing something, mathematically? Or is this explainable behaviour of Mathematica? And, is there a workaround, that would always give me the result Out[3]?
Integrate[]expressions (possibly because integrability is not automatically assumed). Related: (16098), (64422). – Michael E2 Nov 16 '16 at 13:34fthat your hand result of a constant-nis incorrect. (I was assuming you had that right when I made my earlier comment) – george2079 Nov 16 '16 at 14:59Integrate[-n Integrate[Integrate[f[x],x] x^(n-1), x],x]is correct, apart from constants, that is, and for nice f. Confusion may have arisen from SE's line-breaking? – RamonC Nov 16 '16 at 15:06g2[x_] := Integrate[f[x], x] x^2;
g3[x_] := Integrate[g1[x] - g2[x], x];
g4[x_] := Integrate[g1[x], x];
g5[x_] := Integrate[g2[x], x];
g6[x_] := Integrate[g4[x] - g5[x], x]; – Akku14 Nov 18 '16 at 08:52