Ticket #12173: ulong_extras.patch

File ulong_extras.patch, 10.2 KB (added by mhansen, 10 years ago)
  • sage/groups/perm_gps/partn_ref/data_structures_pxd.pxi

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1324150401 0
    # Node ID 5900e845944d87b3d4bbb731383d0626bc8c89b5
    # Parent  b72663c760492cc8c360d328a6d370c8f88d2069
    [mq]: ulong_extras.patch
    
    diff --git a/sage/groups/perm_gps/partn_ref/data_structures_pxd.pxi b/sage/groups/perm_gps/partn_ref/data_structures_pxd.pxi
    a b  
    1313cdef extern from "stdlib.h":
    1414    int rand()
    1515
    16 cdef extern from "FLINT/long_extras.h":
    17     int z_isprime(unsigned long n)
     16cdef extern from "FLINT/ulong_extras.h":
     17    int n_is_prime(unsigned long n)
    1818
    1919cdef struct OrbitPartition:
    2020    # Disjoint set data structure for representing the orbits of the generators
  • .pxd

    diff --git a/sage/libs/flint/long_extras.pxd b/sage/libs/flint/ulong_extras.pxd
    rename from sage/libs/flint/long_extras.pxd
    rename to sage/libs/flint/ulong_extras.pxd
    old new  
    44from sage.libs.flint.flint cimport *
    55
    66
    7 cdef extern from "FLINT/long_extras.h":
     7cdef extern from "FLINT/ulong_extras.h":
    88
    9     ctypedef struct factor_t:
     9    ctypedef struct n_factor_t:
    1010        int num
    1111        unsigned long p[15]
    1212        unsigned long exp[15]
    1313
    14     cdef unsigned long z_randint(unsigned long limit)
     14    cdef int n_jacobi(long x, unsigned long y)
    1515
    16     cdef unsigned long z_randbits(unsigned long bits)
     16    cdef int n_is_prime(unsigned long n)
    1717
    18     cdef unsigned long z_randprime(unsigned long bits, int proved)
     18    cdef unsigned long n_gcd(long x, long y)
    1919
    20     cdef double z_precompute_inverse(unsigned long n)
    21 
    22     cdef double z_precompute_inverse2(unsigned long n)
    23 
    24     cdef double z_ll_precompute_inverse(unsigned long n)
    25 
    26     cdef unsigned long z_addmod(unsigned long a, unsigned long b, unsigned long p)
    27 
    28     cdef unsigned long z_submod(unsigned long a, unsigned long b, unsigned long p)
    29 
    30     cdef unsigned long z_negmod(unsigned long a, unsigned long p)
    31 
    32     cdef unsigned long z_mod_precomp(unsigned long a, unsigned long n, double ninv)
    33 
    34     cdef unsigned long z_div2_precomp(unsigned long a, unsigned long n, double ninv)
    35 
    36     cdef unsigned long z_mod2_precomp(unsigned long a, unsigned long n, double ninv)
    37 
    38     cdef unsigned long z_ll_mod_precomp(unsigned long a_hi, unsigned long a_lo, unsigned long n, double ninv)
    39 
    40     cdef unsigned long z_mulmod_precomp(unsigned long a, unsigned long b, unsigned long n, double ninv)
    41 
    42     cdef unsigned long z_mulmod2_precomp(unsigned long a, unsigned long b, unsigned long n, double ninv)
    43 
    44     cdef unsigned long z_powmod(unsigned long a, long exp, unsigned long n)
    45 
    46     cdef unsigned long z_powmod2(unsigned long a, long exp, unsigned long n)
    47 
    48     cdef unsigned long z_powmod_precomp(unsigned long a, long exp, unsigned long n, double ninv)
    49 
    50     cdef unsigned long z_powmod2_precomp(unsigned long a, long exp, unsigned long n, double ninv)
    51 
    52     cdef int z_legendre_precomp(unsigned long a, unsigned long p, double pinv)
    53 
    54     cdef int z_jacobi(long x, unsigned long y)
    55 
    56     cdef int z_ispseudoprime_fermat(unsigned long n, unsigned long i)
    57 
    58     cdef int z_isprime(unsigned long n)
    59 
    60     cdef int z_isprime_precomp(unsigned long n, double ninv)
    61 
    62     cdef unsigned long z_nextprime(unsigned long n, int proved)
    63 
    64     cdef int z_isprime_pocklington(unsigned long n, unsigned long iterations)
    65 
    66     cdef int z_ispseudoprime_lucas_ab(unsigned long n, int a, int b)
    67 
    68     cdef int z_ispseudoprime_lucas(unsigned long n)
    69 
    70     cdef unsigned long z_pow(unsigned long a, unsigned long exp)
    71 
    72     cdef unsigned long z_sqrtmod(unsigned long a, unsigned long p)
    73 
    74     cdef unsigned long z_cuberootmod(unsigned long * cuberoot1, unsigned long a, unsigned long p)
    75 
    76     cdef unsigned long z_invert(unsigned long a, unsigned long p)
    77    
    78     cdef long z_gcd_invert(long* a, long x, long y)
    79 
    80     cdef long z_extgcd(long* a, long* b, long x, long y)
    81 
    82     cdef unsigned long z_gcd(long x, long y)
    83 
    84     cdef unsigned long z_intsqrt(unsigned long r)
    85 
    86     cdef int z_issquare(unsigned long x)
    87 
    88     cdef unsigned long z_CRT(unsigned long x1, unsigned long n1, unsigned long x2, unsigned long n2)
    89 
    90     cdef int z_issquarefree(unsigned long n, int proved)
    91 
    92     cdef int z_remove_precomp(unsigned long * n, unsigned long p, double pinv)
    93 
    94     cdef int z_remove(unsigned long * n, unsigned long p)
    95 
    96     cdef unsigned long z_factor_SQUFOF(unsigned long n)
    97 
    98     cdef unsigned long z_primitive_root(unsigned long p)
    99 
    100     cdef unsigned long z_primitive_root_precomp(unsigned long p, double p_inv)
    101 
    102     cdef void z_factor(factor_t * factors, unsigned long n, int proved)
    103 
    104 
     20    cdef void n_factor(n_factor_t * factors, unsigned long n, int proved)
  • sage/libs/flint/zmod_poly_linkage.pxi

    diff --git a/sage/libs/flint/zmod_poly_linkage.pxi b/sage/libs/flint/zmod_poly_linkage.pxi
    a b  
    387387    zmod_poly_init(q, n)
    388388    leadcoeff = zmod_poly_get_coeff_ui(b, zmod_poly_degree(b))
    389389    modulus = zmod_poly_modulus(b)
    390     if (leadcoeff > 1 and z_gcd(modulus,leadcoeff) != 1):
     390    if (leadcoeff > 1 and n_gcd(modulus,leadcoeff) != 1):
    391391        raise ValueError("Leading coefficient of a must be invertible.")
    392392
    393393    zmod_poly_divrem(q, res, a, b)
     
    420420
    421421    leadcoeff = zmod_poly_get_coeff_ui(b, zmod_poly_degree(b))
    422422    modulus = zmod_poly_modulus(b)
    423     if (leadcoeff > 1 and z_gcd(modulus,leadcoeff) != 1):
     423    if (leadcoeff > 1 and n_gcd(modulus,leadcoeff) != 1):
    424424        raise ValueError("Leading coefficient of a must be invertible.")
    425425
    426426    zmod_poly_divrem(q, r, a, b)
     
    569569    zmod_poly_gcd(res, a, b)
    570570    cdef unsigned long leadcoeff = zmod_poly_get_coeff_ui(res, zmod_poly_degree(res))
    571571    cdef unsigned long modulus = zmod_poly_modulus(res)
    572     if z_gcd(modulus,leadcoeff) == 1:
     572    if n_gcd(modulus,leadcoeff) == 1:
    573573        zmod_poly_make_monic(res, res)
    574574
    575575cdef inline int celement_xgcd(zmod_poly_t res, zmod_poly_t s, zmod_poly_t t, zmod_poly_t a, zmod_poly_t b, unsigned long n) except -2:
  • sage/rings/integer.pyx

    diff --git a/sage/rings/integer.pyx b/sage/rings/integer.pyx
    a b  
    165165    cdef void t_INT_to_ZZ( mpz_t value, long *g )
    166166   
    167167from sage.libs.pari.gen cimport gen as pari_gen, PariInstance
    168 from sage.libs.flint.long_extras cimport *
     168from sage.libs.flint.ulong_extras cimport *
    169169
    170170import sage.rings.infinity
    171171import sage.libs.pari.all
     
    32683268            if proof is None:
    32693269                from sage.structure.proof.proof import get_flag
    32703270                proof = get_flag(proof, "arithmetic")
    3271             z_factor(&f, mpz_get_ui(n.value), proof)
     3271            n_factor(&f, mpz_get_ui(n.value), proof)
    32723272            F = [(Integer(f.p[i]), int(f.exp[i])) for i from 0 <= i < f.num]
    32733273            F.sort()
    32743274            return IntegerFactorization(F, unit=unit, unsafe=True,
  • sage/schemes/elliptic_curves/descent_two_isogeny.pyx

    diff --git a/sage/schemes/elliptic_curves/descent_two_isogeny.pyx b/sage/schemes/elliptic_curves/descent_two_isogeny.pyx
    a b  
    268268cdef bint Zp_soluble_siksek(mpz_t a, mpz_t b, mpz_t c, mpz_t d, mpz_t e,
    269269                            mpz_t pp, unsigned long pp_ui,
    270270                            zmod_poly_factor_t f_factzn, zmod_poly_t f,
    271                             fmpz_poly_t f1, fmpz_poly_t linear,
    272                             double pp_ui_inv):
     271                            fmpz_poly_t f1, fmpz_poly_t linear):
    273272    """
    274273    Uses the approach of Algorithm 5.3.1 of Siksek's thesis to test for
    275274    solubility of y^2 == ax^4 + bx^3 + cx^2 + dx + e over Zp.
     
    321320            if f_factzn.exponents[i]&1:
    322321                result = 1
    323322                break
    324         if result == 0 and z_legendre_precomp(qq, pp_ui, pp_ui_inv) == 1:
     323        if result == 0 and n_jacobi(qq, pp_ui) == 1:
    325324            result = 1
    326325        if result:
    327326            return 1
     
    428427                fmpz_poly_get_coeff_mpz(cc, f1, 2)
    429428                fmpz_poly_get_coeff_mpz(dd, f1, 1)
    430429                fmpz_poly_get_coeff_mpz(ee, f1, 0)
    431                 result = Zp_soluble_siksek(aa, bb, cc, dd, ee, pp, pp_ui, f_factzn, f, f1, linear, pp_ui_inv)
     430                result = Zp_soluble_siksek(aa, bb, cc, dd, ee, pp, pp_ui, f_factzn, f, f1, linear)
    432431                mpz_clear(aa)
    433432                mpz_clear(bb)
    434433                mpz_clear(cc)
     
    491490            fmpz_poly_get_coeff_mpz(cc, f1, 2)
    492491            fmpz_poly_get_coeff_mpz(dd, f1, 1)
    493492            fmpz_poly_get_coeff_mpz(ee, f1, 0)
    494             result = Zp_soluble_siksek(aa, bb, cc, dd, ee, pp, pp_ui, f_factzn, f, f1, linear, pp_ui_inv)
     493            result = Zp_soluble_siksek(aa, bb, cc, dd, ee, pp, pp_ui, f_factzn, f, f1, linear)
    495494            if result == 1:
    496495                break
    497496        if j > 0:
     
    752751    cdef int result = 0
    753752    cdef mpz_t a,b,c,d,e
    754753    cdef zmod_poly_t f
    755     cdef double pp_ui_inv = z_precompute_inverse(P)
    756754    zmod_poly_init(f, P)
    757755
    758756    mpz_init_set(a,A)
     
    761759    mpz_init_set(d,D)
    762760    mpz_init_set(e,E)
    763761
    764     if Zp_soluble_siksek(a,b,c,d,e,p,P,f_factzn, f, f1, linear, pp_ui_inv):
     762    if Zp_soluble_siksek(a,b,c,d,e,p,P,f_factzn, f, f1, linear):
    765763        result = 1
    766764    else:
    767765        mpz_set(a,A)
     
    769767        mpz_set(c,C)
    770768        mpz_set(d,D)
    771769        mpz_set(e,E)
    772         if Zp_soluble_siksek(e,d,c,b,a,p,P,f_factzn, f, f1, linear, pp_ui_inv):
     770        if Zp_soluble_siksek(e,d,c,b,a,p,P,f_factzn, f, f1, linear):
    773771            result = 1
    774772
    775773    mpz_clear(a)
     
    12291227        p_list_mpz = <mpz_t *> sage_malloc(20 * sizeof(mpz_t))
    12301228        mpz_init_set_ui(p_list_mpz[0], ui2)
    12311229        p_list_len = 1
    1232         z_factor(&fact, mpz_get_ui(d_mpz), proof)
     1230        n_factor(&fact, mpz_get_ui(d_mpz), proof)
    12331231        for i from 0 <= i < fact.num:
    12341232            p = fact.p[i]
    12351233            if p != ui2:
    12361234                mpz_init_set_ui(p_list_mpz[p_list_len], p)
    12371235                p_list_len += 1
    1238         z_factor(&fact, mpz_get_ui(d_prime_mpz), proof)
     1236        n_factor(&fact, mpz_get_ui(d_prime_mpz), proof)
    12391237        for i from 0 <= i < fact.num:
    12401238            p = fact.p[i]
    12411239            found = 0