Ticket #12142: trac_12142-singular_conversion.patch

File trac_12142-singular_conversion.patch, 4.7 KB (added by pbruin, 10 years ago)
  • sage/libs/singular/singular.pxd

    # HG changeset patch
    # User Peter Bruin <peter.bruin@math.uzh.ch>
    # Date 1372363347 -7200
    # Node ID 40d656baff968c8dc0e8bc5301e64308171c9b5f
    # Parent  0e41a7f040c15446cd1ae1b8b22f1a32deb6b12f
    Trac 12142: convert finite field elements from and to Singular
    
    diff --git a/sage/libs/singular/singular.pxd b/sage/libs/singular/singular.pxd
    a b  
    2222
    2323cdef FFgivE   si2sa_GFqGivaro(number *n, ring *_ring, Cache_givaro cache)
    2424cdef FFgf2eE  si2sa_GFqNTLGF2E(number *n, ring *_ring, Cache_ntl_gf2e cache)
    25 cdef object   si2sa_GFqPari(number *n, ring *_ring, object base)
     25cdef object   si2sa_GFq_generic(number *n, ring *_ring, object base)
    2626cdef object   si2sa_ZZmod(number *n, ring *_ring, object base)
    2727
    2828cdef object   si2sa_NF(number *n, ring *_ring, object base)
     
    4040cdef number *sa2si_ZZ(Integer d, ring *_ring)
    4141
    4242cdef number *sa2si_GFqGivaro(int exp ,ring (*))
    43 cdef number *sa2si_GFqPari(object vector, ring *_ring)
    4443cdef number *sa2si_GFqNTLGF2E(FFgf2eE elem, ring *_ring)
     44cdef number *sa2si_GFq_generic(object vector, ring *_ring)
    4545cdef inline number *sa2si_ZZmod(IntegerMod_abstract d, ring *_ring)
    4646
    4747cdef number *sa2si_NF(object element, ring *_ring)
  • sage/libs/singular/singular.pyx

    diff --git a/sage/libs/singular/singular.pyx b/sage/libs/singular/singular.pyx
    a b  
    4343from sage.rings.rational_field import RationalField
    4444from sage.rings.integer_ring cimport IntegerRing_class
    4545from sage.rings.finite_rings.integer_mod_ring import IntegerModRing_generic
     46from sage.rings.finite_rings.finite_field_base import FiniteField
    4647from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn
    47 from sage.rings.finite_rings.finite_field_ext_pari import FiniteField_ext_pari
    4848from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro
    4949from sage.rings.finite_rings.finite_field_ntl_gf2e import FiniteField_ntl_gf2e
    5050from sage.libs.pari.all import pari
     
    202202        z = <napoly*>pNext(<poly*>z)
    203203    return ret
    204204
    205 cdef object si2sa_GFqPari(number *n, ring *_ring, object base):
     205cdef object si2sa_GFq_generic(number *n, ring *_ring, object base):
    206206    """
    207207    TESTS::
    208208   
     
    220220    cdef object ret
    221221
    222222    if naIsZero(n):
    223         return base._zero_element
     223        return base.zero_element()
    224224    elif naIsOne(n):
    225         return base._one_element
     225        return base.one_element()
    226226    z = (<lnumber*>n).z
    227227
    228     a = pari("a")
    229     ret = pari(int(0)).Mod(int(_ring.ch))
     228    a = base.gen()
     229    ret = base.zero_element()
    230230
    231231    while z:
    232232        c = <long>napGetCoeff(z)
     
    236236        elif c != 0:
    237237            ret = ret  + c * a**e
    238238        z = <napoly*>pNext(<poly*>z)
    239     return base(ret)
     239    return ret
    240240
    241241cdef object si2sa_NF(number *n, ring *_ring, object base):
    242242    """
     
    408408
    409409    return n1
    410410
    411 cdef number *sa2si_GFqPari(object elem, ring *_ring):
     411cdef number *sa2si_GFq_generic(object elem, ring *_ring):
    412412    """
    413413    """
    414414    cdef int i
    415415    cdef number *n1, *n2, *a, *coeff, *apow1, *apow2
    416     elem = elem._pari_().lift().lift()
     416    elem = elem.polynomial()
    417417
    418418    if _ring != currRing: rChangeCurrRing(_ring)
    419     if len(elem) > 1:
     419    if elem.degree() > 0:
    420420        n1 = naInit(0, _ring)
    421421        a = naPar(1)
    422422        apow1 = naInit(1, _ring)
    423423
    424         for i from 0 <= i < len(elem):
     424        for i from 0 <= i <= elem.degree():
    425425            coeff = naInit(int(elem[i]), _ring)
    426426
    427427            if not naIsZero(coeff):
     
    556556    elif PY_TYPE_CHECK(base, FiniteField_givaro):
    557557        return si2sa_GFqGivaro(n, _ring, base._cache)
    558558
    559     elif PY_TYPE_CHECK(base, FiniteField_ext_pari):
    560         return si2sa_GFqPari(n, _ring, base)
    561 
    562559    elif PY_TYPE_CHECK(base, FiniteField_ntl_gf2e):
    563560        return si2sa_GFqNTLGF2E(n, _ring, <Cache_ntl_gf2e>base._cache)
    564561
     562    elif PY_TYPE_CHECK(base, FiniteField):
     563        return si2sa_GFq_generic(n, _ring, base)
     564
    565565    elif PY_TYPE_CHECK(base, NumberField) and base.is_absolute():
    566566        return si2sa_NF(n, _ring, base)
    567567
     
    587587    elif isinstance(elem._parent, FiniteField_givaro):
    588588        return sa2si_GFqGivaro( (<FFgivE>elem)._cache.objectptr.convert(i, (<FFgivE>elem).element ), _ring )
    589589
    590     elif PY_TYPE_CHECK(elem._parent, FiniteField_ext_pari):
    591         return sa2si_GFqPari(elem, _ring)
    592 
    593590    elif PY_TYPE_CHECK(elem._parent, FiniteField_ntl_gf2e):
    594591        return sa2si_GFqNTLGF2E(elem, _ring)
    595592
     593    elif PY_TYPE_CHECK(elem._parent, FiniteField):
     594        return sa2si_GFq_generic(elem, _ring)
     595
    596596    elif PY_TYPE_CHECK(elem._parent, NumberField) and elem._parent.is_absolute():
    597597        return sa2si_NF(elem, _ring)
    598598    elif PY_TYPE_CHECK(elem._parent, IntegerModRing_generic):