How to implement Ramanujan's summation in symbolic form in Mathematica?

For instance, I want as input the function $f(x)=x$, as output $-1/12$, as input $f(x)=1/x$, as output $\gamma$ (Euler's constant).

  • $\begingroup$ Have you looked at the existing Ramanujan functions currently available in Mathematica? $\endgroup$
    – Edmund
    Apr 21 '15 at 2:46
  • $\begingroup$ Well, actually I really tried to solve this problem for a while on the day you raised this question, but finally be confused and worn out by the definition in the wikipedia page. There seems to be several different definitions in wiki, and none of them produces the desired result, maybe I didn't understand them correctly... $\endgroup$
    – xzczd
    May 7 '15 at 5:32

The first result can be obtained using Dirichlet regularization:

Sum[n, {n, 1, Infinity}, Regularization -> "Dirichlet"]


The second can not be obtained, though. I don't have enough smarts to know if this is because it would actually require different regularization, or that Mma just doesn't know how to handle this case.

  • 3
    $\begingroup$ Ramanujan's summation applies not only to power series, so Zeta regularization is not applicable in the majority of cases. One of the general formulas is $$-\sum_{n=1}^{\infty} \frac{ g^{(n-1)} (0)}{n!} B_n(1)$$ for $g(x)=\Delta [f(x)]$ but how to get it in closed form? $\endgroup$
    – Anixx
    Apr 21 '15 at 10:56
  • 1
    $\begingroup$ @Anixx What's the definition of $\Delta[]$? $\endgroup$
    – xzczd
    May 7 '15 at 5:11
  • 1
    $\begingroup$ @xzczd difference delta, f(x+1)-f(x). $\endgroup$
    – Anixx
    May 7 '15 at 6:16
  • 2
    $\begingroup$ @Anixx Seems to be another invalid definition: f[x_] = x; g[x_] = DifferenceDelta[f[x], x]; -NSum[ BernoulliB[Floor@n, 1]/n! Derivative[n - 1][g][0], {n, Infinity}] produces -0.5. $\endgroup$
    – xzczd
    May 7 '15 at 6:45
  • 1
    $\begingroup$ @xzczd this is correct, my comment is somewhat confusing. The ramanujan's sum of g(x)=1 is indeed -0.5. In the comment I meant that I want the Ramanujan's sum of the difference delta. I want a similar formula but giving symbolic results. $\endgroup$
    – Anixx
    May 7 '15 at 7:37

OK, with your new formula I'm able to give an incomplete answer now. The difficulty in implementing the forumla

$$-\sum _{n=1}^{\infty } \frac{B_n(1) f^{(n-1)}(0)}{n!}$$

is how to symbolically compute the n-th derivative, which is discussed here. Use the solution in that post, we can easily obtain this:

ramanujanSum[f_] := 
 Block[{x, n}, 
     -Sum[BernoulliB[n, 1]/n SeriesCoefficient[f[x], {x, 0, n - 1}], {n, ∞}], 
   n >= 1]]

Notice that f should be a functional relation.

It manages to handle some of the Ramanujan summation mentioned in the corresponding wikipedia page:

ramanujanSum[# &]
(* -1/12 *)
ramanujanSum[1 &]
(* -1/2 *)
Assuming[{k ∈ Integers, k > 0}, ramanujanSum[#^(2 k - 1) &]]
(* -BernoulliB[2 k, 1]/(2 k) *)    
Assuming[{k ∈ Integers, k > 0}, ramanujanSum[#^(2 k) &]]
(* 0 *)

But fails in others:

ramanujanSum[1/# &]
(* The output is wrong, which is expected: 
   the implemented formula doesn't apply to this sequence. *)
trouble = ramanujanSum[(-1)^(# - 1) &]
(*  Sadly Sum seems not to be able to handle the final summation. *)

How can one improve it? I've no idea at the moment.

BTW, I doubt if the Ramanujan summation for $(-1)^{n-1}$ is (as stated in the wikipedia page) $1/2$:

trouble /. Sum -> NSum // Quiet
(* 0.5 + 0.31831 I *)
  • $\begingroup$ One can use the filliwing formula alternatively: $$\sum_{k=1}^{\infty}\frac{\Delta^{k-1}[f](1)}{k!}(-1)_k$$ where $$(x)_k=\frac{\Gamma(x+1)}{\Gamma(x-k+1)}$$ is the Porchhammer symbol (failing factorial). AFAIK it is implemented in Mathematica, otherwise one should employ limits because the both numerfator and denomenator have poles at the points. $\endgroup$
    – Anixx
    May 7 '15 at 9:25
  • $\begingroup$ I think your method is not suitable for anything other the polynomials because in that case the sum becomes finite. Mathematica cannot find the infinite sums :-(. $\endgroup$
    – Anixx
    May 7 '15 at 9:33
  • 1
    $\begingroup$ @Anixx Yeah, the ability of Sum seems to become the new threshold. BTW the new formula using DifferenceDelta is even harder to implement… p.s. I suggest you to add these formulas to the question rather than in the comment only. $\endgroup$
    – xzczd
    May 7 '15 at 11:47

As Kirma correctly stated, the infinite sum of all natural numbers (Ramanujan's Summation) can be calculated in Mathematica through the Dirichlet Regularization denoted by:

Sum[n, {n, 1, Infinity}, Regularization -> "Dirichlet"]

However, the second part of your question is partially wrong which is why you're getting an incorrect answer. The Euler–Mascheroni constant gamma is defined by the limit as n goes to infinity of the harmonic series (the sum from one to infinity, or n in this case with the limit) of 1/k minus the natural logarithm of n. So in this case,

Limit[Sum[1/k, {k, 1, n}] - Log[n], n -> ∞]

returns EulerGamma, which is that constant that you're referring to.

I'm not sure how you do all of the cool formatting, but hopefully this helps!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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