[sage-support] Arbitrary precision in Cython NumPy?
Dear all, I am trying to implement a recursive algorithm that is rather complex, in the sense that it uses a high number of variables and (elementary) computations. The output in Sage looks fine but it gets quite slow, so I am thinking of ways to speed it up. Given that it is mainly a lot of looping and a lot of elementary computations, I would guess translating it to Cython could help a lot. However I am afraid that doubles won't have enough precision to avoid too much numerical noise in the end result of the algorithm. So I would like to use a higher precision real number representation. The question is whether this is possible, and if so what is a sensible choice? Could/Should I use mpmath e.g. or rather something else? What I need to be doing, next to elementary computations, is: - compute exponentials - perform find_root's - being able to store those real numbers in a few big Numpy-arrays. I am very grateful for any hint! Many thanks, Kees -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Arbitrary precision in cython
Hi, Jason Grout wrote: sage: pari(RealField(500)(10)).eint1().python() 4.15696892968532427740285981027818038434629008241953313262759569712786222819608803586147163177527802101305497591041862309918139192016097135380721447598904e-6 sage: RealField(500)(10).eint() 2492.22897624187775913844014399852484898964710143094234538818526713774122742888744417794599665663156560488342454657568480015672868779475213684965774390 sage: sage: pari(RealField(500)(-10)).eint1().python() -2492.22897624187775913844014399852484898964710143094234538818526713774122742888744417794599665663156560488342454657568480015672868779475213684965774390402 sage: RealField(500)(-10).eint() NaN the RealField() results correspond to the definition of eint in mpfr: -- Function: int mpfr_eint (mpfr_t Y, mpfr_t X, mp_rnd_t RND) Set Y to the exponential integral of X, rounded in the direction RND. For positive X, the exponential integral is the sum of Euler's constant, of the logarithm of X, and of the sum for k from 1 to infinity of X to the power k, divided by k and factorial(k). For negative X, the returned value is NaN. and Carl Witty wrote: Actually, Sage doesn't print the entire value for floating-point numbers by default; it leaves a few digits off the end, so the potential binary-decimal conversion error above is a lot more than 1/2 ulp. To get the entire within-1/2-ulp decimal value, you can use: sage: RealField(150)(10).eint().str(truncate=False) '2492.2289762418777591384401439985248489896471010' thank you Carl for pointing out that. This means that the total error is less that 1/2 ulp on the binary value, plus 1/2 ulp on the decimal conversion (with truncate=False), or plus 0.5005 ulp on the default printing if 3 digits are left off (assuming rounding to nearest). Paul Zimmermann --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Arbitrary precision in cython
Hi, as a followup on the Arbitrary precision in cython thread, I'd like to mention that one can directly use mpfr's implementation from within Sage: sage: RealField(150)(10).eint() 2492.2289762418777591384401439985248489896471 It only works for real numbers, but has the advantage to guarantee correct rounding (for the 150-bit binary result; if you are using the decimal result above, you have to take into account the binary-decimal conversion error, which is at most 1/2 ulp). Paul Zimmermann --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Arbitrary precision in cython
I have recently been experimenting with converting some simple python functions that I have made into cython. I have been quite impressed by how simple it is for the massive speed increases that I have seen. However, one thing that is mildly annoying at times is the limitation to double precision computation. Is there any simple way to do arbitrary precision floating-point arithmetic in cython? I tried using importing mpfr, but I gave up after I saw the sheer number of different things that seemed to need to be individually imported. Thanks, Michael Yurko --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---