A case when the sum rule in integration does not work in Mathematica
Instead of comparing with the sum rule, it is perhaps more direct to differentiate the integral and compare. When integrating just two terms of the sum for n
up to 10
, there are 7 pairs which integrate incorrectly:
ClearAll[test];
mem : test[i_, j_] := mem = Module[{func, prim},
func = 1/i^s*2^(s - 1) + 1/j^s*2^(s - 1);
prim = Integrate[func, s];
Simplify[func - D[prim, s]] === 0
];
nn = 10;
failed = Flatten@Table[! test[i, j], {i, nn}, {j, i + 1, nn}];
Pick[Flatten[Table[{i, j}, {i, nn}, {j, i + 1, nn}], 1], failed]
(* {{1, 6}, {1, 10}, {3, 5}, {3, 7}, {5, 7}, {5, 9}, {7, 9}} *)
Checking the first failure explicitly:
With[{i = 1, j = 6},
func = 1/i^s*2^(s - 1) + 1/j^s*2^(s - 1)];
prim = Integrate[func, s]
func - D[prim, s] // Simplify
func - D[prim, s] /. s -> 1.
(*
1/2 (-(3^-s/Log[3]) + 2^s/Log[12])
(2^(-1 + s) Log[6])/Log[12]
0.721057
*)
These integration results are the same in version 11.2.
It seems as though the issue may be related the indefinite integration. The expressions produced if an arbitrary definite integration is chosen instead are equivalent:
a = Sum[Integrate[1/n^s*2^(s - 1), {s, si, sf}], {n, 1, 6}];
b = Integrate[Sum[1/n^s*2^(s - 1), {n, 1, 6}], {s, si, sf}];
Simplify[a==b]
True
Of course, any sum of different constants of integration would be expected to also be constant, which is not the case here.
As an even more minimal case of issues:
a = Sum[Integrate[1/n^s*2^(s - 1), s], {n, {3, 5}}];
b = Integrate[Sum[1/n^s*2^(s - 1), {n, {3, 5}}], s];
Simplify[a == b]
Produces a variable expression as well, despite only being the sum of two terms.