JensGrabner / mpmath-2

Automatically exported from code.google.com/p/mpmath
Other
3 stars 0 forks source link

compare mpmath to clnum #95

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
http://calcrpnpy.sourceforge.net/clnum.html

It brings arbitrary-precision floating-point and rational arithmetic to
Python using a C++ library:

http://www.ginac.de/CLN/

It'd be interesting to compare speed. And what about rationals in mpmath?
Rip it from Python 2.6?

Original issue reported on code.google.com by Vinzent.Steinberg@gmail.com on 4 Nov 2008 at 6:42

GoogleCodeExporter commented 9 years ago
> And what about rationals in mpmath?
> Rip it from Python 2.6?

See issue 53 and http://www.dd.chalmers.se/~frejohl/code/libarith/

Original comment by fredrik....@gmail.com on 4 Nov 2008 at 6:56

GoogleCodeExporter commented 9 years ago
import mpmath
import clnum

for prec in [10, 100, 1000, 10000, 100000]:
    mpmath.mp.dps = prec
    t1 = mpmath.timing((mpmath.mpf(1)/7).__mul__, (mpmath.mpf(1)/3))
    t2 = mpmath.timing((clnum.mpf(1, prec)/7).__mul__, (clnum.mpf(1, prec)/3))
    print "mul %8i %14g %14g %f" % (prec, t1, t2, t1/t2)
    t1 = mpmath.timing(mpmath.exp, mpmath.mpf(4)/3)
    t2 = mpmath.timing(clnum.exp, clnum.mpf(4, prec)/3)
    print "exp %8i %14g %14g %f" % (prec, t1, t2, t1/t2)
    t1 = mpmath.timing(mpmath.sin, mpmath.mpf(4)/3)
    t2 = mpmath.timing(clnum.sin, clnum.mpf(4, prec)/3)
    print "sin %8i %14g %14g %f" % (prec, t1, t2, t1/t2)

mul       10   5.33587e-006   2.15111e-006 2.480519
exp       10   2.86349e-005    3.6094e-005 0.793344
sin       10   3.67924e-005   3.60102e-005 1.021722
mul      100   5.83873e-006   2.65397e-006 2.200000
exp      100     5.984e-005   9.85879e-005 0.606971
sin      100   8.13791e-005    0.000101354 0.802922
mul     1000     2.816e-005   2.98641e-005 0.942937
exp     1000     0.00120957     0.00398872 0.303247
sin     1000     0.00235544      0.0016368 1.439051
mul    10000      0.0007656     0.00112417 0.681039
exp    10000       0.108139       0.172615 0.626472
sin    10000       0.258261       0.182251 1.417066
mul   100000       0.014017      0.0208563 0.672077
exp   100000         3.0189        4.90705 0.615217
sin   100000        15.2075        7.15519 2.125383

Original comment by fredrik....@gmail.com on 28 Jan 2009 at 6:57

GoogleCodeExporter commented 9 years ago
Thank you! Interesting, clnum's sin() seems to be asymptotically faster than
mpmath's. And they are doing low-precision multiplication faster.

Original comment by Vinzent.Steinberg@gmail.com on 28 Jan 2009 at 3:13

GoogleCodeExporter commented 9 years ago
Yes, CLN evidently uses a better algorithm for sin.

I already have some faster code for high-precision cos and sin sitting on my 
hard
drive. It is actually almost exactly as fast as clnum (very slightly faster at 
10000
digits and slightly slower at 100000 digits, so maybe it can be tuned further). 
It's
been delayed because I want to go over log, exp, cosh and sinh first.

Original comment by fredrik....@gmail.com on 28 Jan 2009 at 3:32