Changeset 4366:32bd4665bebf


Ignore:
Timestamp:
05/08/07 09:37:28 (6 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Parents:
4361:b1269633403c (diff), 4365:578007346d9e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sage/rings/multi_polynomial_libsingular.pyx

    r4109 r4366  
    7171 
    7272from sage.misc.sage_eval import sage_eval 
     73from sage.misc.latex import latex 
     74 
    7375 
    7476# shared library loading 
     
    9597 
    9698 
    97     lib = os.environ['SAGE_LOCAL']+"/lib/libsingular.so" 
    98     if os.path.exists(lib): 
    99        handle = dlopen(lib, 256+1) 
    100     else: 
    101         lib = os.environ['SAGE_LOCAL']+"/lib/libsingular.dylib" 
     99    for extension in ["so", "dylib", "dll"]: 
     100        lib = os.environ['SAGE_LOCAL']+"/lib/libsingular."+extension 
    102101        if os.path.exists(lib): 
    103102            handle = dlopen(lib, 256+1) 
    104         else: 
    105             raise ImportError, "cannot load libSINGULAR library" 
     103            break 
    106104 
    107105    if handle == NULL: 
    108106        print dlerror() 
     107        raise ImportError, "cannot load libSINGULAR library" 
    109108 
    110109    # Load Singular 
     
    228227        self._zero = <MPolynomial_libsingular>new_MP(self,NULL) 
    229228 
     229        for i from 0 <= i < n: 
     230            free(_names[i]) # strdup() --> free() 
    230231        sage_free(_names) 
    231232 
     
    10661067        if l != parent._ring.N: 
    10671068            raise TypeError, "number of arguments does not match number of variables in parent" 
    1068          
    1069         cdef ideal *to_id = idInit(l,1) 
    1070  
    1071         try: 
    1072             for i from 0 <= i < l: 
    1073                 e = x[i] # TODO: optimize this line 
    1074                 to_id.m[i]= p_Copy( (<MPolynomial_libsingular>(<MPolynomialRing_libsingular>parent._coerce_c(x[i])))._poly, _ring) 
    1075  
    1076         except TypeError: 
    1077             id_Delete(&to_id, _ring) 
    1078             raise TypeError, "cannot coerce in arguments" 
    1079  
    1080         cdef ideal *from_id=idInit(1,1) 
    1081         from_id.m[0] = p_Copy(self._poly, _ring) 
    1082  
    1083         cdef ideal *res_id = fast_map(from_id, _ring, to_id, _ring) 
    1084         cdef poly *res = p_Copy(res_id.m[0], _ring) 
    1085  
    1086         id_Delete(&to_id, _ring) 
    1087         id_Delete(&from_id, _ring) 
    1088         id_Delete(&res_id, _ring) 
    1089         return new_MP(parent, res) 
     1069 
     1070        return self.fix(dict(zip(parent.gens(), x)))  
     1071 
     1072        ### the following is going to be faster at some size, but slower in general 
     1073        ### TODO: find the crossover point 
     1074##         cdef ideal *to_id = idInit(l,1) 
     1075 
     1076##         try: 
     1077##             for i from 0 <= i < l: 
     1078##                 e = x[i] # TODO: optimize this line 
     1079##                 to_id.m[i]= p_Copy( (<MPolynomial_libsingular>(<MPolynomialRing_libsingular>parent._coerce_c(x[i])))._poly, _ring) 
     1080 
     1081##         except TypeError: 
     1082##             id_Delete(&to_id, _ring) 
     1083##             raise TypeError, "cannot coerce in arguments" 
     1084 
     1085##         cdef ideal *from_id=idInit(1,1) 
     1086##         from_id.m[0] = p_Copy(self._poly, _ring) 
     1087 
     1088##         cdef ideal *res_id = fast_map(from_id, _ring, to_id, _ring) 
     1089##         cdef poly *res = p_Copy(res_id.m[0], _ring) 
     1090 
     1091##         id_Delete(&to_id, _ring) 
     1092##         id_Delete(&from_id, _ring) 
     1093##         id_Delete(&res_id, _ring) 
     1094##         return new_MP(parent, res) 
    10901095             
    10911096    def __richcmp__(left, right, int op): 
     
    13441349    def __pow__(MPolynomial_libsingular self,int exp,ignored): 
    13451350        """ 
     1351        Return self^(exp). 
     1352 
     1353        EXAMPLE: 
     1354            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     1355            sage: R.<x,y>=MPolynomialRing_libsingular(QQ,2) 
     1356            sage: f = x^3 + y 
     1357            sage: f^2 
     1358            x^6 + 2*x^3*y + y^2 
     1359         
    13461360        """ 
    13471361        cdef ring *_ring 
     
    13601374 
    13611375    def __neg__(self): 
     1376        """ 
     1377        Return -self. 
     1378 
     1379        EXAMPLE: 
     1380            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     1381            sage: R.<x,y>=MPolynomialRing_libsingular(QQ,2) 
     1382            sage: f = x^3 + y 
     1383            sage: -f 
     1384            -x^3 - y 
     1385        """ 
    13621386        cdef ring *_ring 
    13631387        _ring = (<MPolynomialRing_libsingular>self._parent)._ring 
     
    13961420        return s 
    13971421 
    1398     def _latex(self): 
    1399         #do it for real, may be slow 
    1400         raise NotImplementedError 
     1422    def _latex_(self): 
     1423        """ 
     1424        Return a polynomial latex representation of self. 
     1425 
     1426        EXAMPLE: 
     1427            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     1428            sage: P.<x,y,z> = MPolynomialRing_libsingular(QQ,3) 
     1429            sage: f = - 1*x^2*y - 25/27 * y^3 - z^2 
     1430            sage: latex(f) 
     1431            - x^{2}y - \frac{25}{27} y^{3} - z^{2} 
     1432     
     1433        """ 
     1434        cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring 
     1435        cdef int n = _ring.N 
     1436        cdef int j, e 
     1437        cdef poly *p = self._poly 
     1438        poly = "" 
     1439        gens = self.parent().gens() 
     1440        base = self.parent().base() 
     1441         
     1442        while p: 
     1443            sign_switch = False 
     1444 
     1445            # First determine the multinomial: 
     1446            multi = "" 
     1447            for j from 1 <= j <= n: 
     1448                e = p_GetExp(p, j, _ring) 
     1449                if e > 0: 
     1450                    multi += str(gens[j-1]) 
     1451                if e > 1: 
     1452                    multi += "^{%d}"%e 
     1453 
     1454            # Next determine coefficient of multinomial 
     1455            c =  co.si2sa( p_GetCoeff(p, _ring), _ring, base)  
     1456            if len(multi) == 0: 
     1457                multi = latex(c) 
     1458            elif c != 1: 
     1459                if  c == -1: 
     1460                    if len(poly) > 0: 
     1461                        sign_switch = True 
     1462                    else: 
     1463                        multi = "- %s"%(multi) 
     1464                else: 
     1465                    multi = "%s %s"%(latex(c),multi) 
     1466 
     1467            # Now add on coefficiented multinomials 
     1468            if len(poly) > 0: 
     1469                if sign_switch: 
     1470                    poly = poly + " - " 
     1471                else: 
     1472                    poly = poly + " + " 
     1473            poly = poly + multi 
     1474             
     1475            p = pNext(p) 
     1476 
     1477        poly = poly.lstrip().rstrip() 
     1478        poly = poly.replace("+ -","- ") 
     1479 
     1480        if len(poly) == 0: 
     1481            return "0" 
     1482        return poly 
    14011483 
    14021484    def _repr_with_changed_varnames(self, varnames): 
    1403         #plan: replace self._ring.names for the moment with varnames 
    1404         raise NotImplementedError 
    1405      
     1485        """ 
     1486        Return string representing self but change the variable names 
     1487        to varnames. 
     1488 
     1489        EXAMPLE: 
     1490            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     1491            sage: P.<x,y,z> = MPolynomialRing_libsingular(QQ,3) 
     1492            sage: f = - 1*x^2*y - 25/27 * y^3 - z^2 
     1493            sage: print f._repr_with_changed_varnames(['FOO', 'BAR', 'FOOBAR']) 
     1494            -FOO^2*BAR - 25/27*BAR^3 - FOOBAR^2 
     1495 
     1496        """ 
     1497        cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring 
     1498        cdef char **_names 
     1499        cdef char **_orig_names 
     1500        cdef char *_name 
     1501        cdef int i 
     1502 
     1503        if len(varnames) != _ring.N: 
     1504            raise TypeError, "len(varnames) doesn't equal self.parent().ngens()" 
     1505 
     1506 
     1507        _names = <char**>sage_malloc(sizeof(char*)*_ring.N) 
     1508        for i from 0 <= i < _ring.N: 
     1509            _name = varnames[i] 
     1510            _names[i] = strdup(_name) 
     1511 
     1512        _orig_names = _ring.names 
     1513        _ring.names = _names 
     1514        s = str(self) 
     1515        _ring.names = _orig_names 
     1516 
     1517        for i from 0 <= i < _ring.N: 
     1518            free(_names[i]) # strdup() --> free() 
     1519        sage_free(_names) 
     1520 
     1521        return s 
     1522             
    14061523    def degree(self, MPolynomial_libsingular x=None): 
    14071524        """ 
     
    15871704 
    15881705    def dict(self): 
     1706        """ 
     1707        Return a dictionary representing self. This dictionary is in 
     1708        the same format as the generic MPolynomial: The dictionary 
     1709        consists of ETuple:coefficient pairs. 
     1710 
     1711        EXAMPLE: 
     1712            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     1713            sage: R.<x,y,z> = MPolynomialRing_libsingular(QQ, 3) 
     1714            sage: f=2*x*y^3*z^2 + 1/7*x^2 + 2/3 
     1715            sage: f.dict() 
     1716            {(2, 0, 0): 1/7, (0, 0, 0): 2/3, (1, 3, 2): 2} 
     1717        """ 
    15891718        cdef poly *p 
    15901719        cdef ring *r 
     
    15971726        while p: 
    15981727            d = dict() 
    1599             # assuming that SINGULAR stores monomial dense 
    16001728            for v from 1 <= v <= r.N: 
    16011729                n = p_GetExp(p,v,r) 
     
    17591887 
    17601888    def homogenize(self, var='h'): 
    1761         raise NotImplementedError 
     1889        """ 
     1890        Return self is self is homogeneous.  Otherwise return a 
     1891        homogeneous polynomial. If a string is given, return a 
     1892        polynomial in one more variable such that setting that 
     1893        variable equal to 1 yields self. This variable is added to the 
     1894        end of the variables. If either a variable in self.parent() or 
     1895        an index is given, this variable is used to homogenize the 
     1896        polynomial. 
     1897         
     1898        INPUT: 
     1899            var -- either a string (default: 'h'); a variable name for the new variable  
     1900                   to be added in when homogenizing or a variable/index to specify the existing 
     1901                   variable to be used. 
     1902                    
     1903        OUTPUT: 
     1904            a multivariate polynomial 
     1905             
     1906        EXAMPLES: 
     1907            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular         
     1908            sage: P.<x,y> = MPolynomialRing_libsingular(QQ,2) 
     1909            sage: f = x^2 + y + 1 + 5*x*y^10 
     1910            sage: g = f.homogenize('z'); g 
     1911            5*x*y^10 + x^2*z^9 + y*z^10 + z^11 
     1912            sage: g.parent() 
     1913            Polynomial Ring in x, y, z over Rational Field 
     1914            sage: f.homogenize(x) 
     1915            2*x^11 + x^10*y + 5*x*y^10 
     1916 
     1917        """ 
     1918        cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent 
     1919        cdef MPolynomial_libsingular f 
     1920 
     1921        if self.is_homogeneous(): 
     1922            return self 
     1923 
     1924        if PY_TYPE_CHECK(var, MPolynomial_libsingular): 
     1925            if (<MPolynomial_libsingular>var)._parent is self._parent: 
     1926                var = var._variable_indices_() 
     1927                if len(var) == 1: 
     1928                    var = var[0] 
     1929                else: 
     1930                    raise TypeError, "parameter var must be single variable" 
     1931 
     1932        if PY_TYPE_CHECK(var,str): 
     1933            names = [str(e) for e in parent.gens()] + [var] 
     1934            P = MPolynomialRing_libsingular(parent.base(),parent.ngens()+1, names, order=parent.term_order()) 
     1935            f = P(str(self)) 
     1936            return new_MP(P, pHomogen(f._poly,len(names))) 
     1937        elif PY_TYPE_CHECK(var,int) or PY_TYPE_CHECK(var,Integer): 
     1938            if var < parent._ring.N: 
     1939                return new_MP(parent, pHomogen(p_Copy(self._poly, parent._ring), var+1)) 
     1940            else: 
     1941                raise TypeError, "var must be < self.parent().ngens()" 
     1942        else: 
     1943            raise TypeError, "parameter var not understood" 
    17621944 
    17631945    def is_monomial(self): 
     
    17891971            sage: f.fix({x:5}) 
    17901972            25*y^2 + y + 30 
     1973 
     1974        TESTS: 
     1975            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular         
     1976            sage: P.<x,y,z> = MPolynomialRing_libsingular(QQ,3) 
     1977            sage: f = y 
     1978            sage: f.fix({y:x}).fix({x:z}) 
     1979            z 
    17911980             
    17921981        """ 
     
    18051994            elif PY_TYPE_CHECK(m,MPolynomial_libsingular) and <MPolynomialRing_libsingular>m.parent() is parent: 
    18061995                for i from 0 < i <= _ring.N: 
    1807                     mi = p_GetExp((<MPolynomial_libsingular>m)._poly,i, _ring) 
    1808                     if mi!=0: 
     1996                    if p_GetExp((<MPolynomial_libsingular>m)._poly, i, _ring) != 0: 
     1997                        mi = i 
    18091998                        break 
     1999                if i > _ring.N: 
     2000                    raise TypeError, "key does not match" 
    18102001            else: 
    18112002                raise TypeError, "keys do not match self's parent" 
    1812                                    
    1813             _p = pSubst(p_Copy(_p, _ring), mi, (<MPolynomial_libsingular>parent._coerce_c(v))._poly) 
     2003            _p = pSubst(_p, mi, (<MPolynomial_libsingular>parent._coerce_c(v))._poly) 
    18142004 
    18152005        return new_MP(parent,_p) 
    18162006 
    18172007    def monomials(self): 
    1818         raise NotImplementedError 
     2008        """ 
     2009        Return the list of monomials in self. The returned list is 
     2010        ordered by the term ordering of self.parent(). 
     2011 
     2012        EXAMPLE: 
     2013            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     2014            sage: P.<x,y,z> = MPolynomialRing_libsingular(QQ,3) 
     2015            sage: f = x + 3/2*y*z^2 + 2/3 
     2016            sage: f.monomials() 
     2017            [y*z^2, x, 1] 
     2018            sage: f = P(3/2) 
     2019            sage: f.monomials() 
     2020            [1] 
     2021 
     2022        TESTS: 
     2023            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     2024            sage: P.<x,y,z> = MPolynomialRing_libsingular(QQ,3) 
     2025            sage: f = x 
     2026            sage: f.monomials() 
     2027            [x] 
     2028            sage: f = P(0) 
     2029            sage: f.monomials() 
     2030            [0] 
     2031         
     2032         
     2033        """ 
     2034        l = list() 
     2035        cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent 
     2036        cdef ring *_ring = parent._ring 
     2037        cdef poly *p = p_Copy(self._poly, _ring) 
     2038        cdef poly *t 
     2039 
     2040        if p == NULL: 
     2041            return [parent._zero] 
     2042         
     2043        while p: 
     2044            t = pNext(p) 
     2045            p.next = NULL 
     2046            p_SetCoeff(p, n_Init(int(1),_ring), _ring) 
     2047            p_Setm(p, _ring) 
     2048            l.append( new_MP(parent,p) ) 
     2049            p = t 
     2050 
     2051        return l 
    18192052 
    18202053    def constant_coefficent(self): 
     
    18222055 
    18232056    def is_univariate(self): 
     2057        """ 
     2058        Return True if self is a univariate polynomial, that is if 
     2059        self contains only one variable. 
     2060 
     2061        EXAMPLE: 
     2062            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     2063            sage: P.<x,y,z> = MPolynomialRing_libsingular(GF(2),3) 
     2064            sage: f = x^2 + 1 
     2065            sage: f.is_univariate() 
     2066            True 
     2067            sage: f = y*x^2 + 1 
     2068            sage: f.is_univariate() 
     2069            False 
     2070            sage: f = P(0) 
     2071            sage: f.is_univariate() 
     2072            True 
     2073        """ 
    18242074        return bool(len(self._variable_indices_(sort=False))<2) 
    18252075 
     
    18282078 
    18292079    def _variable_indices_(self, sort=True): 
     2080        """ 
     2081        Return the indices of all variables occuring in self. 
     2082        This index is the index as SAGE uses them (starting at zero), not 
     2083        as SINGULAR uses them (starting at one). 
     2084 
     2085        INPUT: 
     2086            sort -- specifies whether the indices shall be sorted 
     2087 
     2088        EXAMPLE: 
     2089            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     2090            sage: P.<x,y,z> = MPolynomialRing_libsingular(GF(2),3) 
     2091            sage: f = x*z^2 + z + 1 
     2092            sage: f._variable_indices_() 
     2093            [0, 2] 
     2094         
     2095        """ 
    18302096        cdef poly *p 
    18312097        cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring 
     
    18362102            for i from 1 <= i <= r.N: 
    18372103                if p_GetExp(p,i,r): 
    1838                     s.add(i) 
     2104                    s.add(i-1) 
    18392105            p = pNext(p) 
    18402106        if sort: 
     
    18442110 
    18452111    def variables(self, sort=True): 
     2112        """ 
     2113        Return a list of all variables occuring in self. 
     2114 
     2115        INPUT: 
     2116            sort -- specifies whether the indices shall be sorted 
     2117 
     2118        EXAMPLE: 
     2119            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     2120            sage: P.<x,y,z> = MPolynomialRing_libsingular(GF(2),3) 
     2121            sage: f = x*z^2 + z + 1 
     2122            sage: f.variables() 
     2123            [z, x] 
     2124            sage: f.variables(sort=False) 
     2125            [x, z] 
     2126 
     2127        """ 
    18462128        cdef poly *p, *v 
    18472129        cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring 
     
    18652147 
    18662148    def variable(self, i=0): 
     2149        """ 
     2150        Return the i-th variable occuring in self. The index i is the 
     2151        index in self.variables(). 
     2152 
     2153        EXAMPLE: 
     2154            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     2155            sage: P.<x,y,z> = MPolynomialRing_libsingular(GF(2),3) 
     2156            sage: f = x*z^2 + z + 1 
     2157            sage: f.variables() 
     2158            [z, x] 
     2159            sage: f.variable(1) 
     2160            x 
     2161        """ 
    18672162        return self.variables()[i] 
    18682163         
    18692164    def nvariables(self): 
     2165        """ 
     2166        """ 
    18702167        return self._variable_indices_(sort=False) 
    18712168 
    18722169    def is_constant(self): 
     2170        """ 
     2171        """ 
    18732172        return bool(p_IsConstant(self._poly, (<MPolynomialRing_libsingular>self._parent)._ring)) 
    18742173 
     
    18772176 
    18782177    def __hash__(self): 
     2178        """ 
     2179        """ 
    18792180        s = p_String(self._poly, (<MPolynomialRing_libsingular>self._parent)._ring, (<MPolynomialRing_libsingular>self._parent)._ring) 
    18802181        return hash(s) 
    1881          
    18822182 
    18832183    def lm(MPolynomial_libsingular self): 
     
    19682268    def factor(self, param=0): 
    19692269        """ 
     2270 
     2271        Return the factorization of self. 
     2272 
     2273        INPUT: 
     2274            param --  0: returns factors and multiplicities, first factor is a constant. 
     2275                      1: returns non-constant factors (no multiplicities). 
     2276                      2: returns non-constant factors and multiplicities. 
     2277        EXAMPLE: 
     2278            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular         
     2279            sage: R.<x,y,z> = MPolynomialRing_libsingular(GF(32003),3) 
     2280            sage: f = 9*(x-1)^2*(y+z) 
     2281            sage: f.factor(0) 
     2282            9 * (y + z) * (x - 1)^2 
     2283            sage: f.factor(1) 
     2284            (y + z) * (x - 1) 
     2285            sage: f.factor(2) 
     2286            (y + z) * (x - 1)^2 
     2287 
    19702288        """ 
    19712289        cdef ring *_ring 
     
    19952313        F.sort() 
    19962314 
    1997         # delete intvec 
    1998         # delete ideal 
     2315        omFree(iv) 
     2316        id_Delete(&I,_ring) 
    19992317         
    20002318        return F 
     
    20042322        #matrix_to_list(m) 
    20052323        raise NotImplementedError 
     2324 
     2325    def reduce(self,I): 
     2326        """ 
     2327        Return the normal form of self w.r.t. I, i.e. return the 
     2328        remainder of self with respect to the polynomials in I. If the 
     2329        polynomial set/list I is not a Groebner basis the result is 
     2330        not canonical. 
     2331 
     2332        INPUT: 
     2333            I -- a list/set of polynomials in self.parent(). If I is an ideal, 
     2334                 the generators are used. 
     2335 
     2336        EXAMPLE: 
     2337            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular         
     2338            sage: P.<x,y,z> = MPolynomialRing_libsingular(QQ,3) 
     2339            sage: f1 = -2 * x^2 + x^3 
     2340            sage: f2 = -2 * y + x* y 
     2341            sage: f3 = -x^2 + y^2 
     2342            sage: F = Ideal([f1,f2,f3]) 
     2343            sage: g = x*y - 3*x*y^2 
     2344            sage: g.reduce(F) 
     2345            -6*y^2 + 2*y 
     2346            sage: g.reduce(F.gens()) 
     2347            -6*y^2 + 2*y 
     2348         
     2349        """ 
     2350        cdef ideal *_I 
     2351        cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent 
     2352        cdef int i = 0 
     2353        cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring 
     2354        cdef poly *res 
     2355         
     2356        if(r != currRing): rChangeCurrRing(r) 
     2357         
     2358        if PY_TYPE_CHECK(I, MPolynomialIdeal): 
     2359            I = I.gens() 
     2360 
     2361        _I = idInit(len(I),1) 
     2362        for f in I: 
     2363            if not (PY_TYPE_CHECK(f,MPolynomial_libsingular) \ 
     2364                   and <MPolynomialRing_libsingular>(<MPolynomial_libsingular>f)._parent is parent): 
     2365                try: 
     2366                    f = parent._coerce_c(f) 
     2367                except TypeError, msg: 
     2368                    id_Delete(&_I,r) 
     2369                    raise TypeError, msg 
     2370                     
     2371            _I.m[i] = p_Copy((<MPolynomial_libsingular>f)._poly, r) 
     2372            i+=1 
     2373 
     2374        #the second parameter would be qring! 
     2375        res = kNF(_I, NULL, p_Copy(self._poly, r)) 
     2376        return new_MP(parent,res) 
    20062377 
    20072378    def gcd(self, right): 
     
    20492420        return new_MP((<MPolynomialRing_libsingular>self._parent), _res) 
    20502421 
    2051     def lcm(self, g): 
    2052         #poly *singclap_alglcm ( poly *f, poly *g ); 
    2053         raise NotImplementedError 
     2422##     def lcm(self, MPolynomial_libsingular g): 
     2423##         cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring 
     2424##         cdef poly *ret 
     2425##         if(_ring != currRing): rChangeCurrRing(_ring) 
     2426 
     2427##         if self._parent is not g._parent: 
     2428##             g = (<MPolynomialRing_libsingular>self._parent)._coerce_c(g) 
     2429 
     2430##         # This guy calculates on napoly not poly 
     2431##         ret = singclap_alglcm(self._poly, (<MPolynomial_libsingular>g)._poly) 
     2432##         return new_MP(self._parent, ret) 
    20542433 
    20552434    def is_square_free(self): 
    2056         #BOOLEAN singclap_isSqrFree(poly f); 
    2057         raise NotImplementedError 
     2435        """ 
     2436        """ 
     2437        cdef ring *_ring = (<MPolynomialRing_libsingular>self._parent)._ring 
     2438        if(_ring != currRing): rChangeCurrRing(_ring) 
     2439        return bool(singclap_isSqrFree(self._poly)) 
    20582440 
    20592441    def quo_rem(self, MPolynomial_libsingular right): 
     2442        """ 
     2443        """ 
    20602444        if self._parent is not right._parent: 
    20612445            right = self._parent._coerce_c(right) 
    20622446        raise NotImplementedError 
    20632447 
    2064     def _magma_(self): 
    2065         raise NotImplementedError 
    2066  
     2448    def _magma_(self, magma=None): 
     2449        """ 
     2450        Returns the MAGMA representation of self. 
     2451         
     2452        EXAMPLES: 
     2453            sage: from sage.rings.multi_polynomial_libsingular import MPolynomialRing_libsingular 
     2454            sage: R.<x,y> = MPolynomialRing_libsingular(GF(2),2) 
     2455            sage: f = y*x^2 + x +1 
     2456            sage: f._magma_() #optional 
     2457            x^2*y + x + 1 
     2458        """ 
     2459        if magma is None: 
     2460            # TODO: import this globally 
     2461            import sage.interfaces.magma 
     2462            magma = sage.interfaces.magma.magma 
     2463         
     2464        magma_gens = [e.name() for e in self.parent()._magma_().gens()] 
     2465        f = self._repr_with_changed_varnames(magma_gens) 
     2466        return magma(f) 
     2467         
    20672468    def _singular_(self, singular=singular_default, have_ring=False): 
    20682469        """ 
  • sage/rings/multi_polynomial_libsingular.pyx

    r4365 r4366  
    473473            sage: P.<x,y,z> = MPolynomialRing_libsingular(QQ,3) 
    474474            sage: sage.rings.ideal.Katsura(P) 
    475             Ideal (x + 2*y + 2*z - 1, 2*x*y + 2*y*z - y, x^2 + 2*y^2 + 2*z^2 - x) of Polynomial Ring in x, y, z over Rational Field 
     475            Ideal (x + 2*y + 2*z - 1, x^2 + 2*y^2 + 2*z^2 - x, 2*x*y + 2*y*z - y) of Polynomial Ring in x, y, z over Rational Field 
    476476 
    477477            sage: P.ideal([x + 2*y + 2*z-1, 2*x*y + 2*y*z-y, x^2 + 2*y^2 + 2*z^2-x]) 
Note: See TracChangeset for help on using the changeset viewer.