[sage-support] Re: Quaternions, how to speed up computation
sage-support is one of the best list. English is not my mother language and sometimes I don't explain myself well but always people here are very kind and trying to help... It's very important this can long ! Le vendredi 14 septembre 2018 18:00:55 UTC+2, Peter Luschny a écrit : > > How can I speed up this computation? > > H. = QuaternionAlgebra(SR, -1, -1) > def Q(a, b, c, d): return H(a + b*i + c*j + d*k) > def P(n): return Q(x+1,1,1,1)*P(n-1) if n > 0 else Q(1,0,0,0) > def p(n): return P(n)[0].list() > for n in (0..20): print [n], p(n) > > [0] [1] > [1] [1, 1] > [2] [-2, 2, 1] > [3] [-8, -6, 3, 1] > [4] [-8, -32, -12, 4, 1] > [5] [16, -40, -80, -20, 5, 1] > [6] [64, 96, -120, -160, -30, 6, 1] > ... > > With Mathematica this takes 6 sec, with Sage it takes > hours, (in fact I interrupted after n=15). > > Thanks, Peter > > > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
Re: [sage-support] Re: Quaternions, how to speed up computation
Thanks. This answer my question and I put the tip in https://groups.google.com/d/msg/sage-support/NFtI5XqjQWg/sz5WPcFMAgAJ On Monday, November 19, 2018 at 3:58:50 AM UTC-8, John Cremona wrote: > > I recommend importing anything you need from sage.all since the details of > where everything is might change in time. This works perfectly well: > > $ sage -python # so we use Sage's python not my system-wide one > Python 2.7.15 (default, Nov 2 2018, 14:32:42) > [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from sage.all import PolynomialRing, QQ > >>> R = PolynomialRing(QQ,'x') > >>> x = R.gen() > >>> f = x^3+1 # no good as no preparser > Traceback (most recent call last): > File "", line 1, in > File "sage/structure/element.pyx", line 944, in > sage.structure.element.Element.__xor__ > (build/cythonized/sage/structure/element.c:9006) > RuntimeError: Use ** for exponentiation, not '^', which means xor > in Python, and has the wrong precedence. > > # Now we can work with this: > > >>> f = x**3+1 # that's better > >>> f.factor() > (x + 1) * (x^2 - x + 1) > > Another thing I do is to put my commands into a .py file and run pyflakes > on it, as that reveals what things need to be imported. Then import them > all from sage.all. > > John Cremona > > On Mon, 19 Nov 2018 at 11:48, Kolen Cheung > wrote: > >> Thank you both for the answers. However, I’m still stuck: >> >> Focusing on just translating the first line: R. = QQ[] >> >> In sage, >> >> >>> preparse("R. = QQ[]")"R = QQ['x']; (x,) = R._first_ngens(1)">>> >> >>> import_statements(QQ)# ** Warning **: several names for that object: Q, >> >>> QQfrom sage.rings.rational_field import Q>>> import_statements(R)from >> >>> sage.rings.qqbar import QQx >> >> Immediately I have a question: how come the import_statements of QQ is ... >> import Q, and the import statement of R is ... import QQx? In either >> case the namespace in question is not imported. Does it mean ... import >> Q as QQ and ... import QQx as R respectively? >> >> Then I’ve a problem: In sage, I can import them using these import >> statements. But when entering these 2 import statements in Python, >> >> >>> from sage.rings.rational_field import Q >> --- >> ImportError Traceback (most recent call last) >> in () >> > 1 from sage.rings.rational_field import Q >> >> /usr/lib/python2.7/site-packages/sage/rings/rational_field.py in () >> 62 _long_type = int >> 63 >> ---> 64 from .rational import Rational >> 65 from .integer import Integer >> 66 >> >> /usr/lib/python2.7/site-packages/sage/rings/rational.pyx in init >> sage.rings.rational (build/cythonized/sage/rings/rational.c:40976)() >> 94 >> 95 >> ---> 96 import sage.rings.real_mpfr >> 97 import sage.rings.real_double >> 98 from libc.stdint cimport uint64_t >> >> /usr/lib/python2.7/site-packages/sage/rings/real_mpfr.pyx in init >> sage.rings.real_mpfr (build/cythonized/sage/rings/real_mpfr.c:44298)() >> > 1 r""" >> 2 Arbitrary Precision Real Numbers >> 3 >> 4 AUTHORS: >> 5 >> >> /usr/lib/python2.7/site-packages/sage/rings/complex_number.pxd in init >> sage.libs.mpmath.utils (build/cythonized/sage/libs/mpmath/utils.c:8831)() >> 4 from .real_mpfr cimport RealNumber >> 5 >> > 6 cdef class ComplexNumber(sage.structure.element.FieldElement): >> 7 cdef mpfr_t __re >> 8 cdef mpfr_t __im >> >> /usr/lib/python2.7/site-packages/sage/rings/complex_double.pxd in init >> sage.rings.complex_number >> (build/cythonized/sage/rings/complex_number.c:24212)() >> 8 >> 9 >> ---> 10 cdef class ComplexDoubleField_class(sage.rings.ring.Field): >> 11 pass >> 12 >> >> /usr/lib/python2.7/site-packages/sage/rings/complex_double.pyx in init >> sage.rings.complex_double >> (build/cythonized/sage/rings/complex_double.c:24230)() >> 96 from cypari2.convert cimport new_gen_from_double, >> new_t_COMPLEX_from_double >> 97 >> ---> 98 from . import complex_number >> 99 >> 100 from .complex_field import ComplexField >> >> ImportError: cannot import name complex_number >> >>> from sage.rings.qqbar import QQx >> --- >> ImportError Traceback (most recent call last) >> in () >> > 1 from sage.rings.qqbar import QQx >> >> /usr/lib/python2.7/site-packages/sage/rings/qqbar.py in () >> 512 rich_to_bool, richcmp_not_equal, >> 513 op_EQ, op_NE) >> --> 514 from sage.rings.real_mpfr import RR >> 515 from sage.rings.real_mpfi import RealIntervalField, RIF, >> is_RealIntervalFieldElement, RealIntervalField_class >> 516 from sage.rings.compl
Re: [sage-support] Re: Quaternions, how to speed up computation
I wonder why for me the result is >>> import_statements(QQ) # ** Warning **: several names for that object: Q, QQ from sage.rings.rational_field import Q On Monday, November 19, 2018 at 4:05:55 AM UTC-8, Dima Pasechnik wrote: On Mon, Nov 19, 2018 at 11:58 AM John Cremona > wrote: > > > > I recommend importing anything you need from sage.all since the details > of where everything is might change in time. This works perfectly well: > > > > $ sage -python # so we use Sage's python not my system-wide one > > Python 2.7.15 (default, Nov 2 2018, 14:32:42) > > [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> from sage.all import PolynomialRing, QQ > > >>> R = PolynomialRing(QQ,'x') > > >>> x = R.gen() > > >>> f = x^3+1 # no good as no preparser > > Traceback (most recent call last): > > File "", line 1, in > > File "sage/structure/element.pyx", line 944, in > sage.structure.element.Element.__xor__ > (build/cythonized/sage/structure/element.c:9006) > > RuntimeError: Use ** for exponentiation, not '^', which means xor > > in Python, and has the wrong precedence. > > > > # Now we can work with this: > > > > >>> f = x**3+1 # that's better > > >>> f.factor() > > (x + 1) * (x^2 - x + 1) > > > > Another thing I do is to put my commands into a .py file and run > pyflakes on it, as that reveals what things need to be imported. Then > import them all from sage.all. > > you can also find out exactly what you need to import: > > sage: import_statements("QQ") > from sage.rings.rational_field import QQ > > > > > > John Cremona > > > > On Mon, 19 Nov 2018 at 11:48, Kolen Cheung > wrote: > >> > >> Thank you both for the answers. However, I’m still stuck: > >> > >> Focusing on just translating the first line: R. = QQ[] > >> > >> In sage, > >> > >> >>> preparse("R. = QQ[]") > >> "R = QQ['x']; (x,) = R._first_ngens(1)" > >> >>> import_statements(QQ) > >> # ** Warning **: several names for that object: Q, QQ > >> from sage.rings.rational_field import Q > >> >>> import_statements(R) > >> from sage.rings.qqbar import QQx > >> > >> Immediately I have a question: how come the import_statements of QQ is > ... import Q, and the import statement of R is ... import QQx? In either > case the namespace in question is not imported. Does it mean ... import Q > as QQ and ... import QQx as R respectively? > >> > >> Then I’ve a problem: In sage, I can import them using these import > statements. But when entering these 2 import statements in Python, > >> > >> >>> from sage.rings.rational_field import Q > >> > --- > >> ImportError Traceback (most recent call > last) > >> in () > >> > 1 from sage.rings.rational_field import Q > >> > >> /usr/lib/python2.7/site-packages/sage/rings/rational_field.py in > () > >> 62 _long_type = int > >> 63 > >> ---> 64 from .rational import Rational > >> 65 from .integer import Integer > >> 66 > >> > >> /usr/lib/python2.7/site-packages/sage/rings/rational.pyx in init > sage.rings.rational (build/cythonized/sage/rings/rational.c:40976)() > >> 94 > >> 95 > >> ---> 96 import sage.rings.real_mpfr > >> 97 import sage.rings.real_double > >> 98 from libc.stdint cimport uint64_t > >> > >> /usr/lib/python2.7/site-packages/sage/rings/real_mpfr.pyx in init > sage.rings.real_mpfr (build/cythonized/sage/rings/real_mpfr.c:44298)() > >> > 1 r""" > >> 2 Arbitrary Precision Real Numbers > >> 3 > >> 4 AUTHORS: > >> 5 > >> > >> /usr/lib/python2.7/site-packages/sage/rings/complex_number.pxd in init > sage.libs.mpmath.utils (build/cythonized/sage/libs/mpmath/utils.c:8831)() > >> 4 from .real_mpfr cimport RealNumber > >> 5 > >> > 6 cdef class ComplexNumber(sage.structure.element.FieldElement): > >> 7 cdef mpfr_t __re > >> 8 cdef mpfr_t __im > >> > >> /usr/lib/python2.7/site-packages/sage/rings/complex_double.pxd in init > sage.rings.complex_number > (build/cythonized/sage/rings/complex_number.c:24212)() > >> 8 > >> 9 > >> ---> 10 cdef class ComplexDoubleField_class(sage.rings.ring.Field): > >> 11 pass > >> 12 > >> > >> /usr/lib/python2.7/site-packages/sage/rings/complex_double.pyx in init > sage.rings.complex_double > (build/cythonized/sage/rings/complex_double.c:24230)() > >> 96 from cypari2.convert cimport new_gen_from_double, > new_t_COMPLEX_from_double > >> 97 > >> ---> 98 from . import complex_number > >> 99 > >> 100 from .complex_field import ComplexField > >> > >> ImportError: cannot import name complex_number > >> >>> from sage.rings.qqbar import QQx > >> > --- > >> ImportError
Re: [sage-support] Re: Quaternions, how to speed up computation
On Mon, Nov 19, 2018 at 11:58 AM John Cremona wrote: > > I recommend importing anything you need from sage.all since the details of > where everything is might change in time. This works perfectly well: > > $ sage -python # so we use Sage's python not my system-wide one > Python 2.7.15 (default, Nov 2 2018, 14:32:42) > [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from sage.all import PolynomialRing, QQ > >>> R = PolynomialRing(QQ,'x') > >>> x = R.gen() > >>> f = x^3+1 # no good as no preparser > Traceback (most recent call last): > File "", line 1, in > File "sage/structure/element.pyx", line 944, in > sage.structure.element.Element.__xor__ > (build/cythonized/sage/structure/element.c:9006) > RuntimeError: Use ** for exponentiation, not '^', which means xor > in Python, and has the wrong precedence. > > # Now we can work with this: > > >>> f = x**3+1 # that's better > >>> f.factor() > (x + 1) * (x^2 - x + 1) > > Another thing I do is to put my commands into a .py file and run pyflakes on > it, as that reveals what things need to be imported. Then import them all > from sage.all. you can also find out exactly what you need to import: sage: import_statements("QQ") from sage.rings.rational_field import QQ > > John Cremona > > On Mon, 19 Nov 2018 at 11:48, Kolen Cheung wrote: >> >> Thank you both for the answers. However, I’m still stuck: >> >> Focusing on just translating the first line: R. = QQ[] >> >> In sage, >> >> >>> preparse("R. = QQ[]") >> "R = QQ['x']; (x,) = R._first_ngens(1)" >> >>> import_statements(QQ) >> # ** Warning **: several names for that object: Q, QQ >> from sage.rings.rational_field import Q >> >>> import_statements(R) >> from sage.rings.qqbar import QQx >> >> Immediately I have a question: how come the import_statements of QQ is ... >> import Q, and the import statement of R is ... import QQx? In either case >> the namespace in question is not imported. Does it mean ... import Q as QQ >> and ... import QQx as R respectively? >> >> Then I’ve a problem: In sage, I can import them using these import >> statements. But when entering these 2 import statements in Python, >> >> >>> from sage.rings.rational_field import Q >> --- >> ImportError Traceback (most recent call last) >> in () >> > 1 from sage.rings.rational_field import Q >> >> /usr/lib/python2.7/site-packages/sage/rings/rational_field.py in () >> 62 _long_type = int >> 63 >> ---> 64 from .rational import Rational >> 65 from .integer import Integer >> 66 >> >> /usr/lib/python2.7/site-packages/sage/rings/rational.pyx in init >> sage.rings.rational (build/cythonized/sage/rings/rational.c:40976)() >> 94 >> 95 >> ---> 96 import sage.rings.real_mpfr >> 97 import sage.rings.real_double >> 98 from libc.stdint cimport uint64_t >> >> /usr/lib/python2.7/site-packages/sage/rings/real_mpfr.pyx in init >> sage.rings.real_mpfr (build/cythonized/sage/rings/real_mpfr.c:44298)() >> > 1 r""" >> 2 Arbitrary Precision Real Numbers >> 3 >> 4 AUTHORS: >> 5 >> >> /usr/lib/python2.7/site-packages/sage/rings/complex_number.pxd in init >> sage.libs.mpmath.utils (build/cythonized/sage/libs/mpmath/utils.c:8831)() >> 4 from .real_mpfr cimport RealNumber >> 5 >> > 6 cdef class ComplexNumber(sage.structure.element.FieldElement): >> 7 cdef mpfr_t __re >> 8 cdef mpfr_t __im >> >> /usr/lib/python2.7/site-packages/sage/rings/complex_double.pxd in init >> sage.rings.complex_number >> (build/cythonized/sage/rings/complex_number.c:24212)() >> 8 >> 9 >> ---> 10 cdef class ComplexDoubleField_class(sage.rings.ring.Field): >> 11 pass >> 12 >> >> /usr/lib/python2.7/site-packages/sage/rings/complex_double.pyx in init >> sage.rings.complex_double >> (build/cythonized/sage/rings/complex_double.c:24230)() >> 96 from cypari2.convert cimport new_gen_from_double, >> new_t_COMPLEX_from_double >> 97 >> ---> 98 from . import complex_number >> 99 >> 100 from .complex_field import ComplexField >> >> ImportError: cannot import name complex_number >> >>> from sage.rings.qqbar import QQx >> --- >> ImportError Traceback (most recent call last) >> in () >> > 1 from sage.rings.qqbar import QQx >> >> /usr/lib/python2.7/site-packages/sage/rings/qqbar.py in () >> 512 rich_to_bool, richcmp_not_equal, >> 513 op_EQ, op_NE) >> --> 514 from sage.rings.real_mpfr import RR >> 515 from sage.rings.real_mpfi import RealIntervalField, RIF, >> is_RealIntervalFieldElement, RealIntervalField_class >> 516 from sage.rings.complex_field import ComplexFi
Re: [sage-support] Re: Quaternions, how to speed up computation
I recommend importing anything you need from sage.all since the details of where everything is might change in time. This works perfectly well: $ sage -python # so we use Sage's python not my system-wide one Python 2.7.15 (default, Nov 2 2018, 14:32:42) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sage.all import PolynomialRing, QQ >>> R = PolynomialRing(QQ,'x') >>> x = R.gen() >>> f = x^3+1 # no good as no preparser Traceback (most recent call last): File "", line 1, in File "sage/structure/element.pyx", line 944, in sage.structure.element.Element.__xor__ (build/cythonized/sage/structure/element.c:9006) RuntimeError: Use ** for exponentiation, not '^', which means xor in Python, and has the wrong precedence. # Now we can work with this: >>> f = x**3+1 # that's better >>> f.factor() (x + 1) * (x^2 - x + 1) Another thing I do is to put my commands into a .py file and run pyflakes on it, as that reveals what things need to be imported. Then import them all from sage.all. John Cremona On Mon, 19 Nov 2018 at 11:48, Kolen Cheung wrote: > Thank you both for the answers. However, I’m still stuck: > > Focusing on just translating the first line: R. = QQ[] > > In sage, > > >>> preparse("R. = QQ[]")"R = QQ['x']; (x,) = R._first_ngens(1)">>> > >>> import_statements(QQ)# ** Warning **: several names for that object: Q, > >>> QQfrom sage.rings.rational_field import Q>>> import_statements(R)from > >>> sage.rings.qqbar import QQx > > Immediately I have a question: how come the import_statements of QQ is ... > import Q, and the import statement of R is ... import QQx? In either case > the namespace in question is not imported. Does it mean ... import Q as QQ > and ... import QQx as R respectively? > > Then I’ve a problem: In sage, I can import them using these import > statements. But when entering these 2 import statements in Python, > > >>> from sage.rings.rational_field import Q > --- > ImportError Traceback (most recent call last) > in () > > 1 from sage.rings.rational_field import Q > > /usr/lib/python2.7/site-packages/sage/rings/rational_field.py in () > 62 _long_type = int > 63 > ---> 64 from .rational import Rational > 65 from .integer import Integer > 66 > > /usr/lib/python2.7/site-packages/sage/rings/rational.pyx in init > sage.rings.rational (build/cythonized/sage/rings/rational.c:40976)() > 94 > 95 > ---> 96 import sage.rings.real_mpfr > 97 import sage.rings.real_double > 98 from libc.stdint cimport uint64_t > > /usr/lib/python2.7/site-packages/sage/rings/real_mpfr.pyx in init > sage.rings.real_mpfr (build/cythonized/sage/rings/real_mpfr.c:44298)() > > 1 r""" > 2 Arbitrary Precision Real Numbers > 3 > 4 AUTHORS: > 5 > > /usr/lib/python2.7/site-packages/sage/rings/complex_number.pxd in init > sage.libs.mpmath.utils (build/cythonized/sage/libs/mpmath/utils.c:8831)() > 4 from .real_mpfr cimport RealNumber > 5 > > 6 cdef class ComplexNumber(sage.structure.element.FieldElement): > 7 cdef mpfr_t __re > 8 cdef mpfr_t __im > > /usr/lib/python2.7/site-packages/sage/rings/complex_double.pxd in init > sage.rings.complex_number > (build/cythonized/sage/rings/complex_number.c:24212)() > 8 > 9 > ---> 10 cdef class ComplexDoubleField_class(sage.rings.ring.Field): > 11 pass > 12 > > /usr/lib/python2.7/site-packages/sage/rings/complex_double.pyx in init > sage.rings.complex_double > (build/cythonized/sage/rings/complex_double.c:24230)() > 96 from cypari2.convert cimport new_gen_from_double, > new_t_COMPLEX_from_double > 97 > ---> 98 from . import complex_number > 99 > 100 from .complex_field import ComplexField > > ImportError: cannot import name complex_number > >>> from sage.rings.qqbar import QQx > --- > ImportError Traceback (most recent call last) > in () > > 1 from sage.rings.qqbar import QQx > > /usr/lib/python2.7/site-packages/sage/rings/qqbar.py in () > 512 rich_to_bool, richcmp_not_equal, > 513 op_EQ, op_NE) > --> 514 from sage.rings.real_mpfr import RR > 515 from sage.rings.real_mpfi import RealIntervalField, RIF, > is_RealIntervalFieldElement, RealIntervalField_class > 516 from sage.rings.complex_field import ComplexField > > /usr/lib/python2.7/site-packages/sage/rings/real_mpfr.pyx in init > sage.rings.real_mpfr (build/cythonized/sage/rings/real_mpfr.c:44298)() > > 1 r""" > 2 Arbitrary Precision Real Numbers > 3 > 4 AUTHORS: > 5 > > /usr/lib/python2.7/site-packages/sage/rings/complex_number.pxd in init > sage.libs.mpmath.util
[sage-support] Re: Quaternions, how to speed up computation
Thank you both for the answers. However, I’m still stuck: Focusing on just translating the first line: R. = QQ[] In sage, >>> preparse("R. = QQ[]")"R = QQ['x']; (x,) = R._first_ngens(1)">>> >>> import_statements(QQ)# ** Warning **: several names for that object: Q, >>> QQfrom sage.rings.rational_field import Q>>> import_statements(R)from >>> sage.rings.qqbar import QQx Immediately I have a question: how come the import_statements of QQ is ... import Q, and the import statement of R is ... import QQx? In either case the namespace in question is not imported. Does it mean ... import Q as QQ and ... import QQx as R respectively? Then I’ve a problem: In sage, I can import them using these import statements. But when entering these 2 import statements in Python, >>> from sage.rings.rational_field import Q --- ImportError Traceback (most recent call last) in () > 1 from sage.rings.rational_field import Q /usr/lib/python2.7/site-packages/sage/rings/rational_field.py in () 62 _long_type = int 63 ---> 64 from .rational import Rational 65 from .integer import Integer 66 /usr/lib/python2.7/site-packages/sage/rings/rational.pyx in init sage.rings.rational (build/cythonized/sage/rings/rational.c:40976)() 94 95 ---> 96 import sage.rings.real_mpfr 97 import sage.rings.real_double 98 from libc.stdint cimport uint64_t /usr/lib/python2.7/site-packages/sage/rings/real_mpfr.pyx in init sage.rings.real_mpfr (build/cythonized/sage/rings/real_mpfr.c:44298)() > 1 r""" 2 Arbitrary Precision Real Numbers 3 4 AUTHORS: 5 /usr/lib/python2.7/site-packages/sage/rings/complex_number.pxd in init sage.libs.mpmath.utils (build/cythonized/sage/libs/mpmath/utils.c:8831)() 4 from .real_mpfr cimport RealNumber 5 > 6 cdef class ComplexNumber(sage.structure.element.FieldElement): 7 cdef mpfr_t __re 8 cdef mpfr_t __im /usr/lib/python2.7/site-packages/sage/rings/complex_double.pxd in init sage.rings.complex_number (build/cythonized/sage/rings/complex_number.c:24212)() 8 9 ---> 10 cdef class ComplexDoubleField_class(sage.rings.ring.Field): 11 pass 12 /usr/lib/python2.7/site-packages/sage/rings/complex_double.pyx in init sage.rings.complex_double (build/cythonized/sage/rings/complex_double.c:24230)() 96 from cypari2.convert cimport new_gen_from_double, new_t_COMPLEX_from_double 97 ---> 98 from . import complex_number 99 100 from .complex_field import ComplexField ImportError: cannot import name complex_number >>> from sage.rings.qqbar import QQx --- ImportError Traceback (most recent call last) in () > 1 from sage.rings.qqbar import QQx /usr/lib/python2.7/site-packages/sage/rings/qqbar.py in () 512 rich_to_bool, richcmp_not_equal, 513 op_EQ, op_NE) --> 514 from sage.rings.real_mpfr import RR 515 from sage.rings.real_mpfi import RealIntervalField, RIF, is_RealIntervalFieldElement, RealIntervalField_class 516 from sage.rings.complex_field import ComplexField /usr/lib/python2.7/site-packages/sage/rings/real_mpfr.pyx in init sage.rings.real_mpfr (build/cythonized/sage/rings/real_mpfr.c:44298)() > 1 r""" 2 Arbitrary Precision Real Numbers 3 4 AUTHORS: 5 /usr/lib/python2.7/site-packages/sage/rings/complex_number.pxd in init sage.libs.mpmath.utils (build/cythonized/sage/libs/mpmath/utils.c:8831)() 4 from .real_mpfr cimport RealNumber 5 > 6 cdef class ComplexNumber(sage.structure.element.FieldElement): 7 cdef mpfr_t __re 8 cdef mpfr_t __im /usr/lib/python2.7/site-packages/sage/rings/complex_double.pxd in init sage.rings.complex_number (build/cythonized/sage/rings/complex_number.c:24212)() 8 9 ---> 10 cdef class ComplexDoubleField_class(sage.rings.ring.Field): 11 pass 12 /usr/lib/python2.7/site-packages/sage/rings/complex_double.pyx in init sage.rings.complex_double (build/cythonized/sage/rings/complex_double.c:24230)() 96 from cypari2.convert cimport new_gen_from_double, new_t_COMPLEX_from_double 97 ---> 98 from . import complex_number 99 100 from .complex_field import ComplexField ImportError: cannot import name complex_number Thanks. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d
[sage-support] Re: Quaternions, how to speed up computation
Mon 2018-11-19 09:41:03 UTC+1, Simon King: > > If I recall correctly, there is a function that for *many* (not all) > interactively created objects in Sage tells how they can be constructed, > but I don't recall the name of that function. That is sage_input, which can be used as follows: sage: R. = QQ[] sage: sage_input(R) QQ['x'] sage: sage_input(x) R. = QQ[] x Note that it does not always work: sage: K = R.fraction_field() sage: sage_input(K) Traceback (most recent call last) ... ValueError: Can't convert Fraction Field of Univariate Polynomial Ring in x over Rational Field to sage_input form -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Quaternions, how to speed up computation
Hi On 2018-11-19, Kolen Cheung wrote: > Then I thought I can import it in Python like this: > > import sage.rings > # OK > > sage.rings.polynomial.polynomial_ring.PolynomialRing_field > # AttributeError Admittedly the following is not an ideal solution, but you can do >>> from sage import all >>> from sage.rings.polynomial.polynomial_ring import PolynomialRing_field > sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category The "..._with_category" classes cannot be imported: These are dynamically created classes. > How would you write the same program in Python using sage as a library? And > in general I see many unfamiliar syntax (from Python’s point of view) like > R., QQ[], (0..20), etc. That's a feature. Syntax such as R. = QQ[] was inspired from Magma (if I recall correctly). This and other syntactical features are very useful in interactive sessions. It works because of a preparser. If you want to know how to translate an interactive session into module code, the "preparse" function is your friend: sage: preparse("R. = QQ[]") "R = QQ['x']; (x,) = R._first_ngens(1)" So, the output of preparse(`interactive sage command`) is `valid python command`. Concerning imports of constants, there is the "import_statements" function: sage: R. = QQ[] sage: import_statements(R) from sage.rings.qqbar import QQx sage: R. = QQ[] sage: import_statements(R) from sage.rings.qqbar import QQxy sage: R. = QQ[] sage: import_statements(R) Traceback (most recent call last): ... ValueError: no import statement found for 'Multivariate Polynomial Ring in x, y, z over Rational Field'. So, "import_statements" is for stuff that is defined in some Sage module, not for interactively created objects If I recall correctly, there is a function that for *many* (not all) interactively created objects in Sage tells how they can be constructed, but I don't recall the name of that function. > Do you think it is realistic to use sage as a > Python library and completely not using sage (as an interpreter) itself? Sure. If you write code (in the sense of "python or cython module") for Sage, then you are in fact using Sage as a Python library. To execute it in Python, I think "from sage import all" should be enough to make it work (but a less thorough import statement might work too). Best regards, Simon -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.