Ticket #12173: trac_12173-ffixes.patch

File trac_12173-ffixes.patch, 3.4 KB (added by jpflori, 9 years ago)

Further fixes

  • sage/libs/flint/nmod_poly_linkage.pxi

    # HG changeset patch
    # User Jean-Pierre Flori <jean-pierre.flori@ssi.gouv.fr>
    # Date 1367856527 -3600
    # Node ID 493c7a2b9b6f50af095ba3d06784a350afcc1301
    # Parent  bcad2b5fb602cd38899d25a3ad0dd31367597517
    #12173: Further fixes
    
    diff --git a/sage/libs/flint/nmod_poly_linkage.pxi b/sage/libs/flint/nmod_poly_linkage.pxi
    a b  
    495495    elif e == 1:
    496496        nmod_poly_set(res, x)
    497497    elif e == 2:
    498         nmod_poly_mul(res, x, x)
     498        nmod_poly_pow(res, x, 2)
    499499    else:
    500500        if res == x:
    501501            nmod_poly_set(tmp, x)
     
    509509            nmod_poly_set_coeff_ui(res, 0, 1)
    510510        e = e >> 1
    511511        while(e != 0):
    512             nmod_poly_mul(pow2, pow2, pow2)
     512            nmod_poly_pow(pow2, pow2, 2)
    513513            if e % 2:
    514514                nmod_poly_mul(res, res, pow2)
    515515            e = e >> 1
  • sage/rings/fraction_field_FpT.pyx

    diff --git a/sage/rings/fraction_field_FpT.pyx b/sage/rings/fraction_field_FpT.pyx
    a b  
    99
    1010from sage.rings.all import GF
    1111from sage.libs.flint.nmod_poly cimport *
     12from sage.libs.flint.ulong_extras cimport n_jacobi
    1213from sage.structure.element cimport Element, ModuleElement, RingElement
    1314from sage.rings.integer_ring import ZZ
    1415from sage.rings.fraction_field import FractionField_generic, FractionField_1poly_field
     
    648649                finally:
    649650                    nmod_poly_clear(g)
    650651        return next
    651        
     652
    652653    cpdef _sqrt_or_None(self):
    653654        """
    654655        Returns the squre root of self, or None. Differs from sqrt() by not raising an exception.
     
    686687            []
    687688
    688689        """
    689         if nmod_poly_degree(self._numer) == -1:
     690        if nmod_poly_is_zero(self._numer):
    690691            return self
     692
     693        if not nmod_poly_sqrt_check(self._numer) or not nmod_poly_sqrt_check(self._denom):
     694            return None
     695
    691696        cdef nmod_poly_t numer
    692697        cdef nmod_poly_t denom
    693698        cdef long a
     
    16401645        d -= 1
    16411646    return 0
    16421647
     1648cdef bint nmod_poly_sqrt_check(nmod_poly_t poly):
     1649     """
     1650     Quick check to see if poly could possibly be a square.
     1651     """
     1652     # We could use Sage's jacobi_int which is for 32 bits integers rather
     1653     # than FLINT's n_jacobi which is for longs as the FpT class is crafted
     1654     # for primes 2 < p < 2^16
     1655     return (nmod_poly_degree(poly) % 2 == 0
     1656         and n_jacobi(nmod_poly_leading(poly), poly.mod.n) == 1
     1657         and n_jacobi(nmod_poly_get_coeff_ui(poly, 0), poly.mod.n) != -1)
     1658
    16431659def unpickle_FpT_element(K, numer, denom):
    16441660    """
    16451661    Used for pickling.
  • sage/rings/polynomial/polynomial_zmod_flint.pyx

    diff --git a/sage/rings/polynomial/polynomial_zmod_flint.pyx b/sage/rings/polynomial/polynomial_zmod_flint.pyx
    a b  
    152152
    153153        INPUT:
    154154
    155         - ``x`` - a list of coefficients
     155        - ``x`` - a list of coefficients - the coefficients are assumed to be
     156          reduced already and the list contains no trailing zeroes.
     157
    156158
    157159        EXAMPLES::
    158160
     
    178180        sig_off()
    179181
    180182        sig_on()
     183        # The following depends on the internals of FLINT
    181184        for i from 0 <= i < length:
    182             nmod_poly_set_coeff_ui(&self.x, i, l_in[i])
     185            self.x.coeffs[i] = l_in[i]
     186        self.x.length = length
    183187        sig_off()
    184188        return 0
    185189