Skip to main content
1 of 3
xzczd
  • 68.4k
  • 9
  • 174
  • 489

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. *)
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.

xzczd
  • 68.4k
  • 9
  • 174
  • 489