1 /*
2     Copyright (C) 2011 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 <https://www.gnu.org/licenses/>.
10 */
11 
12 #include "flint.h"
13 #include "fmpz.h"
14 #include "fmpz_mod_poly.h"
15 
fmpz_mod_poly_make_monic(fmpz_mod_poly_t res,const fmpz_mod_poly_t poly,const fmpz_mod_ctx_t ctx)16 void fmpz_mod_poly_make_monic(fmpz_mod_poly_t res, const fmpz_mod_poly_t poly,
17                                                       const fmpz_mod_ctx_t ctx)
18 {
19     const slong len = poly->length;
20     fmpz_t inv;
21 
22     if (len == 0)
23     {
24         fmpz_mod_poly_zero(res, ctx);
25         return;
26     }
27 
28     fmpz_init(inv);
29     fmpz_invmod(inv, fmpz_mod_poly_lead(poly, ctx), fmpz_mod_ctx_modulus(ctx));
30 
31     fmpz_mod_poly_fit_length(res, len, ctx);
32     _fmpz_mod_poly_set_length(res, len);
33 
34     _fmpz_mod_poly_scalar_mul_fmpz(res->coeffs,
35                             poly->coeffs, len, inv, fmpz_mod_ctx_modulus(ctx));
36 
37     fmpz_clear(inv);
38 }
39 
40