ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 12 Oct 2014 10:40:27 -0500A hypergeometric serieshttps://ask.sagemath.org/question/24257/a-hypergeometric-series/Mathematica's
Table[2 HypergeometricPFQ[{-n+1,2-n},{2},-1],{n,0,46}]
as well as Maple's
seq(round(evalf(2*hypergeom([-n+1,2-n],[2],-1),100)),n=0..46);
lead to
1, 2, 2, 0, -2, 0, 4, 0, -10, ... https://oeis.org/A182122
How can I compute this sequence with Sage?
A182122 = lambda n: 2*hypergeometric([-n+1,2-n],[2],-1)
[A182122(n).n(100) for n in (0..46)]
Unfortunately this was not successful.
*Addition:*
This is not an isolated problem. I give a second example:
Motzkin sums http://oeis.org/A005043
A005043 = lambda n: (-1)^n*hypergeometric([-n,1/2],[2],4)
[Integer(A005043(n).n(100)) for n in (0..29)]
In this case there is this 'workaround':
A005043 = lambda n: (-1)^n*jacobi_P(n,1,-n-3/2,-7)/(n+1)
[Integer(A005043(n).n(100)) for n in (0..29)]
And Maxima gets it right too:
maxima_calculus('makelist((-1)^n*hypergeometric([-n,1/2],[2],4),n,0,29)')
Tue, 23 Sep 2014 07:39:52 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/Comment by Dima for <p>Mathematica's </p>
<pre><code>Table[2 HypergeometricPFQ[{-n+1,2-n},{2},-1],{n,0,46}]
</code></pre>
<p>as well as Maple's</p>
<pre><code>seq(round(evalf(2*hypergeom([-n+1,2-n],[2],-1),100)),n=0..46);
</code></pre>
<p>lead to </p>
<pre><code>1, 2, 2, 0, -2, 0, 4, 0, -10, ... https://oeis.org/A182122
</code></pre>
<p>How can I compute this sequence with Sage? </p>
<pre><code>A182122 = lambda n: 2*hypergeometric([-n+1,2-n],[2],-1)
[A182122(n).n(100) for n in (0..46)]
</code></pre>
<p>Unfortunately this was not successful.</p>
<p><em>Addition:</em></p>
<p>This is not an isolated problem. I give a second example:
Motzkin sums <a href="http://oeis.org/A005043">http://oeis.org/A005043</a> </p>
<pre><code>A005043 = lambda n: (-1)^n*hypergeometric([-n,1/2],[2],4)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>In this case there is this 'workaround':</p>
<pre><code>A005043 = lambda n: (-1)^n*jacobi_P(n,1,-n-3/2,-7)/(n+1)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>And Maxima gets it right too:</p>
<pre><code>maxima_calculus('makelist((-1)^n*hypergeometric([-n,1/2],[2],4),n,0,29)')
</code></pre>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24266#post-id-24266you can do the last line as
sage: [(-1)^n*maxima_calculus.hgfred([-n,1/2],[2],4) for n in [0..29]]Wed, 24 Sep 2014 05:33:51 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24266#post-id-24266Comment by Dima for <p>Mathematica's </p>
<pre><code>Table[2 HypergeometricPFQ[{-n+1,2-n},{2},-1],{n,0,46}]
</code></pre>
<p>as well as Maple's</p>
<pre><code>seq(round(evalf(2*hypergeom([-n+1,2-n],[2],-1),100)),n=0..46);
</code></pre>
<p>lead to </p>
<pre><code>1, 2, 2, 0, -2, 0, 4, 0, -10, ... https://oeis.org/A182122
</code></pre>
<p>How can I compute this sequence with Sage? </p>
<pre><code>A182122 = lambda n: 2*hypergeometric([-n+1,2-n],[2],-1)
[A182122(n).n(100) for n in (0..46)]
</code></pre>
<p>Unfortunately this was not successful.</p>
<p><em>Addition:</em></p>
<p>This is not an isolated problem. I give a second example:
Motzkin sums <a href="http://oeis.org/A005043">http://oeis.org/A005043</a> </p>
<pre><code>A005043 = lambda n: (-1)^n*hypergeometric([-n,1/2],[2],4)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>In this case there is this 'workaround':</p>
<pre><code>A005043 = lambda n: (-1)^n*jacobi_P(n,1,-n-3/2,-7)/(n+1)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>And Maxima gets it right too:</p>
<pre><code>maxima_calculus('makelist((-1)^n*hypergeometric([-n,1/2],[2],4),n,0,29)')
</code></pre>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24260#post-id-24260looks like a bug in Maxima interface to me (or perhaps the options Sage starts Maxima with are causing this). (EDIT, nope, it has nothing to do with Maxima, it's mpmath)Tue, 23 Sep 2014 15:31:31 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24260#post-id-24260Answer by rws for <p>Mathematica's </p>
<pre><code>Table[2 HypergeometricPFQ[{-n+1,2-n},{2},-1],{n,0,46}]
</code></pre>
<p>as well as Maple's</p>
<pre><code>seq(round(evalf(2*hypergeom([-n+1,2-n],[2],-1),100)),n=0..46);
</code></pre>
<p>lead to </p>
<pre><code>1, 2, 2, 0, -2, 0, 4, 0, -10, ... https://oeis.org/A182122
</code></pre>
<p>How can I compute this sequence with Sage? </p>
<pre><code>A182122 = lambda n: 2*hypergeometric([-n+1,2-n],[2],-1)
[A182122(n).n(100) for n in (0..46)]
</code></pre>
<p>Unfortunately this was not successful.</p>
<p><em>Addition:</em></p>
<p>This is not an isolated problem. I give a second example:
Motzkin sums <a href="http://oeis.org/A005043">http://oeis.org/A005043</a> </p>
<pre><code>A005043 = lambda n: (-1)^n*hypergeometric([-n,1/2],[2],4)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>In this case there is this 'workaround':</p>
<pre><code>A005043 = lambda n: (-1)^n*jacobi_P(n,1,-n-3/2,-7)/(n+1)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>And Maxima gets it right too:</p>
<pre><code>maxima_calculus('makelist((-1)^n*hypergeometric([-n,1/2],[2],4),n,0,29)')
</code></pre>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?answer=24469#post-id-24469There is another way to solve it in Sage, and we can completely do away with the use of Maxima here:
sage: from sage.functions.hypergeometric import closed_form
sage: [2*closed_form(hypergeometric([1-n,2-n],[2],-1)) for n in [1..20]]
[2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0, -858, 0, 2860, 0, -9724]
Maxima is still 2x faster with `n in [1..2000]` though.
See documentation at http://sagemath.org/doc/reference/functions/sage/functions/hypergeometric.htmlSun, 12 Oct 2014 10:40:27 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?answer=24469#post-id-24469Answer by nbruin for <p>Mathematica's </p>
<pre><code>Table[2 HypergeometricPFQ[{-n+1,2-n},{2},-1],{n,0,46}]
</code></pre>
<p>as well as Maple's</p>
<pre><code>seq(round(evalf(2*hypergeom([-n+1,2-n],[2],-1),100)),n=0..46);
</code></pre>
<p>lead to </p>
<pre><code>1, 2, 2, 0, -2, 0, 4, 0, -10, ... https://oeis.org/A182122
</code></pre>
<p>How can I compute this sequence with Sage? </p>
<pre><code>A182122 = lambda n: 2*hypergeometric([-n+1,2-n],[2],-1)
[A182122(n).n(100) for n in (0..46)]
</code></pre>
<p>Unfortunately this was not successful.</p>
<p><em>Addition:</em></p>
<p>This is not an isolated problem. I give a second example:
Motzkin sums <a href="http://oeis.org/A005043">http://oeis.org/A005043</a> </p>
<pre><code>A005043 = lambda n: (-1)^n*hypergeometric([-n,1/2],[2],4)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>In this case there is this 'workaround':</p>
<pre><code>A005043 = lambda n: (-1)^n*jacobi_P(n,1,-n-3/2,-7)/(n+1)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>And Maxima gets it right too:</p>
<pre><code>maxima_calculus('makelist((-1)^n*hypergeometric([-n,1/2],[2],4),n,0,29)')
</code></pre>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?answer=24269#post-id-24269 There's definitely a bug in the numerical evaluation of hypergeometric functions here, but if you are interested in the integer values that this sequence takes, ".n()" by itself is a bit risky: You'd need to instruct it to produce a result to sufficient precision that rounding gives you the correct answer.
As was noted already, Maxima knows how to evaluate these hypergeometric functions properly and does so without numerical approximation. The easier way to get the sequence you want is to give maxima an opportunity to look at the expression, which is what "simplify" does. So:
sage: [A182122(n).simplify() for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
If you don't like simplify because it might do strange things, simply round-tripping to maxima works too:
sage: [ZZ(maxima_calculus(A182122(n))) for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
(and you'll get a sequence of integers that way, not a sequence of symbolic expressions that happen to be integers)Wed, 24 Sep 2014 10:38:09 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?answer=24269#post-id-24269Comment by Peter Luschny for <p>There's definitely a bug in the numerical evaluation of hypergeometric functions here, but if you are interested in the integer values that this sequence takes, ".n()" by itself is a bit risky: You'd need to instruct it to produce a result to sufficient precision that rounding gives you the correct answer.</p>
<p>As was noted already, Maxima knows how to evaluate these hypergeometric functions properly and does so without numerical approximation. The easier way to get the sequence you want is to give maxima an opportunity to look at the expression, which is what "simplify" does. So:</p>
<pre><code>sage: [A182122(n).simplify() for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>If you don't like simplify because it might do strange things, simply round-tripping to maxima works too:</p>
<pre><code>sage: [ZZ(maxima_calculus(A182122(n))) for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>(and you'll get a sequence of integers that way, not a sequence of symbolic expressions that happen to be integers)</p>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24278#post-id-24278"If you are interested in the integer values that this sequence takes, .n() is the wrong tool anyway." Why? If we can approximate this value fast numerically what is wrong doing so and then round to an integer? I think your proposed 'simplify'-method is *much* slower.
No, I suspect the problem is the extension in the limit. Consider A = lambda x: -pi/(gamma(x/2)^2*x*sin(pi*(1+x/2))*gamma(2-x)).
Now for instance limit(A(x), x = 10) gives the ValueError: "oo times number < oo not defined". But 2*limit(A(x), x = 10) exists and is 28. Another error? The same error in disguise?Wed, 24 Sep 2014 14:30:52 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24278#post-id-24278Comment by nbruin for <p>There's definitely a bug in the numerical evaluation of hypergeometric functions here, but if you are interested in the integer values that this sequence takes, ".n()" by itself is a bit risky: You'd need to instruct it to produce a result to sufficient precision that rounding gives you the correct answer.</p>
<p>As was noted already, Maxima knows how to evaluate these hypergeometric functions properly and does so without numerical approximation. The easier way to get the sequence you want is to give maxima an opportunity to look at the expression, which is what "simplify" does. So:</p>
<pre><code>sage: [A182122(n).simplify() for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>If you don't like simplify because it might do strange things, simply round-tripping to maxima works too:</p>
<pre><code>sage: [ZZ(maxima_calculus(A182122(n))) for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>(and you'll get a sequence of integers that way, not a sequence of symbolic expressions that happen to be integers)</p>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24280#post-id-24280@kcrisman: yes, you're right! I didn't know. I assumed some basic maxima tools would be called too.Wed, 24 Sep 2014 19:06:14 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24280#post-id-24280Comment by nbruin for <p>There's definitely a bug in the numerical evaluation of hypergeometric functions here, but if you are interested in the integer values that this sequence takes, ".n()" by itself is a bit risky: You'd need to instruct it to produce a result to sufficient precision that rounding gives you the correct answer.</p>
<p>As was noted already, Maxima knows how to evaluate these hypergeometric functions properly and does so without numerical approximation. The easier way to get the sequence you want is to give maxima an opportunity to look at the expression, which is what "simplify" does. So:</p>
<pre><code>sage: [A182122(n).simplify() for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>If you don't like simplify because it might do strange things, simply round-tripping to maxima works too:</p>
<pre><code>sage: [ZZ(maxima_calculus(A182122(n))) for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>(and you'll get a sequence of integers that way, not a sequence of symbolic expressions that happen to be integers)</p>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24279#post-id-24279@Luschny: yes, I've edited the answer to reflect this. There's a bit of extra
work, though: you'd have to first bound the size of the answer and then
determine a precision that will allow you to recognize the integer from it. And
of course ensure that the algorithm actually produces an answer that is correct
to the requested precision.
If we're lucky, maxima is already using something efficient to evaluate these
integer values. It certainly seems fairly competitive with the other
maxima-based option:
sage: %timeit [ZZ(maxima_calculus(A182122(n))) for n in [1..2000]]
1 loops, best of 3: 9.93 s per loop
sage: %timeit [2*maxima_calculus.hgfred([1-n,2-n],[2],-1) for n in [1..2000]]
1 loops, best of 3: 24.1 s per loop
So among the methods that readily seem to work, relying on what maxima does with
`hypergeometric` doesn't seem so bad.Wed, 24 Sep 2014 19:04:22 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24279#post-id-24279Comment by kcrisman for <p>There's definitely a bug in the numerical evaluation of hypergeometric functions here, but if you are interested in the integer values that this sequence takes, ".n()" by itself is a bit risky: You'd need to instruct it to produce a result to sufficient precision that rounding gives you the correct answer.</p>
<p>As was noted already, Maxima knows how to evaluate these hypergeometric functions properly and does so without numerical approximation. The easier way to get the sequence you want is to give maxima an opportunity to look at the expression, which is what "simplify" does. So:</p>
<pre><code>sage: [A182122(n).simplify() for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>If you don't like simplify because it might do strange things, simply round-tripping to maxima works too:</p>
<pre><code>sage: [ZZ(maxima_calculus(A182122(n))) for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>(and you'll get a sequence of integers that way, not a sequence of symbolic expressions that happen to be integers)</p>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24274#post-id-24274But doesn't simplify just round-trip to Maxima as well? Should there be any difference? Or would the types change or something?Wed, 24 Sep 2014 12:25:52 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24274#post-id-24274Comment by rws for <p>There's definitely a bug in the numerical evaluation of hypergeometric functions here, but if you are interested in the integer values that this sequence takes, ".n()" by itself is a bit risky: You'd need to instruct it to produce a result to sufficient precision that rounding gives you the correct answer.</p>
<p>As was noted already, Maxima knows how to evaluate these hypergeometric functions properly and does so without numerical approximation. The easier way to get the sequence you want is to give maxima an opportunity to look at the expression, which is what "simplify" does. So:</p>
<pre><code>sage: [A182122(n).simplify() for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>If you don't like simplify because it might do strange things, simply round-tripping to maxima works too:</p>
<pre><code>sage: [ZZ(maxima_calculus(A182122(n))) for n in (0..15)]
[1, 2, 2, 0, -2, 0, 4, 0, -10, 0, 28, 0, -84, 0, 264, 0]
</code></pre>
<p>(and you'll get a sequence of integers that way, not a sequence of symbolic expressions that happen to be integers)</p>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24346#post-id-24346Fix is in http://trac.sagemath.org/ticket/17066
Please review.Tue, 30 Sep 2014 11:52:47 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24346#post-id-24346Answer by Dima for <p>Mathematica's </p>
<pre><code>Table[2 HypergeometricPFQ[{-n+1,2-n},{2},-1],{n,0,46}]
</code></pre>
<p>as well as Maple's</p>
<pre><code>seq(round(evalf(2*hypergeom([-n+1,2-n],[2],-1),100)),n=0..46);
</code></pre>
<p>lead to </p>
<pre><code>1, 2, 2, 0, -2, 0, 4, 0, -10, ... https://oeis.org/A182122
</code></pre>
<p>How can I compute this sequence with Sage? </p>
<pre><code>A182122 = lambda n: 2*hypergeometric([-n+1,2-n],[2],-1)
[A182122(n).n(100) for n in (0..46)]
</code></pre>
<p>Unfortunately this was not successful.</p>
<p><em>Addition:</em></p>
<p>This is not an isolated problem. I give a second example:
Motzkin sums <a href="http://oeis.org/A005043">http://oeis.org/A005043</a> </p>
<pre><code>A005043 = lambda n: (-1)^n*hypergeometric([-n,1/2],[2],4)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>In this case there is this 'workaround':</p>
<pre><code>A005043 = lambda n: (-1)^n*jacobi_P(n,1,-n-3/2,-7)/(n+1)
[Integer(A005043(n).n(100)) for n in (0..29)]
</code></pre>
<p>And Maxima gets it right too:</p>
<pre><code>maxima_calculus('makelist((-1)^n*hypergeometric([-n,1/2],[2],4),n,0,29)')
</code></pre>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?answer=24261#post-id-24261Looks like a bug in mpmath (or in mpmath interface).
A workaround is to call Maxima directly (via its library interface), as follows:
sage: maxima_calculus('makelist(2*hypergeometric([-n+2,3-n],[2],-1),n,47)')
EDIT: the following is more Sage-like:
sage: [2*maxima_calculus.hgfred([1-n,2-n],[2],-1) for n in [0..46]]
EDIT': one particular issue with mpmath is that it tries evaluating up to correct relative precision (unless told not to), and this does not work when the actual value is 0.
See discussion [here](https://groups.google.com/d/msg/sage-devel/8z2HyH5Y8Dc/F7662ug9chUJ).Tue, 23 Sep 2014 16:02:53 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?answer=24261#post-id-24261Comment by rws for <p>Looks like a bug in mpmath (or in mpmath interface).
A workaround is to call Maxima directly (via its library interface), as follows:</p>
<pre><code>sage: maxima_calculus('makelist(2*hypergeometric([-n+2,3-n],[2],-1),n,47)')
</code></pre>
<p>EDIT: the following is more Sage-like:</p>
<pre><code>sage: [2*maxima_calculus.hgfred([1-n,2-n],[2],-1) for n in [0..46]]
</code></pre>
<p>EDIT': one particular issue with mpmath is that it tries evaluating up to correct relative precision (unless told not to), and this does not work when the actual value is 0.
See discussion <a href="https://groups.google.com/d/msg/sage-devel/8z2HyH5Y8Dc/F7662ug9chUJ">here</a>.</p>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24273#post-id-24273The mpmath issue is at
https://github.com/fredrik-johansson/mpmath/issues/296 .Wed, 24 Sep 2014 11:03:36 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24273#post-id-24273Comment by rws for <p>Looks like a bug in mpmath (or in mpmath interface).
A workaround is to call Maxima directly (via its library interface), as follows:</p>
<pre><code>sage: maxima_calculus('makelist(2*hypergeometric([-n+2,3-n],[2],-1),n,47)')
</code></pre>
<p>EDIT: the following is more Sage-like:</p>
<pre><code>sage: [2*maxima_calculus.hgfred([1-n,2-n],[2],-1) for n in [0..46]]
</code></pre>
<p>EDIT': one particular issue with mpmath is that it tries evaluating up to correct relative precision (unless told not to), and this does not work when the actual value is 0.
See discussion <a href="https://groups.google.com/d/msg/sage-devel/8z2HyH5Y8Dc/F7662ug9chUJ">here</a>.</p>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24270#post-id-24270The mpmath problem was also an issue with the recent implementation of Legendre polynomials, but above n>1000, mind you. There is also a blogpost by Fredrik where he did some work on this:
http://fredrik-j.blogspot.de/2010/01/accurate-hypergeometric-functions-for.html .Wed, 24 Sep 2014 10:47:19 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24270#post-id-24270Comment by Dima for <p>Looks like a bug in mpmath (or in mpmath interface).
A workaround is to call Maxima directly (via its library interface), as follows:</p>
<pre><code>sage: maxima_calculus('makelist(2*hypergeometric([-n+2,3-n],[2],-1),n,47)')
</code></pre>
<p>EDIT: the following is more Sage-like:</p>
<pre><code>sage: [2*maxima_calculus.hgfred([1-n,2-n],[2],-1) for n in [0..46]]
</code></pre>
<p>EDIT': one particular issue with mpmath is that it tries evaluating up to correct relative precision (unless told not to), and this does not work when the actual value is 0.
See discussion <a href="https://groups.google.com/d/msg/sage-devel/8z2HyH5Y8Dc/F7662ug9chUJ">here</a>.</p>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24262#post-id-24262for some reason, `maxima_calculus.hgfpoly([1-n,2-n],[2],-1)` only works here for n > 1!Tue, 23 Sep 2014 16:21:26 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24262#post-id-24262Comment by Peter Luschny for <p>Looks like a bug in mpmath (or in mpmath interface).
A workaround is to call Maxima directly (via its library interface), as follows:</p>
<pre><code>sage: maxima_calculus('makelist(2*hypergeometric([-n+2,3-n],[2],-1),n,47)')
</code></pre>
<p>EDIT: the following is more Sage-like:</p>
<pre><code>sage: [2*maxima_calculus.hgfred([1-n,2-n],[2],-1) for n in [0..46]]
</code></pre>
<p>EDIT': one particular issue with mpmath is that it tries evaluating up to correct relative precision (unless told not to), and this does not work when the actual value is 0.
See discussion <a href="https://groups.google.com/d/msg/sage-devel/8z2HyH5Y8Dc/F7662ug9chUJ">here</a>.</p>
https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24275#post-id-24275Ralf, thanks for bringing this to the attention of Fredrik.Wed, 24 Sep 2014 13:40:35 -0500https://ask.sagemath.org/question/24257/a-hypergeometric-series/?comment=24275#post-id-24275