Ticket #4539: extpluralmore3.patch
File extpluralmore3.patch, 11.9 KB (added by AlexanderDreyer, 5 years ago) 


sage/rings/polynomial/plural.pxd
diff r 02bd6ab343a2 sage/rings/polynomial/plural.pxd
a b 1 1 include "../../libs/singular/singularcdefs.pxi" 2 2 3 3 from sage.rings.ring cimport Ring 4 from sage.structure.element cimport RingElement 4 from sage.structure.element cimport RingElement, Element 5 from sage.structure.parent cimport Parent 5 6 from sage.libs.singular.function cimport RingWrap 6 7 from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomialRing_libsingular 7 8 8 9 9 10 cdef class NCPolynomialRing_plural(Ring): 10 11 cdef object __ngens 12 cdef object _c 13 cdef object _d 11 14 cdef object __term_order 12 15 cdef public object _has_singular 13 16 cdef public object _magma_gens, _magma_cache 17 # cdef _richcmp_c_impl(left, Parent right, int op) 18 cdef int _cmp_c_impl(left, Parent right) except 2 14 19 15 20 cdef ring *_ring 16 21 # cdef NCPolynomial_plural _one_element 
sage/rings/polynomial/plural.pyx
diff r 02bd6ab343a2 sage/rings/polynomial/plural.pyx
a b 33 33 cdef class NCPolynomialRing_plural(Ring): 34 34 def __init__(self, base_ring, n, names, c, d, order='degrevlex', check = True): 35 35 order = TermOrder(order,n) 36 self._relations = None 36 37 n = int(n) 37 38 if n < 0: 38 39 raise ValueError, "Multivariate Polynomial Rings must " + \ … … 42 43 PolynomialRing 43 44 44 45 P = PolynomialRing(base_ring, n, names, order) 45 c = c.change_ring(P)46 d = d.change_ring(P)46 self._c = c.change_ring(P) 47 self._d = d.change_ring(P) 47 48 48 #print "c:",c 49 #print "c.parent()",c.parent() 49 50 #print "c:",self._c 51 #print "c.parent()",self._c.parent() 50 52 #print "type(c):",type(c) 51 #print "d:", d52 #print "d.parent()", d.parent()53 #print "d:",self._d 54 #print "d.parent()",self._d.parent() 53 55 #print "type(d):",type(d) 54 56 55 57 from sage.libs.singular.function import singular_function 56 58 ncalgebra = singular_function('nc_algebra') 57 59 58 cdef RingWrap rw = ncalgebra( c,d, ring = P)60 cdef RingWrap rw = ncalgebra(self._c, self._d, ring = P) 59 61 self._ring = rw._ring 60 62 self._ring.ShortOut = 0 61 63 … … 72 74 self._one_element = new_NCP(self, p_ISet(1, self._ring)) 73 75 self._zero_element = new_NCP(self, NULL) 74 76 75 self._relations = self.relations()76 77 77 78 if check: 78 79 import sage.libs.singular … … 183 184 sage: P(0) 184 185 0 185 186 """ 186 187 187 188 if element == 0: 188 189 return self._zero_element 189 190 if element == 1: … … 198 199 base_ring = self.base_ring() 199 200 200 201 if(_ring != currRing): rChangeCurrRing(_ring) 201 202 203 if PY_TYPE_CHECK(element, NCPolynomial_plural): 204 if element.parent() is <object>self: 205 return element 206 elif element.parent() == self: 207 # is this safe? 208 _p = p_Copy((<NCPolynomial_plural>element)._poly, _ring) 202 209 203 210 if PY_TYPE_CHECK(element, CommutativeRingElement): 204 211 # base ring elements … … 289 296 """ 290 297 return hash(self.__repr__()) 291 298 292 ## def _richcmp_(self, right, int op): 293 ## return (<Parent>self)._richcmp_helper(right, op) 294 299 300 def __cmp__(self, right): 301 r""" 302 Multivariate polynomial rings are said to be equal if: 295 303 296 ## ## cdef int _cmp_c_impl(left, Parent right) except 2: 297 ## ## return 0#cmp(type(left),type(right)) 304  their base rings match, 305  their generator names match, 306  their term orderings match, and 307  their relations match. 298 308 299 ## def __cmp__(self, x):300 ## """301 ## EXAMPLES::302 309 303 ## """ 304 ## if PY_TYPE_CHECK(x, NCPolynomialRing_plural): 305 ## print "huhu" 306 ## return 0 307 ## print "hihi" 308 ## return 0# return cmp(type(self), type(x)) 309 310 ## def __richcmp__(self, right, int op): 311 ## print "CMP" 312 ## print "base", self.base_ring() 313 ## print "gens" 314 ## for elt in self.gens(): 315 ## print elt 316 ## print self.term_order() 317 ## for elt in self.relations(): 318 ## print elt 319 ## print PY_TYPE_CHECK(right, NCPolynomialRing_plural), "huhu" 310 EXAMPLES:: 311 sage: A.<x,y,z> = FreeAlgebra(QQ, 3) 312 sage: P = A.g_algebra(relations={y*x:x*y}, order = 'lex') 320 313 321 ## print "base", right.base_ring() 322 ## print "gens" 323 ## for elt in right.gens(): 324 ## print elt 325 ## print right.term_order() 326 ## for elt in right.relations(): 327 ## print elt 328 ## return False 329 330 ## print cmp(self.base_ring(), right.base_ring()) 331 ## print cmp( map(str, self.gens()), map(str, right.gens())) 332 ## print cmp( map(str, self.relations()), map(str, right.relations())) 314 sage: P == P 315 True 316 sage: Q = A.g_algebra(relations={y*x:x*y}, order = 'lex') 317 sage: Q == P 318 True 319 320 sage: from sage.matrix.constructor import Matrix 321 sage: c = Matrix(3) 322 sage: c[0,1] = 1 323 sage: c[0,2] = 1 324 sage: c[1,2] = 1 325 sage: from sage.rings.polynomial.plural import NCPolynomialRing_plural 326 sage: R.<x,y,z> = NCPolynomialRing_plural(QQ, 3, c = c, d = Matrix(3), order='lex') 327 sage: R == P 328 True 329 330 sage: c[0,1] = 2 331 sage: R.<x,y,z> = NCPolynomialRing_plural(QQ, 3, c = c, d = Matrix(3), order='lex') 332 sage: P == R 333 False 334 """ 333 335 334 ## return False 335 ## if PY_TYPE_CHECK(right, NCPolynomialRing_plural): 336 ## return cmp( (self.base_ring(), map(str, self.gens()), 337 ## self.term_order(), map(str, self.relations())), 338 ## (right.base_ring(), map(str, right.gens()), 339 ## right.term_order(), map(str, right.relations())) 340 ## ) 341 ## else: 342 ## return cmp(type(self),type(right)) 336 if PY_TYPE_CHECK(right, NCPolynomialRing_plural): 343 337 344 ## # return False 345 346 # def __richcmp__(left, right, int op): 347 # return (<ParentWithGens>left)._richcmp(right, op) 348 # return False 349 ## r""" 350 ## Multivariate polynomial rings are said to be equal if: 351 352 ##  their base rings match, 353 ##  their generator names match, 354 ##  their term orderings match, and 355 ##  their relations match. 338 return cmp( (self.base_ring(), map(str, self.gens()), 339 self.term_order(), self._c, self._d), 340 (right.base_ring(), map(str, right.gens()), 341 right.term_order(), 342 (<NCPolynomialRing_plural>right)._c, 343 (<NCPolynomialRing_plural>right)._d) 344 ) 345 else: 346 return cmp(type(self),type(right)) 356 347 357 358 ## EXAMPLES::359 ## sage: A.<x,y,z> = FreeAlgebra(QQ, 3)360 ## sage: P = A.g_algebra(relations={y*x:x*y}, order = 'lex')361 362 ## sage: P == P363 ## True364 ## sage: Q = copy(P)365 ## sage: Q == P366 ## True367 368 ## sage: from sage.matrix.constructor import Matrix369 ## sage: c = Matrix(3)370 ## sage: c[0,1] = 1371 ## sage: c[0,2] = 1372 ## sage: c[1,2] = 1373 ## sage: from sage.rings.polynomial.plural import NCPolynomialRing_plural374 ## sage: R.<x,y,z> = NCPolynomialRing_plural(QQ, 3, c = c, d = Matrix(3), order='lex')375 ## sage: R == P376 ## True377 378 ## sage: c[0,1] = 2379 ## sage: R.<x,y,z> = NCPolynomialRing_plural(QQ, 3, c = c, d = Matrix(3), order='lex')380 ## sage: P == R381 ## False382 ## """383 ### return (<Parent>left)._richcmp(right, op)384 ##return (<ParentWithGens>left)._richcmp(right, op)385 ## cdef int _cmp_c_impl(left, Parent right) except 2:386 ## r"""387 ## Multivariate polynomial rings are said to be equal if:388 389 ##  their base rings match,390 ##  their generator names match,391 ##  their term orderings match, and392 ##  their relations match.393 394 395 ## EXAMPLES::396 ## sage: A.<x,y,z> = FreeAlgebra(QQ, 3)397 ## sage: P = A.g_algebra(relations={y*x:x*y}, order = 'lex')398 399 ## sage: P == P400 ## True401 ## sage: Q = copy(P)402 ## sage: Q == P403 ## True404 405 ## sage: from sage.matrix.constructor import Matrix406 ## sage: c = Matrix(3)407 ## sage: c[0,1] = 1408 ## sage: c[0,2] = 1409 ## sage: c[1,2] = 1410 ## sage: from sage.rings.polynomial.plural import NCPolynomialRing_plural411 ## sage: R.<x,y,z> = NCPolynomialRing_plural(QQ, 3, c = c, d = Matrix(3), order='lex')412 ## sage: R == P413 ## True414 415 ## sage: c[0,1] = 2416 ## sage: R.<x,y,z> = NCPolynomialRing_plural(QQ, 3, c = c, d = Matrix(3), order='lex')417 ## sage: P == R418 ## False419 ## """420 ## print "huhu", PY_TYPE_CHECK(right, NCPolynomialRing_plural)421 ## if PY_TYPE_CHECK(right, NCPolynomialRing_plural):422 ## return True423 ## return cmp( (left.base_ring(), map(str, left.gens()),424 ## left.term_order(), map(str, left.relations())),425 ## (right.base_ring(), map(str, right.gens()),426 ## right.term_order(), map(str, right.relations()))427 ## )428 ## else:429 ## return cmp(type(left),type(right))430 431 432 433 348 def __pow__(self, n, _): 434 349 """ 435 350 Return the free module of rank `n` over this ring. … … 466 381 """ 467 382 #TODO: print the relations 468 383 varstr = ", ".join([ rRingVar(i,self._ring) for i in range(self.__ngens) ]) 469 return "Noncommutative Multivariate Polynomial Ring in %s over %s, ncrelations: %s"%(varstr,self.base_ring(), self._relations)384 return "Noncommutative Multivariate Polynomial Ring in %s over %s, ncrelations: %s"%(varstr,self.base_ring(), self.relations()) 470 385 471 386 472 387 def _ringlist(self): … … 486 401 sage: P # indirect doctest 487 402 Noncommutative Multivariate Polynomial Ring in x, y over Rational Field, ncrelations: ... 488 403 """ 489 #TODO: get the relations 490 L = self._ringlist() 491 492 assert( len(L) == 6 ) 493 494 C = L[4] 495 D = L[5] 404 if self._relations is not None: 405 return self._relations 496 406 497 407 from sage.algebras.free_algebra import FreeAlgebra 498 408 A = FreeAlgebra( self.base_ring(), self.ngens(), self.gens() ) … … 501 411 n = self.ngens() 502 412 for r in range(0, n1, 1): 503 413 for c in range(r+1, n, 1): 504 if ( (C[r, c] * self.gen(r) * self.gen(c) + D[r, c]) != self.gen(r) * self.gen(c)) or add_commutative:505 res[ A.gen(c) * A.gen(r) ] = C[r, c] * self.gen(r) * self.gen(c) + D[r, c]414 if (self.gen(c) * self.gen(r) != self.gen(r) * self.gen(c)) or add_commutative: 415 res[ A.gen(c) * A.gen(r) ] = self.gen(c) * self.gen(r) # C[r, c] * P.gen(r) * P.gen(c) + D[r, c] 506 416 507 return res508 509 417 418 self._relations = res 419 return self._relations 510 420 511 421 def ngens(self): 512 422 """