# HG changeset patch
# User Jean-Pierre Flori <jean-pierre.flori@ssi.gouv.fr>
# Date 1341325684 14400
# Node ID c64a79af8e3d7da61ef811ee5a64860590ffb67b
# Parent f56b53b2570206522e01855c176985a3ccd4cc9a
#12173: Rebase on #10617
diff --git a/sage/libs/flint/fmpz.pxi b/sage/libs/flint/fmpz.pxi
a
|
b
|
|
2 | 2 | |
3 | 3 | cdef extern from "flint/fmpz.h": |
4 | 4 | |
5 | | ctypedef long fmpz |
| 5 | ctypedef long fmpz |
6 | 6 | ctypedef long * fmpz_t |
7 | 7 | ctypedef void * mpz_t |
8 | 8 | |
… |
… |
|
10 | 10 | |
11 | 11 | void fmpz_set_ui(fmpz_t res, unsigned long x) |
12 | 12 | void fmpz_set_si(fmpz_t res, long x) |
13 | | |
| 13 | |
14 | 14 | void fmpz_clear(fmpz_t f) |
15 | 15 | void fmpz_print(fmpz_t f) |
16 | 16 | int fmpz_is_one(fmpz_t f) |
17 | | |
| 17 | |
18 | 18 | void fmpz_get_mpz(mpz_t rop, fmpz_t op) |
19 | 19 | void fmpz_set_mpz(fmpz_t rop, mpz_t op) |
20 | 20 | |
21 | 21 | void fmpz_add_ui(fmpz_t f, fmpz_t g, unsigned long c) |
22 | | |
23 | | void mpz_to_fmpz(fmpz_t rop, mpz_t op) |
24 | | |
diff --git a/sage/libs/flint/fmpz_poly.pxi b/sage/libs/flint/fmpz_poly.pxi
a
|
b
|
|
108 | 108 | |
109 | 109 | void fmpz_poly_invmod(fmpz_t d, fmpz_poly_t H, fmpz_poly_t poly1, fmpz_poly_t poly2) |
110 | 110 | void fmpz_poly_derivative(fmpz_poly_t der, fmpz_poly_t poly) |
111 | | void fmpz_poly_evaluate(fmpz_t output, fmpz_poly_t poly, fmpz_t val) |
| 111 | void fmpz_poly_evaluate_fmpz(fmpz_t output, fmpz_poly_t poly, fmpz_t val) |
112 | 112 | void fmpz_poly_compose(fmpz_poly_t output, fmpz_poly_t f, fmpz_poly_t g) |
113 | 113 | void fmpz_poly_scalar_div_ui(fmpz_poly_t output, fmpz_poly_t poly, unsigned long x) |
114 | 114 | |
diff --git a/sage/rings/polynomial/polynomial_integer_dense_flint.pyx b/sage/rings/polynomial/polynomial_integer_dense_flint.pyx
a
|
b
|
|
260 | 260 | |
261 | 261 | def __call__(self, *x, **kwds): |
262 | 262 | """ |
263 | | Calls this polynomial with the given parameters, which can be |
264 | | interpreted as polynomial composition or evaluation by this |
| 263 | Calls this polynomial with the given parameters, which can be |
| 264 | interpreted as polynomial composition or evaluation by this |
265 | 265 | method. |
266 | 266 | |
267 | | If the argument is not simply an integer (``int``, ``long`` or |
268 | | ``Integer``) or a polynomial (of the same type as ``self``), |
269 | | the call is passed on to the generic implementation in the |
| 267 | If the argument is not simply an integer (``int``, ``long`` or |
| 268 | ``Integer``) or a polynomial (of the same type as ``self``), |
| 269 | the call is passed on to the generic implementation in the |
270 | 270 | ``Polynomial`` class. |
271 | 271 | |
272 | 272 | EXAMPLES: |
273 | 273 | |
274 | 274 | The first example illustrates polynomial composition:: |
275 | | |
| 275 | |
276 | 276 | sage: R.<t> = ZZ[] |
277 | 277 | sage: f = t^2 - 1 |
278 | 278 | sage: g = t + 1 |
279 | 279 | sage: f(g) # indirect doctest |
280 | 280 | t^2 + 2*t |
281 | | |
282 | | Now we illustrate how a polynomial can be evaluated at an |
| 281 | |
| 282 | Now we illustrate how a polynomial can be evaluated at an |
283 | 283 | integer:: |
284 | | |
| 284 | |
285 | 285 | sage: f(2) # indirect doctest |
286 | 286 | 3 |
287 | 287 | """ |
… |
… |
|
291 | 291 | cdef unsigned long limbs |
292 | 292 | cdef fmpz_t a_fmpz |
293 | 293 | cdef fmpz_t z_fmpz |
294 | | |
295 | | if len(x) == 1: |
| 294 | |
| 295 | if len(x) == 1: |
296 | 296 | x0 = x[0] |
297 | 297 | if isinstance(x, Polynomial_integer_dense_flint): |
298 | 298 | f = self._new() |
… |
… |
|
311 | 311 | if mpz_sgn(a.value) == 0: |
312 | 312 | return self[0] |
313 | 313 | |
314 | | # As of FLINT1.5, memory management for the fmpz_t type |
315 | | # has to be done manually. Without inspection of all |
316 | | # coefficients, we can only naively bound the size of |
317 | | # the answer by the very large value of "limbs" below. |
318 | | # If this number is too large, we move on to the generic |
319 | | # polynomial evaluation code, which might either happen |
320 | | # to work (in special cases) or simply run out of memory. |
321 | | # |
322 | | # It is expected that this workaround is unnecessary |
323 | | # with FLINT2. |
324 | | 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) |
325 | 315 | |
326 | | 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 |
327 | 325 | |
328 | | _sig_on |
329 | | limbs = fmpz_poly_length(self.__poly) * (fmpz_poly_limbs(self.__poly) + fmpz_poly_length(self.__poly) * mpz_size(a.value)) |
330 | | a_fmpz = fmpz_init(mpz_size(a.value)) |
331 | | z_fmpz = fmpz_init(limbs) |
332 | | mpz_to_fmpz(a_fmpz, a.value) |
| 326 | return z |
333 | 327 | |
334 | | fmpz_poly_evaluate(z_fmpz, self.__poly, a_fmpz) |
335 | | |
336 | | fmpz_to_mpz(z.value, z_fmpz) |
337 | | fmpz_clear(a_fmpz) |
338 | | fmpz_clear(z_fmpz) |
339 | | _sig_off |
340 | | |
341 | | return z |
342 | | |
343 | | return Polynomial.__call__(self, *x, **kwds) |
| 328 | return Polynomial.__call__(self, *x, **kwds) |
344 | 329 | |
345 | 330 | cpdef Integer content(self): |
346 | 331 | r""" |
347 | 332 | Return the greatest common divisor of the coefficients of this |
348 | | polynomial. |
| 333 | polynomial. |
349 | 334 | |
350 | 335 | EXAMPLES:: |
351 | 336 | |