Ticket #4539: plural_2.patch
| File plural_2.patch, 11.0 KB (added by burcin, 5 years ago) |
|---|
-
sage/algebras/free_algebra.py
# HG changeset patch # User Michael Brickenstein <brickenstein@mfo.de> # Date 1226934659 -3600 # Node ID 0acacd97c7f38f5afdb0c762b421e12b1ee8c3ea # Parent 1611ab2e6f45c6b11ace32518e8d36e8231179ed MPolynomialRing_plural now accepts matrix parameters to specify commutativity relations. Added ExteriorAlgebra. diff --git a/sage/algebras/free_algebra.py b/sage/algebras/free_algebra.py
a b 55 55 56 56 import sage.structure.parent_gens 57 57 58 59 58 def FreeAlgebra(R, n, names): 60 59 """ 61 60 Return the free algebra over the ring $R$ on $n$ generators with … … 394 393 """ 395 394 return self.__monoid 396 395 397 396 def g_algebra(self, relations, order='degrevlex'): 397 """ 398 399 The G-Algebra derrived from this algebra by relations. 400 By default is assumed, that two variables commute. 401 402 TODO: 403 * Coercion doesn't work yet, there is some cheating about assumptions 404 * Check degeneracy conditions 405 Furthermore, the default values interfere with non degeneracy conditions... 406 407 EXAMPLES: 408 sage: A.<x,y,z>=FreeAlgebra(QQ,3) 409 sage: G=A.g_algebra({y*x:-x*y}) 410 sage: (x,y,z)=G.gens() 411 sage: x*y 412 x*y 413 sage: y*x 414 -x*y 415 sage: z*x 416 x*z 417 sage: (x,y,z)=A.gens() 418 sage: G=A.g_algebra({y*x:-x*y+1}) 419 sage: (x,y,z)=G.gens() 420 sage: y*x 421 -x*y + 1 422 sage: (x,y,z)=A.gens() 423 sage: G=A.g_algebra({y*x:-x*y+z}) 424 sage: (x,y,z)=G.gens() 425 sage: y*x 426 -x*y + z 427 """ 428 from sage.matrix.constructor import Matrix 429 from sage.rings.polynomial.plural import MPolynomialRing_plural 430 431 base_ring=self.base_ring() 432 n=self.ngens() 433 cmat=Matrix(base_ring,n) 434 dmat=Matrix(self,n) 435 for i in xrange(n): 436 for j in xrange(i+1,n): 437 cmat[i,j]=1 438 for (to_commute,commuted) in relations.iteritems(): 439 #This is dirty, coercion is broken 440 assert isinstance(to_commute,FreeAlgebraElement), to_commute.__class__ 441 assert isinstance(commuted,FreeAlgebraElement), commuted 442 ((v1,e1),(v2,e2))=list(list(to_commute)[0][1]) 443 assert e1==1 444 assert e2==1 445 assert v1>v2 446 c_coef=None 447 d_poly=None 448 for (c,m) in commuted: 449 if list(m)==[(v2,1),(v1,1)]: 450 c_coef=c 451 #buggy coercion workaround 452 d_poly=commuted-self(c)*self(m) 453 break 454 assert not c_coef is None,list(m) 455 cmat[v2,v1]=c_coef 456 if d_poly: 457 dmat[v2,v1]=d_poly 458 459 return MPolynomialRing_plural(base_ring, n, ",".join([str(g) for g in self.gens()]), c=cmat, d=dmat,order=order) 460 461 398 462 from sage.misc.cache import Cache 399 463 cache = Cache(FreeAlgebra_generic) -
sage/algebras/free_algebra_element.py
diff --git a/sage/algebras/free_algebra_element.py b/sage/algebras/free_algebra_element.py
a b 57 57 self.__monomial_coefficients = dict([ (A.monoid()(e1),R(e2)) for e1,e2 in x.items()]) 58 58 else: 59 59 raise TypeError, "Argument x (= %s) is of the wrong type."%x 60 61 def __iter__(self): 62 """ 63 Returns an iterator which yields tuples of coeficient and monoid. 64 65 EXAMPLES: 66 sage: a = FreeAlgebra(QQ, 5, 'a').gens() 67 sage: list(3*a[0]*a[1]*a[4]**3*a[0]+1) 68 [(1, 1), (3, a0*a1*a4^3*a0)] 69 """ 70 for (key,val) in self.__monomial_coefficients.iteritems(): 71 yield (val,key) 72 60 73 61 74 def _repr_(self): 62 75 """ -
sage/libs/singular/singular-cdefs.pxi
diff --git a/sage/libs/singular/singular-cdefs.pxi b/sage/libs/singular/singular-cdefs.pxi
a b 91 91 napoly *n 92 92 int s 93 93 94 # polynomials 95 96 ctypedef struct poly "polyrec": 97 poly *next 98 99 # ideals 100 101 ctypedef struct ideal "ip_sideal": 102 poly **m # gens array 103 long rank # rank of module, 1 for ideals 104 int nrows # always 1 105 int ncols # number of gens 106 107 # polynomial procs 108 ctypedef struct p_Procs_s "p_Procs_s": 109 pass 94 110 # rings 95 111 96 112 ctypedef struct ring "ip_sring": … … 103 119 int CanShortOut # control printing capabilities 104 120 number *minpoly # minpoly for base extension field 105 121 char **names # variable names 122 p_Procs_s *p_Procs #polxnomial procs 123 ideal *qideal #quotient ideal 124 106 125 char **parameter # parameter names 107 126 ring *algring # base extension field 108 127 short N # number of variables … … 134 153 ringorder_Ws 135 154 ringorder_L 136 155 137 # polynomials138 156 139 ctypedef struct poly "polyrec":140 poly *next141 157 142 158 143 159 # groebner basis options … … 146 162 isNotHomog 147 163 isHomog 148 164 testHomog 149 150 # ideals151 152 ctypedef struct ideal "ip_sideal":153 poly **m # gens array154 long rank # rank of module, 1 for ideals155 int nrows # always 1156 int ncols # number of gens157 165 158 166 # dense matrices 159 167 … … 694 702 695 703 int nc_CallPlural(matrix* CC, matrix* DD, poly* CN, poly* DN, ring* r) 696 704 705 # Plural functions 706 707 int nc_CallPlural(matrix* CC, matrix* DD, poly* CN, poly* DN, ring* r) 708 709 bint nc_SetupQuotient(ring *, ring *) 710 711 ctypedef enum nc_type: 712 713 nc_error # Something's gone wrong! 714 nc_general # yx=q xy+... 715 nc_skew # yx=q xy 716 nc_comm # yx= xy 717 nc_lie, # yx=xy+... 718 nc_undef, # for internal reasons */ 719 nc_exterior # 720 721 cdef extern from "sca.h": 722 void sca_p_ProcsSet(ring *, p_Procs_s *) 723 724 void scaFirstAltVar(ring *, int) 725 726 void scaLastAltVar(ring *, int) 727 728 void ncRingType(ring *, int) 729 697 730 cdef extern from "stairc.h": 698 731 # Computes the monomial basis for R[x]/I 699 732 ideal *scKBase(int deg, ideal *s, ideal *Q) -
sage/monoids/free_monoid_element.py
diff --git a/sage/monoids/free_monoid_element.py b/sage/monoids/free_monoid_element.py
a b 78 78 else: 79 79 # TODO: should have some other checks here... 80 80 raise TypeError, "Argument x (= %s) is of the wrong type."%x 81 81 def __iter__(self): 82 """ 83 Returns an iterator which yields tuples of variable and exponent. 84 85 EXAMPLES: 86 sage: a = FreeMonoid(5, 'a').gens() 87 sage: list(a[0]*a[1]*a[4]**3*a[0]) 88 [(0, 1), (1, 1), (4, 3), (0, 1)] 89 """ 90 return iter(self._element_list) 82 91 ## def __cmp__(left, right): 83 92 ## """ 84 93 ## Compare two free monoid elements with the same parents. -
sage/rings/polynomial/plural.pxd
diff --git a/sage/rings/polynomial/plural.pxd b/sage/rings/polynomial/plural.pxd
a b 5 5 cdef class MPolynomialRing_plural(MPolynomialRing_libsingular): 6 6 pass 7 7 8 cdef class ExteriorAlgebra_plural(MPolynomialRing_plural): 9 pass -
sage/rings/polynomial/plural.pyx
diff --git a/sage/rings/polynomial/plural.pyx b/sage/rings/polynomial/plural.pyx
a b 1 1 include "sage/ext/stdsage.pxi" 2 2 include "sage/ext/interrupt.pxi" 3 3 4 from sage.matrix.constructor import Matrix 5 4 6 cdef class MPolynomialRing_plural(MPolynomialRing_libsingular): 5 def __init__(self, base_ring, n, names, order='degrevlex'):7 def __init__(self, base_ring, n, names, c, d, order='degrevlex'): 6 8 MPolynomialRing_libsingular.__init__(self, base_ring, n, names, order) 7 8 9 cdef matrix* matc=mpNew(n,n) 9 10 cdef matrix* matd=mpNew(n,n) 10 11 cdef MPolynomial_libsingular f 12 11 13 for i from 0 <= i < n: 12 14 for j from i+1 <= j < n: 13 matc.m[n*i+j] = p_ISet(-1, self._ring) 14 15 for i from 0 <= i < n: 16 for j from i+1 <= j < n: 17 matd.m[n*i+j] = p_ISet(-1, self._ring) 18 19 nc_CallPlural(matc, matd, NULL, NULL, self._ring) 20 15 if int(c[i,j])!=0: 16 matc.m[n*i+j] = p_ISet(int(c[i,j]), self._ring) 17 if not d is None: 18 #have matrix 19 for i from 0 <= i < n: 20 for j from i+1 <= j < n: 21 commuted=d[i,j] 22 if commuted and commuted!=0: 23 f =self(commuted) 24 matd.m[n*i+j] = p_Copy(f._poly, self._ring) 25 26 nc_CallPlural(matc,matd, NULL, NULL, self._ring) 21 27 id_Delete(<ideal**>&matc, self._ring) 22 28 id_Delete(<ideal**>&matd, self._ring) 23 29 24 30 def _repr_(self): 25 31 """ 26 32 EXAMPLE: 27 sage: from sage.rings.polynomial.plural import MPolynomial_plural 28 sage: P = MPolynomialRing_plural(QQ, 2, 'x,y') 33 sage: from sage.rings.polynomial.plural import MPolynomialRing_plural 34 sage: from sage.matrix.constructor import Matrix 35 sage: c=Matrix(2) 36 sage: c[0,1]=-1 37 sage: P = MPolynomialRing_plural(QQ, 2, 'x,y', c=c, d=Matrix(2)) 29 38 sage: P # indirect doctest 30 Multivariate Polynomial Ring in x, y over Rational Field 39 Noncommutative Multivariate Polynomial Ring in x, y over Rational Field 40 sage: P("x")*P("y") 41 x*y 42 sage: P("y")*P("x") 43 -x*y 31 44 """ 32 45 #TODO: print the relations 33 46 varstr = ", ".join([ rRingVar(i,self._ring) for i in range(self.__ngens) ]) 34 47 return "Noncommutative Multivariate Polynomial Ring in %s over %s"%(varstr,self.base_ring()) 48 49 cdef class ExteriorAlgebra_plural(MPolynomialRing_plural): 50 """docstring for ExteriorAlgebra_plural""" 51 def __init__(self, base_ring, n, names): 52 """ 53 EXAMPLE: 54 sage: from sage.rings.polynomial.plural import ExteriorAlgebra_plural 55 56 sage: P = ExteriorAlgebra_plural(QQ, 3, 'x,y,z') 57 sage: P("x")*P("y") 58 x*y 59 sage: P("y")*P("x") 60 -x*y 61 sage: P("x")*P("x") 62 0 63 """ 64 c=Matrix(n) 65 d=Matrix(n) 66 for i from 0 <= i < n: 67 for j from i+1 <= j < n: 68 c[i,j]=-1 69 70 super(ExteriorAlgebra_plural, self).__init__(base_ring, n,names,c=c,d=d) 71 self.setupQuotient() 72 73 def setupQuotient(self): 74 cdef int n=int(self.ngens()) 75 ncRingType( self._ring, nc_exterior ); 76 scaFirstAltVar( self._ring, 1); 77 scaLastAltVar( self._ring, n ); 78 sca_p_ProcsSet(self._ring, self._ring.p_Procs);
