#4132: complex arithmetic passes via pari
------------------------------+---------------------------------------------
Reporter: robertwb | Owner: somebody
Type: enhancement | Status: new
Priority: major | Milestone: sage-3.1.3
Component: basic arithmetic | Resolution:
Keywords: |
------------------------------+---------------------------------------------
Comment (by robertwb):
Yes, thanks for the clarification. I meant for many of them one could
implement them directly against mpfr. For example:
{{{
include "sage/rings/mpfr.pxi"
from sage.rings.complex_number cimport ComplexNumber
def my_exp(ComplexNumber self):
cdef ComplexNumber z = self._new()
cdef mpfr_t r
mpfr_init2(r, self._prec)
mpfr_exp(r, self.__re, GMP_RNDN)
mpfr_cos(z.__re, self.__im, GMP_RNDN)
mpfr_mul(z.__re, z.__re, r, GMP_RNDN)
mpfr_sin(z.__im, self.__im, GMP_RNDN)
mpfr_mul(z.__im, z.__im, r, GMP_RNDN)
mpfr_clear(r)
return z
}}}
Then
{{{
sage: a = CC.pi() + CC.0/3
sage: my_exp(a) == a.exp()
True
sage: timeit("a.exp()")
625 loops, best of 3: 514 µs per loop
sage: timeit("my_exp(a)")
625 loops, best of 3: 16.1 µs per loop
sage: 514/16.1
31.9254658385093
}}}
This could be low-hanging fruit for a new developer.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/4132#comment:2>
SAGE <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---