# Differing answers when comparing Wolfram Alpha and Mathematica v.10.2

Out of curiousity, please consider following expression:

Sum[(-1)^(n + 1)/n, {n, 1, 100000}]


When evaluated using Wolfram Alpha:

Result: 0.693142 - 1.3494*10^-16 I , complex number

When evaluated using Mathematica v.10.2 (to 6 decimal places):

Result: 0.693142, rational number

Why Wolfram Alpha evaluates expression stated above to a complex number?

• Pure speculation: Maybe WA evaluates a^b as Exp[Log[a]*b]. That would give complex numbers in intermediate calculations, where the imaginary part doesn't perfectly cancel out due to numerical inaccuracy. Compare: Sum[Exp[Log[(-1.)]*(n + 1)]/n, {n, 1, 100000}] in Mathematica gives a complex result, too (though not the same...) Apr 7, 2016 at 16:11
• After a discussion with my mentor, he suggested that it must be a rounding error with which I tend to agree. If WA evaluates it as a^b it would be rather inefficient although generic at the same time. It's rather curious to say the least. Apr 7, 2016 at 16:44
• Sum[(-1)^(n + 1)/n, {n, 1, m}] /. m -> 100000. or (Sum[(-1)^(n + 1)/n, {n, 1, m}] /. m -> 100000) // N or NSum[(-1)^(n + 1)/n, {n, 1, 1000000}] // Chop Apr 7, 2016 at 23:20

For large enough bounds, NSum is used. Compare timings:

NSum[(-1)^(n + 1)/n, {n, 1, 100000}] // AbsoluteTiming

{0.004744, 0.693142 - 1.3494*10^-16 I}

N[Sum[(-1)^(n + 1)/n, {n, 1, 100000}]] // AbsoluteTiming

{1.84727, 0.693142}