1 /*
2     Copyright (C) 2012 Sebastian Pancratz
3 
4     This file is part of FLINT.
5 
6     FLINT is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include "fmpz_mod_poly.h"
13 #include "padic_poly.h"
14 
_padic_poly_derivative(fmpz * rop,slong * rval,slong N,const fmpz * op,slong val,slong len,const padic_ctx_t ctx)15 void _padic_poly_derivative(fmpz *rop, slong *rval, slong N,
16                             const fmpz *op, slong val, slong len,
17                             const padic_ctx_t ctx)
18 {
19     fmpz_t pow;
20     int alloc;
21 
22     _fmpz_poly_derivative(rop, op, len);
23     *rval = val;
24 
25     alloc = _padic_ctx_pow_ui(pow, N - *rval, ctx);
26 
27     _fmpz_vec_scalar_mod_fmpz(rop, rop, len - 1, pow);
28     _padic_poly_canonicalise(rop, rval, len - 1, ctx->p);
29 
30     if (alloc)
31         fmpz_clear(pow);
32 }
33 
padic_poly_derivative(padic_poly_t rop,const padic_poly_t op,const padic_ctx_t ctx)34 void padic_poly_derivative(padic_poly_t rop,
35                            const padic_poly_t op, const padic_ctx_t ctx)
36 {
37     const slong len = op->length;
38 
39     if (len < 2 || op->val >= rop->N)
40     {
41         padic_poly_zero(rop);
42     }
43     else
44     {
45         padic_poly_fit_length(rop, len - 1);
46         _padic_poly_derivative(rop->coeffs, &(rop->val), rop->N,
47                                op->coeffs, op->val, len, ctx);
48         _padic_poly_set_length(rop, len - 1);
49         _padic_poly_normalise(rop);
50     }
51 }
52 
53