ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 23 Sep 2014 14:25:11 +0200Why does Sage offer unusable SciPy?https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/ In the docs of special functions [1] there is a warning:
"SciPy’s versions are poorly documented and seem less
accurate than the Maxima and PARI versions."
Less accurate? Where does Sage draw the border to unusable code?
I certainly do not expect such incorrect results produced with Sage:
A000262 = lambda n: (-1)^(n-1)*hypergeometric_U(1-n, 2, -1, "scipy")
[round(A000262(n).n(100)) for n in (0..19)]
[1, 1, 3, 13, 73, 501, 4051, 37633, 394353, 4596553, 58941091,
824073141, 12470162233, 202976401213, 3535017524400, 65573803186900,
1290434218670000, 26846616451200000, 588633468315000064,
13564373693600000000]
Peter
[1] http://www.sagemath.org/doc/reference/functions/sage/functions/special.html
[2] https://oeis.org/A000262
Wed, 17 Sep 2014 13:32:32 +0200https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/Answer by Dima for <p>In the docs of special functions [1] there is a warning:</p>
<p>"SciPy’s versions are poorly documented and seem less
accurate than the Maxima and PARI versions."</p>
<p>Less accurate? Where does Sage draw the border to unusable code?</p>
<p>I certainly do not expect such incorrect results produced with Sage:</p>
<pre><code>A000262 = lambda n: (-1)^(n-1)*hypergeometric_U(1-n, 2, -1, "scipy")
[round(A000262(n).n(100)) for n in (0..19)]
[1, 1, 3, 13, 73, 501, 4051, 37633, 394353, 4596553, 58941091,
824073141, 12470162233, 202976401213, 3535017524400, 65573803186900,
1290434218670000, 26846616451200000, 588633468315000064,
13564373693600000000]
</code></pre>
<p>Peter</p>
<p>[1] <a href="http://www.sagemath.org/doc/reference/functions/sage/functions/special.html">http://www.sagemath.org/doc/reference...</a></p>
<p>[2] <a href="https://oeis.org/A000262">https://oeis.org/A000262</a></p>
https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?answer=24176#post-id-24176AFAIK, scipy calls a Fortran numerical routine to compute this. Naturally, it doesn't do arbitrary precision. The relative precision is probably still quite OK, I didn't check. If you try adding optional parameter prec, with prec not equal to 53, you get an error.
Not sure whether this is an acceptable solution, but perhaps Sage should return the result as RDF, not as an arbitrary precision real.
(EDIT: this is now http://trac.sagemath.org/ticket/17011)
One might also just call `hypergeometric` instead. This will use Maxima (Maxima doesn't know this particular function, but it can do qFp,
and this is precisely what is needed here). E.g. `round(hypergeometric((-18,-19),(),1).n(100))` gives the correct 19th term of the sequence in question.Thu, 18 Sep 2014 10:54:56 +0200https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?answer=24176#post-id-24176Comment by Volker Braun for <p>AFAIK, scipy calls a Fortran numerical routine to compute this. Naturally, it doesn't do arbitrary precision. The relative precision is probably still quite OK, I didn't check. If you try adding optional parameter prec, with prec not equal to 53, you get an error.</p>
<p>Not sure whether this is an acceptable solution, but perhaps Sage should return the result as RDF, not as an arbitrary precision real.
(EDIT: this is now <a href="http://trac.sagemath.org/ticket/17011">http://trac.sagemath.org/ticket/17011</a>)</p>
<p>One might also just call <code>hypergeometric</code> instead. This will use Maxima (Maxima doesn't know this particular function, but it can do qFp,
and this is precisely what is needed here). E.g. <code>round(hypergeometric((-18,-19),(),1).n(100))</code> gives the correct 19th term of the sequence in question.</p>
https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?comment=24232#post-id-24232Sage is also a system for doing research, that includes comparing different implementations. A lot of work went into picking suitable defaults. Why shouldn't we expose the other implementations, too? Maybe SciPy improves in some future version...Sun, 21 Sep 2014 19:13:01 +0200https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?comment=24232#post-id-24232Comment by Peter Luschny for <p>AFAIK, scipy calls a Fortran numerical routine to compute this. Naturally, it doesn't do arbitrary precision. The relative precision is probably still quite OK, I didn't check. If you try adding optional parameter prec, with prec not equal to 53, you get an error.</p>
<p>Not sure whether this is an acceptable solution, but perhaps Sage should return the result as RDF, not as an arbitrary precision real.
(EDIT: this is now <a href="http://trac.sagemath.org/ticket/17011">http://trac.sagemath.org/ticket/17011</a>)</p>
<p>One might also just call <code>hypergeometric</code> instead. This will use Maxima (Maxima doesn't know this particular function, but it can do qFp,
and this is precisely what is needed here). E.g. <code>round(hypergeometric((-18,-19),(),1).n(100))</code> gives the correct 19th term of the sequence in question.</p>
https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?comment=24255#post-id-24255"A lot of work went into picking suitable defaults." Did you notice that the default in our case, i.e. not using the option "scipy", does not work?
"Why shouldn't we expose the other implementations, too?" If you offer something which will lead a normal user with a certain trust in Sage inevitably into making errors than this is a disservice. Better save your time and at the same time preserve your customers from mistakes.Tue, 23 Sep 2014 14:25:11 +0200https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?comment=24255#post-id-24255Comment by Peter Luschny for <p>AFAIK, scipy calls a Fortran numerical routine to compute this. Naturally, it doesn't do arbitrary precision. The relative precision is probably still quite OK, I didn't check. If you try adding optional parameter prec, with prec not equal to 53, you get an error.</p>
<p>Not sure whether this is an acceptable solution, but perhaps Sage should return the result as RDF, not as an arbitrary precision real.
(EDIT: this is now <a href="http://trac.sagemath.org/ticket/17011">http://trac.sagemath.org/ticket/17011</a>)</p>
<p>One might also just call <code>hypergeometric</code> instead. This will use Maxima (Maxima doesn't know this particular function, but it can do qFp,
and this is precisely what is needed here). E.g. <code>round(hypergeometric((-18,-19),(),1).n(100))</code> gives the correct 19th term of the sequence in question.</p>
https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?comment=24218#post-id-24218Dima, yes of course it is simple to avoid the errors provided you are aware of them. As you noted U(1-n, 2, -1) = (-1)^(n-1)*hypergeometric([-n,-n+1],[],1) does the job. But this was not my question. I asked why Sage *offers* such dangerous functions. "Sage should return the result as RDF, not as an arbitrary precision real." Yes, at least this.Sat, 20 Sep 2014 13:13:40 +0200https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?comment=24218#post-id-24218Comment by Peter Luschny for <p>AFAIK, scipy calls a Fortran numerical routine to compute this. Naturally, it doesn't do arbitrary precision. The relative precision is probably still quite OK, I didn't check. If you try adding optional parameter prec, with prec not equal to 53, you get an error.</p>
<p>Not sure whether this is an acceptable solution, but perhaps Sage should return the result as RDF, not as an arbitrary precision real.
(EDIT: this is now <a href="http://trac.sagemath.org/ticket/17011">http://trac.sagemath.org/ticket/17011</a>)</p>
<p>One might also just call <code>hypergeometric</code> instead. This will use Maxima (Maxima doesn't know this particular function, but it can do qFp,
and this is precisely what is needed here). E.g. <code>round(hypergeometric((-18,-19),(),1).n(100))</code> gives the correct 19th term of the sequence in question.</p>
https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?comment=24254#post-id-24254"Sage is also a system for doing research, that includes comparing different implementations." To compare comparable implementations is of course OK. Comparing Maxima and PARI versions is OK. However, for instance, creating the impression that a 32-bit integer implementation will give the same results as an arbitrary precision implementation is not OK. Similarly here: To sell SciPy's very limited validity in hypergeometric_U() as 'less accurate' is not sufficient as long the impression persists that it is comparable to PARI or Maxima. (contd.)Tue, 23 Sep 2014 14:24:46 +0200https://ask.sagemath.org/question/24163/why-does-sage-offer-unusable-scipy/?comment=24254#post-id-24254