Ticket #11339: trac_11339_refcount_singular_polynomials.patch
File trac_11339_refcount_singular_polynomials.patch, 65.3 KB (added by , 10 years ago) |
---|
-
sage/libs/singular/ring.pyx
# HG changeset patch # User Volker Braun <vbraun@stp.dias.ie> # Date 1317064847 -7200 # Node ID e4388ef9ba0f236f4dabc62e154235838180e595 # Parent dca107e84dc194d9dae39c5e7e5e24c684dcda34 Trac #11339: Refcount singular rings This patch switches over the Singular-based multivariate polynomial ring and polynomials to the refcounted rings. Lots of cleanup and some minor bugfixes. diff --git a/sage/libs/singular/ring.pyx b/sage/libs/singular/ring.pyx
a b 223 223 raise NotImplementedError("Base ring is not supported.") 224 224 225 225 _ring = <ring*>omAlloc0Bin(sip_sring_bin) 226 if (_ring is NULL): 227 raise ValueError("Failed to allocate Singular ring.") 226 228 _ring.ch = characteristic 227 229 _ring.ringtype = ringtype 228 230 _ring.N = n -
sage/rings/polynomial/multi_polynomial_libsingular.pxd
diff --git a/sage/rings/polynomial/multi_polynomial_libsingular.pxd b/sage/rings/polynomial/multi_polynomial_libsingular.pxd
a b 8 8 9 9 cdef class MPolynomial_libsingular(MPolynomial): 10 10 cdef poly *_poly 11 cdef ring *_parent_ring 11 12 cpdef _repr_short_(self) 12 13 cpdef is_constant(self) 13 14 cpdef _homogenize(self, int var) -
sage/rings/polynomial/multi_polynomial_libsingular.pyx
diff --git a/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/sage/rings/polynomial/multi_polynomial_libsingular.pyx
a b 36 36 - Simon King (2011-03): Use a faster way of conversion from the base 37 37 ring. 38 38 39 - Volker Braun (2011-06): Major cleanup, refcount singular rings. 40 39 41 TODO: 40 42 41 43 - implement Real, Complex coefficient rings via libSINGULAR … … 150 152 b - 1728*c 151 153 """ 152 154 155 # The Singular API is as follows: 156 # 157 # pXXX does assume the currRing to be set 158 # p_XXX does not. 159 # 160 # However, sometimes there are bugs, i.e. you call p_XXX and it 161 # crashes unless currRing is set. 162 # 163 # Notable exceptions: 164 # * pNext and pIter don't need currRing 165 # * p_Normalize apparently needs currRing 166 153 167 include "sage/ext/stdsage.pxi" 154 168 include "sage/ext/interrupt.pxi" 155 169 … … 157 171 from sage.libs.singular.decl cimport ring, poly, ideal, intvec, number, currRing 158 172 159 173 # singular functions 160 from sage.libs.singular.decl cimport p_ISet, rChangeCurrRing, p_Copy, p_Init, p_SetCoeff, p_Setm, p_SetExp, p_Add_q 161 from sage.libs.singular.decl cimport p_NSet, p_GetCoeff, p_Delete, p_GetExp, pNext, rRingVar, omAlloc0, omStrDup 162 from sage.libs.singular.decl cimport omFree, pDivide, p_SetCoeff0, n_Init, p_DivisibleBy, pLcm, p_LmDivisibleBy 163 from sage.libs.singular.decl cimport pDivide, p_IsConstant, p_ExpVectorEqual, p_String, p_LmInit, n_Copy 164 from sage.libs.singular.decl cimport p_IsUnit, pInvers, n_IsOne, p_Head, pSubst, idInit, fast_map, id_Delete 165 from sage.libs.singular.decl cimport pIsHomogeneous, pHomogen, pTotaldegree, singclap_pdivide, singclap_factorize 166 from sage.libs.singular.decl cimport delete, idLift, IDELEMS, On, Off, SW_USE_CHINREM_GCD, SW_USE_EZGCD 167 from sage.libs.singular.decl cimport p_LmIsConstant, pTakeOutComp1, singclap_gcd, pp_Mult_qq, p_GetMaxExp 168 from sage.libs.singular.decl cimport pLength, kNF, singclap_isSqrFree, p_Neg, p_Minus_mm_Mult_qq, p_Plus_mm_Mult_qq 169 from sage.libs.singular.decl cimport pDiff, singclap_resultant, p_Normalize 170 from sage.libs.singular.decl cimport prCopyR, prCopyR_NoSort 174 from sage.libs.singular.decl cimport ( 175 p_ISet, rChangeCurrRing, p_Copy, p_Init, p_SetCoeff, p_Setm, p_SetExp, p_Add_q, 176 p_NSet, p_GetCoeff, p_Delete, p_GetExp, pNext, rRingVar, omAlloc0, omStrDup, 177 omFree, pDivide, p_SetCoeff0, n_Init, p_DivisibleBy, pLcm, p_LmDivisibleBy, 178 pDivide, p_IsConstant, p_ExpVectorEqual, p_String, p_LmInit, n_Copy, 179 p_IsUnit, pInvers, n_IsOne, p_Head, pSubst, idInit, fast_map, id_Delete, 180 pIsHomogeneous, pHomogen, pTotaldegree, singclap_pdivide, singclap_factorize, 181 delete, idLift, IDELEMS, On, Off, SW_USE_CHINREM_GCD, SW_USE_EZGCD, 182 p_LmIsConstant, pTakeOutComp1, singclap_gcd, pp_Mult_qq, p_GetMaxExp, 183 pLength, kNF, singclap_isSqrFree, p_Neg, p_Minus_mm_Mult_qq, p_Plus_mm_Mult_qq, 184 pDiff, singclap_resultant, p_Normalize, 185 prCopyR, prCopyR_NoSort ) 171 186 172 187 # singular conversion routines 173 188 from sage.libs.singular.singular cimport si2sa, sa2si, overflow_check 174 189 175 190 # singular poly arith 176 from sage.libs.singular.polynomial cimport singular_polynomial_call, singular_polynomial_cmp, singular_polynomial_add, singular_polynomial_sub, singular_polynomial_neg 177 from sage.libs.singular.polynomial cimport singular_polynomial_rmul, singular_polynomial_mul, singular_polynomial_div_coeff, singular_polynomial_pow 178 from sage.libs.singular.polynomial cimport singular_polynomial_str, singular_polynomial_latex, singular_polynomial_str_with_changed_varnames 179 from sage.libs.singular.polynomial cimport singular_polynomial_deg 180 from sage.libs.singular.polynomial cimport singular_polynomial_length_bounded 191 from sage.libs.singular.polynomial cimport ( 192 singular_polynomial_call, singular_polynomial_cmp, singular_polynomial_add, 193 singular_polynomial_sub, singular_polynomial_neg, singular_polynomial_rmul, 194 singular_polynomial_mul, singular_polynomial_div_coeff, singular_polynomial_pow, 195 singular_polynomial_str, singular_polynomial_latex, 196 singular_polynomial_str_with_changed_varnames, singular_polynomial_deg, 197 singular_polynomial_length_bounded ) 181 198 182 199 # singular rings 183 from sage.libs.singular.ring cimport singular_ring_new, singular_ring_ delete200 from sage.libs.singular.ring cimport singular_ring_new, singular_ring_reference, singular_ring_delete 184 201 185 202 # polynomial imports 186 203 from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain … … 226 243 import polynomial_element 227 244 228 245 cdef class MPolynomialRing_libsingular(MPolynomialRing_generic): 246 247 def __cinit__(self): 248 """ 249 The Cython constructor. 250 251 EXAMPLES:: 252 253 sage: from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomialRing_libsingular 254 sage: MPolynomialRing_libsingular(QQ, 3, ('x', 'y', 'z'), TermOrder('degrevlex', 3)) 255 Multivariate Polynomial Ring in x, y, z over Rational Field 256 sage: type(_) 257 <type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular'> 258 259 sage: P.<x,y,z> = QQ[]; P 260 Multivariate Polynomial Ring in x, y, z over Rational Field 261 sage: type(P) 262 <type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular'> 263 """ 264 self._ring = NULL 265 229 266 def __init__(self, base_ring, n, names, order='degrevlex'): 230 267 """ 231 268 Construct a multivariate polynomial ring subject to the … … 307 344 Polynomial base injection morphism: 308 345 From: Integer Ring 309 346 To: Multivariate Polynomial Ring in x, y over Integer Ring 310 311 347 """ 312 348 MPolynomialRing_generic.__init__(self, base_ring, n, names, order) 313 349 self._has_singular = True 314 350 assert(n == len(self._names)) 315 351 self.__ngens = n 316 352 self._ring = singular_ring_new(base_ring, n, self._names, order) 317 self._one_element = <MPolynomial_libsingular>new_MP(self,p_ISet(1, self._ring)) 318 self._one_element_poly = (<MPolynomial_libsingular>self._one_element)._poly 319 self._zero_element = <MPolynomial_libsingular>new_MP(self,NULL) 353 self._zero_element = new_MP(self, NULL) 354 cdef MPolynomial_libsingular one = new_MP(self, p_ISet(1, self._ring)) 355 self._one_element = one 356 self._one_element_poly = one._poly 320 357 # This polynomial ring should belong to Algebras(base_ring). 321 358 # Algebras(...).parent_class, which was called from MPolynomialRing_generic.__init__, 322 359 # tries to provide a conversion from the base ring, if it does not exist. … … 329 366 330 367 def __dealloc__(self): 331 368 r""" 332 Carefully deallocate the ring, without changing "currRing" 333 (since this method can be at unpredictable times due to garbage 334 collection). 369 Deallocate the ring without changing ``currRing`` 335 370 336 371 TESTS: 372 337 373 This example caused a segmentation fault with a previous version 338 of this method: 374 of this method:: 375 339 376 sage: import gc 340 377 sage: from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomialRing_libsingular 341 378 sage: R1 = MPolynomialRing_libsingular(GF(5), 2, ('x', 'y'), TermOrder('degrevlex', 2)) … … 351 388 sage: del R3 352 389 sage: _ = gc.collect() 353 390 """ 354 singular_ring_delete(self._ring) 391 if self._ring != NULL: # the constructor did not raise an exception 392 singular_ring_delete(self._ring) 393 394 def __copy__(self): 395 """ 396 Copy ``self``. 397 398 The ring is unique and immutable, so we do not copy. 399 400 TESTS:: 401 402 sage: import gc 403 sage: from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomialRing_libsingular 404 sage: from sage.libs.singular.ring import ring_refcount_dict 405 sage: n = len(ring_refcount_dict) 406 sage: R = MPolynomialRing_libsingular(GF(547), 2, ('x', 'y'), TermOrder('degrevlex', 2)) 407 sage: len(ring_refcount_dict) == n + 1 408 True 409 410 sage: Q = copy(R) # indirect doctest 411 sage: p = R.gen(0) ^2+R.gen(1)^2 412 sage: q = copy(p) 413 sage: del R 414 sage: del Q 415 sage: del p 416 sage: del q 417 sage: gc.collect() # random output 418 sage: len(ring_refcount_dict) == n 419 True 420 """ 421 return self 422 423 def __deepcopy__(self, memo): 424 """ 425 Deep copy ``self``. 426 427 The ring should be immutable, so we do not copy. 428 429 TESTS:: 430 431 sage: R.<x,y> = GF(547)[] 432 sage: R is deepcopy(R) # indirect doctest 433 True 434 """ 435 memo[id(self)] = self 436 return self 355 437 356 438 cdef _coerce_c_impl(self, element): 357 439 """ … … 440 522 5 441 523 """ 442 524 cdef poly *_p 443 cdef ring *_ring 525 cdef ring *_ring = self._ring 444 526 cdef number *_n 445 527 cdef poly *mon 446 528 cdef int i 447 448 _ring = self._ring449 529 450 530 base_ring = self.base_ring() 451 531 452 if(_ring != currRing): rChangeCurrRing(_ring) 453 454 if PY_TYPE_CHECK(element, MPolynomial_libsingular): 455 if element.parent() is <object>self: 532 if isinstance(element, MPolynomial_libsingular): 533 n = (<MPolynomial_libsingular>element)._parent.ngens() 534 if element.parent() is self: 456 535 return element 457 elif element.parent() == self:458 # is this safe?459 _p = p_Copy((<MPolynomial_libsingular>element)._poly, _ring)460 536 elif base_ring is element.base_ring() and \ 461 self.ngens() >= (<MPolynomial_libsingular>element)._parent.ngens()and \462 self.variable_names()[: (<MPolynomial_libsingular>element)._parent.ngens()] == (<MPolynomial_libsingular>element)._parent.variable_names():537 self.ngens() >= n and \ 538 self.variable_names()[:n] == (<MPolynomial_libsingular>element)._parent.variable_names(): 463 539 if self.term_order() == (<MPolynomial_libsingular>element)._parent.term_order(): 464 _p = prCopyR_NoSort((<MPolynomial_libsingular>element)._poly, (<MPolynomialRing_libsingular>(<MPolynomial_libsingular>element)._parent)._ring, _ring) 540 _p = prCopyR_NoSort((<MPolynomial_libsingular>element)._poly, 541 (<MPolynomial_libsingular>element)._parent_ring, 542 _ring) 465 543 else: 466 _p = prCopyR((<MPolynomial_libsingular>element)._poly, (<MPolynomialRing_libsingular>(<MPolynomial_libsingular>element)._parent)._ring, _ring) 544 _p = prCopyR((<MPolynomial_libsingular>element)._poly, 545 (<MPolynomial_libsingular>element)._parent_ring, _ring) 467 546 elif base_ring.has_coerce_map_from(element.parent()._mpoly_base_ring(self.variable_names())): 468 547 return self(element._mpoly_dict_recursive(self.variable_names(), base_ring)) 469 548 else: 470 549 raise TypeError, "parents do not match" 471 550 472 elif PY_TYPE_CHECK(element, MPolynomial_polydict):551 elif isinstance(element, MPolynomial_polydict): 473 552 if (<Element>element)._parent == self: 474 553 _p = p_ISet(0, _ring) 475 554 for (m,c) in element.element().dict().iteritems(): … … 495 574 else: 496 575 raise TypeError("incompatable parents.") 497 576 498 elif PY_TYPE_CHECK(element, CommutativeRingElement):577 elif isinstance(element, CommutativeRingElement): 499 578 # base ring elements 500 579 if <Parent>element.parent() is base_ring: 501 580 # shortcut for GF(p) … … 519 598 _p = p_NSet(_n, _ring) 520 599 521 600 # Accepting int 522 elif PY_TYPE_CHECK(element, int):601 elif isinstance(element, int): 523 602 if isinstance(base_ring, FiniteField_prime_modn): 524 603 _p = p_ISet(int(element) % _ring.ch,_ring) 525 604 else: … … 527 606 _p = p_NSet(_n, _ring) 528 607 529 608 # and longs 530 elif PY_TYPE_CHECK(element, long):609 elif isinstance(element, long): 531 610 if isinstance(base_ring, FiniteField_prime_modn): 532 611 element = element % self.base_ring().characteristic() 533 _p = p_ISet(int(element), _ring)612 _p = p_ISet(int(element), _ring) 534 613 else: 535 614 _n = sa2si(base_ring(element),_ring) 536 615 _p = p_NSet(_n, _ring) 537 616 else: 538 617 raise TypeError, "Cannot coerce element" 539 618 540 return new_MP(self, _p)619 return new_MP(self, _p) 541 620 542 621 def __call__(self, element): 543 622 """ … … 687 766 0 688 767 sage: P.<x,y> = Zmod(2^10)[]; P(0) 689 768 0 690 691 769 """ 692 cdef poly *_p, *mon, * _element770 cdef poly *_p, *mon, *El_poly 693 771 cdef ring *_ring = self._ring 694 772 cdef ring *El_ring 773 cdef long mpos 695 774 cdef MPolynomial_libsingular Element 696 775 cdef MPolynomialRing_libsingular El_parent 697 776 cdef unsigned int i, j 698 if _ring!=currRing: rChangeCurrRing(_ring)699 777 cdef list ind_map = [] 700 778 cdef int e 779 if _ring!=currRing: rChangeCurrRing(_ring) 701 780 702 781 # try to coerce first 703 782 try: … … 705 784 except TypeError: 706 785 pass 707 786 708 if PY_TYPE_CHECK(element, SingularElement) or \ 709 PY_TYPE_CHECK(element, sage.libs.pari.gen.gen): 787 if isinstance(element, (SingularElement, sage.libs.pari.gen.gen)): 710 788 element = str(element) 711 789 712 if PY_TYPE_CHECK(element, MPolynomial_libsingular) and element.parent() is not self and element.parent() != self: 713 790 if isinstance(element, MPolynomial_libsingular) and element.parent() is not self and element.parent() != self: 714 791 variable_names_s = element.parent().variable_names() 715 792 variable_names_t = self.variable_names() 716 793 … … 726 803 K = self.base_ring() 727 804 base = self._base 728 805 Element = <MPolynomial_libsingular>element 729 _element= Element._poly730 El_parent = <MPolynomialRing_libsingular>Element.parent()731 El_ring = El _parent._ring806 El_poly = Element._poly 807 El_parent = Element._parent 808 El_ring = Element._parent_ring 732 809 El_base = El_parent._base 733 810 734 while _element:811 while El_poly: 735 812 rChangeCurrRing(El_ring) 736 c = si2sa(p_GetCoeff( _element, El_ring), El_ring, El_base)813 c = si2sa(p_GetCoeff(El_poly, El_ring), El_ring, El_base) 737 814 try: 738 815 c = K(c) 739 816 except TypeError, msg: … … 742 819 if c: 743 820 rChangeCurrRing(_ring) 744 821 mon = p_Init(_ring) 745 p_SetCoeff(mon, sa2si(c 822 p_SetCoeff(mon, sa2si(c, _ring), _ring) 746 823 for j from 1 <= j <= El_ring.N: 747 e = p_GetExp( _element, j, El_ring)824 e = p_GetExp(El_poly, j, El_ring) 748 825 if e: 749 826 p_SetExp(mon, ind_map[j-1], e, _ring) 750 827 p_Setm(mon, _ring) 751 828 _p = p_Add_q(_p, mon, _ring) 752 _element = pNext(_element)829 El_poly = pNext(El_poly) 753 830 return new_MP(self, _p) 754 831 755 if PY_TYPE_CHECK(element, MPolynomial_polydict): 756 832 if isinstance(element, MPolynomial_polydict): 757 833 variable_names_s = element.parent().variable_names() 758 834 variable_names_t = self.variable_names() 759 835 … … 784 860 return new_MP(self, _p) 785 861 786 862 from sage.rings.polynomial.pbori import BooleanPolynomial 787 788 if PY_TYPE_CHECK(element, BooleanPolynomial): 789 863 if isinstance(element, BooleanPolynomial): 790 864 if element.constant(): 791 865 if element: 792 866 return self._one_element 793 867 else: 794 868 return self._zero_element 795 869 796 797 870 variable_names_s = set(element.parent().variable_names()) 798 871 variable_names_t = self.variable_names() 799 872 … … 805 878 gens_map = dict(zip(Q.variable_names(),self.gens()[:Q.ngens()])) 806 879 return eval(str(element),gens_map) 807 880 808 if PY_TYPE_CHECK(element, basestring):881 if isinstance(element, basestring): 809 882 # let python do the parsing 810 883 d = self.gens_dict() 811 884 if self.base_ring().gen() != 1: … … 823 896 # element in self. 824 897 return self._coerce_c(element) 825 898 826 if PY_TYPE_CHECK(element, dict):899 if isinstance(element, dict): 827 900 _p = p_ISet(0, _ring) 828 901 K = self.base_ring() 829 902 for (m,c) in element.iteritems(): … … 926 999 raise ValueError, "Generator not defined." 927 1000 928 1001 rChangeCurrRing(_ring) 929 _p = p_ISet(1, _ring)1002 _p = p_ISet(1, _ring) 930 1003 p_SetExp(_p, n+1, 1, _ring) 931 1004 p_Setm(_p, _ring); 932 1005 933 return new_MP(self, _p)1006 return new_MP(self, _p) 934 1007 935 1008 def ideal(self, *gens, **kwds): 936 1009 """ … … 1098 1171 return R 1099 1172 if self.base_ring().is_prime_field(): 1100 1173 return R 1101 if self.base_ring().is_finite() or (PY_TYPE_CHECK(self.base_ring(), NumberField) and self.base_ring().is_absolute()): 1174 if self.base_ring().is_finite() \ 1175 or (isinstance(self.base_ring(), NumberField) and self.base_ring().is_absolute()): 1102 1176 R.set_ring() #sorry for that, but needed for minpoly 1103 1177 if singular.eval('minpoly') != "(" + self.__minpoly + ")": 1104 1178 singular.eval("minpoly=%s"%(self.__minpoly)) … … 1307 1381 - their generator names match and 1308 1382 - their term orderings match. 1309 1383 1310 1311 1384 EXAMPLES:: 1312 1385 1313 1386 sage: P.<x,y,z> = QQ[] … … 1330 1403 return (<Parent>left)._richcmp(right, op) 1331 1404 1332 1405 cdef int _cmp_c_impl(left, Parent right) except -2: 1333 if PY_TYPE_CHECK(right, MPolynomialRing_libsingular) or PY_TYPE_CHECK(right, MPolynomialRing_polydict_domain): 1334 return cmp( (left.base_ring(), map(str, left.gens()), left.term_order()), 1335 (right.base_ring(), map(str, right.gens()), right.term_order()) 1336 ) 1406 if isinstance(right, (MPolynomialRing_libsingular, MPolynomialRing_polydict_domain)): 1407 return cmp((left.base_ring(), map(str, left.gens()), left.term_order()), 1408 (right.base_ring(), map(str, right.gens()), right.term_order())) 1337 1409 else: 1338 1410 return cmp(type(left),type(right)) 1339 1411 … … 1366 1438 sage: P == loads(dumps(P)) 1367 1439 True 1368 1440 """ 1369 return sage.rings.polynomial.multi_polynomial_libsingular.unpickle_MPolynomialRing_libsingular, ( self.base_ring(), 1370 map(str, self.gens()), 1371 self.term_order() ) 1441 return sage.rings.polynomial.multi_polynomial_libsingular.unpickle_MPolynomialRing_libsingular, \ 1442 (self.base_ring(), map(str, self.gens()), self.term_order()) 1372 1443 1373 1444 def __temporarily_change_names(self, names, latex_names): 1374 1445 """ … … 1382 1453 ... 1383 1454 z^3 + w^3 - z*w 1384 1455 """ 1385 cdef ring *_ring = (<MPolynomialRing_libsingular>self)._ring1456 cdef ring *_ring = self._ring 1386 1457 cdef char **_names, **_orig_names 1387 1458 cdef char *_name 1388 1459 cdef int i … … 1494 1565 if not g._poly: 1495 1566 raise ZeroDivisionError 1496 1567 1497 res = pDivide(f._poly, g._poly)1568 res = pDivide(f._poly, g._poly) 1498 1569 if coeff: 1499 1570 if r.ringtype == 0 or r.cf.nDivBy(p_GetCoeff(f._poly, r), p_GetCoeff(g._poly, r)): 1500 1571 n = r.cf.nDiv( p_GetCoeff(f._poly, r) , p_GetCoeff(g._poly, r)) … … 1538 1609 cdef poly *_b 1539 1610 cdef ring *_r 1540 1611 if a._parent is not b._parent: 1541 b = (<MPolynomialRing_libsingular>a._parent)._coerce_c(b)1612 b = a._parent._coerce_c(b) 1542 1613 1543 1614 _a = a._poly 1544 1615 _b = b._poly 1545 _r = (<MPolynomialRing_libsingular>a._parent)._ring1616 _r = a._parent_ring 1546 1617 1547 1618 if _a == NULL: 1548 1619 raise ZeroDivisionError … … 1649 1720 return f,f 1650 1721 1651 1722 for g in G: 1652 if PY_TYPE_CHECK(g, MPolynomial_libsingular) \1723 if isinstance(g, MPolynomial_libsingular) \ 1653 1724 and (<MPolynomial_libsingular>g) \ 1725 and g.parent() is self \ 1654 1726 and p_LmDivisibleBy((<MPolynomial_libsingular>g)._poly, m, r): 1655 1727 flt = pDivide(f._poly, (<MPolynomial_libsingular>g)._poly) 1656 1728 #p_SetCoeff(flt, n_Div( p_GetCoeff(f._poly, r) , p_GetCoeff((<MPolynomial_libsingular>g)._poly, r), r), r) … … 1697 1769 cdef poly *p, *q 1698 1770 1699 1771 if h._parent is not g._parent: 1700 g = (<MPolynomialRing_libsingular>h._parent)._coerce_c(g)1701 1702 r = (<MPolynomialRing_libsingular>h._parent)._ring1772 g = h._parent._coerce_c(g) 1773 1774 r = h._parent_ring 1703 1775 p = g._poly 1704 1776 q = h._poly 1705 1777 … … 1708 1780 return False #GCD(0,0) = 0 1709 1781 else: 1710 1782 return True #GCD(x,0) = 1 1711 1712 1783 elif q == NULL: 1713 1784 return True # GCD(0,x) = 1 1714 1715 1785 elif p_IsConstant(p,r) or p_IsConstant(q,r): # assuming a base field 1716 1786 return False 1717 1787 … … 1753 1823 1754 1824 while not p_ExpVectorEqual(tempvector, maxvector, _ring): 1755 1825 tempvector = addwithcarry(tempvector, maxvector, pos, _ring) 1756 M.append(new_MP(self, p_Copy(tempvector, _ring)))1826 M.append(new_MP(self, p_Copy(tempvector, _ring))) 1757 1827 return M 1758 1828 1759 1829 def unpickle_MPolynomialRing_libsingular(base_ring, names, term_order): … … 1791 1861 """ 1792 1862 self._poly = NULL 1793 1863 self._parent = <ParentWithBase>parent 1864 self._parent_ring = singular_ring_reference(parent._ring) 1794 1865 1795 1866 def __dealloc__(self): 1796 # TODO: Warn otherwise! 1797 # for some mysterious reason, various things may be NULL in some cases 1798 if self._parent is not <ParentWithBase>None and (<MPolynomialRing_libsingular>self._parent)._ring != NULL and self._poly != NULL: 1799 p_Delete(&self._poly, (<MPolynomialRing_libsingular>self._parent)._ring) 1867 # WARNING: the Cython class self._parent is now no longer accessible! 1868 if self._poly==NULL: 1869 # e.g. MPolynomialRing_libsingular._zero_element 1870 singular_ring_delete(self._parent_ring) 1871 return 1872 assert self._parent_ring != NULL # the constructor has no way to raise an exception 1873 1874 ### If you suspect that the poly data was corrupted, then this is a good way to trigger a segfault: 1875 rChangeCurrRing(self._parent_ring) 1876 p_Normalize(self._poly, self._parent_ring) 1877 1878 p_Delete(&self._poly, self._parent_ring) 1879 singular_ring_delete(self._parent_ring) 1880 1881 def __copy__(self): 1882 """ 1883 Copy ``self``. 1884 1885 OUTPUT: 1886 1887 A copy. 1888 1889 EXAMPLES:: 1890 1891 sage: F.<a> = GF(7^2) 1892 sage: R.<x,y> = F[] 1893 sage: p = a*x^2 + y + a^3; p 1894 (a)*x^2 + y + (-2*a - 3) 1895 sage: q = copy(p) 1896 sage: p == q 1897 True 1898 sage: p is q 1899 False 1900 sage: lst = [p,q]; 1901 sage: matrix(ZZ, 2, 2, lambda i,j: bool(lst[i]==lst[j])) 1902 [1 1] 1903 [1 1] 1904 sage: matrix(ZZ, 2, 2, lambda i,j: bool(lst[i] is lst[j])) 1905 [1 0] 1906 [0 1] 1907 """ 1908 return new_MP(self._parent, p_Copy(self._poly, self._parent_ring)) 1909 1910 def __deepcopy__(self, memo={}): 1911 """ 1912 Deep copy ``self`` 1913 1914 TESTS:: 1915 1916 sage: R.<x,y> = QQ[] 1917 sage: p = x^2 + y^2 1918 sage: p is deepcopy(p) 1919 False 1920 sage: p == deepcopy(p) 1921 True 1922 sage: p.parent() is deepcopy(p).parent() 1923 True 1924 """ 1925 cpy = self.__copy__() 1926 memo[id(self)] = cpy 1927 return cpy 1800 1928 1801 1929 cpdef MPolynomial_libsingular _new_constant_poly(self, x, MPolynomialRing_libsingular P): 1802 1930 r""" … … 1815 1943 1816 1944 """ 1817 1945 if not x: 1818 return <MPolynomial_libsingular>new_MP(P, NULL) 1819 cdef ring *_ring = P._ring 1946 return new_MP(P, NULL) 1820 1947 cdef poly *_p 1821 singular_polynomial_rmul(&_p, P._one_element_poly, x, _ring)1822 return new_MP(P, _p)1948 singular_polynomial_rmul(&_p, P._one_element_poly, x, P._ring) 1949 return new_MP(P, _p) 1823 1950 1824 1951 def __call__(self, *x, **kwds): 1825 1952 """ … … 1883 2010 9 1884 2011 sage: a.parent() is QQ 1885 2012 True 1886 1887 2013 """ 1888 2014 if len(kwds) > 0: 1889 2015 f = self.subs(**kwds) … … 1893 2019 return f 1894 2020 1895 2021 cdef int l = len(x) 1896 cdef MPolynomialRing_libsingular parent = (<MPolynomialRing_libsingular>self._parent)2022 cdef MPolynomialRing_libsingular parent = self._parent 1897 2023 cdef ring *_ring = parent._ring 1898 2024 1899 if l == 1 and (PY_TYPE_CHECK(x[0], tuple) or PY_TYPE_CHECK(x[0], list)):2025 if l == 1 and isinstance(x[0], (list, tuple)): 1900 2026 x = x[0] 1901 2027 l = len(x) 1902 2028 … … 1918 2044 if res == NULL: 1919 2045 return parent._base._zero_element 1920 2046 if p_LmIsConstant(res, _ring): 1921 return si2sa( p_GetCoeff(res, _ring), _ring, (<MPolynomialRing_libsingular>self._parent)._base)2047 return si2sa(p_GetCoeff(res, _ring), _ring, parent._base) 1922 2048 return new_MP(parent, res) 1923 2049 1924 2050 # you may have to replicate this boilerplate code in derived classes if you override … … 2007 2133 return 0 2008 2134 cdef poly *p = (<MPolynomial_libsingular>left)._poly 2009 2135 cdef poly *q = (<MPolynomial_libsingular>right)._poly 2010 cdef ring *r = (<MPolynomial Ring_libsingular>left._parent)._ring2136 cdef ring *r = (<MPolynomial_libsingular>left)._parent_ring 2011 2137 return singular_polynomial_cmp(p, q, r) 2012 2138 2013 cpdef ModuleElement _add_( 2139 cpdef ModuleElement _add_(left, ModuleElement right): 2014 2140 """ 2015 2141 Add left and right. 2016 2142 … … 2019 2145 sage: P.<x,y,z>=PolynomialRing(QQ,3) 2020 2146 sage: 3/2*x + 1/2*y + 1 2021 2147 3/2*x + 1/2*y + 1 2022 2023 2148 """ 2149 cdef ring *r = (<MPolynomial_libsingular>left)._parent_ring 2024 2150 cdef poly *_p 2025 2151 singular_polynomial_add(&_p, left._poly, 2026 (<MPolynomial_libsingular>right)._poly, 2027 (<MPolynomialRing_libsingular>left._parent)._ring) 2028 return new_MP((<MPolynomialRing_libsingular>left._parent), _p) 2029 2030 cpdef ModuleElement _sub_( left, ModuleElement right): 2152 (<MPolynomial_libsingular>right)._poly, r) 2153 return new_MP((<MPolynomial_libsingular>left)._parent, _p) 2154 2155 cpdef ModuleElement _sub_(left, ModuleElement right): 2031 2156 """ 2032 2157 Subtract left and right. 2033 2158 … … 2036 2161 sage: P.<x,y,z>=PolynomialRing(QQ,3) 2037 2162 sage: 3/2*x - 1/2*y - 1 2038 2163 3/2*x - 1/2*y - 1 2039 2040 2164 """ 2041 cdef ring *_ring = (<MPolynomialRing_libsingular>left._parent)._ring 2042 2165 cdef ring *_ring = (<MPolynomial_libsingular>left)._parent_ring 2043 2166 cdef poly *_p 2044 2167 singular_polynomial_sub(&_p, left._poly, 2045 2168 (<MPolynomial_libsingular>right)._poly, 2046 2169 _ring) 2047 return new_MP((<MPolynomial Ring_libsingular>left._parent), _p)2170 return new_MP((<MPolynomial_libsingular>left)._parent, _p) 2048 2171 2049 2172 cpdef ModuleElement _rmul_(self, RingElement left): 2050 2173 """ … … 2057 2180 3/2*x 2058 2181 """ 2059 2182 2060 cdef ring *_ring = (<MPolynomial Ring_libsingular>self._parent)._ring2183 cdef ring *_ring = (<MPolynomial_libsingular>self)._parent_ring 2061 2184 if not left: 2062 return (<MPolynomial Ring_libsingular>self._parent)._zero_element2185 return (<MPolynomial_libsingular>self)._parent._zero_element 2063 2186 cdef poly *_p 2064 2187 singular_polynomial_rmul(&_p, self._poly, left, _ring) 2065 return new_MP((<MPolynomial Ring_libsingular>self._parent),_p)2188 return new_MP((<MPolynomial_libsingular>self)._parent, _p) 2066 2189 2067 2190 cpdef ModuleElement _lmul_(self, RingElement right): 2068 2191 # all currently implemented rings are commutative 2069 2192 return self._rmul_(right) 2070 2193 2071 cpdef RingElement 2194 cpdef RingElement _mul_(left, RingElement right): 2072 2195 """ 2073 2196 Multiply left and right. 2074 2197 … … 2088 2211 cdef poly *_p 2089 2212 singular_polynomial_mul(&_p, left._poly, 2090 2213 (<MPolynomial_libsingular>right)._poly, 2091 (<MPolynomial Ring_libsingular>left._parent)._ring)2092 return new_MP((<MPolynomial Ring_libsingular>left._parent),_p)2093 2094 cpdef RingElement _div_(left, RingElement right ):2214 (<MPolynomial_libsingular>left)._parent_ring) 2215 return new_MP((<MPolynomial_libsingular>left)._parent,_p) 2216 2217 cpdef RingElement _div_(left, RingElement right_ringelement): 2095 2218 """ 2096 2219 Divide left by right 2097 2220 … … 2153 2276 ... 2154 2277 ZeroDivisionError: rational division by zero 2155 2278 """ 2156 cdef poly *p 2279 cdef poly *p 2280 cdef MPolynomial_libsingular right = <MPolynomial_libsingular>right_ringelement 2157 2281 cdef bint is_field = left._parent._base.is_field() 2158 if p_IsConstant( (<MPolynomial_libsingular>right)._poly, (<MPolynomialRing_libsingular>right._parent)._ring):2282 if p_IsConstant(right._poly, right._parent_ring): 2159 2283 if is_field: 2160 singular_polynomial_div_coeff(&p, left._poly, (<MPolynomial_libsingular>right)._poly, (<MPolynomialRing_libsingular>right._parent)._ring)2284 singular_polynomial_div_coeff(&p, left._poly, right._poly, right._parent_ring) 2161 2285 return new_MP(left._parent, p) 2162 2286 else: 2163 return left.change_ring(left.base_ring().fraction_field())/right 2287 return left.change_ring(left.base_ring().fraction_field())/right_ringelement 2164 2288 else: 2165 return ( <MPolynomialRing_libsingular>left._parent).fraction_field()(left,right)2289 return (left._parent).fraction_field()(left,right_ringelement) 2166 2290 2167 2291 def __pow__(MPolynomial_libsingular self, exp, ignored): 2168 2292 """ … … 2207 2331 if exp < 0: 2208 2332 return 1/(self**(-exp)) 2209 2333 elif exp == 0: 2210 return (<MPolynomialRing_libsingular>self._parent)._one_element2211 2212 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring2334 return self._parent._one_element 2335 2336 cdef ring *_ring = self._parent_ring 2213 2337 cdef poly *_p 2214 2338 singular_polynomial_pow(&_p, self._poly, exp, _ring) 2215 return new_MP( (<MPolynomialRing_libsingular>self._parent),_p)2339 return new_MP(self._parent, _p) 2216 2340 2217 2341 def __neg__(self): 2218 2342 """ … … 2225 2349 sage: -f 2226 2350 -x^3 - y 2227 2351 """ 2228 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring2352 cdef ring *_ring = self._parent_ring 2229 2353 2230 2354 cdef poly *p 2231 2355 singular_polynomial_neg(&p, self._poly, _ring) 2232 return new_MP( (<MPolynomialRing_libsingular>self._parent), p)2356 return new_MP(self._parent, p) 2233 2357 2234 2358 def _repr_(self): 2235 2359 """ … … 2240 2364 sage: f # indirect doctest 2241 2365 x^3 + y 2242 2366 """ 2243 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring2367 cdef ring *_ring = self._parent_ring 2244 2368 s = singular_polynomial_str(self._poly, _ring) 2245 2369 return s 2246 2370 … … 2256 2380 sage: f._repr_short_() 2257 2381 'x3+y' 2258 2382 """ 2259 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring2383 cdef ring *_ring = self._parent_ring 2260 2384 rChangeCurrRing(_ring) 2261 2385 if _ring.CanShortOut: 2262 2386 _ring.ShortOut = 1 … … 2277 2401 sage: latex(f) 2278 2402 - x^{2} y - \frac{25}{27} y^{3} - z^{2} 2279 2403 """ 2280 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring2404 cdef ring *_ring = self._parent_ring 2281 2405 gens = self.parent().latex_variable_names() 2282 2406 base = self.parent().base() 2283 2407 return singular_polynomial_latex(self._poly, _ring, base, gens) … … 2294 2418 sage: print f._repr_with_changed_varnames(['FOO', 'BAR', 'FOOBAR']) 2295 2419 -FOO^2*BAR - 25/27*BAR^3 - FOOBAR^2 2296 2420 """ 2297 return singular_polynomial_str_with_changed_varnames(self._poly, (<MPolynomialRing_libsingular>self._parent)._ring, varnames)2421 return singular_polynomial_str_with_changed_varnames(self._poly, self._parent_ring, varnames) 2298 2422 2299 2423 def degree(self, MPolynomial_libsingular x=None): 2300 2424 """ … … 2333 2457 0 2334 2458 2335 2459 """ 2336 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring2460 cdef ring *r = self._parent_ring 2337 2461 cdef poly *p = self._poly 2338 2462 if not x: 2339 2463 return singular_polynomial_deg(p,NULL,r) … … 2342 2466 if not x in self._parent.gens(): 2343 2467 raise TypeError("x must be one of the generators of the parent.") 2344 2468 2345 return singular_polynomial_deg(p, (<MPolynomial_libsingular>x)._poly, r)2469 return singular_polynomial_deg(p, x._poly, r) 2346 2470 2347 2471 def total_degree(self): 2348 2472 """ … … 2380 2504 0 2381 2505 """ 2382 2506 cdef poly *p = self._poly 2383 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring2384 return singular_polynomial_deg(p, NULL,r)2507 cdef ring *r = self._parent_ring 2508 return singular_polynomial_deg(p, NULL, r) 2385 2509 2386 2510 def degrees(self): 2387 2511 """ … … 2400 2524 (5, 2, 1) 2401 2525 """ 2402 2526 cdef poly *p = self._poly 2403 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring2527 cdef ring *r = self._parent_ring 2404 2528 cdef int i 2405 2529 cdef list d = [0 for _ in range(r.N)] 2406 2530 while p: … … 2472 2596 """ 2473 2597 cdef poly *_degrees = <poly*>0 2474 2598 cdef poly *p = self._poly 2475 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring2599 cdef ring *r = self._parent_ring 2476 2600 cdef poly *newp = p_ISet(0,r) 2477 2601 cdef poly *newptemp 2478 2602 cdef int i … … 2482 2606 for i from 0<=i<gens: 2483 2607 exps[i] = -1 2484 2608 2485 if PY_TYPE_CHECK(degrees, MPolynomial_libsingular) and self._parent is (<MPolynomial_libsingular>degrees)._parent: 2609 if isinstance(degrees, MPolynomial_libsingular) \ 2610 and self._parent is (<MPolynomial_libsingular>degrees)._parent: 2486 2611 _degrees = (<MPolynomial_libsingular>degrees)._poly 2487 2612 if pLength(_degrees) != 1: 2488 2613 raise TypeError, "degrees must be a monomial" 2489 2614 for i from 0<=i<gens: 2490 2615 if p_GetExp(_degrees,i+1,r)!=0: 2491 2616 exps[i] = p_GetExp(_degrees,i+1,r) 2492 elif type(degrees) is list:2617 elif isinstance(degrees, list): 2493 2618 for i from 0<=i<gens: 2494 2619 if degrees[i] is None: 2495 2620 exps[i] = -1 2496 2621 else: 2497 2622 exps[i] = int(degrees[i]) 2498 elif type(degrees) is dict:2623 elif isinstance(degrees, dict): 2499 2624 # Extract the ordered list of degree specifications from the dictionary 2500 2625 poly_vars = self.parent().gens() 2501 2626 for i from 0<=i<gens: … … 2524 2649 p = pNext(p) 2525 2650 2526 2651 sage_free(exps) 2527 2528 return new_MP(self.parent(),newp) 2652 return new_MP(self._parent, newp) 2529 2653 2530 2654 def monomial_coefficient(self, MPolynomial_libsingular mon): 2531 2655 """ … … 2570 2694 """ 2571 2695 cdef poly *p = self._poly 2572 2696 cdef poly *m = mon._poly 2573 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring2697 cdef ring *r = self._parent_ring 2574 2698 2575 2699 if not mon._parent is self._parent: 2576 2700 raise TypeError("mon must have same parent as self.") 2577 2701 2578 2702 while(p): 2579 2703 if p_ExpVectorEqual(p, m, r) == 1: 2580 return si2sa(p_GetCoeff(p, r), r, (<MPolynomialRing_libsingular>self._parent)._base)2704 return si2sa(p_GetCoeff(p, r), r, self._parent._base) 2581 2705 p = pNext(p) 2582 2706 2583 return (<MPolynomialRing_libsingular>self._parent)._base._zero_element2707 return self._parent._base._zero_element 2584 2708 2585 2709 def dict(self): 2586 2710 """ … … 2596 2720 {(1, 3, 2): 2, (0, 0, 0): 2/3, (2, 0, 0): 1/7} 2597 2721 """ 2598 2722 cdef poly *p 2599 cdef ring *r 2723 cdef ring *r = self._parent_ring 2600 2724 cdef int n 2601 2725 cdef int v 2602 r = (<MPolynomialRing_libsingular>self._parent)._ring2603 2726 if r!=currRing: rChangeCurrRing(r) 2604 base = (<MPolynomialRing_libsingular>self._parent)._base2727 base = self._parent._base 2605 2728 p = self._poly 2606 2729 pd = dict() 2607 2730 while p: … … 2620 2743 """ 2621 2744 See ``self.__hash__`` 2622 2745 """ 2623 cdef poly *p 2624 cdef ring *r 2746 cdef poly *p = self._poly 2747 cdef ring *r = self._parent_ring 2625 2748 cdef int n 2626 2749 cdef int v 2627 r = (<MPolynomialRing_libsingular>self._parent)._ring2628 2750 if r!=currRing: rChangeCurrRing(r) 2629 base = (<MPolynomialRing_libsingular>self._parent)._base 2630 p = self._poly 2751 base = self._parent._base 2631 2752 cdef long result = 0 # store it in a c-int and just let the overflowing additions wrap 2632 2753 cdef long result_mon 2633 2754 var_name_hash = [hash(vn) for vn in self._parent.variable_names()] … … 2679 2800 """ 2680 2801 cdef poly *m 2681 2802 cdef poly *p = self._poly 2682 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring2803 cdef ring *r = self._parent_ring 2683 2804 cdef int i 2684 2805 2685 if PY_TYPE_CHECK(x, MPolynomial_libsingular):2806 if isinstance(x, MPolynomial_libsingular): 2686 2807 return self.monomial_coefficient(x) 2687 if not PY_TYPE_CHECK(x, tuple):2808 if not isinstance(x, tuple): 2688 2809 try: 2689 2810 x = tuple(x) 2690 2811 except TypeError: 2691 2812 x = (x,) 2692 2813 2693 if len(x) != (<MPolynomialRing_libsingular>self._parent).__ngens:2814 if len(x) != self._parent.ngens(): 2694 2815 raise TypeError, "x must have length self.ngens()" 2695 2816 2696 2817 m = p_ISet(1,r) … … 2704 2825 while(p): 2705 2826 if p_ExpVectorEqual(p, m, r) == 1: 2706 2827 p_Delete(&m,r) 2707 return si2sa(p_GetCoeff(p, r), r, (<MPolynomialRing_libsingular>self._parent)._base)2828 return si2sa(p_GetCoeff(p, r), r, self._parent._base) 2708 2829 p = pNext(p) 2709 2830 2710 2831 p_Delete(&m,r) 2711 return (<MPolynomialRing_libsingular>self._parent)._base._zero_element2832 return self._parent._base._zero_element 2712 2833 2713 2834 def exponents(self, as_ETuples=True): 2714 2835 """ … … 2730 2851 sage: f.exponents(as_ETuples=False) 2731 2852 [(3, 0, 0), (0, 2, 0), (0, 1, 0)] 2732 2853 """ 2733 cdef poly *p 2734 cdef ring *r 2854 cdef poly *p = self._poly 2855 cdef ring *r = self._parent_ring 2735 2856 cdef int v 2736 2857 cdef list pl, ml 2737 2858 2738 r = (<MPolynomialRing_libsingular>self._parent)._ring2739 p = self._poly2740 2741 2859 pl = list() 2742 2860 ml = range(r.N) 2743 2861 while p: … … 2779 2897 """ 2780 2898 cdef bint is_field = self._parent._base.is_field() 2781 2899 if is_field: 2782 return bool(p_IsUnit(self._poly, (<MPolynomialRing_libsingular>self._parent)._ring))2900 return bool(p_IsUnit(self._poly, self._parent_ring)) 2783 2901 else: 2784 return bool(p_IsConstant(self._poly, (<MPolynomialRing_libsingular>self._parent)._ring) and self.constant_coefficient().is_unit())2902 return bool(p_IsConstant(self._poly, self._parent_ring) and self.constant_coefficient().is_unit()) 2785 2903 2786 2904 def inverse_of_unit(self): 2787 2905 """ … … 2798 2916 sage: R(1/2).inverse_of_unit() 2799 2917 2 2800 2918 """ 2801 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring2919 cdef ring *_ring = self._parent_ring 2802 2920 if(_ring != currRing): rChangeCurrRing(_ring) 2803 2921 2804 2922 if not p_IsUnit(self._poly, _ring): … … 2826 2944 sage: (x^2*y + y^2*x).is_homogeneous() 2827 2945 True 2828 2946 """ 2829 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring2947 cdef ring *_ring = self._parent_ring 2830 2948 if(_ring != currRing): rChangeCurrRing(_ring) 2831 2949 return bool(pIsHomogeneous(self._poly)) 2832 2950 … … 2857 2975 2858 2976 SEE: ``self.homogenize`` 2859 2977 """ 2860 cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent2978 cdef MPolynomialRing_libsingular parent = self._parent 2861 2979 cdef MPolynomial_libsingular f 2862 2980 2863 2981 if self.is_homogeneous(): 2864 2982 return self 2865 2983 2866 2984 if var < parent._ring.N: 2867 return new_MP(parent, pHomogen(p_Copy(self._poly, parent._ring), var+1))2985 return new_MP(parent, pHomogen(p_Copy(self._poly, self._parent_ring), var+1)) 2868 2986 else: 2869 2987 raise TypeError, "var must be < self.parent().ngens()" 2870 2988 … … 2888 3006 cdef poly *_p 2889 3007 cdef ring *_ring 2890 3008 cdef number *_n 2891 _ring = (<MPolynomialRing_libsingular>self._parent)._ring3009 _ring = self._parent_ring 2892 3010 2893 3011 if self._poly == NULL: 2894 3012 return True … … 2980 3098 """ 2981 3099 cdef int mi, i, need_map, try_symbolic 2982 3100 2983 cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent3101 cdef MPolynomialRing_libsingular parent = self._parent 2984 3102 cdef ring *_ring = parent._ring 2985 3103 2986 3104 if(_ring != currRing): rChangeCurrRing(_ring) … … 2996 3114 2997 3115 if fixed is not None: 2998 3116 for m,v in fixed.iteritems(): 2999 if PY_TYPE_CHECK(m,int) or PY_TYPE_CHECK(m,Integer):3117 if isinstance(m, (int, Integer)): 3000 3118 mi = m+1 3001 elif PY_TYPE_CHECK(m,MPolynomial_libsingular) and <MPolynomialRing_libsingular>m.parent() is parent:3119 elif isinstance(m,MPolynomial_libsingular) and m.parent() is parent: 3002 3120 for i from 0 < i <= _ring.N: 3003 3121 if p_GetExp((<MPolynomial_libsingular>m)._poly, i, _ring) != 0: 3004 3122 mi = i … … 3073 3191 3074 3192 if fixed is not None: 3075 3193 for m,v in fixed.iteritems(): 3076 if PY_TYPE_CHECK(m,int) or PY_TYPE_CHECK(m,Integer):3194 if isinstance(m, (int, Integer)): 3077 3195 mi = m+1 3078 elif PY_TYPE_CHECK(m,MPolynomial_libsingular) and <MPolynomialRing_libsingular>m.parent() is parent:3196 elif isinstance(m, MPolynomial_libsingular) and m.parent() is parent: 3079 3197 for i from 0 < i <= _ring.N: 3080 3198 if p_GetExp((<MPolynomial_libsingular>m)._poly, i, _ring) != 0: 3081 3199 mi = i … … 3141 3259 [x] 3142 3260 """ 3143 3261 l = list() 3144 cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent3262 cdef MPolynomialRing_libsingular parent = self._parent 3145 3263 cdef ring *_ring = parent._ring 3146 3264 if(_ring != currRing): rChangeCurrRing(_ring) 3147 3265 cdef poly *p = p_Copy(self._poly, _ring) … … 3176 3294 0 3177 3295 """ 3178 3296 cdef poly *p = self._poly 3179 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring3297 cdef ring *r = self._parent_ring 3180 3298 if p == NULL: 3181 return (<MPolynomialRing_libsingular>self._parent)._base._zero_element3299 return self._parent._base._zero_element 3182 3300 3183 3301 while p.next: 3184 3302 p = pNext(p) 3185 3303 3186 3304 if p_LmIsConstant(p, r): 3187 return si2sa( p_GetCoeff(p, r), r, (<MPolynomialRing_libsingular>self._parent)._base)3305 return si2sa(p_GetCoeff(p, r), r, self._parent._base) 3188 3306 else: 3189 return (<MPolynomialRing_libsingular>self._parent)._base._zero_element3307 return self._parent._base._zero_element 3190 3308 3191 3309 def univariate_polynomial(self, R=None): 3192 3310 """ … … 3227 3345 Univariate Polynomial Ring in x over Rational Field 3228 3346 """ 3229 3347 cdef poly *p = self._poly 3230 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring3348 cdef ring *r = self._parent_ring 3231 3349 k = self.base_ring() 3232 3350 3233 3351 if not self.is_univariate(): … … 3288 3406 3289 3407 """ 3290 3408 cdef poly *p 3291 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring3409 cdef ring *r = self._parent_ring 3292 3410 cdef int i 3293 3411 s = set() 3294 3412 p = self._poly … … 3314 3432 (x, z) 3315 3433 """ 3316 3434 cdef poly *p, *v 3317 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring3435 cdef ring *r = self._parent_ring 3318 3436 if(r != currRing): rChangeCurrRing(r) 3319 3437 cdef int i 3320 3438 l = list() … … 3376 3494 sage: P(1).is_constant() 3377 3495 True 3378 3496 """ 3379 return bool(p_IsConstant(self._poly, (<MPolynomialRing_libsingular>self._parent)._ring))3497 return bool(p_IsConstant(self._poly, self._parent_ring)) 3380 3498 3381 3499 def lm(MPolynomial_libsingular self): 3382 3500 """ … … 3412 3530 3413 3531 """ 3414 3532 cdef poly *_p 3415 cdef ring *_ring 3416 _ring = (<MPolynomialRing_libsingular>self._parent)._ring 3533 cdef ring *_ring = self._parent_ring 3417 3534 if self._poly == NULL: 3418 return (<MPolynomialRing_libsingular>self._parent)._zero_element3535 return self._parent._zero_element 3419 3536 _p = p_Head(self._poly, _ring) 3420 3537 p_SetCoeff(_p, n_Init(1,_ring), _ring) 3421 3538 p_Setm(_p,_ring) 3422 return new_MP( (<MPolynomialRing_libsingular>self._parent), _p)3539 return new_MP(self._parent, _p) 3423 3540 3424 3541 def lc(MPolynomial_libsingular self): 3425 3542 """ … … 3439 3556 """ 3440 3557 3441 3558 cdef poly *_p 3442 cdef ring *_ring 3559 cdef ring *_ring = self._parent_ring 3443 3560 cdef number *_n 3444 _ring = (<MPolynomialRing_libsingular>self._parent)._ring3445 3561 3446 3562 if self._poly == NULL: 3447 return (<MPolynomialRing_libsingular>self._parent)._base._zero_element3563 return self._parent._base._zero_element 3448 3564 3449 3565 if(_ring != currRing): rChangeCurrRing(_ring) 3450 3566 3451 3567 _p = p_Head(self._poly, _ring) 3452 3568 _n = p_GetCoeff(_p, _ring) 3453 3569 3454 ret = si2sa(_n, _ring, (<MPolynomialRing_libsingular>self._parent)._base)3570 ret = si2sa(_n, _ring, self._parent._base) 3455 3571 p_Delete(&_p, _ring) 3456 3572 return ret 3457 3573 … … 3472 3588 -2*x^3*y^2*z^4 3473 3589 """ 3474 3590 if self._poly == NULL: 3475 return (<MPolynomialRing_libsingular>self._parent)._zero_element 3476 3477 return new_MP((<MPolynomialRing_libsingular>self._parent), 3478 p_Head(self._poly,(<MPolynomialRing_libsingular>self._parent)._ring)) 3591 return self._parent._zero_element 3592 return new_MP(self._parent, p_Head(self._poly, self._parent_ring)) 3479 3593 3480 3594 def is_zero(self): 3481 3595 """ … … 3509 3623 else: 3510 3624 return False 3511 3625 3512 def __floordiv__( self, right):3626 def __floordiv__(MPolynomial_libsingular self, right): 3513 3627 """ 3514 3628 Perform division with remainder and return the quotient. 3515 3629 … … 3547 3661 ... 3548 3662 NotImplementedError: Division of multivariate polynomials over non fields by non-monomials not implemented. 3549 3663 """ 3550 cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>(<MPolynomial_libsingular>self)._parent3551 cdef ring *r = parent._ring3664 cdef MPolynomialRing_libsingular parent = self._parent 3665 cdef ring *r = self._parent_ring 3552 3666 if(r != currRing): rChangeCurrRing(r) 3553 3667 cdef MPolynomial_libsingular _self, _right 3554 3668 cdef poly *quo, *temp, *p 3555 3669 3556 3670 _self = self 3557 3671 3558 if not PY_TYPE_CHECK(right, MPolynomial_libsingular) or (<ParentWithBase>parent is not (<MPolynomial_libsingular>right)._parent): 3672 if not isinstance(right, MPolynomial_libsingular) \ 3673 or (parent is not (<MPolynomial_libsingular>right)._parent): 3559 3674 _right = parent._coerce_c(right) 3560 3675 else: 3561 3676 _right = right … … 3563 3678 if right.is_zero(): 3564 3679 raise ZeroDivisionError 3565 3680 3566 if (<MPolynomial_libsingular>self)._parent._base.is_finite() and (<MPolynomial_libsingular>self)._parent._base.characteristic() > 1<<29:3681 if self._parent._base.is_finite() and self._parent._base.characteristic() > 1<<29: 3567 3682 raise NotImplementedError, "Division of multivariate polynomials over prime fields with characteristic > 2^29 is not implemented." 3568 3683 3569 3684 if r.ringtype != 0: … … 3712 3827 ... 3713 3828 NotImplementedError: proof = True factorization not implemented. Call factor with proof=False. 3714 3829 """ 3715 cdef ring *_ring 3830 cdef ring *_ring = self._parent_ring 3716 3831 cdef poly *ptemp 3717 3832 cdef intvec *iv 3718 3833 cdef int *ivv 3719 3834 cdef ideal *I 3720 cdef MPolynomialRing_libsingular parent 3835 cdef MPolynomialRing_libsingular parent = self._parent 3721 3836 cdef int i 3722 3837 3723 parent = self._parent3724 _ring = parent._ring3725 3726 3838 if proof is None: 3727 3839 from sage.structure.proof.proof import get_flag 3728 3840 proof = get_flag(proof, "polynomial") … … 3785 3897 3786 3898 cdef ideal *fI = idInit(1,1) 3787 3899 cdef ideal *_I 3788 cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent3900 cdef MPolynomialRing_libsingular parent = self._parent 3789 3901 cdef int i = 0 3790 3902 cdef int j 3791 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring3903 cdef ring *r = self._parent_ring 3792 3904 cdef ideal *res 3793 3905 3794 3906 if PY_TYPE_CHECK(I, MPolynomialIdeal): … … 3797 3909 _I = idInit(len(I),1) 3798 3910 3799 3911 for f in I: 3800 if not ( PY_TYPE_CHECK(f,MPolynomial_libsingular) \3801 and <MPolynomialRing_libsingular>(<MPolynomial_libsingular>f)._parent is parent):3912 if not (isinstance(f,MPolynomial_libsingular) \ 3913 and (<MPolynomial_libsingular>f)._parent is parent): 3802 3914 try: 3803 3915 f = parent._coerce_c(f) 3804 3916 except TypeError, msg: … … 3869 3981 3*x 3870 3982 """ 3871 3983 cdef ideal *_I 3872 cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent3984 cdef MPolynomialRing_libsingular parent = self._parent 3873 3985 cdef int i = 0 3874 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring3986 cdef ring *r = self._parent_ring 3875 3987 cdef poly *res 3876 3988 3877 3989 if(r != currRing): rChangeCurrRing(r) … … 3886 3998 3887 3999 _I = idInit(len(I),1) 3888 4000 for f in I: 3889 if not ( PY_TYPE_CHECK(f,MPolynomial_libsingular) \3890 and <MPolynomialRing_libsingular>(<MPolynomial_libsingular>f)._parent is parent):4001 if not (isinstance(f,MPolynomial_libsingular) \ 4002 and (<MPolynomial_libsingular>f)._parent is parent): 3891 4003 try: 3892 4004 f = parent._coerce_c(f) 3893 4005 except TypeError, msg: … … 3972 4084 """ 3973 4085 cdef MPolynomial_libsingular _right 3974 4086 cdef poly *_res 3975 cdef ring *_ring 4087 cdef ring *_ring = self._parent_ring 3976 4088 3977 4089 if algorithm is None: 3978 4090 algorithm = "modular" … … 3986 4098 else: 3987 4099 raise TypeError, "algorithm %s not supported"%(algorithm) 3988 4100 3989 _ring = (<MPolynomialRing_libsingular>self._parent)._ring3990 3991 3992 3993 4101 if _ring.ringtype != 0: 3994 4102 if _ring.ringtype == 4: 3995 4103 P = self._parent.change_ring(RationalField()) … … 4004 4112 4005 4113 if(_ring != currRing): rChangeCurrRing(_ring) 4006 4114 4007 if not (PY_TYPE_CHECK(right, MPolynomial_libsingular) and (<MPolynomial_libsingular>right)._parent is (<MPolynomial_libsingular>self)._parent): 4008 _right = (<MPolynomialRing_libsingular>self._parent)._coerce_c(right) 4115 if not (isinstance(right, MPolynomial_libsingular) \ 4116 and (<MPolynomial_libsingular>right)._parent is self._parent): 4117 _right = self._parent._coerce_c(right) 4009 4118 else: 4010 _right = (<MPolynomial_libsingular>right) 4011 4012 cdef int count = singular_polynomial_length_bounded(self._poly,20)+singular_polynomial_length_bounded(_right._poly,20) 4119 _right = <MPolynomial_libsingular>right 4120 4121 cdef int count = singular_polynomial_length_bounded(self._poly,20) \ 4122 + singular_polynomial_length_bounded(_right._poly,20) 4013 4123 if count >= 20: 4014 4124 sig_on() 4015 4125 _res = singclap_gcd(p_Copy(self._poly, _ring), p_Copy(_right._poly, _ring)) 4016 4126 if count >= 20: 4017 4127 sig_off() 4018 4128 4019 res = new_MP( (<MPolynomialRing_libsingular>self._parent), _res)4129 res = new_MP(self._parent, _res) 4020 4130 return res 4021 4131 4022 4132 @coerce_binop … … 4045 4155 sage: lcm(p,q) 4046 4156 6*x*y*z^4 + 6*y^2*z^4 + 6*x*z^5 + 6*y*z^5 + 12*x*y + 12*y^2 + 12*x*z + 12*y*z 4047 4157 """ 4048 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring4158 cdef ring *_ring = self._parent_ring 4049 4159 cdef poly *ret, *prod, *gcd 4050 4160 cdef MPolynomial_libsingular _g 4051 4161 if(_ring != currRing): rChangeCurrRing(_ring) … … 4061 4171 raise TypeError("LCM over non-integral domains not available.") 4062 4172 4063 4173 if self._parent is not g._parent: 4064 _g = (<MPolynomialRing_libsingular>self._parent)._coerce_c(g)4174 _g = self._parent._coerce_c(g) 4065 4175 else: 4066 4176 _g = <MPolynomial_libsingular>g 4067 4177 4068 4178 if self._parent._base.is_finite() and self._parent._base.characteristic() > 1<<29: 4069 4179 raise NotImplementedError, "LCM of multivariate polynomials over prime fields with characteristic > 2^29 is not implemented." 4070 4180 4071 cdef int count = singular_polynomial_length_bounded(self._poly,20)+singular_polynomial_length_bounded(_g._poly,20) 4181 cdef int count = singular_polynomial_length_bounded(self._poly,20) \ 4182 + singular_polynomial_length_bounded(_g._poly,20) 4072 4183 if count >= 20: 4073 4184 sig_on() 4074 4185 gcd = singclap_gcd(p_Copy(self._poly, _ring), p_Copy(_g._poly, _ring)) … … 4094 4205 sage: h.is_squarefree() 4095 4206 False 4096 4207 """ 4097 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring4208 cdef ring *_ring = self._parent_ring 4098 4209 if(_ring != currRing): rChangeCurrRing(_ring) 4099 4210 4100 4211 if self._parent._base.is_finite() and self._parent._base.characteristic() > 1<<29: … … 4137 4248 4138 4249 """ 4139 4250 cdef poly *quo, *rem 4140 cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent4141 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring4251 cdef MPolynomialRing_libsingular parent = self._parent 4252 cdef ring *r = self._parent_ring 4142 4253 if(r != currRing): rChangeCurrRing(r) 4143 4254 4144 4255 if right.is_zero(): … … 4214 4325 sage: x.sub_m_mul_q(Q.gen(1),Q.gen(2)) 4215 4326 -y*z + x 4216 4327 """ 4217 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring4328 cdef ring *r = self._parent_ring 4218 4329 4219 4330 if not self._parent is m._parent: 4220 4331 m = self._parent._coerce_c(m) … … 4293 4404 sage: x.add_m_mul_q(R.gen(),R.gen(1)) 4294 4405 x*y + x 4295 4406 """ 4296 cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring4407 cdef ring *r = self._parent_ring 4297 4408 4298 4409 if not self._parent is m._parent: 4299 4410 m = self._parent._coerce_c(m) … … 4402 4513 cdef poly *p 4403 4514 if var._parent is not self._parent: 4404 4515 raise TypeError, "provided variable is not in same ring as self" 4405 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring4516 cdef ring *_ring = self._parent_ring 4406 4517 if _ring != currRing: 4407 4518 rChangeCurrRing(_ring) 4408 4519 … … 4478 4589 sage: f.resultant(g,y) 4479 4590 x^2 + x 4480 4591 """ 4481 cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring4592 cdef ring *_ring = self._parent_ring 4482 4593 cdef poly *rt 4483 4594 4484 4595 if variable is None: … … 4501 4612 elif not self._parent._base.is_field(): 4502 4613 raise ValueError("Resultants require base fields or integer base ring.") 4503 4614 4504 cdef int count = singular_polynomial_length_bounded(self._poly,20)+singular_polynomial_length_bounded(other._poly,20) 4615 cdef int count = singular_polynomial_length_bounded(self._poly,20) \ 4616 + singular_polynomial_length_bounded(other._poly,20) 4505 4617 if count >= 20: 4506 4618 sig_on() 4507 rt = singclap_resultant(self._poly, other._poly, (<MPolynomial_libsingular>variable)._poly )4619 rt = singclap_resultant(self._poly, other._poly, (<MPolynomial_libsingular>variable)._poly ) 4508 4620 if count >= 20: 4509 4621 sig_off() 4510 4622 return new_MP(self._parent, rt) … … 4560 4672 if r == 0 or r == 1: 4561 4673 u = 1 4562 4674 an = self.coefficient(variable**n)**(n - k - 2) 4563 return self.parent()(u * self.resultant(d, variable) * an)4675 return self.parent()(u * self.resultant(d, variable) * an) 4564 4676 4565 4677 def coefficients(self): 4566 4678 """ … … 4585 4697 - Didier Deshommes 4586 4698 """ 4587 4699 cdef poly *p 4588 cdef ring *r 4589 r = (<MPolynomialRing_libsingular>self._parent)._ring 4700 cdef ring *r = self._parent_ring 4590 4701 if r!=currRing: rChangeCurrRing(r) 4591 base = (<MPolynomialRing_libsingular>self._parent)._base4702 base = self._parent._base 4592 4703 p = self._poly 4593 4704 coeffs = list() 4594 4705 while p: … … 4608 4719 sage: f.gradient() 4609 4720 [y, x, 0] 4610 4721 """ 4611 cdef ring *r 4722 cdef ring *r = self._parent_ring 4612 4723 cdef int k 4613 4724 4614 r = (<MPolynomialRing_libsingular>self._parent)._ring4615 4725 if r!=currRing: rChangeCurrRing(r) 4616 4726 i = [] 4617 4727 for k from 0 < k <= r.N: 4618 4728 i.append( new_MP(self._parent, pDiff(self._poly, k))) 4619 4620 4729 return i 4621 4730 4622 4731 … … 4628 4737 numerator is a polynomial whose base_ring is the Integer Ring, 4629 4738 this is done for compatibility to the univariate case. 4630 4739 4631 .. warning::4632 4633 This is not the numerator of the rational function4634 defined by self, which would always be self since self is a4635 polynomial.4636 4637 EXAMPLES:4638 4639 First we compute the numerator of a polynomial with4640 integer coefficients, which is of course self.4641 4642 ::4643 4644 sage: R.<x, y> = ZZ[]4645 sage: f = x^3 + 17*y + 14646 sage: f.numerator()4647 x^3 + 17*y + 14648 sage: f == f.numerator()4649 True4650 4651 Next we compute the numerator of a polynomial with rational4652 coefficients.4653 4654 ::4655 4656 sage: R.<x,y> = PolynomialRing(QQ)4657 sage: f = (1/17)*x^19 - (2/3)*y + 1/3; f4658 1/17*x^19 - 2/3*y + 1/34659 sage: f.numerator()4660 3*x^19 - 34*y + 174661 sage: f == f.numerator()4662 False4663 sage: f.numerator().base_ring()4664 Integer Ring4665 4666 We check that the computation the numerator and denominator4667 are valid4668 4669 ::4670 4671 sage: K=QQ['x,y']4672 sage: f=K.random_element()4673 sage: f.numerator() / f.denominator() == f4674 True4740 .. warning:: 4741 4742 This is not the numerator of the rational function 4743 defined by self, which would always be self since self is a 4744 polynomial. 4745 4746 EXAMPLES: 4747 4748 First we compute the numerator of a polynomial with 4749 integer coefficients, which is of course self. 4750 4751 :: 4752 4753 sage: R.<x, y> = ZZ[] 4754 sage: f = x^3 + 17*y + 1 4755 sage: f.numerator() 4756 x^3 + 17*y + 1 4757 sage: f == f.numerator() 4758 True 4759 4760 Next we compute the numerator of a polynomial with rational 4761 coefficients. 4762 4763 :: 4764 4765 sage: R.<x,y> = PolynomialRing(QQ) 4766 sage: f = (1/17)*x^19 - (2/3)*y + 1/3; f 4767 1/17*x^19 - 2/3*y + 1/3 4768 sage: f.numerator() 4769 3*x^19 - 34*y + 17 4770 sage: f == f.numerator() 4771 False 4772 sage: f.numerator().base_ring() 4773 Integer Ring 4774 4775 We check that the computation the numerator and denominator 4776 are valid 4777 4778 :: 4779 4780 sage: K=QQ['x,y'] 4781 sage: f=K.random_element() 4782 sage: f.numerator() / f.denominator() == f 4783 True 4675 4784 """ 4676 4785 if self.base_ring() == RationalField(): 4677 4786 #This part is for compatibility with the univariate case, … … 4710 4819 for i,e in mon.sparse_iter(): 4711 4820 _i = i 4712 4821 if _i >= r.N: 4713 p_Delete(&p, r)4714 p_Delete(&m, r)4822 p_Delete(&p, r) 4823 p_Delete(&m, r) 4715 4824 raise TypeError, "variable index too big" 4716 4825 _e = e 4717 4826 if _e <= 0: 4718 p_Delete(&p, r)4719 p_Delete(&m, r)4827 p_Delete(&p, r) 4828 p_Delete(&m, r) 4720 4829 raise TypeError, "exponent too small" 4721 4830 overflow_check(_e) 4722 p_SetExp(m, _i+1, _e, r)4831 p_SetExp(m, _i+1, _e, r) 4723 4832 p_SetCoeff(m, sa2si(c, r), r) 4724 p_Setm(m, r)4725 p = p_Add_q(p, m,r)4726 return new_MP(R, p)4727 4728 4729 cdef poly *addwithcarry(poly *tempvector, poly *maxvector, int pos, ring *_ring):4833 p_Setm(m, r) 4834 p = p_Add_q(p, m, r) 4835 return new_MP(R, p) 4836 4837 4838 cdef inline poly *addwithcarry(poly *tempvector, poly *maxvector, int pos, ring *_ring): 4730 4839 if p_GetExp(tempvector, pos, _ring) < p_GetExp(maxvector, pos, _ring): 4731 4840 p_SetExp(tempvector, pos, p_GetExp(tempvector, pos, _ring)+1, _ring) 4732 4841 else: … … 4735 4844 p_Setm(tempvector, _ring) 4736 4845 return tempvector 4737 4846 4847 4738 4848 cdef inline MPolynomial_libsingular new_MP(MPolynomialRing_libsingular parent, poly *juice): 4739 4849 """ 4740 4850 Construct MPolynomial_libsingular from parent and SINGULAR poly. 4851 4852 INPUT: 4853 4854 - ``parent`` -- a :class:`MPolynomialRing_libsingular`` 4855 instance. The parent of the polynomial to create. 4856 4857 - ``juice`` -- a pointer to a Singular ``poly`` C struct. 4858 4859 OUTPUT: 4860 4861 A Python object :class:`MPolynomial_libsingular`. 4862 4863 The ownership of ``juice`` will be transferred to the Python 4864 object. You must not free it yourself. Singular will modify the 4865 polynomial, so it is your repsonsiblity to make a copy if the 4866 Singular data structure is used elsewhere. 4741 4867 """ 4742 cdef MPolynomial_libsingular p 4743 p = PY_NEW(MPolynomial_libsingular) 4868 cdef MPolynomial_libsingular p = PY_NEW(MPolynomial_libsingular) 4744 4869 p._parent = <ParentWithBase>parent 4870 p._parent_ring = singular_ring_reference(parent._ring) 4745 4871 p._poly = juice 4746 p_Normalize(p._poly, p arent._ring)4872 p_Normalize(p._poly, p._parent_ring) 4747 4873 return p 4748 4874 4749 4875