<commit_before>/*=============================================================================

    This file is part of FLINT.

    FLINT is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    FLINT is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FLINT; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

=============================================================================*/
/******************************************************************************

    Copyright (C) 2010 <NAME>

******************************************************************************/

*******************************************************************************

    Memory management

*******************************************************************************

void nmod_poly_init(nmod_poly_t poly, mp_limb_t n)

    Initialises \code{poly}. It will have coefficients modulo~$n$.

void nmod_poly_init_preinv(nmod_poly_t poly, mp_limb_t n, mp_limb_t ninv)

    Initialises \code{poly}. It will have coefficients modulo~$n$.  
    The caller supplies a precomputed inverse limb generated by 
    \code{n_preinvert_limb()}.

void nmod_poly_init2(nmod_poly_t poly, mp_limb_t n, long alloc)

    Initialises \code{poly}. It will have coefficients modulo~$n$.
    Up to \code{alloc} coefficients may be stored in \code{poly}.

void nmod_poly_init2_preinv(nmod_poly_t poly, 
                       mp_limb_t n, mp_limb_t ninv, long alloc)

    Initialises \code{poly}. It will have coefficients modulo~$n$. 
    The caller supplies a precomputed inverse limb generated by 
    \code{n_preinvert_limb()}. Up to \code{alloc} coefficients may 
    be stored in \code{poly}.

void nmod_poly_realloc(nmod_poly_t poly, long alloc)

    Reallocates \code{poly} to the given length. If the current 
    length is less than \code{alloc}, the polynomial is truncated 
    and normalised.  If \code{alloc} is zero, the polynomial is 
    cleared.

void nmod_poly_clear(nmod_poly_t poly)

    Clears the polynomial and releases any memory it used. The polynomial 
    cannot be used again until it is initialised.

void nmod_poly_fit_length(nmod_poly_t poly, long alloc)

    Ensures \code{poly} has space for at least \code{alloc} coefficients. 
    This function only ever grows the allocated space, so no data loss can 
    occur.

*******************************************************************************

    Basic manipulation

*******************************************************************************

void _nmod_poly_normalise(nmod_poly_t poly)

    Internal function for normalising a polynomial so that the final 
    coefficient (if there are any at all) is not zero.

void nmod_poly_swap(nmod_poly_t poly1, nmod_poly_t poly2)

    Efficiently swaps \code{poly1} and \code{poly2} by swapping pointers 
    internally. 

mp_bitcnt_t nmod_poly_max_bits(const nmod_poly_t poly)

    Returns the maximum number of bits of any coefficient of \code{poly}.

void nmod_poly_truncate(nmod_poly_t poly, long len)

    Truncates \code{poly} to the given length and normalises it. 
    If \code{len} is bigger than the current length of \code{poly}, 
    then nothing happens.

*******************************************************************************

    Polynomial properties

*******************************************************************************

long nmod_poly_length(const nmod_poly_t poly)

   Return the length of the polynomial \code{poly}. The zero polynomial
   has length zsro.

long nmod_poly_degree(const nmod_poly_t poly)

   Return the degree of the polynomial \code{poly}. The zero polynomial
   is deemed to have degree \code{-1}.

mp_limb_t nmod_poly_modulus(const nmod_poly_t poly)

   Return the modulus of the polynomial \code{poly}. This will be a 
   positive integer.

int nmod_poly_is_zero(const nmod_poly_t poly)

   Return one if the polynomial \code{poly} is the zero polynomial,
   otherwise return zero.

*******************************************************************************

    Getting and setting coefficients

*******************************************************************************

ulong nmod_poly_get_coeff_ui(const nmod_poly_t poly, ulong j)

   Get the coefficient of \code{poly} at index \code{j} (coefficients 
   being numbered with zero being the constant coefficient) and return
   it as a \code{ulong}. If \code{j} refers to a coefficient beyond the
   end of \code{poly}, zero is returned.

void nmod_poly_set_coeff_ui(nmod_poly_t poly, ulong j, ulong c)

   Set the coefficient of \code{poly} at index \code{j} (coefficients 
   being numbered with zero being the constant coefficient) to the value
   \code{c} reduced modulo the modulus of \code{poly}. If \code{j} 
   refers to a coefficient beyond the current end of \code{poly}, the
   polynomial is first resized, with intervening coefficients being
   set to zero.

*******************************************************************************

    Random generation

*******************************************************************************

void nmod_poly_randtest(nmod_poly_t poly, long len)

    Generates a random polynomial with up to the given length.

*******************************************************************************

    Comparison<commit_msg>Update "Polynomial properties" and "Getting ... coefficients" in nmod_poly<commit_after>/*=============================================================================

    This file is part of FLINT.

    FLINT is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    FLINT is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FLINT; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

=============================================================================*/
/******************************************************************************

    Copyright (C) 2010 <NAME>

******************************************************************************/

*******************************************************************************

    Memory management

*******************************************************************************

void nmod_poly_init(nmod_poly_t poly, mp_limb_t n)

    Initialises \code{poly}. It will have coefficients modulo~$n$.

void nmod_poly_init_preinv(nmod_poly_t poly, mp_limb_t n, mp_limb_t ninv)

    Initialises \code{poly}. It will have coefficients modulo~$n$.  
    The caller supplies a precomputed inverse limb generated by 
    \code{n_preinvert_limb()}.

void nmod_poly_init2(nmod_poly_t poly, mp_limb_t n, long alloc)

    Initialises \code{poly}. It will have coefficients modulo~$n$.
    Up to \code{alloc} coefficients may be stored in \code{poly}.

void nmod_poly_init2_preinv(nmod_poly_t poly, 
                       mp_limb_t n, mp_limb_t ninv, long alloc)

    Initialises \code{poly}. It will have coefficients modulo~$n$. 
    The caller supplies a precomputed inverse limb generated by 
    \code{n_preinvert_limb()}. Up to \code{alloc} coefficients may 
    be stored in \code{poly}.

void nmod_poly_realloc(nmod_poly_t poly, long alloc)

    Reallocates \code{poly} to the given length. If the current 
    length is less than \code{alloc}, the polynomial is truncated 
    and normalised.  If \code{alloc} is zero, the polynomial is 
    cleared.

void nmod_poly_clear(nmod_poly_t poly)

    Clears the polynomial and releases any memory it used. The polynomial 
    cannot be used again until it is initialised.

void nmod_poly_fit_length(nmod_poly_t poly, long alloc)

    Ensures \code{poly} has space for at least \code{alloc} coefficients. 
    This function only ever grows the allocated space, so no data loss can 
    occur.

*******************************************************************************

    Basic manipulation

*******************************************************************************

void _nmod_poly_normalise(nmod_poly_t poly)

    Internal function for normalising a polynomial so that the final 
    coefficient (if there are any at all) is not zero.

void nmod_poly_swap(nmod_poly_t poly1, nmod_poly_t poly2)

    Efficiently swaps \code{poly1} and \code{poly2} by swapping pointers 
    internally. 

mp_bitcnt_t nmod_poly_max_bits(const nmod_poly_t poly)

    Returns the maximum number of bits of any coefficient of \code{poly}.

void nmod_poly_truncate(nmod_poly_t poly, long len)

    Truncates \code{poly} to the given length and normalises it. 
    If \code{len} is bigger than the current length of \code{poly}, 
    then nothing happens.

*******************************************************************************

    Polynomial properties

*******************************************************************************

long nmod_poly_length(const nmod_poly_t poly)

    Returns the length of the polynomial \code{poly}. The zero polynomial
    has length zero.

long nmod_poly_degree(const nmod_poly_t poly)

    Returns the degree of the polynomial \code{poly}. The zero polynomial
    is deemed to have degree~$-1$.

mp_limb_t nmod_poly_modulus(const nmod_poly_t poly)

    Returns the modulus of the polynomial \code{poly}. This will be a 
    positive integer.

int nmod_poly_is_zero(const nmod_poly_t poly)

    Returns one if the polynomial \code{poly} is the zero polynomial,
    otherwise return zero.

*******************************************************************************

    Getting and setting coefficients

*******************************************************************************

ulong nmod_poly_get_coeff_ui(const nmod_poly_t poly, ulong j)

    Gets the coefficient of \code{poly} at index \code{j}, where coefficients 
    are numbered with zero being the constant coefficient, and returns it as 
    a \code{ulong}. If \code{j} refers to a coefficient beyond the end of 
    \code{poly}, zero is returned.

void nmod_poly_set_coeff_ui(nmod_poly_t poly, ulong j, ulong c)

    Sets the coefficient of \code{poly} at index \code{j}, where 
    coefficients are numbered with zero being the constant coefficient, 
    to the value \code{c} reduced modulo the modulus of \code{poly}. 
    If \code{j} refers to a coefficient beyond the current end of \code{poly}, 
    the polynomial is first resized, with intervening coefficients being
    set to zero.

*******************************************************************************

    Random generation

*******************************************************************************

void nmod_poly_randtest(nmod_poly_t poly, long len)

    Generates a random polynomial with up to the given length.

*******************************************************************************

    Comparison
{'fraction_non_alphanumeric': 0.24614991916957374, 'fraction_numerical': 0.003913894324853229, 'mean_word_length': 4.640115163147793, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1524659', 'n_tokens_mistral': 3132, 'n_tokens_neox': 2869, 'n_words': 1163}