# 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/sage/groups/perm_gps/partn_ref/data_structures_pxd.pxi
+++ b/sage/groups/perm_gps/partn_ref/data_structures_pxd.pxi
@@ -13,8 +13,8 @@
 cdef extern from "stdlib.h":
     int rand()
 
-cdef extern from "FLINT/long_extras.h":
-    int z_isprime(unsigned long n)
+cdef extern from "FLINT/ulong_extras.h":
+    int n_is_prime(unsigned long n)
 
 cdef struct OrbitPartition:
     # Disjoint set data structure for representing the orbits of the generators
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
--- a/sage/libs/flint/long_extras.pxd
+++ b/sage/libs/flint/ulong_extras.pxd
@@ -4,101 +4,17 @@
 from sage.libs.flint.flint cimport *
 
 
-cdef extern from "FLINT/long_extras.h":
+cdef extern from "FLINT/ulong_extras.h":
 
-    ctypedef struct factor_t: 
+    ctypedef struct n_factor_t: 
         int num 
         unsigned long p[15] 
         unsigned long exp[15] 
 
-    cdef unsigned long z_randint(unsigned long limit)
+    cdef int n_jacobi(long x, unsigned long y)
 
-    cdef unsigned long z_randbits(unsigned long bits)
+    cdef int n_is_prime(unsigned long n)
 
-    cdef unsigned long z_randprime(unsigned long bits, int proved)
+    cdef unsigned long n_gcd(long x, long y)
 
-    cdef double z_precompute_inverse(unsigned long n)
-
-    cdef double z_precompute_inverse2(unsigned long n)
-
-    cdef double z_ll_precompute_inverse(unsigned long n)
-
-    cdef unsigned long z_addmod(unsigned long a, unsigned long b, unsigned long p)
-
-    cdef unsigned long z_submod(unsigned long a, unsigned long b, unsigned long p)
-
-    cdef unsigned long z_negmod(unsigned long a, unsigned long p)
-
-    cdef unsigned long z_mod_precomp(unsigned long a, unsigned long n, double ninv)
-
-    cdef unsigned long z_div2_precomp(unsigned long a, unsigned long n, double ninv)
-
-    cdef unsigned long z_mod2_precomp(unsigned long a, unsigned long n, double ninv)
-
-    cdef unsigned long z_ll_mod_precomp(unsigned long a_hi, unsigned long a_lo, unsigned long n, double ninv)
-
-    cdef unsigned long z_mulmod_precomp(unsigned long a, unsigned long b, unsigned long n, double ninv)
-
-    cdef unsigned long z_mulmod2_precomp(unsigned long a, unsigned long b, unsigned long n, double ninv)
-
-    cdef unsigned long z_powmod(unsigned long a, long exp, unsigned long n)
-
-    cdef unsigned long z_powmod2(unsigned long a, long exp, unsigned long n)
-
-    cdef unsigned long z_powmod_precomp(unsigned long a, long exp, unsigned long n, double ninv)
-
-    cdef unsigned long z_powmod2_precomp(unsigned long a, long exp, unsigned long n, double ninv)
-
-    cdef int z_legendre_precomp(unsigned long a, unsigned long p, double pinv)
-
-    cdef int z_jacobi(long x, unsigned long y)
-
-    cdef int z_ispseudoprime_fermat(unsigned long n, unsigned long i)
-
-    cdef int z_isprime(unsigned long n)
-
-    cdef int z_isprime_precomp(unsigned long n, double ninv)
-
-    cdef unsigned long z_nextprime(unsigned long n, int proved)
-
-    cdef int z_isprime_pocklington(unsigned long n, unsigned long iterations)
-
-    cdef int z_ispseudoprime_lucas_ab(unsigned long n, int a, int b)
-
-    cdef int z_ispseudoprime_lucas(unsigned long n)
-
-    cdef unsigned long z_pow(unsigned long a, unsigned long exp)
-
-    cdef unsigned long z_sqrtmod(unsigned long a, unsigned long p) 
-
-    cdef unsigned long z_cuberootmod(unsigned long * cuberoot1, unsigned long a, unsigned long p)
-
-    cdef unsigned long z_invert(unsigned long a, unsigned long p)
-    
-    cdef long z_gcd_invert(long* a, long x, long y)
-
-    cdef long z_extgcd(long* a, long* b, long x, long y)
-
-    cdef unsigned long z_gcd(long x, long y)
-
-    cdef unsigned long z_intsqrt(unsigned long r)
-
-    cdef int z_issquare(unsigned long x)
-
-    cdef unsigned long z_CRT(unsigned long x1, unsigned long n1, unsigned long x2, unsigned long n2)
-
-    cdef int z_issquarefree(unsigned long n, int proved)
-
-    cdef int z_remove_precomp(unsigned long * n, unsigned long p, double pinv)
-
-    cdef int z_remove(unsigned long * n, unsigned long p)
-
-    cdef unsigned long z_factor_SQUFOF(unsigned long n)
-
-    cdef unsigned long z_primitive_root(unsigned long p)
-
-    cdef unsigned long z_primitive_root_precomp(unsigned long p, double p_inv)
-
-    cdef void z_factor(factor_t * factors, unsigned long n, int proved)
-
-
+    cdef void n_factor(n_factor_t * factors, unsigned long n, int proved)
diff --git a/sage/libs/flint/zmod_poly_linkage.pxi b/sage/libs/flint/zmod_poly_linkage.pxi
--- a/sage/libs/flint/zmod_poly_linkage.pxi
+++ b/sage/libs/flint/zmod_poly_linkage.pxi
@@ -387,7 +387,7 @@
     zmod_poly_init(q, n)
     leadcoeff = zmod_poly_get_coeff_ui(b, zmod_poly_degree(b))
     modulus = zmod_poly_modulus(b)
-    if (leadcoeff > 1 and z_gcd(modulus,leadcoeff) != 1):
+    if (leadcoeff > 1 and n_gcd(modulus,leadcoeff) != 1):
         raise ValueError("Leading coefficient of a must be invertible.")
 
     zmod_poly_divrem(q, res, a, b)
@@ -420,7 +420,7 @@
 
     leadcoeff = zmod_poly_get_coeff_ui(b, zmod_poly_degree(b))
     modulus = zmod_poly_modulus(b)
-    if (leadcoeff > 1 and z_gcd(modulus,leadcoeff) != 1):
+    if (leadcoeff > 1 and n_gcd(modulus,leadcoeff) != 1):
         raise ValueError("Leading coefficient of a must be invertible.")
 
     zmod_poly_divrem(q, r, a, b)
@@ -569,7 +569,7 @@
     zmod_poly_gcd(res, a, b)
     cdef unsigned long leadcoeff = zmod_poly_get_coeff_ui(res, zmod_poly_degree(res))
     cdef unsigned long modulus = zmod_poly_modulus(res)
-    if z_gcd(modulus,leadcoeff) == 1:
+    if n_gcd(modulus,leadcoeff) == 1:
         zmod_poly_make_monic(res, res)
 
 cdef 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:
diff --git a/sage/rings/integer.pyx b/sage/rings/integer.pyx
--- a/sage/rings/integer.pyx
+++ b/sage/rings/integer.pyx
@@ -165,7 +165,7 @@
     cdef void t_INT_to_ZZ( mpz_t value, long *g )
     
 from sage.libs.pari.gen cimport gen as pari_gen, PariInstance
-from sage.libs.flint.long_extras cimport * 
+from sage.libs.flint.ulong_extras cimport * 
 
 import sage.rings.infinity
 import sage.libs.pari.all
@@ -3268,7 +3268,7 @@
             if proof is None:
                 from sage.structure.proof.proof import get_flag
                 proof = get_flag(proof, "arithmetic")
-            z_factor(&f, mpz_get_ui(n.value), proof)
+            n_factor(&f, mpz_get_ui(n.value), proof)
             F = [(Integer(f.p[i]), int(f.exp[i])) for i from 0 <= i < f.num]
             F.sort()
             return IntegerFactorization(F, unit=unit, unsafe=True, 
diff --git a/sage/schemes/elliptic_curves/descent_two_isogeny.pyx b/sage/schemes/elliptic_curves/descent_two_isogeny.pyx
--- a/sage/schemes/elliptic_curves/descent_two_isogeny.pyx
+++ b/sage/schemes/elliptic_curves/descent_two_isogeny.pyx
@@ -268,8 +268,7 @@
 cdef bint Zp_soluble_siksek(mpz_t a, mpz_t b, mpz_t c, mpz_t d, mpz_t e,
                             mpz_t pp, unsigned long pp_ui,
                             zmod_poly_factor_t f_factzn, zmod_poly_t f,
-                            fmpz_poly_t f1, fmpz_poly_t linear,
-                            double pp_ui_inv):
+                            fmpz_poly_t f1, fmpz_poly_t linear):
     """
     Uses the approach of Algorithm 5.3.1 of Siksek's thesis to test for
     solubility of y^2 == ax^4 + bx^3 + cx^2 + dx + e over Zp.
@@ -321,7 +320,7 @@
             if f_factzn.exponents[i]&1:
                 result = 1
                 break
-        if result == 0 and z_legendre_precomp(qq, pp_ui, pp_ui_inv) == 1:
+        if result == 0 and n_jacobi(qq, pp_ui) == 1:
             result = 1
         if result:
             return 1
@@ -428,7 +427,7 @@
                 fmpz_poly_get_coeff_mpz(cc, f1, 2)
                 fmpz_poly_get_coeff_mpz(dd, f1, 1)
                 fmpz_poly_get_coeff_mpz(ee, f1, 0)
-                result = Zp_soluble_siksek(aa, bb, cc, dd, ee, pp, pp_ui, f_factzn, f, f1, linear, pp_ui_inv)
+                result = Zp_soluble_siksek(aa, bb, cc, dd, ee, pp, pp_ui, f_factzn, f, f1, linear)
                 mpz_clear(aa)
                 mpz_clear(bb)
                 mpz_clear(cc)
@@ -491,7 +490,7 @@
             fmpz_poly_get_coeff_mpz(cc, f1, 2)
             fmpz_poly_get_coeff_mpz(dd, f1, 1)
             fmpz_poly_get_coeff_mpz(ee, f1, 0)
-            result = Zp_soluble_siksek(aa, bb, cc, dd, ee, pp, pp_ui, f_factzn, f, f1, linear, pp_ui_inv)
+            result = Zp_soluble_siksek(aa, bb, cc, dd, ee, pp, pp_ui, f_factzn, f, f1, linear)
             if result == 1:
                 break
         if j > 0:
@@ -752,7 +751,6 @@
     cdef int result = 0
     cdef mpz_t a,b,c,d,e
     cdef zmod_poly_t f
-    cdef double pp_ui_inv = z_precompute_inverse(P)
     zmod_poly_init(f, P)
 
     mpz_init_set(a,A)
@@ -761,7 +759,7 @@
     mpz_init_set(d,D)
     mpz_init_set(e,E)
 
-    if Zp_soluble_siksek(a,b,c,d,e,p,P,f_factzn, f, f1, linear, pp_ui_inv):
+    if Zp_soluble_siksek(a,b,c,d,e,p,P,f_factzn, f, f1, linear):
         result = 1
     else:
         mpz_set(a,A)
@@ -769,7 +767,7 @@
         mpz_set(c,C)
         mpz_set(d,D)
         mpz_set(e,E)
-        if Zp_soluble_siksek(e,d,c,b,a,p,P,f_factzn, f, f1, linear, pp_ui_inv):
+        if Zp_soluble_siksek(e,d,c,b,a,p,P,f_factzn, f, f1, linear):
             result = 1
 
     mpz_clear(a)
@@ -1229,13 +1227,13 @@
         p_list_mpz = <mpz_t *> sage_malloc(20 * sizeof(mpz_t))
         mpz_init_set_ui(p_list_mpz[0], ui2)
         p_list_len = 1
-        z_factor(&fact, mpz_get_ui(d_mpz), proof)
+        n_factor(&fact, mpz_get_ui(d_mpz), proof)
         for i from 0 <= i < fact.num:
             p = fact.p[i]
             if p != ui2:
                 mpz_init_set_ui(p_list_mpz[p_list_len], p)
                 p_list_len += 1
-        z_factor(&fact, mpz_get_ui(d_prime_mpz), proof)
+        n_factor(&fact, mpz_get_ui(d_prime_mpz), proof)
         for i from 0 <= i < fact.num:
             p = fact.p[i]
             found = 0
