Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem with infinite sum

With Maple everything is so simple.

R := n -> sum(bernoulli(2*k)/n^(2*k), k = 1..infinity);
seq(evalf(R(i)), i = 1..5);
0.1449340668,0.03986813370,...

With Sage that's another story.

def R(n):
    var('k')
    return sum(bernoulli(2*k)/n^(2*k), k, 1, infinity)

[R(i) for i in (1..5)]

TypeError: unable to convert x (=2*k) to an integer. What do I miss?

Problem with infinite sum

With Maple everything is so simple.

R := n -> sum(bernoulli(2*k)/n^(2*k), k = 1..infinity);
seq(evalf(R(i)), i = 1..5);
0.1449340668,0.03986813370,...

With Sage that's another story.

def R(n):
    var('k')
    return sum(bernoulli(2*k)/n^(2*k), k, 1, infinity)

[R(i) for i in (1..5)]

TypeError: unable to convert x (=2*k) to an integer. What do I miss?

EDIT:

kcrisman suggested the magic:

B = lambda k,n: bernoulli(2*k)/n^(2*k)
def S(n):
    var('k')
    return sum(B(n,k), k, 1, oo)
[S(i).n() for i in (1..5)]
[0.274155677808038, -0.0360774411237046, 0.0242224538567726,...

DSM suggested the magic:

from mpmath import *
mp.dps = 16; mp.pretty = True
R = lambda n: mp.nsum(lambda k: mp.bernoulli(2*k)/n**(2*k), [1, mp.inf]) 
[R(i) for i in (1..5)]
[0.1449340673576982, 0.03986813369645288, 0.01813553387801264, ...

Obviously the two magics are not compatible.

Problem with infinite sum

With Maple everything is so simple.

R := n -> sum(bernoulli(2*k)/n^(2*k), k = 1..infinity);
seq(evalf(R(i)), i = 1..5);
0.1449340668,0.03986813370,...

With Sage that's another story.

def R(n):
    var('k')
    return sum(bernoulli(2*k)/n^(2*k), k, 1, infinity)

[R(i) for i in (1..5)]

TypeError: unable to convert x (=2*k) to an integer. What do I miss?

EDIT:

kcrisman suggested the magic:

B = lambda k,n: bernoulli(2*k)/n^(2*k)
def S(n):
    var('k')
    return sum(B(n,k), k, 1, oo)
[S(i).n() for i in (1..5)]
[0.274155677808038, -0.0360774411237046, 0.0242224538567726,...

DSM suggested the magic:

from mpmath import *
mp.dps = 16; mp.pretty = True
R = lambda n: mp.nsum(lambda k: mp.bernoulli(2*k)/n**(2*k), [1, mp.inf]) 
[R(i) for i in (1..5)]
[0.1449340673576982, 0.03986813369645288, 0.01813553387801264, ...

Obviously the two magics are not compatible. EDIT with errors deleted.