Hello all, So I took the plunge and started trying to write optimized code in Cython for my enumeration problem. The code can be found at http://www.cems.uvm.edu/~voight/tr_data.spyx http://www.cems.uvm.edu/~voight/totallyreal.py and for the experts out there, I'd appreciate any feedback you can give, including tricks and such. I also have a bunch of questions, some of which are probably just due to my inexperience:
(1) At a certain moment in the algorithm, I need to test if a polynomial with integer coefficients is squarefree (using exact arithmetic). Is it acceptable practice to do this in a brutal way, like: import sage.rings.all PolynomialRing, IntegerRing, gcd ZZx = PolynomialRing(IntegerRing(), 'x') [...] f = ZZx([...]) df = ZZx([...]) if gcd(f,df) <> 1: What exactly is happening internally there? And what is the overhead and effect on the timing? (1a) Shouldn't the integer polynomial gcd work using modular arithmetic to avoid coefficient blow-up? Or does it do this already? (If gcd(f,g) mod p is 1 for p >> 0 then gcd(f,g) = 1, etc.) (2) I have my Cython code in a tr_data.spyx file and my Python code in a totallyreal.py file. How do I include the former into the latter-- or do I have to include both at the prompt? (3) I understand that there is significantly more overhead when a function is declared using cdef incr(self) instead of def incr(self). in tr_data.spyx. But if I do this, how do I then access incr in totallyreal.py? (4) Sometimes I need quite verbose output, when debugging and testing, and othertimes I just want to turn it all off. Is there a way to set a global parameter which controls the verbosity for several routines, like the SetVerbose() in magma? Otherwise, I have to pass a "verbose" parameter around... (5) Is garbage collection automatic, or do I have to declare a __del__ function and do a sage_free? (6) Craig, did you ever get around to making the line K1._pari_().nfisisom(K2): for testing isomorphism between number fields any less ugly? Shouldn't it read is_isomorphic(K1, K2)? While you're at it, I need to be able to run an LLL-optimization routine to speed up these functions: the function is called polred(). (7) What overhead happens in declaring a number field? Unless I am reading this incorrectly, it now dominates my computation now! sage: prun enumerate_totallyreal_fields(5,10^5) 390120 function calls (390117 primitive calls) in 8.774 CPU seconds Ordered by: internal time ncalls tottime percall cumtime percall filename:lineno(function) 971 3.795 0.004 3.795 0.004 {method 'nfinit' of 'sage.libs.pari.gen.gen' objects} 1979 1.024 0.001 1.901 0.001 {method 'is_irreducible' of 'sage.rings.polynomial.polynomial_element.Polynomial' objects} 7600 0.403 0.000 0.710 0.000 polynomial_element_generic.py:946(__init__) 21686 0.332 0.000 0.381 0.000 rational_field.py: 120(__call__) 971 0.230 0.000 0.431 0.000 {method '_pari_' of 'sage.rings.polynomial.polynomial_element.Polynomial' objects} 111586 0.223 0.000 0.223 0.000 {isinstance} 8571 0.211 0.000 1.318 0.000 polynomial_ring.py: 162(__call__) 7581 0.197 0.000 0.197 0.000 {sage.libs.ntl.ntl.make_new_ZZX} 1996 0.169 0.000 0.419 0.000 polynomial_element_generic.py:878(list) 1 0.164 0.164 8.774 8.774 totallyreal.py: 24(enumerate_totallyreal_fields) 22151 0.142 0.000 0.226 0.000 polynomial_element_generic.py:1180(degree) 971 0.129 0.000 0.247 0.000 polynomial_element_generic.py:518(__init__) 45 0.123 0.003 0.123 0.003 {method 'nfisisom' of 'sage.libs.pari.gen.gen' objects} 2120 0.119 0.000 0.444 0.000 {method 'incr' of 'tr_data_spyx_0.tr_data' objects} 90 0.112 0.001 0.130 0.001 {method '_pari_' of 'sage.structure.sage_object.SageObject' objects} 971 0.101 0.000 0.922 0.001 number_field.py: 157(NumberField) [...] It'd better not be the case that invariants of the field are automatically computed...! (8) When printing a list of integers, why does it print vertically instead of horizontally, i.e. [1, 2, ... ] instead of [1, 2, ...] or is this a vagary of Python? Thanks, John Voight Assistant Professor of Mathematics University of Vermont [EMAIL PROTECTED] [EMAIL PROTECTED] http://www.cems.uvm.edu/~voight/ --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---