ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 30 Dec 2012 15:21:02 -0600Problem with infinite sumhttp://ask.sagemath.org/question/9666/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 with errors deleted.Sat, 29 Dec 2012 10:00:10 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/Comment by petropolis for <p>With Maple everything is so simple.</p>
<pre><code>R := n -> sum(bernoulli(2*k)/n^(2*k), k = 1..infinity);
seq(evalf(R(i)), i = 1..5);
0.1449340668,0.03986813370,...
</code></pre>
<p>With Sage that's another story.</p>
<pre><code>def R(n):
var('k')
return sum(bernoulli(2*k)/n^(2*k), k, 1, infinity)
[R(i) for i in (1..5)]
</code></pre>
<p>TypeError: unable to convert x (=2*k) to an integer. What do I miss?</p>
<p>EDIT with errors deleted.</p>
http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18467#post-id-18467Yes, you suggested import mpmath. Because of the effects you describe I always work with different worksheets, one with mpmath and one without. Of course this is peripheral here with regard to the problem.Sun, 30 Dec 2012 04:08:06 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18467#post-id-18467Comment by petropolis for <p>With Maple everything is so simple.</p>
<pre><code>R := n -> sum(bernoulli(2*k)/n^(2*k), k = 1..infinity);
seq(evalf(R(i)), i = 1..5);
0.1449340668,0.03986813370,...
</code></pre>
<p>With Sage that's another story.</p>
<pre><code>def R(n):
var('k')
return sum(bernoulli(2*k)/n^(2*k), k, 1, infinity)
[R(i) for i in (1..5)]
</code></pre>
<p>TypeError: unable to convert x (=2*k) to an integer. What do I miss?</p>
<p>EDIT with errors deleted.</p>
http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18466#post-id-18466Yes, I swapped n and k. Sorry for this. I deleted the edit.Sun, 30 Dec 2012 04:12:40 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18466#post-id-18466Answer by kcrisman for <p>With Maple everything is so simple.</p>
<pre><code>R := n -> sum(bernoulli(2*k)/n^(2*k), k = 1..infinity);
seq(evalf(R(i)), i = 1..5);
0.1449340668,0.03986813370,...
</code></pre>
<p>With Sage that's another story.</p>
<pre><code>def R(n):
var('k')
return sum(bernoulli(2*k)/n^(2*k), k, 1, infinity)
[R(i) for i in (1..5)]
</code></pre>
<p>TypeError: unable to convert x (=2*k) to an integer. What do I miss?</p>
<p>EDIT with errors deleted.</p>
http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?answer=14402#post-id-14402`bernoulli` is not a "symbolic function" in Sage, so it can't accept inputs that aren't integers like `2*k`. We are working on converting many previously only numerical functions in Sage to accept symbolic input (like [Bessel functions](http://trac.sagemath.org/sage_trac/ticket/4102)), but probably the first priority of number theorists in Sage wasn't to allow that particular functionality for Bernoulli numbers. Even if clever power series tricks can allow summations of such things.
So I don't think you can directly do the sum from 1 to infinity this way. However, the magic of lambda functions might make things nearly as good? I don't know what you are looking for exactly.
sage: F = lambda k,n: bernoulli(2*k)/n^(2*k)
But some experimentation suggests that if e.g. the sum for `n=1` really does converge to `-1/4/(e - e^(3/2))`, it must do so VERY slowly, so probably you would only be interested in the symbolic solution, which Maxima doesn't seem to have either.Sat, 29 Dec 2012 11:34:39 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?answer=14402#post-id-14402Comment by DSM for <p><code>bernoulli</code> is not a "symbolic function" in Sage, so it can't accept inputs that aren't integers like <code>2*k</code>. We are working on converting many previously only numerical functions in Sage to accept symbolic input (like <a href="http://trac.sagemath.org/sage_trac/ticket/4102">Bessel functions</a>), but probably the first priority of number theorists in Sage wasn't to allow that particular functionality for Bernoulli numbers. Even if clever power series tricks can allow summations of such things.</p>
<p>So I don't think you can directly do the sum from 1 to infinity this way. However, the magic of lambda functions might make things nearly as good? I don't know what you are looking for exactly.</p>
<pre><code>sage: F = lambda k,n: bernoulli(2*k)/n^(2*k)
</code></pre>
<p>But some experimentation suggests that if e.g. the sum for <code>n=1</code> really does converge to <code>-1/4/(e - e^(3/2))</code>, it must do so VERY slowly, so probably you would only be interested in the symbolic solution, which Maxima doesn't seem to have either.</p>
http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18470#post-id-18470We should really start leveraging more of `mpmath` and `sympy`. As a workaround for the numerics, `import mpmath; R = lambda n: mpmath.nsum(lambda k: mpmath.bernoulli(2*k)/n**(2*k), [1, mpmath.inf])` should work. BTW, you've almost hit 6k!!
Sat, 29 Dec 2012 11:52:15 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18470#post-id-18470Comment by petropolis for <p><code>bernoulli</code> is not a "symbolic function" in Sage, so it can't accept inputs that aren't integers like <code>2*k</code>. We are working on converting many previously only numerical functions in Sage to accept symbolic input (like <a href="http://trac.sagemath.org/sage_trac/ticket/4102">Bessel functions</a>), but probably the first priority of number theorists in Sage wasn't to allow that particular functionality for Bernoulli numbers. Even if clever power series tricks can allow summations of such things.</p>
<p>So I don't think you can directly do the sum from 1 to infinity this way. However, the magic of lambda functions might make things nearly as good? I don't know what you are looking for exactly.</p>
<pre><code>sage: F = lambda k,n: bernoulli(2*k)/n^(2*k)
</code></pre>
<p>But some experimentation suggests that if e.g. the sum for <code>n=1</code> really does converge to <code>-1/4/(e - e^(3/2))</code>, it must do so VERY slowly, so probably you would only be interested in the symbolic solution, which Maxima doesn't seem to have either.</p>
http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18469#post-id-18469@kcrisman Both types of solutions would be nice, of course. Thank you, I will help you to get the 6k for the case n=1 ;-))
@DSM mpmath is nice and even faster than Maple. Thank you. Write it as an answer and I will help you to reach the 5k. (By the way I soon will reach 100, nobody noticed this? :-)Sat, 29 Dec 2012 12:17:24 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18469#post-id-18469Comment by Francis Clarke for <p><code>bernoulli</code> is not a "symbolic function" in Sage, so it can't accept inputs that aren't integers like <code>2*k</code>. We are working on converting many previously only numerical functions in Sage to accept symbolic input (like <a href="http://trac.sagemath.org/sage_trac/ticket/4102">Bessel functions</a>), but probably the first priority of number theorists in Sage wasn't to allow that particular functionality for Bernoulli numbers. Even if clever power series tricks can allow summations of such things.</p>
<p>So I don't think you can directly do the sum from 1 to infinity this way. However, the magic of lambda functions might make things nearly as good? I don't know what you are looking for exactly.</p>
<pre><code>sage: F = lambda k,n: bernoulli(2*k)/n^(2*k)
</code></pre>
<p>But some experimentation suggests that if e.g. the sum for <code>n=1</code> really does converge to <code>-1/4/(e - e^(3/2))</code>, it must do so VERY slowly, so probably you would only be interested in the symbolic solution, which Maxima doesn't seem to have either.</p>
http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18465#post-id-18465The series certainly doesn't converge for n=1, since abs(bernoulli(2*k)) tends to infinity as k tends to infinity. In fact I don't believe that the series converges for any integral value of n, for I think $sum_{k=1}^{\infty}B_{2k}x^{2k}$ has zero radius of convergence. This should follow from knowing that $sum_{k=1}^{\infty}B_{2k}x^{2k}/(2k)!$ has radius of convergence $2\pi$; the value is $x/(e^x-1)-1-x/2$.Sun, 30 Dec 2012 05:10:19 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18465#post-id-18465Comment by petropolis for <p><code>bernoulli</code> is not a "symbolic function" in Sage, so it can't accept inputs that aren't integers like <code>2*k</code>. We are working on converting many previously only numerical functions in Sage to accept symbolic input (like <a href="http://trac.sagemath.org/sage_trac/ticket/4102">Bessel functions</a>), but probably the first priority of number theorists in Sage wasn't to allow that particular functionality for Bernoulli numbers. Even if clever power series tricks can allow summations of such things.</p>
<p>So I don't think you can directly do the sum from 1 to infinity this way. However, the magic of lambda functions might make things nearly as good? I don't know what you are looking for exactly.</p>
<pre><code>sage: F = lambda k,n: bernoulli(2*k)/n^(2*k)
</code></pre>
<p>But some experimentation suggests that if e.g. the sum for <code>n=1</code> really does converge to <code>-1/4/(e - e^(3/2))</code>, it must do so VERY slowly, so probably you would only be interested in the symbolic solution, which Maxima doesn't seem to have either.</p>
http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18464#post-id-18464@Francis Clarke "The series certainly doesn't converge for n=1, since abs(bernoulli(2k)) tends to infinity as k tends to infinity."
Hmmm, abs((-1)^k(k+1/k)) tends to infinity as k tends to infinity but sum((-1)^k(k+1/k)/n^k,k=1..infinity) converges, for n>1, if I am not mistaken.Sun, 30 Dec 2012 06:10:54 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18464#post-id-18464Comment by DSM for <p><code>bernoulli</code> is not a "symbolic function" in Sage, so it can't accept inputs that aren't integers like <code>2*k</code>. We are working on converting many previously only numerical functions in Sage to accept symbolic input (like <a href="http://trac.sagemath.org/sage_trac/ticket/4102">Bessel functions</a>), but probably the first priority of number theorists in Sage wasn't to allow that particular functionality for Bernoulli numbers. Even if clever power series tricks can allow summations of such things.</p>
<p>So I don't think you can directly do the sum from 1 to infinity this way. However, the magic of lambda functions might make things nearly as good? I don't know what you are looking for exactly.</p>
<pre><code>sage: F = lambda k,n: bernoulli(2*k)/n^(2*k)
</code></pre>
<p>But some experimentation suggests that if e.g. the sum for <code>n=1</code> really does converge to <code>-1/4/(e - e^(3/2))</code>, it must do so VERY slowly, so probably you would only be interested in the symbolic solution, which Maxima doesn't seem to have either.</p>
http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18461#post-id-18461Hey, neat! So all we've achieved is to find a way to get Sage to give the same incorrect extrapolated sum as Maple on a divergent series! Our work here is done! ;-)Sun, 30 Dec 2012 15:21:02 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18461#post-id-18461Comment by Francis Clarke for <p><code>bernoulli</code> is not a "symbolic function" in Sage, so it can't accept inputs that aren't integers like <code>2*k</code>. We are working on converting many previously only numerical functions in Sage to accept symbolic input (like <a href="http://trac.sagemath.org/sage_trac/ticket/4102">Bessel functions</a>), but probably the first priority of number theorists in Sage wasn't to allow that particular functionality for Bernoulli numbers. Even if clever power series tricks can allow summations of such things.</p>
<p>So I don't think you can directly do the sum from 1 to infinity this way. However, the magic of lambda functions might make things nearly as good? I don't know what you are looking for exactly.</p>
<pre><code>sage: F = lambda k,n: bernoulli(2*k)/n^(2*k)
</code></pre>
<p>But some experimentation suggests that if e.g. the sum for <code>n=1</code> really does converge to <code>-1/4/(e - e^(3/2))</code>, it must do so VERY slowly, so probably you would only be interested in the symbolic solution, which Maxima doesn't seem to have either.</p>
http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18462#post-id-18462The remark that $|B_{2k}|\to\infty$ was intended only to justify divergence for $n=1$. The final sentence implies divergence for $n>1$.Sun, 30 Dec 2012 11:05:47 -0600http://ask.sagemath.org/question/9666/problem-with-infinite-sum/?comment=18462#post-id-18462