Ticket #7797: plural_functions.patch

File plural_functions.patch, 4.2 KB (added by PolyBoRi, 9 years ago)

some improvements to plural interface, still not much working

  • sage/libs/singular/function.pyx

    diff -r 54342f65c59c sage/libs/singular/function.pyx
    a b  
    1313- Martin Albrecht (2009-07): clean up, enhancements, etc.
    1414- Michael Brickenstein (2009-10): extension to more Singular types
    1515- Martin Albrecht (2010-01): clean up, support for attributes
     16- Burcin Erocal (2010-7): plural support
    1617
    1718EXAMPLES:
    1819
     
    229230    args.CleanUp()
    230231    omFreeBin(args, sleftv_bin)
    231232
     233def is_polynomial(p):
     234    return isinstance(p, MPolynomial_libsingular) or isinstance(p,  NCPolynomial_plural)
    232235
    233236def all_polynomials(s):
    234237    """
     
    245248        False
    246249    """
    247250    for p in s:
    248         if not isinstance(p, MPolynomial_libsingular):
     251        if not is_polynomial(p):
    249252            return False
    250253    return True
    251254
     
    275278    return True
    276279
    277280
     281cdef ring* sage_ring_to_singular_ring(ring) except <ring* > -1:
     282    if PY_TYPE_CHECK(ring, MPolynomialRing_libsingular):
     283        return (<MPolynomialRing_libsingular>ring)._ring
     284    elif PY_TYPE_CHECK(ring, NCPolynomialRing_plural):
     285        return (<NCPolynomialRing_plural>ring)._ring
     286    raise ValueError, "no singular ring found"
     287
    278288
    279289cdef class Converter(SageObject):
    280290    """
     
    305315        cdef leftv *v
    306316        self.args = NULL
    307317        self._sage_ring = ring
    308         if PY_TYPE_CHECK(ring, MPolynomialRing_libsingular):
    309             self._singular_ring = (<MPolynomialRing_libsingular>ring)._ring
    310         elif PY_TYPE_CHECK(ring, NCPolynomialRing_plural):
    311             self._singular_ring = (<NCPolynomialRing_plural>ring)._ring
     318        if ring is not None:
     319            self._singular_ring = sage_ring_to_singular_ring(ring)
    312320       
    313321        from  sage.matrix.matrix_mpolynomial_dense import Matrix_mpolynomial_dense
    314322        from sage.matrix.matrix_integer_dense import Matrix_integer_dense
     
    579587        """
    580588        cdef poly* _p
    581589        if PY_TYPE_CHECK(p, MPolynomial_libsingular):
    582             _p = p_Copy((<MPolynomial_libsingular>p)._poly, <ring*>((<MPolynomial_libsingular>p)._parent)._ring)
     590            _p = p_Copy((<MPolynomial_libsingular>p)._poly,
     591             ((<MPolynomialRing_libsingular>(
     592                <MPolynomial_libsingular>p)._parent))._ring)
    583593        elif PY_TYPE_CHECK(p, NCPolynomial_plural):
    584             _p = p_Copy((<NCPolynomial_plural>p)._poly, <ring*>((<NCPolynomial_plural>p)._parent)._ring)
     594            _p = p_Copy((<NCPolynomial_plural>p)._poly,
     595                ((<NCPolynomialRing_plural>(
     596                        <MPolynomial_libsingular>p)._parent))._ring)
     597               
    585598        return self._append(_p, POLY_CMD)
    586599
    587600    cdef leftv *append_ideal(self,  i) except NULL:
     
    11051118            elif PY_TYPE_CHECK(a, MPolynomialRing_libsingular) or \
    11061119                    PY_TYPE_CHECK(a, NCPolynomialRing_plural):
    11071120                ring2 = a
    1108             elif PY_TYPE_CHECK(a, int) or PY_TYPE_CHECK(a, long) or PY_TYPE_CHECK(a, basestring):
     1121            elif PY_TYPE_CHECK(a, int) or\
     1122                PY_TYPE_CHECK(a, long) or\
     1123                PY_TYPE_CHECK(a, basestring):
    11091124                continue
    11101125            elif PY_TYPE_CHECK(a, Matrix_integer_dense):
    11111126                continue
     
    13991414        <Resolution>
    14001415        sage: singular_list(resolution)
    14011416        [[(-2*y, 2, y + 1, 0), (0, -2, x - 1, 0), (x*y - y, -y + 1, 1, -y), (x^2 + 1, -x - 1, -1, -x)], [(-x - 1, y - 1, 2*x, -2*y)], [(0)]]
    1402 
    1403        
     1417        sage: from sage.rings.polynomial.plural import NCPolynomialRing_plural
     1418        sage: from sage.matrix.constructor  import Matrix
     1419        sage: c=Matrix(2)
     1420        sage: c[0,1]=-1
     1421        sage: P = NCPolynomialRing_plural(QQ, 2, 'x,y', c=c, d=Matrix(2))
     1422        sage: (x,y)=[P.gen(i) for i in xrange(2)]
     1423        sage: I= Sequence([x*y,x+y], check=False, immutable=True)#P.ideal(x*y,x+y)
     1424        sage: twostd = singular_function("twostd")
     1425        sage: twostd(I)
     1426        [x + y, x*y - y, 2*y, x^2 + 1]
     1427        sage: M=syz(I)
     1428        sage: M
     1429        [(-2*y, 2, y + 1, 0), (0, -2, x - 1, 0), (x*y - y, -y + 1, 1, -y), (x^2 + 1, -x - 1, -1, -x)]
     1430        sage: syz(M)
     1431        [(-x - 1, y - 1, 2*x, -2*y)]
    14041432    """
    14051433
    14061434    cdef SingularFunction fnc