Euler-Maclaurin summation

I want to compute asymptotic approximations to partial sum of harmonic series in Mathematica, using Euler-Maclaurin summation formula.

f[x_] := 1/x

em[n_] := Integrate[f[x], {x, 1, n}]
+ (f[1] + f[n])/2
+ Sum[BernoulliB[2k]/(2k)! ((D[ f[x], {x, 2 k - 1}] /. x -> n)
- D[f[x], {x, 2 k - 1}] /. x -> 1), {k, 1, Infinity}]

em[k] // FullSimplify


FullSimplify does not work..

How to simplify this expression? Where is a $\gamma$?

I try it in Maple:

How to do something like this in Mathematica?

• I think the missing $\gamma$ comes from the 'remainder' term of the Euler-Maclaurin formula. Feb 3, 2016 at 21:38

I would suggest adding option GenerateConditions->False to Integrate to speed up the integration. Then, instead of D, use Derivative. Then, to generate a SeriesData apply Series:

f[x_] := 1/x;
max = 4;

em[n_Symbol] :=
Series[Integrate[f[x], {x, 1, n},
GenerateConditions -> False] + (f[1] + f[n])/2 +
Sum[BernoulliB[2 k]/(2 k)! (Derivative[2 k - 1][f][n] -
Derivative[2 k - 1][f][1]), {k, 1, max+3}], {n, Infinity, max}]


Then

em[n]


Note: if you do em[k], you get conflict of local variables.

• I get 2897/5040 for max=1, but for max=4 (in example) I get 51621/80080 Feb 4, 2016 at 10:13
• In addition, for max=10 I get 8268803161823011/160626866400, these terms does not converge to (correct) EulerGamma. This program need a correction. Feb 4, 2016 at 10:20
• Had you a chance to fix this interesting piece of code ? Sep 1, 2017 at 4:48

According to AsymptoticSum,

In[1]:= AsymptoticSum[1/k, {k, 1, n}, n \[Rule] Infinity, SeriesTermGoal \[Rule] 7]

1        1        1      1
Out[1]= EulerGamma - ------ + ------ - ----- + --- + Log[n]
6        4       2   2 n
252 n    120 n    12 n



Alternatively,

In[2]:= Series[Unevaluated[Sum[1/k, {k, 1, n}]], {n, Infinity, 7}]

1      1       1        1          -8
Out[2]= (EulerGamma + Log[n]) + --- - ----- + ------ - ------ + O[n]
2 n       2        4        6
12 n    120 n    252 n



Both of them give the same result as Maple's eulermac(1/k, k = 1 .. n, 5);.