Ticket #12173: ulong_extras.patch
File ulong_extras.patch, 10.2 KB (added by , 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 13 13 cdef extern from "stdlib.h": 14 14 int rand() 15 15 16 cdef extern from "FLINT/ long_extras.h":17 int z_isprime(unsigned long n)16 cdef extern from "FLINT/ulong_extras.h": 17 int n_is_prime(unsigned long n) 18 18 19 19 cdef struct OrbitPartition: 20 20 # 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 4 4 from sage.libs.flint.flint cimport * 5 5 6 6 7 cdef extern from "FLINT/ long_extras.h":7 cdef extern from "FLINT/ulong_extras.h": 8 8 9 ctypedef struct factor_t:9 ctypedef struct n_factor_t: 10 10 int num 11 11 unsigned long p[15] 12 12 unsigned long exp[15] 13 13 14 cdef unsigned long z_randint(unsigned long limit)14 cdef int n_jacobi(long x, unsigned long y) 15 15 16 cdef unsigned long z_randbits(unsigned long bits)16 cdef int n_is_prime(unsigned long n) 17 17 18 cdef unsigned long z_randprime(unsigned long bits, int proved)18 cdef unsigned long n_gcd(long x, long y) 19 19 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 387 387 zmod_poly_init(q, n) 388 388 leadcoeff = zmod_poly_get_coeff_ui(b, zmod_poly_degree(b)) 389 389 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): 391 391 raise ValueError("Leading coefficient of a must be invertible.") 392 392 393 393 zmod_poly_divrem(q, res, a, b) … … 420 420 421 421 leadcoeff = zmod_poly_get_coeff_ui(b, zmod_poly_degree(b)) 422 422 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): 424 424 raise ValueError("Leading coefficient of a must be invertible.") 425 425 426 426 zmod_poly_divrem(q, r, a, b) … … 569 569 zmod_poly_gcd(res, a, b) 570 570 cdef unsigned long leadcoeff = zmod_poly_get_coeff_ui(res, zmod_poly_degree(res)) 571 571 cdef unsigned long modulus = zmod_poly_modulus(res) 572 if z_gcd(modulus,leadcoeff) == 1:572 if n_gcd(modulus,leadcoeff) == 1: 573 573 zmod_poly_make_monic(res, res) 574 574 575 575 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: -
sage/rings/integer.pyx
diff --git a/sage/rings/integer.pyx b/sage/rings/integer.pyx
a b 165 165 cdef void t_INT_to_ZZ( mpz_t value, long *g ) 166 166 167 167 from sage.libs.pari.gen cimport gen as pari_gen, PariInstance 168 from sage.libs.flint. long_extras cimport *168 from sage.libs.flint.ulong_extras cimport * 169 169 170 170 import sage.rings.infinity 171 171 import sage.libs.pari.all … … 3268 3268 if proof is None: 3269 3269 from sage.structure.proof.proof import get_flag 3270 3270 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) 3272 3272 F = [(Integer(f.p[i]), int(f.exp[i])) for i from 0 <= i < f.num] 3273 3273 F.sort() 3274 3274 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 268 268 cdef bint Zp_soluble_siksek(mpz_t a, mpz_t b, mpz_t c, mpz_t d, mpz_t e, 269 269 mpz_t pp, unsigned long pp_ui, 270 270 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): 273 272 """ 274 273 Uses the approach of Algorithm 5.3.1 of Siksek's thesis to test for 275 274 solubility of y^2 == ax^4 + bx^3 + cx^2 + dx + e over Zp. … … 321 320 if f_factzn.exponents[i]&1: 322 321 result = 1 323 322 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: 325 324 result = 1 326 325 if result: 327 326 return 1 … … 428 427 fmpz_poly_get_coeff_mpz(cc, f1, 2) 429 428 fmpz_poly_get_coeff_mpz(dd, f1, 1) 430 429 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) 432 431 mpz_clear(aa) 433 432 mpz_clear(bb) 434 433 mpz_clear(cc) … … 491 490 fmpz_poly_get_coeff_mpz(cc, f1, 2) 492 491 fmpz_poly_get_coeff_mpz(dd, f1, 1) 493 492 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) 495 494 if result == 1: 496 495 break 497 496 if j > 0: … … 752 751 cdef int result = 0 753 752 cdef mpz_t a,b,c,d,e 754 753 cdef zmod_poly_t f 755 cdef double pp_ui_inv = z_precompute_inverse(P)756 754 zmod_poly_init(f, P) 757 755 758 756 mpz_init_set(a,A) … … 761 759 mpz_init_set(d,D) 762 760 mpz_init_set(e,E) 763 761 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): 765 763 result = 1 766 764 else: 767 765 mpz_set(a,A) … … 769 767 mpz_set(c,C) 770 768 mpz_set(d,D) 771 769 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): 773 771 result = 1 774 772 775 773 mpz_clear(a) … … 1229 1227 p_list_mpz = <mpz_t *> sage_malloc(20 * sizeof(mpz_t)) 1230 1228 mpz_init_set_ui(p_list_mpz[0], ui2) 1231 1229 p_list_len = 1 1232 z_factor(&fact, mpz_get_ui(d_mpz), proof)1230 n_factor(&fact, mpz_get_ui(d_mpz), proof) 1233 1231 for i from 0 <= i < fact.num: 1234 1232 p = fact.p[i] 1235 1233 if p != ui2: 1236 1234 mpz_init_set_ui(p_list_mpz[p_list_len], p) 1237 1235 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) 1239 1237 for i from 0 <= i < fact.num: 1240 1238 p = fact.p[i] 1241 1239 found = 0