On Mon, Apr 13, 2009 at 10:13 PM, Nick Alexander <ncalexan...@gmail.com> wrote:
>
>
> On 13-Apr-09, at 8:08 PM, Ondrej Certik wrote:
>
>>
>>> Actually, it's not using fast_callable yet, but I do plan on changing
>>> that (which should make things much faster). As for the zeta
>>> function--is mpmath faster than pari? (If so, should we be using it
>>> for zeta in general?)
>>
>> Probably not (yet). I just didn't know that Pari can do such nice
>> graphs.
>
> I need to compute gamma functions and incomplete gamma functions.
> mpmath is so slow that my doctests take hundreds of seconds (and I
> always killed them) instead of 10-15 seconds using pari to compute
> such things.  The mpmath main loops are pure python, there's no way
> it's going to be faster than even the most naive pari implementation.

Here is a quantitative comparison if the time of mpmath versus pari
for computation of the Riemann zeta function.    This uses the 100%
pure Python version of mpmath, since Sage doesn't include gmpy by
default, however I did try installing gmpy and that made no difference
in timings.

SUMMARY: If you use Sage correctly, and are mainly interested in
*double precision*, then Sage is between 30 and over 2400 (!) times
faster than mpmath at evaluating the Riemann zeta function.

For double precision reals, Sage is dramatically faster than
PARI/mpmath "because" it uses GSL, which evidently has a very fast
zeta implementation.  For complex numbers it is about 30 times faster,
because it uses PARI.

I could not figure out how to make arbitrary precision numbers in mpmath:

sage: sympy.mpmath.mpf("1.59920384023849023840982390482309840298923")
mpf('1.5992038402384903')   # where did all my digits go?

Naively inputing floats to sage's zeta:

sage: import sympy.mpmath
sage: a = float(1.23456)
sage: timeit('zeta(a)')
625 loops, best of 3: 384 µs per loop
sage: timeit('sympy.mpmath.zeta(a)')
625 loops, best of 3: 979 µs per loop
sage: zeta(a)
4.85732614724189
sage: sympy.mpmath.zeta(a)
mpf('4.857326147241892')
sage: a = float(0.45)
sage: timeit('sympy.mpmath.zeta(a)')
625 loops, best of 3: 915 µs per loop
sage: timeit('zeta(a)')
625 loops, best of 3: 499 µs per loop
sage: timeit('sympy.mpmath.zeta(a)')
125 loops, best of 3: 3.31 ms per loop
sage: a = CDF(2,3)
sage: timeit('zeta(a)')
625 loops, best of 3: 108 µs per loop

NOTE: zeta is much faster for RDF/CDF input than float input.  We redo
everything using RDF/CDF:

sage: a = RDF(0.45)
sage: timeit('zeta(a)')
625 loops, best of 3: 375 ns per loop
sage: a = RDF(1.23456)
sage: timeit('zeta(a)')
625 loops, best of 3: 485 ns per loop

sage: 915/.375
2440.00000000000


 -- William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to