Ticket #9541: trac_9541part8libsingularfirst_steps.patch
File trac_9541part8libsingularfirst_steps.patch, 14.5 KB (added by , 7 years ago) 


module_list.py
# HG changeset patch # User William Stein <wstein@gmail.com> # Date 1279763013 7200 # Node ID 6f449c1dcdaad8f3c26a286205d2fa6308feb27d # Parent 53c4551ed34f4ee655eb78c0b9c87fb3c45a9d51 [mq]: trac_9541part8 diff r 53c4551ed34f r 6f449c1dcdaa module_list.py
a b 1204 1204 sources = ['sage/rings/number_field/number_field_base.pyx'], 1205 1205 include_dirs = [SAGE_ROOT+'/local/include/FLINT/', SAGE_ROOT+'/devel/sage/sage/libs/flint'], 1206 1206 extra_compile_args=["std=c99", "D_XPG6"], 1207 ), 1207 libraries=['flint'], 1208 depends = [SAGE_ROOT + "/local/include/FLINT/flint.h"]), 1208 1209 1209 1210 Extension('sage.rings.number_field.implementation', 1210 1211 sources = ['sage/rings/number_field/implementation.pyx' , "sage/libs/flint/fmpq_poly.c"], … … 1242 1243 depends = [SAGE_ROOT + "/local/include/FLINT/flint.h"]), 1243 1244 1244 1245 Extension('sage.rings.number_field.number_field_element_libsingular', 1245 sources = ['sage/rings/number_field/number_field_element_libsingular.pyx']), 1246 sources = ['sage/rings/number_field/number_field_element_libsingular.pyx'], 1247 include_dirs = [SAGE_ROOT+'/local/include/FLINT/', SAGE_ROOT+'/devel/sage/sage/libs/flint', 1248 SAGE_ROOT +'/local/include/singular'], 1249 libraries=['flint', 'singular'], 1250 depends = [SAGE_ROOT + "/local/include/FLINT/flint.h"], 1251 language = 'c++' 1252 ), 1246 1253 1247 1254 Extension('sage.rings.number_field.number_field_element_quadratic', 1248 1255 sources = ['sage/rings/number_field/number_field_element_quadratic.pyx'], 
sage/rings/number_field/implementation.pxd
diff r 53c4551ed34f r 6f449c1dcdaa sage/rings/number_field/implementation.pxd
a b 12 12 13 13 # FLINTbased implementation 14 14 include "../../libs/flint/fmpq_poly.pxd" 15 15 16 cdef class ArithmeticImplementation_flint(ArithmeticImplementation): 16 17 cdef fmpq_poly_t modulus 17 18 18 # Singularbased implementation 19 cdef class ArithmeticImplementation_singular(ArithmeticImplementation): 20 pass 19 cdef class ArithmeticImplementation_libsingular(ArithmeticImplementation): 20 cdef object ring 21 cdef object ideal 22 cdef object groebner_strategy 21 23 22 24 cdef class ArithmeticImplementation_quadratic(ArithmeticImplementation): 23 25 pass 
sage/rings/number_field/implementation.pyx
diff r 53c4551ed34f r 6f449c1dcdaa sage/rings/number_field/implementation.pyx
a b 178 178 """ 179 179 return True 180 180 181 cdef class ArithmeticImplementation_ singular(ArithmeticImplementation):182 def __init__(self ):181 cdef class ArithmeticImplementation_libsingular(ArithmeticImplementation): 182 def __init__(self, ring, ideal): 183 183 """ 184 184 EXAMPLES:: 185 185 186 sage: sage.rings.number_field.implementation.ArithmeticImplementation_ singular()186 sage: sage.rings.number_field.implementation.ArithmeticImplementation_libsingular() 187 187 Arithmetic implementation 'singular' 188 188 """ 189 189 ArithmeticImplementation.__init__(self, 'singular') 190 self.ring = ring 191 self.ideal = ideal 192 self.groebner_strategy = ideal._groebner_strategy() 190 193 191 194 cdef class ArithmeticImplementation_quadratic(ArithmeticImplementation): 192 195 def __init__(self): 
sage/rings/number_field/number_field.py
diff r 53c4551ed34f r 6f449c1dcdaa sage/rings/number_field/number_field.py
a b 643 643 perfect square. 644 644 645 645 INPUT: 646 647 648  ``D``  a rational number 649 650  ``names``  variable name 651 652  ``check``  bool (default: True) 653 654  ``embedding``  bool or square root of D in an 655 ambient field (default: True) 656 657  ``latex_name``  latex variable name (defalt: \sqrt{D}) 658 646  ``D``  a rational number 647  ``names``  variable name 648  ``check``  bool (default: True) 649  ``embedding``  bool or square root of D in an 650 ambient field (default: True) 651  ``latex_name``  latex variable name (defalt: \sqrt{D}) 659 652 660 653 OUTPUT: A number field defined by a quadratic polynomial. Unless 661 654 otherwise specified, it has an embedding into `\RR` or … … 4811 4804 """ 4812 4805 NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding) 4813 4806 if implementation == 'default': 4814 implementation = 'ntl' 4807 implementation = DEFAULT_IMPLEMENTATION['absolute'] 4808 4809 if implementation == 'singular': 4810 implementation = 'flint' 4815 4811 4816 4812 if implementation == 'quadratic': 4817 4813 self._element_class = number_field_element_quadratic.NumberFieldElement_quadratic 
sage/rings/number_field/number_field_element_libsingular.pxd
diff r 53c4551ed34f r 6f449c1dcdaa sage/rings/number_field/number_field_element_libsingular.pxd
a b 1 1 from number_field_element cimport NumberFieldElement 2 2 3 from sage.libs.singular.decl cimport poly, ring 4 5 from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomialRing_libsingular, MPolynomial_libsingular 6 7 from sage.libs.singular.groebner_strategy cimport GroebnerStrategy 8 3 9 cdef class NumberFieldElement_libsingular(NumberFieldElement): 10 cdef poly *_poly 11 4 12 cdef _new(self) 13 cdef ring* ring(self) 14 cdef MPolynomialRing_libsingular mpoly_ring(self) 15 cdef GroebnerStrategy groebner_strategy(self) 16 cdef poly* normal_form(self, poly* p) 17 18 
sage/rings/number_field/number_field_element_libsingular.pyx
diff r 53c4551ed34f r 6f449c1dcdaa sage/rings/number_field/number_field_element_libsingular.pyx
a b 13 13 # http://www.gnu.org/licenses/ 14 14 ############################################################################### 15 15 16 cdef extern from "": 17 int unlikely(int) 18 int likely(int) 19 16 20 include "../../ext/stdsage.pxi" 17 21 18 22 from sage.structure.element cimport RingElement, ModuleElement, Element 23 from number_field_base cimport NumberField 24 25 from implementation cimport ArithmeticImplementation_libsingular 26 27 from sage.libs.singular.polynomial cimport singular_polynomial_str 28 29 from sage.libs.singular.decl cimport p_Copy, currRing, rChangeCurrRing, redNF, redtailBba, p_Delete 30 31 # singular poly arith 32 from sage.libs.singular.polynomial cimport singular_polynomial_call, singular_polynomial_cmp, singular_polynomial_add, singular_polynomial_sub, singular_polynomial_neg 33 from sage.libs.singular.polynomial cimport singular_polynomial_rmul, singular_polynomial_mul, singular_polynomial_div_coeff, singular_polynomial_pow 34 from sage.libs.singular.polynomial cimport singular_polynomial_str, singular_polynomial_latex, singular_polynomial_str_with_changed_varnames 35 from sage.libs.singular.polynomial cimport singular_polynomial_deg 36 from sage.libs.singular.polynomial cimport singular_polynomial_length_bounded 19 37 20 38 cdef class NumberFieldElement_libsingular(NumberFieldElement): 39 40 def bench(self): 41 self._parent 42 43 def bench2(self): 44 (<NumberField>self._parent) 45 46 def bench3(self): 47 (<NumberField>self._parent)._implementation 48 49 def bench4(self): 50 cdef ArithmeticImplementation_libsingular A 51 A = <ArithmeticImplementation_libsingular> (<NumberField>self._parent)._implementation 52 53 def bench5(self): 54 cdef ArithmeticImplementation_libsingular A 55 A = <ArithmeticImplementation_libsingular> (<NumberField>self._parent)._implementation 56 cdef MPolynomialRing_libsingular R = <MPolynomialRing_libsingular>(A.ring) 57 58 def bench6(self): 59 self.the_ring() 60 61 def bench7(self): 62 self._new() 63 64 def bench8(self): 65 self.mpoly_ring() 66 67 def bench9(self): 68 self.groebner_strategy() 69 21 70 def __init__(self, parent, f): 22 71 self._parent = parent 72 cdef MPolynomial_libsingular g = self.mpoly_ring().gen(0) 73 self._poly = p_Copy(g._poly, self.ring()) 74 75 cdef inline ring* ring(self): 76 return self.mpoly_ring()._ring 23 77 24 cdef _new(self): 78 cdef inline MPolynomialRing_libsingular mpoly_ring(self): 79 cdef ArithmeticImplementation_libsingular A 80 A = <ArithmeticImplementation_libsingular> (<NumberField>self._parent)._implementation 81 cdef MPolynomialRing_libsingular R = <MPolynomialRing_libsingular>(A.ring) 82 return R 83 84 cdef GroebnerStrategy groebner_strategy(self): 85 cdef ArithmeticImplementation_libsingular A 86 A = <ArithmeticImplementation_libsingular> (<NumberField>self._parent)._implementation 87 return A.groebner_strategy 88 89 cdef poly* normal_form(self, poly* p): 90 if unlikely(self.ring() != currRing): 91 rChangeCurrRing(self.ring()) 92 cdef int max_ind 93 cdef poly *_p = redNF(p_Copy(p, self.ring()), max_ind, 0, self.groebner_strategy()._strat) 94 if likely(_p!=NULL): 95 _p = redtailBba(_p, max_ind, self.groebner_strategy()._strat) 96 return _p 97 98 cdef inline _new(self): 25 99 cdef NumberFieldElement_libsingular x = PY_NEW(NumberFieldElement_libsingular) 26 100 x._parent = self._parent 101 x._poly = NULL 27 102 return x 28 103 29 104 cdef void _randomize(self, num_bound, den_bound, distribution): … … 32 107 def polynomial(self): 33 108 raise NotImplementedError 34 109 35 cpdef RingElement _mul_(left, RingElement right): 110 def __repr__(self): 111 return singular_polynomial_str(self._poly, self.ring()) 112 113 cpdef RingElement _mul_(left, RingElement r): 114 cdef NumberFieldElement_libsingular right = r 115 cdef poly* p 116 singular_polynomial_mul(&p, left._poly, right._poly, left.ring()) 117 cdef NumberFieldElement_libsingular x = left._new() 118 x._poly = left.normal_form(p) 119 if p != NULL: p_Delete(&p, left.ring()) 120 return x 121 122 cpdef ModuleElement _add_(left, ModuleElement r): 123 cdef NumberFieldElement_libsingular x = left._new(), right = r 124 singular_polynomial_add(&x._poly, left._poly, right._poly, left.ring()) 125 return x 126 127 cpdef ModuleElement _sub_(left, ModuleElement r): 128 cdef NumberFieldElement_libsingular x = left._new(), right = r 129 singular_polynomial_sub(&x._poly, left._poly, right._poly, left.ring()) 130 return x 131 132 cpdef RingElement _div_(left, RingElement r): 133 cdef NumberFieldElement_libsingular x = left._new(), right = r 36 134 raise NotImplementedError 37 38 cpdef ModuleElement _add_(left, ModuleElement right):39 raise NotImplementedError40 41 cpdef ModuleElement _sub_(left, ModuleElement right):42 raise NotImplementedError43 44 cpdef RingElement _div_(left, RingElement right):45 raise NotImplementedError46 135 47 136 def __invert__(self): 48 137 raise NotImplementedError … … 59 148 raise NotImplementedError 60 149 61 150 62 151 cdef class OrderElement_libsingular(NumberFieldElement_libsingular): 152 pass 
sage/rings/number_field/number_field_rel.py
diff r 53c4551ed34f r 6f449c1dcdaa sage/rings/number_field/number_field_rel.py
a b 292 292 self._order_element_class = number_field_element_generic.OrderElement_generic 293 293 self._set_implementation(arithmetic_implementation.ArithmeticImplementation_generic(polynomial)) 294 294 elif implementation == 'singular': 295 import number_field_element_singular 296 self._element_class = number_field_element_singular.NumberFieldElement_singular 297 self._order_element_class = number_field_element_singular.OrderElement_singular 298 self._set_implementation(arithmetic_implementation.ArithmeticImplementation_singular()) 295 import number_field_element_libsingular 296 self._element_class = number_field_element_libsingular.NumberFieldElement_libsingular 297 self._order_element_class = number_field_element_libsingular.OrderElement_libsingular 298 ring, ideal = self._libsingular_ring(polynomial) 299 self._set_implementation(arithmetic_implementation.ArithmeticImplementation_libsingular(ring, ideal)) 299 300 else: 300 301 raise ValueError, "invalid relative number field implementation '%s'"%implementation 301 302 assert self.implementation() is not None … … 360 361 self._zero_element = self(0) 361 362 self._one_element = self(1) 362 363 364 def _libsingular_ring(self, polynomial): 365 """ 366 Return the libsingular ring that we use to implement arithmetic in 367 the relative extension defined by the given polynomial. 368 369 INPUT: 370  ``polynomial``  a polynomial over a number field 371 372 OUTPUT: 373  a singular multivariate polynomial ring 374  an ideal 375 """ 376 from sage.rings.all import PolynomialRing, QQ 377 ring = PolynomialRing(QQ, 2, names=('x','y')) 378 x,y = ring.gens() 379 ideal = ring.ideal([x**3+7,y**3+2]) 380 return ring, ideal 381 363 382 def change_names(self, names): 364 383 r""" 365 384 Return relative number field isomorphic to self but with the 
sage/rings/number_field/todo.txt
diff r 53c4551ed34f r 6f449c1dcdaa sage/rings/number_field/todo.txt
a b 38 38 [x] make sure the _cmp_c_impl's are compatible across number field element implementations. 39 39 [x] make default implementation computation be centralized somehow?? 40 40 41 [ ] libsingular elements 41 [ ] libsingular elements: 42 [ ] constructing the corresponding ring 43 44 42 45 [ ] implement OrderElement_singular 43 46 44 47 [ ] write general implementation of algorithm for computing absolute_field