Ticket #12173: trac_12173-fixes-v6.patch
File trac_12173-fixes-v6.patch, 68.9 KB (added by , 9 years ago) |
---|
-
module_list.py
# HG changeset patch # User Jeroen Demeyer <jdemeyer@cage.ugent.be> # Date 1366201521 -7200 # Node ID 7e5a130a5b6be6fa928cc3adc88567328eb250e7 # Parent 2d7a660149792562f28e8cc0c578aacea4e4f7c7 Manual fixes diff --git a/module_list.py b/module_list.py
a b 1445 1445 Extension('sage.rings.fraction_field_FpT', 1446 1446 sources = ['sage/rings/fraction_field_FpT.pyx'], 1447 1447 libraries = ["csage", "flint", "gmp", "gmpxx", "ntl", "zn_poly"], 1448 extra_compile_args=["-std=c99", "-D_XPG6"],1448 language = 'c++', 1449 1449 include_dirs = [SAGE_INC + '/FLINT'], 1450 1450 depends = flint_depends), 1451 1451 … … 1725 1725 Extension('sage.rings.polynomial.polynomial_zmod_flint', 1726 1726 sources = ['sage/rings/polynomial/polynomial_zmod_flint.pyx'], 1727 1727 libraries = ["csage", "flint", "gmp", "gmpxx", "ntl", "zn_poly"], 1728 extra_compile_args=["-std=c99", "-D_XPG6"],1728 language = 'c++', 1729 1729 include_dirs = [SAGE_INC + '/FLINT'], 1730 1730 depends = flint_depends), 1731 1731 … … 1743 1743 include_dirs = ['sage/libs/ntl/']), 1744 1744 1745 1745 Extension('sage.rings.polynomial.polynomial_rational_flint', 1746 sources = ['sage/rings/polynomial/polynomial_rational_flint.pyx', 'sage/libs/flint/fmpq_poly.c'], 1746 sources = ['sage/rings/polynomial/polynomial_rational_flint.pyx'], 1747 libraries = ["csage", "flint", "ntl", "gmpxx", "gmp"], 1747 1748 language = 'c++', 1748 extra_compile_args=["-std=c99"] + uname_specific('SunOS', [], ['-D_XPG6']),1749 libraries = ["csage", "flint", "ntl", "gmpxx", "gmp"],1750 1749 include_dirs = [SAGE_INC + '/FLINT', 'sage/libs/flint/'], 1751 1750 depends = flint_depends), 1752 1751 -
sage/algebras/quatalg/quaternion_algebra_element.pyx
diff --git a/sage/algebras/quatalg/quaternion_algebra_element.pyx b/sage/algebras/quatalg/quaternion_algebra_element.pyx
a b 1988 1988 # Implementation-wise, we compute the GCD's one at a time, 1989 1989 # and quit if it ever becomes one 1990 1990 1991 cdef fmpz_t content = fmpz_init(fmpz_poly_max_limbs(self.x)) # TODO: think about how big this should be (probably the size of d) 1992 # Note that we have to allocate this here, and not 1993 # as a global variable, because fmpz_t's do not 1994 # self allocate memory 1991 cdef fmpz_t content 1992 fmpz_init(content) 1995 1993 fmpz_poly_content(content, self.x) 1996 1994 fmpz_get_mpz(U1, content) 1997 1995 mpz_gcd(U1, self.d, U1) … … 2008 2006 fmpz_get_mpz(U2, content) 2009 2007 mpz_gcd(U1, U1, U2) 2010 2008 if mpz_cmp_ui(U1, 1) != 0: 2011 fmpz_poly_scalar_ fdiv_mpz(self.x, self.x, U1)2012 fmpz_poly_scalar_ fdiv_mpz(self.y, self.y, U1)2013 fmpz_poly_scalar_ fdiv_mpz(self.z, self.z, U1)2014 fmpz_poly_scalar_ fdiv_mpz(self.w, self.w, U1)2009 fmpz_poly_scalar_divexact_mpz(self.x, self.x, U1) 2010 fmpz_poly_scalar_divexact_mpz(self.y, self.y, U1) 2011 fmpz_poly_scalar_divexact_mpz(self.z, self.z, U1) 2012 fmpz_poly_scalar_divexact_mpz(self.w, self.w, U1) 2015 2013 mpz_divexact(self.d, self.d, U1) 2016 2014 2017 2015 fmpz_clear(content) -
sage/ext/gen_interpreters.py
diff --git a/sage/ext/gen_interpreters.py b/sage/ext/gen_interpreters.py
a b 193 193 that we have to incref/decref at appropriate places. 194 194 195 195 Third is "auto-reference" types. This is how 196 GMP/MPIR/MPFR/MPFI/ flinttypes work. For these types, functions196 GMP/MPIR/MPFR/MPFI/FLINT types work. For these types, functions 197 197 expect arguments to be passed by reference, and the C assignment 198 198 operator does not do what we want. In addition, they take 199 199 advantage of a quirk in C (where arrays are automatically … … 793 793 class StorageTypeAutoReference(StorageType): 794 794 r""" 795 795 StorageTypeAutoReference is a subtype of StorageType that deals with 796 types in the style of GMP/MPIR/MPFR/MPFI/ flint, where copies are796 types in the style of GMP/MPIR/MPFR/MPFI/FLINT, where copies are 797 797 not cheap, functions expect arguments to be passed by reference, 798 798 and the API takes advantage of the C quirk where arrays are 799 799 automatically converted to pointers to automatically pass -
sage/graphs/matchpoly.pyx
diff --git a/sage/graphs/matchpoly.pyx b/sage/graphs/matchpoly.pyx
a b 359 359 """ 360 360 cdef int i, j, k, edge1, edge2, new_edge1, new_edge2, new_nedges 361 361 cdef int *edges1, *edges2, *new_edges1, *new_edges2 362 cdef fmpz _tcoeff362 cdef fmpz * coeff 363 363 364 364 if nverts == 3: 365 365 coeff = fmpz_poly_get_coeff_ptr(pol, 3) 366 366 if coeff is NULL: 367 367 fmpz_poly_set_coeff_ui(pol, 3, 1) 368 368 else: 369 fmpz_add_ui _inplace(coeff, 1)369 fmpz_add_ui(coeff, coeff, 1) 370 370 coeff = fmpz_poly_get_coeff_ptr(pol, 1) 371 371 if coeff is NULL: 372 372 fmpz_poly_set_coeff_ui(pol, 1, nedges) 373 373 else: 374 fmpz_add_ui _inplace(coeff, nedges)374 fmpz_add_ui(coeff, coeff, nedges) 375 375 return 376 376 377 377 if nedges == 0: … … 379 379 if coeff is NULL: 380 380 fmpz_poly_set_coeff_ui(pol, nverts, 1) 381 381 else: 382 fmpz_add_ui _inplace(coeff, 1)382 fmpz_add_ui(coeff, coeff, 1) 383 383 return 384 384 385 385 edges1 = edges[2*depth] -
sage/groups/perm_gps/partn_ref/data_structures_pxd.pxi
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 1 2 1 #***************************************************************************** 3 2 # Copyright (C) 2006 - 2011 Robert L. Miller <rlmillster@gmail.com> 4 3 # … … 60 59 61 60 int **generators # generators for each level, 62 61 int **gen_inverses # and their inverses 63 62 64 63 bitset_s gen_used 65 64 bitset_s gen_is_id 66 65 int *perm_scratch -
sage/libs/flint/flint.pxd
diff --git a/sage/libs/flint/flint.pxd b/sage/libs/flint/flint.pxd
a b 1 cdef extern from "flint .h":1 cdef extern from "flint/flint.h": 2 2 3 3 cdef long FLINT_BITS 4 4 cdef long FLINT_D_BITS 5 5 6 6 cdef unsigned long FLINT_BIT_COUNT(unsigned long) 7 void flint_stack_cleanup() 7 void _fmpz_cleanup() 8 void _fmpz_cleanup_mpz_content() -
sage/libs/flint/flint.pyx
diff --git a/sage/libs/flint/flint.pyx b/sage/libs/flint/flint.pyx
a b 14 14 include "../../ext/cdefs.pxi" 15 15 16 16 def free_flint_stack(): 17 flint_stack_cleanup()17 _fmpz_cleanup_mpz_content() -
sage/libs/flint/fmpq_poly.pxd
diff --git a/sage/libs/flint/fmpq_poly.pxd b/sage/libs/flint/fmpq_poly.pxd
a b 6 6 # http://www.gnu.org/licenses/ # 7 7 ############################################################################### 8 8 9 #include "fmpz_poly.pxi"10 #include "fmpz.pxi"11 12 9 cdef extern from "gmp.h": 13 10 ctypedef void * mpz_t 14 11 ctypedef void * mpq_t 15 12 13 cdef extern from "fmpq.h": 14 ctypedef void * fmpq_t 15 void fmpq_init(fmpq_t) 16 void fmpq_clear(fmpq_t) 17 void fmpq_get_mpq(mpq_t, fmpq_t) 18 void fmpq_set_mpq(fmpq_t, mpq_t) 19 20 cdef extern from "fmpz_vec.h": 21 long _fmpz_vec_max_limbs(void * c, long n) 22 16 23 cdef extern from "fmpq_poly.h": 17 24 ctypedef void * fmpz_t 18 ctypedef void * fmpz_poly_p 19 struct fmpq_poly: 20 fmpz_poly_p num 21 fmpz_t den 22 23 ctypedef fmpq_poly fmpq_poly_struct 24 ctypedef fmpq_poly_struct fmpq_poly_t[1] 25 ctypedef void * fmpq_poly_t 25 26 26 void * fmpq_poly_canonicalize(fmpq_poly_t, fmpz_t)27 void fmpq_poly_canonicalise(fmpq_poly_t) 27 28 28 29 void * fmpq_poly_numref(fmpq_poly_t) 29 30 void * fmpq_poly_denref(fmpq_poly_t) … … 40 41 void fmpq_poly_zero(fmpq_poly_t) 41 42 void fmpq_poly_neg(fmpq_poly_t, fmpq_poly_t) 42 43 44 void fmpq_poly_get_numerator(fmpz_poly_t, fmpq_poly_t) 45 43 46 void fmpq_poly_get_coeff_mpq(mpq_t, fmpq_poly_t, unsigned long) 44 47 void fmpq_poly_set_coeff_si(fmpq_poly_t, unsigned long, long) 45 48 void fmpq_poly_set_coeff_mpq(fmpq_poly_t, unsigned long, mpq_t) 46 49 void fmpq_poly_set_coeff_mpz(fmpq_poly_t, unsigned long, mpz_t) 47 50 48 51 int fmpq_poly_equal(fmpq_poly_t, fmpq_poly_t) 49 52 int fmpq_poly_cmp(fmpq_poly_t, fmpq_poly_t) 50 53 int fmpq_poly_is_zero(fmpq_poly_t) 51 54 52 55 long fmpq_poly_degree(fmpq_poly_t) 53 56 unsigned long fmpq_poly_length(fmpq_poly_t) 54 57 55 58 void fmpq_poly_add(fmpq_poly_t, fmpq_poly_t, fmpq_poly_t) 56 59 void fmpq_poly_sub(fmpq_poly_t, fmpq_poly_t, fmpq_poly_t) 57 60 58 61 void fmpq_poly_scalar_mul_mpq(fmpq_poly_t, fmpq_poly_t, mpq_t) 59 62 void fmpq_poly_scalar_div_mpq(fmpq_poly_t, fmpq_poly_t, mpq_t) 60 63 61 64 void fmpq_poly_mul(fmpq_poly_t, fmpq_poly_t, fmpq_poly_t) 62 65 63 66 void fmpq_poly_divrem(fmpq_poly_t, fmpq_poly_t, fmpq_poly_t, fmpq_poly_t) … … 68 71 69 72 void fmpq_poly_shift_left(fmpq_poly_t, fmpq_poly_t, unsigned long) 70 73 void fmpq_poly_shift_right(fmpq_poly_t, fmpq_poly_t, unsigned long) 71 74 72 75 void fmpq_poly_gcd(fmpq_poly_t, fmpq_poly_t, fmpq_poly_t) 73 void fmpq_poly_xgcd(fmpq_poly_t, fmpq_poly_t, fmpq_poly_t, fmpq_poly_t, fmpq_poly_t) 76 void fmpq_poly_xgcd(fmpq_poly_t, fmpq_poly_t, fmpq_poly_t, fmpq_poly_t, \ 77 fmpq_poly_t) 74 78 void fmpq_poly_lcm(fmpq_poly_t, fmpq_poly_t, fmpq_poly_t) 75 79 76 80 void fmpq_poly_derivative(fmpq_poly_t, fmpq_poly_t) … … 78 82 void fmpq_poly_evaluate_mpz(mpq_t, fmpq_poly_t, mpz_t) 79 83 void fmpq_poly_evaluate_mpq(mpq_t, fmpq_poly_t, mpq_t) 80 84 81 void fmpq_poly_content( mpq_t, fmpq_poly_t)85 void fmpq_poly_content(fmpq_t, fmpq_poly_t) 82 86 void fmpq_poly_primitive_part(fmpq_poly_t, fmpq_poly_t) 83 87 84 void fmpq_poly_resultant( mpq_t, fmpq_poly_t, fmpq_poly_t)88 void fmpq_poly_resultant(fmpq_t, fmpq_poly_t, fmpq_poly_t) 85 89 86 90 void fmpq_poly_compose(fmpq_poly_t, fmpq_poly_t, fmpq_poly_t) 87 91 88 void fmpq_poly_get_slice(fmpq_poly_t, fmpq_poly_t, unsigned long, unsignedlong)89 void fmpq_poly_truncate(fmpq_poly_t, fmpq_poly_t,unsigned long)92 void fmpq_poly_get_slice(fmpq_poly_t, fmpq_poly_t, long, long) 93 void fmpq_poly_truncate(fmpq_poly_t, unsigned long) 90 94 void fmpq_poly_reverse(fmpq_poly_t, fmpq_poly_t, unsigned long) 91 95 92 96 void fmpq_poly_set_array_mpq(fmpq_poly_t, mpq_t *, unsigned long) 93 97 void fmpq_poly_from_string(fmpq_poly_t, char *) 94 98 char * fmpq_poly_to_string(fmpq_poly_t, char *) 95 99 char * fmpq_poly_to_string_pretty(fmpq_poly_t, char *) 96 -
sage/libs/flint/fmpz.pxi
diff --git a/sage/libs/flint/fmpz.pxi b/sage/libs/flint/fmpz.pxi
a b 1 1 include "../ntl/decl.pxi" 2 2 3 3 cdef extern from "flint/fmpz.h": 4 5 ctypedef void * fmpz_t 4 5 ctypedef long fmpz 6 ctypedef long * fmpz_t 6 7 ctypedef void * mpz_t 7 8 8 fmpz_t fmpz_init(unsigned long limbs)9 void fmpz_init(fmpz_t x) 9 10 10 11 void fmpz_set_ui(fmpz_t res, unsigned long x) 11 12 void fmpz_set_si(fmpz_t res, long x) 12 13 13 14 void fmpz_clear(fmpz_t f) 14 15 void fmpz_print(fmpz_t f) 15 16 int fmpz_is_one(fmpz_t f) 16 17 17 void fmpz_add_ui_inplace(fmpz_t output, unsigned long x)18 void fmpz_sub_ui_inplace(fmpz_t output, unsigned long x)19 20 18 void fmpz_get_mpz(mpz_t rop, fmpz_t op) 21 19 void fmpz_set_mpz(fmpz_t rop, mpz_t op) 22 20 21 void fmpz_add_ui(fmpz_t f, fmpz_t g, unsigned long c) -
sage/libs/flint/fmpz_poly.pxi
diff --git a/sage/libs/flint/fmpz_poly.pxi b/sage/libs/flint/fmpz_poly.pxi
a b 1 1 include "fmpz.pxi" 2 2 include "../ntl/decl.pxi" 3 3 4 from sage.libs.flint.nmod_poly cimport nmod_poly_t 5 4 6 cdef extern from "flint/fmpz_poly.h": 5 6 7 ctypedef void* fmpz_poly_t 7 8 8 9 void fmpz_poly_init(fmpz_poly_t poly) 9 void fmpz_poly_init2(fmpz_poly_t poly, unsigned long alloc, \ 10 unsigned long limbs) 10 void fmpz_poly_init2(fmpz_poly_t poly, unsigned long alloc) 11 11 void fmpz_poly_realloc(fmpz_poly_t poly, unsigned long alloc) 12 12 13 13 void fmpz_poly_fit_length(fmpz_poly_t poly, unsigned long alloc) 14 void fmpz_poly_resize_limbs(fmpz_poly_t poly, unsigned long limbs)15 void fmpz_poly_fit_limbs(fmpz_poly_t poly, unsigned long limbs)16 unsigned long fmpz_poly_limbs(fmpz_poly_t poly)17 14 18 15 void fmpz_poly_clear(fmpz_poly_t poly) 19 16 20 17 long fmpz_poly_degree(fmpz_poly_t poly) 21 18 unsigned long fmpz_poly_length(fmpz_poly_t poly) 22 19 23 24 20 void fmpz_poly_set_length(fmpz_poly_t poly, unsigned long length) 25 21 void fmpz_poly_truncate(fmpz_poly_t poly, unsigned long length) 26 22 … … 31 27 unsigned long x) 32 28 void fmpz_poly_set_coeff_mpz(fmpz_poly_t poly, unsigned long n, mpz_t x) 33 29 void fmpz_poly_set_coeff_fmpz(fmpz_poly_t poly, unsigned long n, fmpz_t x) 34 30 35 31 void fmpz_poly_get_coeff_mpz(mpz_t x, fmpz_poly_t poly, unsigned long n) 36 void fmpz_poly_get_coeff_mpz_read_only(mpz_t x, fmpz_poly_t poly, unsigned long n) 37 fmpz_t fmpz_poly_get_coeff_ptr(fmpz_poly_t poly, unsigned long n) 32 void fmpz_poly_get_coeff_mpz_read_only(mpz_t x, fmpz_poly_t poly, \ 33 unsigned long n) 34 fmpz* fmpz_poly_get_coeff_ptr(fmpz_poly_t poly, unsigned long n) 35 36 void fmpz_poly_get_nmod_poly(nmod_poly_t res, fmpz_poly_t poly) 38 37 39 38 void fmpz_poly_add(fmpz_poly_t output, fmpz_poly_t input1, \ 40 39 fmpz_poly_t input2) … … 49 48 void fmpz_poly_mul_trunc_left_n(fmpz_poly_t output, fmpz_poly_t input1, \ 50 49 fmpz_poly_t input2, unsigned long trunc) 51 50 52 # void fmpz_poly_scalar_mul(fmpz_poly_t output, fmpz_poly_t input, fmpz_t x)53 51 void fmpz_poly_scalar_mul_ui(fmpz_poly_t output, fmpz_poly_t input, \ 54 52 unsigned long x) 55 53 void fmpz_poly_scalar_mul_si(fmpz_poly_t output, fmpz_poly_t input, long x) 56 54 57 void fmpz_poly_scalar_mul_mpz(fmpz_poly_t output, fmpz_poly_t poly, 55 void fmpz_poly_scalar_mul_mpz(fmpz_poly_t output, fmpz_poly_t poly, \ 58 56 mpz_t x) 57 void fmpz_poly_scalar_mul_fmpz(fmpz_poly_t output, fmpz_poly_t poly, \ 58 fmpz_t x) 59 59 60 60 void fmpz_poly_scalar_divexact_ui(fmpz_poly_t output, fmpz_poly_t poly, \ 61 61 unsigned long x) 62 62 void fmpz_poly_scalar_divexact_si(fmpz_poly_t output, fmpz_poly_t poly, \ 63 63 long x) 64 void fmpz_poly_scalar_divexact_mpz(fmpz_poly_t output, fmpz_poly_t poly, \ 65 mpz_t x) 64 66 void fmpz_poly_scalar_divexact_fmpz(fmpz_poly_t output, fmpz_poly_t poly, \ 65 67 fmpz_t x) 66 67 void fmpz_poly_scalar_fdiv_mpz( fmpz_poly_t output, fmpz_poly_t poly, mpz_t x) 68 69 void fmpz_poly_scalar_fdiv_ui(fmpz_poly_t output, fmpz_poly_t poly, \ 70 unsigned long x) 71 void fmpz_poly_scalar_fdiv_mpz(fmpz_poly_t output, fmpz_poly_t poly, \ 72 mpz_t x) 68 73 69 74 void fmpz_poly_div(fmpz_poly_t Q, fmpz_poly_t A, fmpz_poly_t B) 70 75 void fmpz_poly_divrem(fmpz_poly_t Q, fmpz_poly_t R, fmpz_poly_t A, \ 71 fmpz_poly_t B) 72 76 fmpz_poly_t B) 77 73 78 void fmpz_poly_pseudo_div(fmpz_poly_t Q, unsigned long *d, fmpz_poly_t A, \ 74 fmpz_poly_t B) 79 fmpz_poly_t B) 75 80 void fmpz_poly_pseudo_divrem(fmpz_poly_t Q, fmpz_poly_t R, \ 76 unsigned long *d, fmpz_poly_t A, fmpz_poly_t B) 77 78 int fmpz_poly_equal(fmpz_poly_t poly1, fmpz_poly_t poly2) 81 unsigned long *d, fmpz_poly_t A, fmpz_poly_t B) 79 82 80 bint fmpz_poly_set_str(fmpz_poly_t poly, char* s) 83 int fmpz_poly_equal(fmpz_poly_t poly1, fmpz_poly_t poly2) 84 85 int fmpz_poly_set_str(fmpz_poly_t poly, char* s) 81 86 char* fmpz_poly_get_str(fmpz_poly_t poly) 82 87 void fmpz_poly_print(fmpz_poly_t poly) 83 88 bint fmpz_poly_read(fmpz_poly_t poly) … … 87 92 void fmpz_poly_pow_trunc(fmpz_poly_t output, fmpz_poly_t poly, \ 88 93 unsigned long exp, unsigned long n) 89 94 90 void fmpz_poly_shift_left ( fmpz_poly_t output ,91 fmpz_poly_t poly , unsigned long n)92 void fmpz_poly_shift_right ( fmpz_poly_t output ,93 fmpz_poly_t poly , unsigned long n )95 void fmpz_poly_shift_left(fmpz_poly_t output, fmpz_poly_t poly, \ 96 unsigned long n) 97 void fmpz_poly_shift_right(fmpz_poly_t output, fmpz_poly_t poly, \ 98 unsigned long n) 94 99 95 void fmpz_poly_derivative ( fmpz_poly_t der , fmpz_poly_t poly)100 void fmpz_poly_derivative(fmpz_poly_t der, fmpz_poly_t poly) 96 101 97 102 void fmpz_poly_content(fmpz_t c, fmpz_poly_t poly) 98 103 void fmpz_poly_primitive_part(fmpz_poly_t prim, fmpz_poly_t poly) 99 104 100 void fmpz_poly_gcd(fmpz_poly_t res, fmpz_poly_t poly1, \ 101 fmpz_poly_t poly2) 105 void fmpz_poly_gcd(fmpz_poly_t res, fmpz_poly_t poly1, fmpz_poly_t poly2) 102 106 103 void fmpz_poly_xgcd(fmpz_t r, fmpz_poly_t s, fmpz_poly_t t, fmpz_poly_t a,\104 fmpz_poly_t b)107 void fmpz_poly_xgcd(fmpz_t r, fmpz_poly_t s, fmpz_poly_t t, \ 108 fmpz_poly_t a, fmpz_poly_t b) 105 109 106 110 unsigned long fmpz_poly_resultant_bound(fmpz_poly_t a, fmpz_poly_t b) 107 111 void fmpz_poly_resultant(fmpz_t r, fmpz_poly_t a, fmpz_poly_t b) 108 112 109 void fmpz_poly_invmod(fmpz_t d, fmpz_poly_t H, fmpz_poly_t poly1, fmpz_poly_t poly2) 113 void fmpz_poly_invmod(fmpz_t d, fmpz_poly_t H, fmpz_poly_t poly1, \ 114 fmpz_poly_t poly2) 110 115 void fmpz_poly_derivative(fmpz_poly_t der, fmpz_poly_t poly) 111 116 void fmpz_poly_evaluate_fmpz(fmpz_t output, fmpz_poly_t poly, fmpz_t val) 112 117 void fmpz_poly_compose(fmpz_poly_t output, fmpz_poly_t f, fmpz_poly_t g) 113 void fmpz_poly_scalar_fdiv_ui(fmpz_poly_t output, fmpz_poly_t poly, unsigned long x)114 118 115 119 unsigned long fmpz_poly_max_limbs(fmpz_poly_t poly) -
sage/libs/flint/fmpz_poly.pyx
diff --git a/sage/libs/flint/fmpz_poly.pyx b/sage/libs/flint/fmpz_poly.pyx
a b 53 53 cdef long c 54 54 cdef Integer w 55 55 if PY_TYPE_CHECK(v, str): 56 if fmpz_poly_set_str(self.poly, v):56 if not fmpz_poly_set_str(self.poly, v): 57 57 return 58 58 else: 59 59 raise ValueError, "Unable to create Fmpz_poly from that string." -
sage/libs/flint/nmod_poly.pxd
diff --git a/sage/libs/flint/nmod_poly.pxd b/sage/libs/flint/nmod_poly.pxd
a b 6 6 from flint import * 7 7 8 8 cdef extern from "flint/nmod_poly.h": 9 ctypedef unsigned long mp_bitcnt_t 10 ctypedef void * mp_srcptr 11 12 ctypedef struct nmod_t: 13 mp_limb_t n 14 mp_limb_t ninv 15 mp_bitcnt_t norm 16 9 17 ctypedef struct nmod_poly_struct: 10 unsigned long *coeffs 11 unsigned long alloc 12 unsigned long length 13 unsigned long p 14 double p_inv 18 mp_limb_t *coeffs 19 long alloc 20 long length 21 nmod_t mod 15 22 16 23 ctypedef nmod_poly_struct* nmod_poly_t 17 24 18 25 ctypedef struct nmod_poly_factor_struct: 19 nmod_poly_t *factors20 unsigned long *exponents21 unsigned long alloc22 unsigned long num_factors26 nmod_poly_t p 27 long *exp 28 long num 29 long alloc 23 30 24 31 ctypedef nmod_poly_factor_struct* nmod_poly_factor_t 25 32 26 cdef void nmod_poly_init(nmod_poly_t poly, unsigned long p) 27 cdef void nmod_poly_init_preinv(nmod_poly_t poly, unsigned long p, double p_inv) 28 cdef void nmod_poly_init2(nmod_poly_t poly, unsigned long p, unsigned long alloc) 29 cdef void nmod_poly_init2_preinv(nmod_poly_t poly, unsigned long p, double p_inv, unsigned long alloc) 33 # Memory management 34 cdef void nmod_poly_init(nmod_poly_t poly, mp_limb_t n) 35 cdef void nmod_poly_init_preinv(nmod_poly_t poly, mp_limb_t n, mp_limb_t ninv) 36 cdef void nmod_poly_init2(nmod_poly_t poly, mp_limb_t n, long alloc) 37 cdef void nmod_poly_init2_preinv(nmod_poly_t poly, mp_limb_t n, mp_limb_t ninv, long alloc) 38 30 39 cdef void nmod_poly_clear(nmod_poly_t poly) 31 40 32 cdef void nmod_poly_realloc(nmod_poly_t poly, unsigned long alloc) 33 # _bits_ only applies to newly allocated coefficients, not existing ones... 41 cdef void nmod_poly_realloc(nmod_poly_t poly, long alloc) 34 42 35 # this non-inlined version REQUIRES that alloc > poly->alloc36 void __nmod_poly_fit_length(nmod_poly_t poly, unsigned long alloc)43 cdef void nmod_poly_fit_length(nmod_poly_t poly, long alloc) 44 cdef void _nmod_poly_normalise(nmod_poly_t poly) 37 45 38 # this is arranged so that the initial comparison (very frequent) is inlined,39 # but the actual allocation (infrequent) is not40 cdef void nmod_poly_ fit_length(nmod_poly_t poly, unsigned long alloc)46 # Getting and setting coefficients 47 cdef unsigned long nmod_poly_get_coeff_ui(nmod_poly_t poly, unsigned long j) 48 cdef void nmod_poly_set_coeff_ui(nmod_poly_t poly, unsigned long j, unsigned long c) 41 49 42 # ------------------------------------------------------ 43 # Setting/retrieving coefficients 50 # Input and output 51 cdef char * nmod_poly_get_str(nmod_poly_t poly) 52 cdef int nmod_poly_set_str(char * s, nmod_poly_t poly) 53 cdef int nmod_poly_print(nmod_poly_t a) 54 cdef int nmod_poly_fread(FILE * f, nmod_poly_t poly) 55 cdef int nmod_poly_fprint(FILE * f, nmod_poly_t poly) 56 cdef int nmod_poly_read(nmod_poly_t poly) 44 57 45 cdef unsigned long nmod_poly_get_coeff_ui(nmod_poly_t poly, unsigned long n) 58 # Polynomial parameters 59 cdef long nmod_poly_length(nmod_poly_t poly) 60 cdef long nmod_poly_degree(nmod_poly_t poly) 61 cdef mp_limb_t nmod_poly_modulus(nmod_poly_t poly) 62 cdef mp_bitcnt_t nmod_poly_max_bits(nmod_poly_t poly) 46 63 47 cdef unsigned long _nmod_poly_get_coeff_ui(nmod_poly_t poly, unsigned long n) 64 # Assignment and basic manipulation 65 cdef void nmod_poly_set(nmod_poly_t a, nmod_poly_t b) 66 cdef void nmod_poly_swap(nmod_poly_t poly1, nmod_poly_t poly2) 67 cdef void nmod_poly_zero(nmod_poly_t res) 68 cdef void nmod_poly_one(nmod_poly_t res) 69 cdef void nmod_poly_truncate(nmod_poly_t poly, long len) 70 cdef void nmod_poly_reverse(nmod_poly_t output, nmod_poly_t input, long m) 71 cdef int nmod_poly_equal(nmod_poly_t a, nmod_poly_t b) 48 72 49 cdef void nmod_poly_set_coeff_ui(nmod_poly_t poly, unsigned long n, unsigned long c) 73 # Powering 74 cdef void nmod_poly_pow(nmod_poly_t res, nmod_poly_t poly, unsigned long e) 75 cdef void nmod_poly_pow_trunc(nmod_poly_t res, nmod_poly_t poly, unsigned long e, long trunc) 50 76 51 cdef void _nmod_poly_set_coeff_ui(nmod_poly_t poly, unsigned long n, unsigned long c) 77 # Inflation and deflation 78 cdef unsigned long nmod_poly_deflation(nmod_poly_t input) 79 cdef void nmod_poly_deflate(nmod_poly_t result, nmod_poly_t input, unsigned long deflation) 80 cdef void nmod_poly_inflate(nmod_poly_t result, nmod_poly_t input, unsigned long inflation) 52 81 53 # ------------------------------------------------------ 54 # String conversions and I/O 82 # Comparison 83 cdef int nmod_poly_is_zero(nmod_poly_t poly) 84 cdef int nmod_poly_is_one(nmod_poly_t poly) 55 85 56 cdef int nmod_poly_from_string(nmod_poly_t poly, char* s) 57 cdef char* nmod_poly_to_string(nmod_poly_t poly) 58 cdef void nmod_poly_print(nmod_poly_t poly) 59 cdef void nmod_poly_fprint(nmod_poly_t poly, FILE* f) 60 cdef int nmod_poly_read(nmod_poly_t poly) 61 cdef int nmod_poly_fread(nmod_poly_t poly, FILE* f) 86 # Addition and subtraction 87 cdef void nmod_poly_add(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 88 cdef void nmod_poly_sub(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 89 cdef void nmod_poly_neg(nmod_poly_t res, nmod_poly_t poly1) 62 90 63 # ------------------------------------------------------ 64 # Length and degree 91 # Shifting 92 cdef void nmod_poly_shift_left(nmod_poly_t res, nmod_poly_t poly, long k) 93 cdef void nmod_poly_shift_right(nmod_poly_t res, nmod_poly_t poly, long k) 65 94 66 cdef void _nmod_poly_normalise(nmod_poly_t poly) 67 cdef int _nmod_poly_normalised(nmod_poly_t poly) 68 cdef void nmod_poly_truncate(nmod_poly_t poly, unsigned long length) 95 # Multiplication 96 cdef void nmod_poly_mul(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 97 cdef void nmod_poly_mullow(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, long trunc) 98 cdef void nmod_poly_mulhigh(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, long n) 99 cdef void nmod_poly_mulmod(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, nmod_poly_t f) 69 100 70 cdef unsigned long nmod_poly_length(nmod_poly_t poly) 101 # Square roots 102 cdef void nmod_poly_invsqrt_series(nmod_poly_t g, nmod_poly_t h, long n) 103 cdef void nmod_poly_sqrt_series(nmod_poly_t g, nmod_poly_t h, long n) 104 int nmod_poly_sqrt(nmod_poly_t b, nmod_poly_t a) 71 105 72 cdef long nmod_poly_degree(nmod_poly_t poly) 106 # Scalar multiplication and division 107 cdef void nmod_poly_scalar_mul_nmod(nmod_poly_t res, nmod_poly_t poly1, mp_limb_t c) 108 cdef void nmod_poly_make_monic(nmod_poly_t output, nmod_poly_t input) 73 109 74 cdef unsigned long nmod_poly_modulus(nmod_poly_t poly) 110 # Division 111 cdef void nmod_poly_divrem(nmod_poly_t Q, nmod_poly_t R, nmod_poly_t A, nmod_poly_t B) 112 cdef void nmod_poly_div(nmod_poly_t Q, nmod_poly_t A, nmod_poly_t B) 113 cdef void nmod_poly_inv_series(nmod_poly_t Qinv, nmod_poly_t Q, long n) 114 cdef void nmod_poly_div_series(nmod_poly_t Q, nmod_poly_t A, nmod_poly_t B, long n) 75 115 76 cdef double nmod_poly_precomputed_inverse(nmod_poly_t poly) 116 # GCD 117 cdef void nmod_poly_gcd(nmod_poly_t G, nmod_poly_t A, nmod_poly_t B) 118 cdef void nmod_poly_xgcd(nmod_poly_t G, nmod_poly_t S, nmod_poly_t T, nmod_poly_t A, nmod_poly_t B) 119 mp_limb_t nmod_poly_resultant(nmod_poly_t f, nmod_poly_t g) 77 120 78 # ------------------------------------------------------79 # Assignment80 121 81 cdef void _nmod_poly_set(nmod_poly_t res, nmod_poly_t poly) 82 cdef void nmod_poly_set(nmod_poly_t res, nmod_poly_t poly) 122 # Evaluation 123 cdef mp_limb_t nmod_poly_evaluate_nmod(nmod_poly_t poly, mp_limb_t c) 124 cdef void nmod_poly_evaluate_nmod_vec(mp_ptr ys, nmod_poly_t poly, mp_srcptr xs, long n) 83 125 84 cdef void nmod_poly_zero(nmod_poly_t poly) 126 # Interpolation 127 cdef void nmod_poly_interpolate_nmod_vec(nmod_poly_t poly, mp_srcptr xs, mp_srcptr ys, long n) 85 128 86 cdef void nmod_poly_swap(nmod_poly_t poly1, nmod_poly_t poly2) 129 # Composition 130 cdef void nmod_poly_compose(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 87 131 88 # 89 # Subpolynomials90 #132 # Power series composition and reversion 133 cdef void nmod_poly_compose_series(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, long n) 134 cdef void nmod_poly_reverse_series(nmod_poly_t Qinv, nmod_poly_t Q, long n) 91 135 92 cdef void _nmod_poly_attach(nmod_poly_t output, nmod_poly_t input) 136 # Factoring 137 cdef void nmod_poly_factor_clear(nmod_poly_factor_t fac) 138 cdef void nmod_poly_factor_init(nmod_poly_factor_t fac) 139 cdef void nmod_poly_factor_insert(nmod_poly_factor_t fac, nmod_poly_t poly, unsigned long exp) 140 cdef void nmod_poly_factor_print(nmod_poly_factor_t fac) 141 cdef void nmod_poly_factor_concat(nmod_poly_factor_t res, nmod_poly_factor_t fac) 142 cdef void nmod_poly_factor_pow(nmod_poly_factor_t fac, unsigned long exp) 143 cdef unsigned long nmod_poly_remove(nmod_poly_t f, nmod_poly_t p) 144 cdef int nmod_poly_is_irreducible(nmod_poly_t f) 145 cdef int nmod_poly_is_squarefree(nmod_poly_t f) 146 cdef void nmod_poly_factor_cantor_zassenhaus(nmod_poly_factor_t res, nmod_poly_t f) 147 cdef void nmod_poly_factor_berlekamp(nmod_poly_factor_t factors, nmod_poly_t f) 148 cdef void nmod_poly_factor_squarefree(nmod_poly_factor_t res, nmod_poly_t f) 149 cdef mp_limb_t nmod_poly_factor_with_berlekamp(nmod_poly_factor_t result, nmod_poly_t input) 150 cdef mp_limb_t nmod_poly_factor_with_cantor_zassenhaus(nmod_poly_factor_t result, nmod_poly_t input) 151 cdef mp_limb_t nmod_poly_factor(nmod_poly_factor_t result, nmod_poly_t input) 93 152 94 cdef void nmod_poly_attach(nmod_poly_t output, nmod_poly_t input) 153 # Derivative 154 cdef void nmod_poly_derivative(nmod_poly_t x_prime, nmod_poly_t x) 155 cdef void nmod_poly_integral(nmod_poly_t x_int, nmod_poly_t x) 95 156 96 # 97 # Attach input shifted right by n to output 98 # 99 100 cdef void _nmod_poly_attach_shift(nmod_poly_t output, nmod_poly_t input, unsigned long n) 101 102 cdef void nmod_poly_attach_shift(nmod_poly_t output, nmod_poly_t input, unsigned long n) 103 104 # 105 # Attach input to first n coefficients of input 106 # 107 108 cdef void _nmod_poly_attach_truncate(nmod_poly_t output, nmod_poly_t input, unsigned long n) 109 110 cdef void nmod_poly_attach_truncate(nmod_poly_t output, nmod_poly_t input, unsigned long n) 111 112 # 113 # Comparison functions 114 # 115 116 cdef int nmod_poly_equal(nmod_poly_t poly1, nmod_poly_t poly2) 117 118 cdef int nmod_poly_is_one(nmod_poly_t poly1) 119 120 # 121 # Reversal 122 # 123 124 cdef void _nmod_poly_reverse(nmod_poly_t output, nmod_poly_t input, unsigned long length) 125 cdef void nmod_poly_reverse(nmod_poly_t output, nmod_poly_t input, unsigned long length) 126 127 # 128 # Monic polys 129 # 130 131 cdef void nmod_poly_make_monic(nmod_poly_t output, nmod_poly_t pol) 132 133 # 134 # Addition and subtraction 135 # 136 137 cdef void nmod_poly_add(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 138 cdef void nmod_poly_add_without_mod(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 139 cdef void nmod_poly_sub(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 140 cdef void _nmod_poly_sub(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 141 cdef void nmod_poly_neg(nmod_poly_t res, nmod_poly_t poly) 142 143 # 144 # Shifting functions 145 # 146 147 cdef void nmod_poly_left_shift(nmod_poly_t res, nmod_poly_t poly, unsigned long k) 148 cdef void nmod_poly_right_shift(nmod_poly_t res, nmod_poly_t poly, unsigned long k) 149 150 # 151 # Polynomial multiplication 152 # 153 # All multiplication functions require that the modulus be no more than FLINT_BITS-1 bits 154 # 155 156 cdef void nmod_poly_mul(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 157 cdef void nmod_poly_sqr(nmod_poly_t res, nmod_poly_t poly) 158 159 # Requires that poly1 bits + poly2 bits + log_length is not greater than 2*FLINT_BITS 160 161 cdef void nmod_poly_mul_KS(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits_input) 162 cdef void _nmod_poly_mul_KS(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits_input) 163 164 cdef void nmod_poly_mul_KS_trunc(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits_input, unsigned long trunc) 165 cdef void _nmod_poly_mul_KS_trunc(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits_input, unsigned long trunc) 166 167 cdef void _nmod_poly_mul_classical(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 168 cdef void __nmod_poly_mul_classical_mod_last(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits) 169 cdef void __nmod_poly_mul_classical_mod_throughout(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits) 170 cdef void nmod_poly_mul_classical(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 171 cdef void _nmod_poly_sqr_classical(nmod_poly_t res, nmod_poly_t poly) 172 cdef void nmod_poly_sqr_classical(nmod_poly_t res, nmod_poly_t poly) 173 174 cdef void _nmod_poly_mul_classical_trunc(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long trunc) 175 cdef void __nmod_poly_mul_classical_trunc_mod_last(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits, unsigned long trunc) 176 cdef void __nmod_poly_mul_classical_trunc_mod_throughout(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits, unsigned long trunc) 177 cdef void nmod_poly_mul_classical_trunc(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long trunc) 178 179 cdef void _nmod_poly_mul_classical_trunc_left(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long trunc) 180 cdef void __nmod_poly_mul_classical_trunc_left_mod_last(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits, unsigned long trunc) 181 cdef void __nmod_poly_mul_classical_trunc_left_mod_throughout(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long bits, unsigned long trunc) 182 cdef void nmod_poly_mul_classical_trunc_left(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long trunc) 183 184 cdef void nmod_poly_mullow(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long trunc) 185 cdef void nmod_poly_mulhigh(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, unsigned long trunc) 186 187 # 188 # Bit packing functions 189 # 190 191 cdef unsigned long nmod_poly_bits(nmod_poly_t poly) 192 cdef void _nmod_poly_bit_pack_mpn(mp_limb_t * res, nmod_poly_t poly, unsigned long bits, unsigned long length) 193 cdef void _nmod_poly_bit_unpack_mpn(nmod_poly_t poly, mp_limb_t *mpn, unsigned long length, unsigned long bits) 194 195 cdef void print_binary(unsigned long n, unsigned long len) 196 cdef void print_binary2(unsigned long n, unsigned long len, unsigned long space_bit) 197 198 # 199 # Scalar multiplication 200 # 201 202 cdef void _nmod_poly_scalar_mul_nmod(nmod_poly_t res, nmod_poly_t poly, unsigned long scalar) 203 cdef void nmod_poly_scalar_mul_nmod(nmod_poly_t res, nmod_poly_t poly, unsigned long scalar) 204 cdef void __nmod_poly_scalar_mul_without_mod(nmod_poly_t res, nmod_poly_t poly, unsigned long scalar) 205 206 # 207 # Division 208 # 209 210 cdef void nmod_poly_divrem_classical(nmod_poly_t Q, nmod_poly_t R, nmod_poly_t A, nmod_poly_t B) 211 cdef void __nmod_poly_divrem_classical_mod_last(nmod_poly_t Q, nmod_poly_t R, nmod_poly_t A, nmod_poly_t B) 212 cdef void nmod_poly_div_classical(nmod_poly_t Q, nmod_poly_t A, nmod_poly_t B) 213 cdef void __nmod_poly_div_classical_mod_last(nmod_poly_t Q, nmod_poly_t A, nmod_poly_t B) 214 cdef void nmod_poly_div_divconquer_recursive(nmod_poly_t Q, nmod_poly_t BQ, nmod_poly_t A, nmod_poly_t B) 215 cdef void nmod_poly_divrem_divconquer(nmod_poly_t Q, nmod_poly_t R, nmod_poly_t A, nmod_poly_t B) 216 cdef void nmod_poly_div_divconquer(nmod_poly_t Q, nmod_poly_t A, nmod_poly_t B) 217 218 # 219 # Newton Inversion 220 # 221 222 cdef void nmod_poly_newton_invert_basecase(nmod_poly_t Q_inv, nmod_poly_t Q, unsigned long n) 223 cdef void nmod_poly_newton_invert(nmod_poly_t Q_inv, nmod_poly_t Q, unsigned long n) 224 225 # 226 # Newton Division 227 # 228 229 cdef void nmod_poly_div_series(nmod_poly_t Q, nmod_poly_t A, nmod_poly_t B, unsigned long n) 230 cdef void nmod_poly_div_newton(nmod_poly_t Q, nmod_poly_t A, nmod_poly_t B) 231 cdef void nmod_poly_divrem_newton(nmod_poly_t Q, nmod_poly_t R, nmod_poly_t A, nmod_poly_t B) 232 233 cdef void nmod_poly_divrem(nmod_poly_t Q, nmod_poly_t R, nmod_poly_t A, nmod_poly_t B) 234 235 cdef void nmod_poly_div(nmod_poly_t Q, nmod_poly_t A, nmod_poly_t B) 236 237 # 238 # Resultant 239 # 240 241 cdef unsigned long nmod_poly_resultant_euclidean(nmod_poly_t a, nmod_poly_t b) 242 243 cdef unsigned long nmod_poly_resultant(nmod_poly_t a, nmod_poly_t b) 244 245 # 246 # GCD 247 # 248 249 cdef void nmod_poly_gcd(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 250 cdef int nmod_poly_gcd_invert(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2) 251 cdef void nmod_poly_xgcd(nmod_poly_t res, nmod_poly_t s, nmod_poly_t t, nmod_poly_t poly1, nmod_poly_t poly2) 252 253 254 255 # Composition / evaluation 256 257 cdef unsigned long nmod_poly_evaluate_nmod(nmod_poly_t, unsigned long) 258 cdef void nmod_poly_compose(nmod_poly_t, nmod_poly_t, nmod_poly_t) 259 260 # Factorization 261 262 cdef bint nmod_poly_is_irreducible(nmod_poly_t p) 263 264 ctypedef struct nmod_poly_factors_struct: 265 unsigned long num_factors 266 unsigned long* exponents 267 nmod_poly_t* factors 268 269 ctypedef nmod_poly_factors_struct* nmod_poly_factor_t 270 271 cdef void nmod_poly_factor_init(nmod_poly_factor_t) 272 cdef void nmod_poly_factor_clear(nmod_poly_factor_t) 273 cdef unsigned long nmod_poly_factor(nmod_poly_factor_t, nmod_poly_t) 274 cdef void nmod_poly_factor_squarefree(nmod_poly_factor_t, nmod_poly_t) 275 cdef void nmod_poly_factor_berlekamp(nmod_poly_factor_t factors, nmod_poly_t f) 276 277 cdef void nmod_poly_factor_add(nmod_poly_factor_t fac, nmod_poly_t poly) 278 cdef void nmod_poly_factor_concat(nmod_poly_factor_t res, nmod_poly_factor_t fac) 279 cdef void nmod_poly_factor_print(nmod_poly_factor_t fac) 280 cdef void nmod_poly_factor_pow(nmod_poly_factor_t fac, unsigned long exp) 281 282 # 283 # Differentiation 284 # 285 286 cdef void nmod_poly_derivative(nmod_poly_t res, nmod_poly_t poly) 287 288 # 289 # Arithmetic modulo a polynomial 290 # 291 292 cdef void nmod_poly_mulmod(nmod_poly_t res, nmod_poly_t poly1, nmod_poly_t poly2, nmod_poly_t f) 293 cdef void nmod_poly_powmod(nmod_poly_t res,nmod_poly_t pol, long exp, nmod_poly_t f) 157 # Transcendental functions 158 cdef void nmod_poly_atan_series(nmod_poly_t g, nmod_poly_t h, long n) 159 cdef void nmod_poly_tan_series(nmod_poly_t g, nmod_poly_t h, long n) 160 cdef void nmod_poly_asin_series(nmod_poly_t g, nmod_poly_t h, long n) 161 cdef void nmod_poly_sin_series(nmod_poly_t g, nmod_poly_t h, long n) 162 cdef void nmod_poly_cos_series(nmod_poly_t g, nmod_poly_t h, long n) 163 cdef void nmod_poly_asinh_series(nmod_poly_t g, nmod_poly_t h, long n) 164 cdef void nmod_poly_atanh_series(nmod_poly_t g, nmod_poly_t h, long n) 165 cdef void nmod_poly_sinh_series(nmod_poly_t g, nmod_poly_t h, long n) 166 cdef void nmod_poly_cosh_series(nmod_poly_t g, nmod_poly_t h, long n) 167 cdef void nmod_poly_tanh_series(nmod_poly_t g, nmod_poly_t h, long n) 168 cdef void nmod_poly_log_series(nmod_poly_t res, nmod_poly_t f, long n) 169 cdef void nmod_poly_exp_series(nmod_poly_t f, nmod_poly_t h, long) -
sage/libs/flint/nmod_poly_linkage.pxi
diff --git a/sage/libs/flint/nmod_poly_linkage.pxi b/sage/libs/flint/nmod_poly_linkage.pxi
a b 89 89 6*x 90 90 """ 91 91 cdef unsigned long i 92 if a. p<= n:92 if a.mod.n <= n: 93 93 nmod_poly_set(res, a) 94 94 else: 95 95 nmod_poly_zero(res) … … 139 139 sage: Q(0).is_zero() 140 140 True 141 141 """ 142 # is_zero doesn't exist 143 return nmod_poly_degree(a) == -1 142 return nmod_poly_is_zero(a) 144 143 145 144 cdef inline bint celement_is_one(nmod_poly_t a, unsigned long n) except -2: 146 145 """ … … 496 495 elif e == 1: 497 496 nmod_poly_set(res, x) 498 497 elif e == 2: 499 nmod_poly_ sqr(res, x)498 nmod_poly_mul(res, x, x) 500 499 else: 501 500 if res == x: 502 501 nmod_poly_set(tmp, x) … … 510 509 nmod_poly_set_coeff_ui(res, 0, 1) 511 510 e = e >> 1 512 511 while(e != 0): 513 nmod_poly_ sqr(pow2, pow2)512 nmod_poly_mul(pow2, pow2, pow2) 514 513 if e % 2: 515 514 nmod_poly_mul(res, res, pow2) 516 515 e = e >> 1 … … 634 633 635 634 factor_list = [] 636 635 cdef Polynomial_zmod_flint t 637 for i in range(factors_c.num _factors):636 for i in range(factors_c.num): 638 637 t = poly._new() 639 nmod_poly_swap(&t.x, factors_c.factors[i])640 factor_list.append((t, factors_c.exp onents[i]))638 nmod_poly_swap(&t.x, &factors_c.p[i]) 639 factor_list.append((t, factors_c.exp[i])) 641 640 642 641 nmod_poly_factor_clear(factors_c) 643 642 -
sage/libs/flint/ntl_interface.pxd
diff --git a/sage/libs/flint/ntl_interface.pxd b/sage/libs/flint/ntl_interface.pxd
a b 6 6 from sage.libs.ntl.ntl_ZZX_decl cimport ZZX_c 7 7 8 8 cdef extern from "flint/NTL-interface.h": 9 unsigned long ZZ_limbs(ZZ_c z)10 11 9 void fmpz_poly_get_ZZX(ZZX_c output, fmpz_poly_t poly) 12 10 void fmpz_poly_set_ZZX(fmpz_poly_t output, ZZX_c poly) 13 11 14 void fmpz_get_ mpz(mpz_t res, fmpz_t f)12 void fmpz_get_ZZ(ZZ_c output, fmpz_t f) 15 13 void fmpz_set_ZZ(fmpz_t output, ZZ_c z) 16 -
sage/libs/flint/ulong_extras.pxd
diff --git a/sage/libs/flint/ulong_extras.pxd b/sage/libs/flint/ulong_extras.pxd
a b 1 include "../../ext/stdsage.pxi" 2 include "../../ext/cdefs.pxi" 3 4 from sage.libs.flint.flint cimport * 5 6 7 cdef extern from "flint/ulong_extras.h": 8 9 ctypedef struct n_factor_t: 10 int num 11 unsigned long exp[15] 12 unsigned long p[15] 13 14 cdef int n_jacobi(long x, unsigned long y) 15 16 cdef int n_is_prime(unsigned long n) 17 18 cdef unsigned long n_gcd(long x, long y) 19 20 cdef void n_factor(n_factor_t * factors, unsigned long n, int proved) 21 cdef void n_factor_init(n_factor_t * factors) -
sage/misc/cython.py
diff --git a/sage/misc/cython.py b/sage/misc/cython.py
a b 761 761 #cargs -std=c99 -O3 -ggdb 762 762 #cinclude $SAGE_ROOT/devel/sage/sage/libs/flint $SAGE_LOCAL/include/flint 763 763 #clib flint 764 #cfile $SAGE_ROOT/devel/sage/sage/libs/flint/fmpq_poly.c765 764 766 765 from sage.rings.rational cimport Rational 767 766 from sage.rings.polynomial.polynomial_rational_flint cimport Polynomial_rational_flint -
sage/rings/fraction_field_FpT.pyx
diff --git a/sage/rings/fraction_field_FpT.pyx b/sage/rings/fraction_field_FpT.pyx
a b 688 688 """ 689 689 if nmod_poly_degree(self._numer) == -1: 690 690 return self 691 if not nmod_poly_sqrt_check(self._numer) or not nmod_poly_sqrt_check(self._denom):692 return None693 691 cdef nmod_poly_t numer 694 692 cdef nmod_poly_t denom 693 cdef long a 695 694 cdef FpTElement res 696 try: 697 nmod_poly_init(denom, self.p) 698 nmod_poly_init(numer, self.p) 699 if not nmod_poly_sqrt0(numer, self._numer): 700 return None 701 if not nmod_poly_sqrt0(denom, self._denom): 702 return None 695 696 nmod_poly_init(denom, self.p) 697 nmod_poly_init(numer, self.p) 698 699 if nmod_poly_sqrt(numer, self._numer) and nmod_poly_sqrt(denom, self._denom): 700 # Make denominator monic 701 a = nmod_poly_leading(denom) 702 if a != 1: 703 a = mod_inverse_int(a, self.p) 704 nmod_poly_scalar_mul_nmod(numer, numer, a) 705 nmod_poly_scalar_mul_nmod(denom, denom, a) 706 # Choose numerator with smaller leading coefficient 707 a = nmod_poly_leading(numer) 708 if a > self.p - a: 709 nmod_poly_neg(numer, numer) 703 710 res = self._new_c() 704 711 nmod_poly_swap(numer, res._numer) 705 712 nmod_poly_swap(denom, res._denom) 706 713 return res 707 finally:714 else: 708 715 nmod_poly_clear(numer) 709 716 nmod_poly_clear(denom) 710 717 return None 718 711 719 cpdef bint is_square(self): 712 720 """ 713 721 Returns True if this element is the square of another element of the fraction field. … … 741 749 742 750 sage: from sage.rings.fraction_field_FpT import * 743 751 sage: K = GF(7)['t'].fraction_field(); t = K.gen(0) 744 sage: ((t + 2)^2/(3*t^3 + 1)^4).sqrt() 752 sage: p = (t + 2)^2/(3*t^3 + 1)^4 753 sage: p.sqrt() 745 754 (3*t + 6)/(t^6 + 3*t^3 + 4) 755 sage: p.sqrt()^2 == p 756 True 757 746 758 """ 747 759 s = self._sqrt_or_None() 748 760 if s is None: … … 1589 1601 """ 1590 1602 cdef long n 1591 1603 cdef long a 1592 cdef long p = poly. p1604 cdef long p = poly.mod.n 1593 1605 for n from 0 <= n <= nmod_poly_degree(poly) + 1: 1594 1606 a = nmod_poly_get_coeff_ui(poly, n) + 1 1595 1607 if a == p: … … 1628 1640 d -= 1 1629 1641 return 0 1630 1642 1631 cdef void nmod_poly_pow(nmod_poly_t res, nmod_poly_t poly, unsigned long e):1632 """1633 Raises poly to the `e`th power and stores the result in ``res``.1634 """1635 if nmod_poly_degree(poly) < 2:1636 if nmod_poly_degree(poly) == -1:1637 nmod_poly_zero(res)1638 return1639 elif nmod_poly_is_one(poly):1640 nmod_poly_set(res, poly)1641 return1642 elif e > 1 and nmod_poly_degree(poly) == 1 and nmod_poly_get_coeff_ui(poly, 0) == 0 and nmod_poly_get_coeff_ui(poly, 1) == 1:1643 nmod_poly_left_shift(res, poly, e-1)1644 return1645 1646 # TODO: Could use the fact that (a+b)^p = a^p + b^p1647 # Only seems to be a big gain for large p, large exponents...1648 cdef nmod_poly_t pow21649 1650 if e < 5:1651 if e == 0:1652 nmod_poly_zero(res)1653 nmod_poly_set_coeff_ui(res, 0, 1)1654 elif e == 1:1655 nmod_poly_set(res, poly)1656 elif e == 2:1657 nmod_poly_sqr(res, poly)1658 elif e == 3:1659 nmod_poly_sqr(res, poly)1660 nmod_poly_mul(res, res, poly)1661 elif e == 4:1662 nmod_poly_sqr(res, poly)1663 nmod_poly_sqr(res, res)1664 else:1665 nmod_poly_init(pow2, poly.p)1666 nmod_poly_zero(res)1667 nmod_poly_set_coeff_ui(res, 0, 1)1668 nmod_poly_set(pow2, poly)1669 while True:1670 if e & 1:1671 nmod_poly_mul(res, res, pow2)1672 e >>= 11673 if e == 0:1674 break1675 nmod_poly_sqr(pow2, pow2)1676 nmod_poly_clear(pow2)1677 1678 1679 cdef long sqrt_mod_int(long a, long p) except -1:1680 """1681 Returns the square root of a modulo p, as a long.1682 """1683 return GF(p)(a).sqrt()1684 1685 cdef bint nmod_poly_sqrt_check(nmod_poly_t poly):1686 """1687 Quick check to see if poly could possibly be a square.1688 """1689 return (nmod_poly_degree(poly) % 2 == 01690 and jacobi_int(nmod_poly_leading(poly), poly.p) == 11691 and jacobi_int(nmod_poly_get_coeff_ui(poly, 0), poly.p) != -1)1692 1693 cdef bint nmod_poly_sqrt(nmod_poly_t res, nmod_poly_t poly):1694 """1695 Compute the square root of poly as res if res is a perfect square.1696 1697 Returns True on success, False on failure.1698 """1699 if not nmod_poly_sqrt_check(poly):1700 return False1701 return nmod_poly_sqrt0(res, poly)1702 1703 cdef bint nmod_poly_sqrt0(nmod_poly_t res, nmod_poly_t poly):1704 """1705 Compute the square root of poly as res if res is a perfect square, assuming that poly passes nmod_poly_sqrt_check.1706 1707 Returns True on success, False on failure.1708 """1709 if nmod_poly_degree(poly) == -1:1710 nmod_poly_zero(res)1711 return True1712 if nmod_poly_degree(poly) == 0:1713 nmod_poly_zero(res)1714 nmod_poly_set_coeff_ui(res, 0, sqrt_mod_int(nmod_poly_get_coeff_ui(poly, 0), poly.p))1715 return True1716 cdef nmod_poly_t g1717 cdef long p = poly.p1718 cdef long n, leading1719 cdef nmod_poly_factor_t factors1720 try:1721 nmod_poly_init(g, p)1722 nmod_poly_derivative(res, poly)1723 nmod_poly_gcd(g, res, poly)1724 if 2*nmod_poly_degree(g) < nmod_poly_degree(poly):1725 return False1726 1727 elif 2*nmod_poly_degree(g) > nmod_poly_degree(poly):1728 try:1729 nmod_poly_factor_init(factors)1730 leading = nmod_poly_leading(poly)1731 if leading == 1:1732 nmod_poly_factor_squarefree(factors, poly)1733 else:1734 nmod_poly_scalar_mul_nmod(res, poly, mod_inverse_int(leading, p))1735 nmod_poly_factor_squarefree(factors, res)1736 for n in range(factors.num_factors):1737 if factors.exponents[n] % 2 != 0:1738 return False1739 nmod_poly_pow(res, factors.factors[0], factors.exponents[0]//2)1740 for n in range(1, factors.num_factors):1741 nmod_poly_pow(factors.factors[n], factors.factors[n], factors.exponents[n]//2)1742 nmod_poly_mul(res, res, factors.factors[n])1743 if leading != 1:1744 nmod_poly_scalar_mul_nmod(res, res, sqrt_mod_int(nmod_poly_leading(poly), p))1745 return True1746 finally:1747 nmod_poly_factor_clear(factors)1748 1749 else: # deg(g) == deg(poly)/21750 nmod_poly_sqr(res, g)1751 leading = nmod_poly_leading(poly) * mod_inverse_int(nmod_poly_leading(res), p)1752 nmod_poly_scalar_mul_nmod(res, res, leading)1753 if nmod_poly_equal(res, poly):1754 nmod_poly_scalar_mul_nmod(res, g, sqrt_mod_int(leading, p))1755 return True1756 else:1757 return False1758 finally:1759 nmod_poly_clear(g)1760 1761 1643 def unpickle_FpT_element(K, numer, denom): 1762 1644 """ 1763 1645 Used for pickling. -
sage/rings/integer.pyx
diff --git a/sage/rings/integer.pyx b/sage/rings/integer.pyx
a b 3469 3469 if proof is None: 3470 3470 from sage.structure.proof.proof import get_flag 3471 3471 proof = get_flag(proof, "arithmetic") 3472 n_factor_init(&f) 3472 3473 n_factor(&f, mpz_get_ui(n.value), proof) 3473 3474 F = [(Integer(f.p[i]), int(f.exp[i])) for i from 0 <= i < f.num] 3474 3475 F.sort() -
sage/rings/polynomial/polynomial_integer_dense_flint.pyx
diff --git a/sage/rings/polynomial/polynomial_integer_dense_flint.pyx b/sage/rings/polynomial/polynomial_integer_dense_flint.pyx
a b 42 42 from sage.rings.arith import lcm 43 43 44 44 from sage.libs.flint.fmpz_poly cimport fmpz_poly_reverse 45 from sage.libs.flint.ntl_interface cimport fmpz_poly_set_ZZX, fmpz_poly_get_ZZX 45 46 from sage.libs.ntl.ntl_ZZX_decl cimport *, vec_pair_ZZX_long_c 46 47 47 48 cdef extern from "limits.h": … … 201 202 degree = i 202 203 try: 203 204 sig_on() 204 fmpz_poly_realloc(self.__poly, degree )205 fmpz_poly_realloc(self.__poly, degree + 1) 205 206 sig_off() 206 207 except RuntimeError: 207 208 raise OverflowError, "Cannot allocate memory!" … … 310 311 if mpz_sgn(a.value) == 0: 311 312 return self[0] 312 313 313 # As of FLINT1.5, memory management for the fmpz_t type 314 # has to be done manually. Without inspection of all 315 # coefficients, we can only naively bound the size of 316 # the answer by the very large value of "limbs" below. 317 # If this number is too large, we move on to the generic 318 # polynomial evaluation code, which might either happen 319 # to work (in special cases) or simply run out of memory. 320 # 321 # It is expected that this workaround is unnecessary 322 # with FLINT2. 323 if fmpz_poly_length(self.__poly) <= ((1 << 25) / fmpz_poly_length(self.__poly) - fmpz_poly_limbs(self.__poly)) / mpz_size(a.value): 314 z = PY_NEW(Integer) 324 315 325 z = PY_NEW(Integer) 316 sig_on() 317 fmpz_init(a_fmpz) 318 fmpz_init(z_fmpz) 319 fmpz_set_mpz(a_fmpz, a.value) 320 fmpz_poly_evaluate_fmpz(z_fmpz, self.__poly, a_fmpz) 321 fmpz_get_mpz(z.value, z_fmpz) 322 fmpz_clear(a_fmpz) 323 fmpz_clear(z_fmpz) 324 sig_off() 326 325 327 _sig_on 328 limbs = fmpz_poly_length(self.__poly) * (fmpz_poly_limbs(self.__poly) + fmpz_poly_length(self.__poly) * mpz_size(a.value)) 329 a_fmpz = fmpz_init(mpz_size(a.value)) 330 z_fmpz = fmpz_init(limbs) 331 fmpz_set_mpz(a_fmpz, a.value) 326 return z 332 327 333 fmpz_poly_evaluate_fmpz(z_fmpz, self.__poly, a_fmpz) 334 335 fmpz_get_mpz(z.value, z_fmpz) 336 fmpz_clear(a_fmpz) 337 fmpz_clear(z_fmpz) 338 _sig_off 339 340 return z 341 342 return Polynomial.__call__(self, *x, **kwds) 328 return Polynomial.__call__(self, *x, **kwds) 343 329 344 330 cpdef Integer content(self): 345 331 r""" 346 332 Return the greatest common divisor of the coefficients of this 347 polynomial. 333 polynomial. 348 334 349 335 EXAMPLES:: 350 336 … … 366 352 sage: (123456789123456789123456789123456789123456789*t).content() 367 353 123456789123456789123456789123456789123456789 368 354 """ 369 cdef fmpz_t c = fmpz_init(fmpz_poly_limbs(self.__poly)) 355 cdef fmpz_t c 356 fmpz_init(c) 370 357 fmpz_poly_content(c, self.__poly) 371 358 cdef Integer z = PY_NEW(Integer) 372 359 fmpz_get_mpz(z.value, c) … … 743 730 """ 744 731 cdef Polynomial_integer_dense_flint ss = self._new() 745 732 cdef Polynomial_integer_dense_flint tt = self._new() 746 cdef unsigned long bound = fmpz_poly_resultant_bound(self.__poly, 747 (<Polynomial_integer_dense_flint>right).__poly) 748 cdef fmpz_t r = fmpz_init(bound/flint_BITS+2) 733 cdef fmpz_t r 734 fmpz_init(r) 749 735 750 736 sig_on() 751 737 fmpz_poly_xgcd(r, ss.__poly, tt.__poly, self.__poly, … … 1187 1173 1188 1174 if not ZZ_IsOne(content): 1189 1175 fac_py = self._new() 1190 tcontent = fmpz_init(ZZ_limbs(content))1176 fmpz_init(tcontent) 1191 1177 fmpz_set_ZZ(tcontent, content) 1192 1178 fmpz_poly_set_coeff_fmpz(fac_py.__poly, 0, tcontent) 1193 1179 results.append( (fac_py,1) ) … … 1359 1345 elif self.parent() is not other.parent(): 1360 1346 raise TypeError 1361 1347 1362 cdef unsigned long bound = fmpz_poly_resultant_bound(self.__poly, 1363 (<Polynomial_integer_dense_flint>other).__poly) 1364 cdef fmpz_t res = fmpz_init(bound/flint_BITS + 2) 1348 cdef fmpz_t res 1349 fmpz_init(res) 1365 1350 cdef Integer x = PY_NEW(Integer) 1366 1351 1367 1352 sig_on() -
sage/rings/polynomial/polynomial_rational_flint.pyx
diff --git a/sage/rings/polynomial/polynomial_rational_flint.pyx b/sage/rings/polynomial/polynomial_rational_flint.pyx
a b 61 61 sage: g = 2/3 + t^2 62 62 sage: _ = f * g # indirect doctest 63 63 """ 64 return fmpz_poly_max_limbs(fmpq_poly_numref(op)) > 1 \ 65 or fmpq_poly_degree(op) > 1000 64 # Trac #12173: check that the degree is greater than 1000 before computing 65 # the max limb size 66 return fmpq_poly_length(op) > 0 and \ 67 (fmpq_poly_degree(op) > 1000 or 68 _fmpz_vec_max_limbs(fmpq_poly_numref(op), fmpq_poly_length(op)) > 1) 66 69 67 70 cdef class Polynomial_rational_flint(Polynomial): 68 71 """ 69 72 Univariate polynomials over the rationals, implemented via FLINT. 70 71 Internally, we represent rational polynomial as the quotient of an integer 72 polynomial and a positive denominator which is coprime to the content of 73 74 Internally, we represent rational polynomial as the quotient of an integer 75 polynomial and a positive denominator which is coprime to the content of 73 76 the numerator. 74 75 The implementation is based on the C module fmpq_poly written on top of76 FLINT 1.77 77 """ 78 78 79 79 ########################################################################### 80 80 # Allocation & initialisation # 81 81 ########################################################################### 82 82 83 83 cdef Polynomial_rational_flint _new(self): 84 84 """ 85 85 Quickly creates a new polynomial object in this class. … … 188 188 189 189 sage: f = ZZ['x']([1..10^6]) 190 190 sage: g = f.change_ring(QQ) 191 sage: g[:10] # long time (5s on sage.math, 2012)191 sage: g[:10] # not long anymore thanks to trac #12173 192 192 10*x^9 + 9*x^8 + 8*x^7 + 7*x^6 + 6*x^5 + 5*x^4 + 4*x^3 + 3*x^2 + 2*x + 1 193 193 """ 194 194 cdef long deg … … 389 389 cdef Polynomial_rational_flint res = self._new() 390 390 cdef bint do_sig = _do_sig(self.__poly) 391 391 if isinstance(n, slice): 392 start, stop, step = n.indices( len(list(self)))392 start, stop, step = n.indices(self.degree() + 1) 393 393 if do_sig: sig_on() 394 394 fmpq_poly_get_slice(res.__poly, self.__poly, start, stop) 395 395 if do_sig: sig_off() … … 517 517 if n > 0: 518 518 do_sig = _do_sig(self.__poly) 519 519 if do_sig: sig_on() 520 fmpq_poly_ truncate(res.__poly, self.__poly, n)520 fmpq_poly_get_slice(res.__poly, self.__poly, 0, n) 521 521 if do_sig: sig_off() 522 522 return res 523 523 … … 1170 1170 sig_on() 1171 1171 Polynomial_integer_dense_flint.__init__(num, parent, x=None, \ 1172 1172 check=False, is_gen=False, construct=False) 1173 fmp z_poly_set(num.__poly, fmpq_poly_numref(self.__poly))1173 fmpq_poly_get_numerator(num.__poly, self.__poly) 1174 1174 sig_off() 1175 1175 return num 1176 1176 … … 1189 1189 if fmpq_poly_denref(self.__poly) is NULL: 1190 1190 mpz_set_ui(den.value, 1) 1191 1191 else: 1192 fmpz_get_mpz(den.value, fmpq_poly_denref(self.__poly))1192 fmpz_get_mpz(den.value, <fmpz *> fmpq_poly_denref(self.__poly)) 1193 1193 return den 1194 1194 1195 1195 def _derivative(self, var = None): … … 1287 1287 0 1288 1288 """ 1289 1289 cdef Rational res = PY_NEW(Rational) 1290 cdef fmpq_t t 1291 fmpq_init(t) 1290 1292 sig_on() 1291 fmpq_poly_resultant( res.value, self.__poly, \1293 fmpq_poly_resultant(t, self.__poly, \ 1292 1294 (<Polynomial_rational_flint>right).__poly) 1295 fmpq_get_mpq(res.value, t) 1293 1296 sig_off() 1297 fmpq_clear(t) 1294 1298 return res 1295 1299 1296 1300 def is_irreducible(self): … … 1340 1344 sig_on() 1341 1345 Polynomial_integer_dense_flint.__init__(primitive, parent, \ 1342 1346 x=None, check=True, is_gen=False, construct=False) 1343 fmpz_poly_primitive_part(primitive.__poly, \ 1344 fmpq_poly_numref(self.__poly)) 1347 1348 fmpq_poly_get_numerator(primitive.__poly, self.__poly) 1349 fmpz_poly_primitive_part(primitive.__poly, primitive.__poly) 1350 1345 1351 sig_off() 1346 1352 return primitive.is_irreducible() 1347 1353 … … 1710 1716 # Alias for discriminant 1711 1717 disc = discriminant 1712 1718 1713 1719 -
sage/rings/polynomial/polynomial_zmod_flint.pxd
diff --git a/sage/rings/polynomial/polynomial_zmod_flint.pxd b/sage/rings/polynomial/polynomial_zmod_flint.pxd
a b 1 cdef extern from "zn_poly/zn_poly.h":2 # This header needs to appear before the flint headers.3 pass4 5 1 from sage.libs.flint.nmod_poly cimport nmod_poly_t, nmod_poly_struct 2 from sage.libs.flint.fmpz_poly cimport fmpz_poly_t 6 3 from sage.structure.parent cimport Parent 4 from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint 7 5 8 6 ctypedef nmod_poly_struct celement 9 7 ctypedef unsigned long cparent … … 14 12 15 13 cdef class Polynomial_zmod_flint(Polynomial_template): 16 14 cdef Polynomial_template _new(self) 17 cdef _set_list(self, x) 15 cdef int _set_list(self, x) except -1 16 cdef int _set_fmpz_poly(self, fmpz_poly_t) except -1 18 17 cpdef _mul_trunc(self, Polynomial_zmod_flint other, length) 19 18 cpdef _mul_trunc_opposite(self, Polynomial_zmod_flint other, length) 20 19 cpdef rational_reconstruct(self, m, n_deg=?, d_deg=?) 21 -
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 36 36 from sage.libs.ntl.ntl_lzz_pX import ntl_zz_pX 37 37 from sage.structure.factorization import Factorization 38 38 from sage.structure.element import coerce_binop, parent 39 from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint 39 40 40 41 # We need to define this stuff before including the templating stuff 41 42 # to make sure the function get_cparent is found since it is used in … … 60 61 cdef void zn_mod_clear(zn_mod_struct *mod) 61 62 cdef void zn_array_mul(unsigned long* res, unsigned long* op1, size_t n1, unsigned long* op2, size_t n2, zn_mod_struct *mod) 62 63 64 include "../../libs/flint/fmpz_poly.pxi" 65 63 66 cdef class Polynomial_zmod_flint(Polynomial_template): 64 67 def __init__(self, parent, x=None, check=True, is_gen=False, construct=False): 65 68 """ … … 84 87 Polynomial_template.__init__(self, parent, 0, check, is_gen, construct) 85 88 self._set_list(lst) 86 89 return 90 elif PY_TYPE_CHECK(x, Polynomial_integer_dense_flint): 91 Polynomial_template.__init__(self, parent, 0, check, is_gen, construct) 92 self._set_fmpz_poly((<Polynomial_integer_dense_flint>x).__poly) 93 return 87 94 else: 88 95 if PY_TYPE_CHECK(x, ntl_zz_pX): 89 96 x = x.list() … … 139 146 celement_set_si(&r.x, int(x), (<Polynomial_template>self)._cparent) 140 147 return r 141 148 142 cdef _set_list(self, x):149 cdef int _set_list(self, x) except -1: 143 150 """ 151 Set the coefficients of ``self`` from a list of coefficients. 152 153 INPUT: 154 155 - ``x`` - a list of coefficients 156 144 157 EXAMPLES:: 145 158 146 159 sage: P.<a>=GF(7)[] … … 157 170 cdef int i 158 171 if length == 0: 159 172 nmod_poly_zero(&self.x) 160 return 173 return 0 161 174 162 175 # resize to length of list 163 176 sig_on() 164 177 nmod_poly_realloc(&self.x, length) 165 178 sig_off() 166 179 180 sig_on() 167 181 for i from 0 <= i < length: 168 _nmod_poly_set_coeff_ui(&self.x, i, l_in[i]) 169 # we need to set the length manually, we used _nmod_poly_set_coeff_ui 170 self.x.length = length 182 nmod_poly_set_coeff_ui(&self.x, i, l_in[i]) 183 sig_off() 184 return 0 185 186 cdef int _set_fmpz_poly(self, fmpz_poly_t x) except -1: 187 """ 188 Set the coefficients of ``self`` from the coefficients of an ``fmpz_poly_t`` element. 189 190 INPUT: 191 192 - ``x`` - an ``fmpz_poly_t`` element 193 194 EXAMPLES:: 195 196 sage: a = ZZ['x'](range(17)) 197 sage: R = Integers(7)['x'] 198 sage: R(a) 199 2*x^16 + x^15 + 6*x^13 + 5*x^12 + 4*x^11 + 3*x^10 + 2*x^9 + x^8 + 6*x^6 + 5*x^5 + 4*x^4 + 3*x^3 + 2*x^2 + x 200 201 TESTS: 202 203 The following test from :trac:`12173` used to be horribly slow:: 204 205 sage: a = ZZ['x'](range(100000)) 206 sage: R = Integers(3)['x'] 207 sage: R(a) 208 2*x^99998 + ... + x 209 """ 210 sig_on() 211 fmpz_poly_get_nmod_poly(&self.x, x) 212 sig_off() 213 return 0 171 214 172 215 def __getitem__(self, i): 173 216 """ … … 404 447 nmod_poly_init2(&r.x, p, n1 + n2 -1 ) 405 448 406 449 zn_mod_init(&zn_mod, p) 407 zn_array_mul( r.x.coeffs, self.x.coeffs, n1,_other.x.coeffs, n2, &zn_mod)450 zn_array_mul(<unsigned long *> r.x.coeffs, <unsigned long *> self.x.coeffs, n1, <unsigned long*> _other.x.coeffs, n2, &zn_mod) 408 451 r.x.length = n1 + n2 -1 409 452 _nmod_poly_normalise(&r.x) 410 453 zn_mod_clear(&zn_mod) -
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 25 25 include "../../libs/flint/fmpz_poly.pxi" 26 26 27 27 from sage.libs.flint.nmod_poly cimport *, nmod_poly_t 28 from sage.libs.flint.ulong_extras cimport *, factor_t28 from sage.libs.flint.ulong_extras cimport *, n_factor_t 29 29 from sage.libs.ratpoints cimport ratpoints_mpz_exists_only 30 30 31 31 cdef int N_RES_CLASSES_BSD = 10 … … 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 nmod_poly_factor_t f_factzn, nmod_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. … … 315 314 nmod_poly_set_coeff_ui(f, 4, mpz_fdiv_ui(a, pp_ui)) 316 315 317 316 result = 0 318 (<nmod_poly_factor_struct *>f_factzn)[0].num _factors= 0 # reset data struct317 (<nmod_poly_factor_struct *>f_factzn)[0].num = 0 # reset data struct 319 318 qq = nmod_poly_factor(f_factzn, f) 320 for i from 0 <= i < f_factzn.num _factors:321 if f_factzn.exp onents[i]&1:319 for i from 0 <= i < f_factzn.num: 320 if f_factzn.exp[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 328 327 329 328 nmod_poly_zero(f) 330 329 nmod_poly_set_coeff_ui(f, 0, ui1) 331 for i from 0 <= i < f_factzn.num _factors:332 for j from 0 <= j < (f_factzn.exp onents[i]>>1):333 nmod_poly_mul(f, f, f_factzn.factors[i])330 for i from 0 <= i < f_factzn.num: 331 for j from 0 <= j < (f_factzn.exp[i]>>1): 332 nmod_poly_mul(f, f, &f_factzn.p[i]) 334 333 335 (<nmod_poly_factor_struct *>f_factzn)[0].num _factors= 0 # reset data struct334 (<nmod_poly_factor_struct *>f_factzn)[0].num = 0 # reset data struct 336 335 nmod_poly_factor(f_factzn, f) 337 336 has_roots = 0 338 337 j = 0 339 for i from 0 <= i < f_factzn.num _factors:340 if nmod_poly_degree( f_factzn.factors[i]) == 1 and 0 != nmod_poly_get_coeff_ui(f_factzn.factors[i], 1):338 for i from 0 <= i < f_factzn.num: 339 if nmod_poly_degree(&f_factzn.p[i]) == 1 and 0 != nmod_poly_get_coeff_ui(&f_factzn.p[i], 1): 341 340 has_roots = 1 342 roots[j] = pp_ui - nmod_poly_get_coeff_ui( f_factzn.factors[i], 0)341 roots[j] = pp_ui - nmod_poly_get_coeff_ui(&f_factzn.p[i], 0) 343 342 j += 1 344 343 if not has_roots: 345 344 return 0 … … 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) … … 450 449 nmod_poly_set_coeff_ui(f, 2, mpz_fdiv_ui(c, pp_ui)) 451 450 nmod_poly_set_coeff_ui(f, 3, mpz_fdiv_ui(b, pp_ui)) 452 451 nmod_poly_set_coeff_ui(f, 4, mpz_fdiv_ui(a, pp_ui)) 453 (<nmod_poly_factor_struct *>f_factzn)[0].num _factors= 0 # reset data struct452 (<nmod_poly_factor_struct *>f_factzn)[0].num = 0 # reset data struct 454 453 nmod_poly_factor(f_factzn, f) 455 454 has_roots = 0 456 455 has_single_roots = 0 457 456 j = 0 458 for i from 0 <= i < f_factzn.num _factors:459 if nmod_poly_degree( f_factzn.factors[i]) == 1 and 0 != nmod_poly_get_coeff_ui(f_factzn.factors[i], 1):457 for i from 0 <= i < f_factzn.num: 458 if nmod_poly_degree(&f_factzn.p[i]) == 1 and 0 != nmod_poly_get_coeff_ui(&f_factzn.p[i], 1): 460 459 has_roots = 1 461 if f_factzn.exp onents[i] == 1:460 if f_factzn.exp[i] == 1: 462 461 has_single_roots = 1 463 462 break 464 roots[j] = pp_ui - nmod_poly_get_coeff_ui( f_factzn.factors[i], 0)463 roots[j] = pp_ui - nmod_poly_get_coeff_ui(&f_factzn.p[i], 0) 465 464 j += 1 466 465 467 466 if not has_roots: return 0 … … 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 nmod_poly_t f 755 cdef double pp_ui_inv = z_precompute_inverse(P)756 754 nmod_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 1230 n_factor_init(&fact) 1232 1231 n_factor(&fact, mpz_get_ui(d_mpz), proof) 1233 1232 for i from 0 <= i < fact.num: 1234 1233 p = fact.p[i]