210int nut_Poly_fprint(FILE *restrict file, const
nut_Poly *restrict f, const
char *vname, const
char *add, const
char *sub, const
char *pow,
bool descending);
230int nut_Poly_parse(
nut_Poly *restrict f, int64_t *restrict n, const
char *restrict str, const
char *restrict *restrict end);
#define NUT_ATTR_ACCESS(...)
Wrapper for gcc's access function annotation - no clang equivalent, and currently disabled because it...
#define NUT_ATTR_NONNULL(...)
Wrapper for gnu::nonnull attr.
#define NUT_ATTR_NODISCARD
Wrapper for nodiscard attr - requires return value be used.
#define NUT_ATTR_PURE
Wrapper for gnu::pure attr - similar to const but the function can read non-volatile memory (includin...
bool nut_Poly_compose_modn(nut_Poly *restrict h, const nut_Poly *f, const nut_Poly *g, int64_t n, uint64_t cn, nut_Poly tmps[restrict static 2])
Compose polynomial f(g(x)) mod n and store the result in h.
bool nut_Poly_quotrem_modn(nut_Poly *restrict q, nut_Poly *restrict r, const nut_Poly *restrict f, const nut_Poly *restrict g, int64_t n)
Divide two polynomials to get a quotient and remainder.
bool nut_Poly_roots_modn_tmptmp(const nut_Poly *restrict f, int64_t n, nut_Roots *restrict roots)
Find all roots of a polynomial in an odd prime field.
bool nut_Poly_sub_modn(nut_Poly *h, const nut_Poly *f, const nut_Poly *g, int64_t n)
Subtract polynomials f - g mod n and store the result in h.
bool nut_Poly_factor1_modn(nut_Poly *restrict g, const nut_Poly *restrict f, uint64_t d, int64_t n, nut_Poly tmps[restrict static 4])
Attempt to find a divisor of f_d.
NUT_ATTR_PURE int64_t nut_Poly_eval_modn(const nut_Poly *f, int64_t x, int64_t n)
Evaluate a polynomial mod a number.
bool nut_Poly_mul_modn(nut_Poly *restrict h, const nut_Poly *f, const nut_Poly *g, int64_t n)
Multiply polynomials f*g mod n and store the result in h.
bool nut_Poly_dot_modn(nut_Poly *h, const nut_Poly *f, const nut_Poly *g, int64_t n)
Take the termwise product of polynomials f and g mod n and store the result in h.
bool nut_Poly_compose_modn_tmptmp(nut_Poly *restrict h, const nut_Poly *f, const nut_Poly *g, int64_t n, uint64_t cn)
Compose polynomial f(g(x)) mod n and store the result in h.
bool nut_Poly_rand_modn(nut_Poly *f, uint64_t max_len, int64_t n)
Generate a random polynomial.
bool nut_Poly_roots_modn(const nut_Poly *restrict f, int64_t n, nut_Roots *restrict roots, nut_Poly tmps[restrict static 6])
Find all roots of a polynomial in an odd prime field.
void nut_Poly_normalize_exps_modn(nut_Poly *f, uint64_t cn)
Reduce any exponents over cn.
NUT_ATTR_NODISCARD bool nut_Poly_copy(nut_Poly *restrict g, const nut_Poly *restrict f)
Copy a polynomial.
bool nut_Poly_pow_modn(nut_Poly *restrict g, const nut_Poly *restrict f, uint64_t e, int64_t n, uint64_t cn, nut_Poly tmps[restrict static 2])
Raise f**x mod n and store the result in g.
int nut_Poly_parse(nut_Poly *restrict f, int64_t *restrict n, const char *restrict str, const char *restrict *restrict end)
Convert a string to a polynomial (and possibly modulus)
NUT_ATTR_NODISCARD bool nut_Roots_ensure_cap(nut_Roots *roots, uint64_t cap)
Extend the capacity of a root buffer if needed.
bool nut_Poly_powmod_modn_tmptmp(nut_Poly *restrict h, const nut_Poly *restrict f, uint64_t e, const nut_Poly *restrict g, int64_t n)
Compute the power of a polynomial mod another polynomial.
bool nut_Poly_gcd_modn(nut_Poly *restrict d, const nut_Poly *restrict f, const nut_Poly *restrict g, int64_t n, nut_Poly tmps[restrict static 3])
Find the gcd of two polynomials.
bool nut_Poly_powmod_modn(nut_Poly *restrict h, const nut_Poly *restrict f, uint64_t e, const nut_Poly *restrict g, int64_t n, nut_Poly tmps[restrict static 3])
Compute the power of a polynomial mod another polynomial.
bool nut_Poly_factors_d_modn(nut_Poly *restrict f_d, const nut_Poly *restrict f, uint64_t d, int64_t n, nut_Poly tmps[restrict static 4])
Compute the product of all irreducible factors of degree d.
bool nut_Poly_gcd_modn_tmptmp(nut_Poly *restrict d, const nut_Poly *restrict f, const nut_Poly *restrict g, int64_t n)
Find the gcd of two polynomials.
void nut_Poly_normalize_modn(nut_Poly *f, int64_t n, bool use_negatives)
Reduce coefficients mod n, then normalize.
NUT_ATTR_NODISCARD bool nut_Roots_init(nut_Roots *roots, uint64_t reserve)
Initialize a root buffer with at least a given capacity.
bool nut_Poly_pow_modn_tmptmp(nut_Poly *restrict g, const nut_Poly *restrict f, uint64_t e, int64_t n, uint64_t cn)
Raise f**x mod n and store the result in g.
NUT_ATTR_NODISCARD bool nut_Poly_zero_extend(nut_Poly *f, uint64_t len)
Extend the capacity of a polynomial struct if needed and set any new terms to 0.
void nut_Roots_destroy(nut_Roots *roots)
Free resources held by a root buffer.
NUT_ATTR_PURE int nut_Poly_cmp(const nut_Poly *a, const nut_Poly *b)
Asymptotically compare polynomials.
NUT_ATTR_NODISCARD bool nut_Poly_init(nut_Poly *f, uint64_t reserve)
Initialize a polynomial with at least a given capacity.
void nut_Poly_destroy(nut_Poly *f)
Free resources held by a polynomial struct.
NUT_ATTR_NODISCARD bool nut_Poly_setconst(nut_Poly *f, int64_t c)
Set a polynomial to a constant (linear terms and up zero).
bool nut_Poly_scale_modn(nut_Poly *g, const nut_Poly *f, int64_t a, int64_t n)
Multiply a polynomial f by a scalar a and store the result in h.
bool nut_Poly_add_modn(nut_Poly *h, const nut_Poly *f, const nut_Poly *g, int64_t n)
Add polynomials f + g mod n and store the result in h.
NUT_ATTR_NODISCARD bool nut_Poly_ensure_cap(nut_Poly *f, uint64_t cap)
Extend the capacity of a polynomial struct if needed.
int nut_Poly_fprint(FILE *restrict file, const nut_Poly *restrict f, const char *vname, const char *add, const char *sub, const char *pow, bool descending)
Print a polynomial to a file.
void nut_Poly_normalize(nut_Poly *f)
Strip off terms so the leading term is nonzero if needed.
A polynomial with signed integer coefficients.
uint64_t cap
Maximum length polynomial the coeffs buffer can currently store.
uint64_t len
Length of the polynomial.
int64_t * coeffs
Array of coefficients.
The roots of a polynomial over a finite field, ignoring multiplicity.
int64_t * roots
Array of roots.
uint64_t len
Number of roots, can be 0 if there are none.
uint64_t cap
Maximum number of roots the roots buffer can currently store.