Ticket #4539: plural_2.sage4.4.4.patch
File plural_2.sage4.4.4.patch, 9.6 KB (added by , 6 years ago) 


sage/algebras/free_algebra.py
# HG changeset patch # User Michael Brickenstein <brickenstein@mfo.de> # Date 1226934659 3600 # Node ID 51207796acad184730ea938cafeb9e55af5ca1d5 # Parent 13d10923e377463ab5aebbd5c989c185fd5ad33a 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 68 68 69 69 import sage.structure.parent_gens 70 70 71 72 71 def FreeAlgebra(R, n, names): 73 72 """ 74 73 Return the free algebra over the ring `R` on `n` … … 451 450 """ 452 451 return self.__monoid 453 452 454 453 def g_algebra(self, relations, order='degrevlex'): 454 """ 455 456 The GAlgebra derrived from this algebra by relations. 457 By default is assumed, that two variables commute. 458 459 TODO: 460 * Coercion doesn't work yet, there is some cheating about assumptions 461 * Check degeneracy conditions 462 Furthermore, the default values interfere with non degeneracy conditions... 463 464 EXAMPLES: 465 sage: A.<x,y,z>=FreeAlgebra(QQ,3) 466 sage: G=A.g_algebra({y*x:x*y}) 467 sage: (x,y,z)=G.gens() 468 sage: x*y 469 x*y 470 sage: y*x 471 x*y 472 sage: z*x 473 x*z 474 sage: (x,y,z)=A.gens() 475 sage: G=A.g_algebra({y*x:x*y+1}) 476 sage: (x,y,z)=G.gens() 477 sage: y*x 478 x*y + 1 479 sage: (x,y,z)=A.gens() 480 sage: G=A.g_algebra({y*x:x*y+z}) 481 sage: (x,y,z)=G.gens() 482 sage: y*x 483 x*y + z 484 """ 485 from sage.matrix.constructor import Matrix 486 from sage.rings.polynomial.plural import MPolynomialRing_plural 487 488 base_ring=self.base_ring() 489 n=self.ngens() 490 cmat=Matrix(base_ring,n) 491 dmat=Matrix(self,n) 492 for i in xrange(n): 493 for j in xrange(i+1,n): 494 cmat[i,j]=1 495 for (to_commute,commuted) in relations.iteritems(): 496 #This is dirty, coercion is broken 497 assert isinstance(to_commute,FreeAlgebraElement), to_commute.__class__ 498 assert isinstance(commuted,FreeAlgebraElement), commuted 499 ((v1,e1),(v2,e2))=list(list(to_commute)[0][1]) 500 assert e1==1 501 assert e2==1 502 assert v1>v2 503 c_coef=None 504 d_poly=None 505 for (c,m) in commuted: 506 if list(m)==[(v2,1),(v1,1)]: 507 c_coef=c 508 #buggy coercion workaround 509 d_poly=commutedself(c)*self(m) 510 break 511 assert not c_coef is None,list(m) 512 v2_ind = self.gens().index(v2) 513 v1_ind = self.gens().index(v1) 514 cmat[v2_ind,v1_ind]=c_coef 515 if d_poly: 516 dmat[v2_ind,v1_ind]=d_poly 517 518 return MPolynomialRing_plural(base_ring, n, ",".join([str(g) for g in self.gens()]), c=cmat, d=dmat,order=order) 519 520 455 521 from sage.misc.cache import Cache 456 522 cache = Cache(FreeAlgebra_generic) 
sage/libs/singular/singularcdefs.pxi
diff git a/sage/libs/singular/singularcdefs.pxi b/sage/libs/singular/singularcdefs.pxi
a b 148 148 bint (*nGreaterZero)(number* a) 149 149 void (*nPower)(number* a, int i, number* * result) 150 150 151 # polynomials 152 153 ctypedef struct poly "polyrec": 154 poly *next 155 156 # ideals 157 158 ctypedef struct ideal "ip_sideal": 159 poly **m # gens array 160 long rank # rank of module, 1 for ideals 161 int nrows # always 1 162 int ncols # number of gens 163 164 # polynomial procs 165 ctypedef struct p_Procs_s "p_Procs_s": 166 pass 151 167 # rings 152 168 153 169 ctypedef struct ring "ip_sring": … … 160 176 int CanShortOut # control printing capabilities 161 177 number *minpoly # minpoly for base extension field 162 178 char **names # variable names 179 p_Procs_s *p_Procs #polxnomial procs 180 ideal *qideal #quotient ideal 181 163 182 char **parameter # parameter names 164 183 ring *algring # base extension field 165 184 short N # number of variables … … 197 216 ringorder_Ws 198 217 ringorder_L 199 218 200 # polynomials201 219 202 ctypedef struct poly "polyrec":203 poly *next204 220 205 221 206 222 # groebner basis options … … 210 226 isHomog 211 227 testHomog 212 228 213 # ideals214 215 ctypedef struct ideal "ip_sideal":216 poly **m # gens array217 long rank # rank of module, 1 for ideals218 int nrows # always 1219 int ncols # number of gens220 221 229 # dense matrices 222 230 223 231 ctypedef struct matrix "ip_smatrix": … … 1003 1011 1004 1012 int nc_CallPlural(matrix* CC, matrix* DD, poly* CN, poly* DN, ring* r) 1005 1013 1014 # Plural functions 1015 1016 int nc_CallPlural(matrix* CC, matrix* DD, poly* CN, poly* DN, ring* r) 1017 1018 bint nc_SetupQuotient(ring *, ring *) 1019 1020 ctypedef enum nc_type: 1021 1022 nc_error # Something's gone wrong! 1023 nc_general # yx=q xy+... 1024 nc_skew # yx=q xy 1025 nc_comm # yx= xy 1026 nc_lie, # yx=xy+... 1027 nc_undef, # for internal reasons */ 1028 nc_exterior # 1029 1030 cdef extern from "sca.h": 1031 void sca_p_ProcsSet(ring *, p_Procs_s *) 1032 1033 void scaFirstAltVar(ring *, int) 1034 1035 void scaLastAltVar(ring *, int) 1036 1037 void ncRingType(ring *, int) 1038 1006 1039 cdef extern from "stairc.h": 1007 1040 # Computes the monomial basis for R[x]/I 1008 1041 ideal *scKBase(int deg, ideal *s, ideal *Q) 
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);