I am sure one has to use indefinite sums and the Euler-Maclaurin formula.

$$\sum_{x=0}^{n} f(x)=\sum_{x}f(n+1)-\sum_{x}f(0)=\int_{0}^{n+1}f(t) \ dt -\frac{1}{2}f(n+1)+\left(\sum_{k=1}^{\infty}\frac{B_{2k}}{(2k)!}f^{(2k-1)}(n+1)\right)+\frac{1}{2}f(0)-\left(\sum_{k=1}^{\infty}\frac{B_{2k}}{(2k)!}f^{(2k-1)}(0)\right)$$

Where $\sum\limits_{x}$ is the anti-difference operator and $B_{2k}$ is the sequence of Bernoulli numbers.

For example with $\tan(x)$I tried the following.

    F[n_] := NIntegrate[Tan[x], {x, 0, n + 1}] - 1/2*Tan[n + 1] + 
  Sum[(BernoulliB[2 k] D[Tan[n + 1], 2 k - 1])/(Factorial[2 k]), {k, 
    1, 1000}] + 1/2*Tan[0] - 
  Sum[(BernoulliB[2 k] D[Tan[0], 2 k - 1])/(Factorial[2 k]), {k, 1, 

But this does not work since the integral does not converge fast enough at the asymptotes.

One person told me approximating such a sum works at an interval from $[-\pi/2,\pi/2]$. In such cases how do we extend the rate of convergence.

Can programming be used efficiently in such a process?

  • $\begingroup$ What have you tried? $\endgroup$
    – JimB
    Commented May 13, 2019 at 3:17
  • $\begingroup$ I'm not sure how to perform an anti-difference operator. I'm looking all over for it in the Mathematica documentation. $\endgroup$
    – Arbuja
    Commented May 13, 2019 at 13:55
  • $\begingroup$ I found the documentation but it won't work for $\tan(x)$. I will use the approximation. $\endgroup$
    – Arbuja
    Commented May 13, 2019 at 14:25
  • $\begingroup$ @JimB Here is what I tried. Could you try generalizing this to all $f(x)$ $\endgroup$
    – Arbuja
    Commented May 13, 2019 at 16:59
  • $\begingroup$ I'm afraid my knowledge is not sufficient to generalize this. My role with my initial comment was to attempt to get you to supply some sort of effort on your part with Mathematica code. Folks here generally respond better when an explicit effort is made. (Although, one can sometimes hook someone with no Mathematica effort if you present a very interesting problem.) $\endgroup$
    – JimB
    Commented May 13, 2019 at 17:09

1 Answer 1


Not a solution but a long comment. tl;dr — I don't think this can be done for $f(x)=\tan(x)$.

One of the conditions for the Euler-Maclaurin formula to work is that the function must be continuous. This is not the case here.

More concretely for this case, using the pigeonhole principle it's easy to see that as $n$ grows larger, some index values $x\in\{0..n\}$ will be arbitrarily close to half-integer multiples of $\pi$, and therefore their contributions to the sum will be arbitrarily large (and quasi-random). As a result, the sum $\sum_{x=0}^{n}\tan(x)$ does wild jumps at quasi-random points, and therefore I do not believe these jumps can be series-approximated by only looking at derivatives around $x=n$, as in the Euler-Maclaurin formula.

Some examples to show the quasi-random behavior. You can see that even for large $n$ this sum has significant structure, and that this structure is different at every scale (i.e., every plot looks different even though I've simply expanded the horizontal axis ten-fold):

pl[n_] := ListPlot[Accumulate[N[Tan[Range[0, n]]]], Frame -> True]
pl /@ (10^Range[6])

enter image description here

  • $\begingroup$ Regarding your first point, would we not be able to restrict the window in which we approximate, such that we see a continuous function? What I mean is, OP mentions an interval, we can use this, no? $\endgroup$ Commented May 20, 2019 at 9:24
  • $\begingroup$ @CATrevillian sure you can use the EML formula to approximate an integral on an interval; but I don't see how that's related to the OP's question. OP mentions an interval but doesn't connect it with the question. $\endgroup$
    – Roman
    Commented May 20, 2019 at 9:32
  • $\begingroup$ My mistake! It is still early here. I had read it as asking how to approximate the Tan[x] function using the Euler-Maclaurin Series/Formula, and that since it works at the interval indicated, how do we increase the rate of convergence, i.e. how do we reduce the number of require steps to approximate the function over the interval. Regardless, very nice work here. I enjoy your answers quite a bit, they help myself and my colleagues to learn a great deal :D $\endgroup$ Commented May 20, 2019 at 9:44
  • $\begingroup$ @Roman What about a series approximation of the anti-difference of $\tan(x)$, mathoverflow.net/questions/41011/… $\endgroup$
    – Arbuja
    Commented May 21, 2019 at 2:39
  • 1
    $\begingroup$ @Arbuja the answer given on the page you link is, in my opinion, an answer only a mathematician can love. The given anti-difference T[x_] = I*x - QPolyGamma[x+π/2, E^(2*I)] indeed technically satisfies DifferenceDelta[T[x], x] == Tan[x], but the function T[x] is itself infinite for almost all $x$ because the $q$-digamma function does not converge for $q=e^{2i}$. In other words, T[x] and T[x+1] are infinite but such that T[x+1]-T[x]==Tan[x]. All this is discussed at length in the comments on the page you link. $\endgroup$
    – Roman
    Commented May 21, 2019 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.