Ticket #4539: plural_2.sage-4.4.4.patch

File plural_2.sage-4.4.4.patch, 9.6 KB (added by burcin, 6 years ago)

rebased to 4.4.4

  • 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  
    6868
    6969import sage.structure.parent_gens
    7070
    71        
    7271def FreeAlgebra(R, n, names):
    7372    """
    7473    Return the free algebra over the ring `R` on `n`
     
    451450        """
    452451        return self.__monoid
    453452   
    454                    
     453    def g_algebra(self, relations, order='degrevlex'):
     454        """
     455           
     456            The G-Algebra 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=commuted-self(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           
    455521from sage.misc.cache import Cache
    456522cache = Cache(FreeAlgebra_generic)
  • sage/libs/singular/singular-cdefs.pxi

    diff --git a/sage/libs/singular/singular-cdefs.pxi b/sage/libs/singular/singular-cdefs.pxi
    a b  
    148148        bint (*nGreaterZero)(number* a)
    149149        void (*nPower)(number* a, int i, number* * result)
    150150
     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
    151167    # rings
    152168
    153169    ctypedef struct ring "ip_sring":
     
    160176        int  CanShortOut # control printing capabilities
    161177        number *minpoly # minpoly for base extension field
    162178        char **names # variable names
     179        p_Procs_s *p_Procs #polxnomial procs
     180        ideal *qideal #quotient ideal
     181       
    163182        char **parameter # parameter names
    164183        ring *algring # base extension field
    165184        short N # number of variables
     
    197216        ringorder_Ws
    198217        ringorder_L
    199218
    200     # polynomials
    201219
    202     ctypedef struct poly "polyrec":
    203         poly *next
    204220
    205221       
    206222    # groebner basis options
     
    210226        isHomog
    211227        testHomog
    212228
    213     # ideals
    214 
    215     ctypedef struct ideal "ip_sideal":
    216         poly **m # gens array
    217         long rank # rank of module, 1 for ideals
    218         int nrows # always 1
    219         int ncols # number of gens
    220 
    221229    # dense matrices
    222230   
    223231    ctypedef struct matrix "ip_smatrix":
     
    10031011   
    10041012    int nc_CallPlural(matrix* CC, matrix* DD, poly* CN, poly* DN, ring* r)
    10051013
     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     
     1030cdef 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   
    10061039cdef extern from "stairc.h":
    10071040    # Computes the monomial basis for R[x]/I
    10081041    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  
    55cdef class MPolynomialRing_plural(MPolynomialRing_libsingular):
    66    pass
    77
     8cdef 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  
    11include "sage/ext/stdsage.pxi"
    22include "sage/ext/interrupt.pxi"
    33
     4from sage.matrix.constructor  import Matrix
     5
    46cdef 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'):
    68        MPolynomialRing_libsingular.__init__(self, base_ring, n, names, order)
    7 
    89        cdef matrix* matc=mpNew(n,n)
    910        cdef matrix* matd=mpNew(n,n)
    10 
     11        cdef MPolynomial_libsingular f
     12       
    1113        for i from 0 <= i < n:
    1214            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)
    2127        id_Delete(<ideal**>&matc, self._ring)
    2228        id_Delete(<ideal**>&matd, self._ring)
    23  
     29
    2430    def _repr_(self):
    2531        """
    2632        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))
    2938            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
    3144        """
    3245#TODO: print the relations
    3346        varstr = ", ".join([ rRingVar(i,self._ring)  for i in range(self.__ngens) ])
    3447        return "Noncommutative Multivariate Polynomial Ring in %s over %s"%(varstr,self.base_ring())
     48
     49cdef 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);