# HG changeset patch
# User Jean-Pierre Flori <jean-pierre.flori@ssi.gouv.fr>
# Date 1367856527 -3600
# Node ID 493c7a2b9b6f50af095ba3d06784a350afcc1301
# Parent bcad2b5fb602cd38899d25a3ad0dd31367597517
#12173: Further fixes
diff --git a/sage/libs/flint/nmod_poly_linkage.pxi b/sage/libs/flint/nmod_poly_linkage.pxi
a
|
b
|
|
495 | 495 | elif e == 1: |
496 | 496 | nmod_poly_set(res, x) |
497 | 497 | elif e == 2: |
498 | | nmod_poly_mul(res, x, x) |
| 498 | nmod_poly_pow(res, x, 2) |
499 | 499 | else: |
500 | 500 | if res == x: |
501 | 501 | nmod_poly_set(tmp, x) |
… |
… |
|
509 | 509 | nmod_poly_set_coeff_ui(res, 0, 1) |
510 | 510 | e = e >> 1 |
511 | 511 | while(e != 0): |
512 | | nmod_poly_mul(pow2, pow2, pow2) |
| 512 | nmod_poly_pow(pow2, pow2, 2) |
513 | 513 | if e % 2: |
514 | 514 | nmod_poly_mul(res, res, pow2) |
515 | 515 | e = e >> 1 |
diff --git a/sage/rings/fraction_field_FpT.pyx b/sage/rings/fraction_field_FpT.pyx
a
|
b
|
|
9 | 9 | |
10 | 10 | from sage.rings.all import GF |
11 | 11 | from sage.libs.flint.nmod_poly cimport * |
| 12 | from sage.libs.flint.ulong_extras cimport n_jacobi |
12 | 13 | from sage.structure.element cimport Element, ModuleElement, RingElement |
13 | 14 | from sage.rings.integer_ring import ZZ |
14 | 15 | from sage.rings.fraction_field import FractionField_generic, FractionField_1poly_field |
… |
… |
|
648 | 649 | finally: |
649 | 650 | nmod_poly_clear(g) |
650 | 651 | return next |
651 | | |
| 652 | |
652 | 653 | cpdef _sqrt_or_None(self): |
653 | 654 | """ |
654 | 655 | Returns the squre root of self, or None. Differs from sqrt() by not raising an exception. |
… |
… |
|
686 | 687 | [] |
687 | 688 | |
688 | 689 | """ |
689 | | if nmod_poly_degree(self._numer) == -1: |
| 690 | if nmod_poly_is_zero(self._numer): |
690 | 691 | return self |
| 692 | |
| 693 | if not nmod_poly_sqrt_check(self._numer) or not nmod_poly_sqrt_check(self._denom): |
| 694 | return None |
| 695 | |
691 | 696 | cdef nmod_poly_t numer |
692 | 697 | cdef nmod_poly_t denom |
693 | 698 | cdef long a |
… |
… |
|
1640 | 1645 | d -= 1 |
1641 | 1646 | return 0 |
1642 | 1647 | |
| 1648 | cdef bint nmod_poly_sqrt_check(nmod_poly_t poly): |
| 1649 | """ |
| 1650 | Quick check to see if poly could possibly be a square. |
| 1651 | """ |
| 1652 | # We could use Sage's jacobi_int which is for 32 bits integers rather |
| 1653 | # than FLINT's n_jacobi which is for longs as the FpT class is crafted |
| 1654 | # for primes 2 < p < 2^16 |
| 1655 | return (nmod_poly_degree(poly) % 2 == 0 |
| 1656 | and n_jacobi(nmod_poly_leading(poly), poly.mod.n) == 1 |
| 1657 | and n_jacobi(nmod_poly_get_coeff_ui(poly, 0), poly.mod.n) != -1) |
| 1658 | |
1643 | 1659 | def unpickle_FpT_element(K, numer, denom): |
1644 | 1660 | """ |
1645 | 1661 | Used for pickling. |
diff --git a/sage/rings/polynomial/polynomial_zmod_flint.pyx b/sage/rings/polynomial/polynomial_zmod_flint.pyx
a
|
b
|
|
152 | 152 | |
153 | 153 | INPUT: |
154 | 154 | |
155 | | - ``x`` - a list of coefficients |
| 155 | - ``x`` - a list of coefficients - the coefficients are assumed to be |
| 156 | reduced already and the list contains no trailing zeroes. |
| 157 | |
156 | 158 | |
157 | 159 | EXAMPLES:: |
158 | 160 | |
… |
… |
|
178 | 180 | sig_off() |
179 | 181 | |
180 | 182 | sig_on() |
| 183 | # The following depends on the internals of FLINT |
181 | 184 | for i from 0 <= i < length: |
182 | | nmod_poly_set_coeff_ui(&self.x, i, l_in[i]) |
| 185 | self.x.coeffs[i] = l_in[i] |
| 186 | self.x.length = length |
183 | 187 | sig_off() |
184 | 188 | return 0 |
185 | 189 | |