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).
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).
The first result can be obtained using Dirichlet regularization:
Sum[n, {n, 1, Infinity}, Regularization -> "Dirichlet"]
-(1/12)
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.
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$
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},
FullSimplify[
-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 *)
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$
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!