add poly is_zero, is_one, is_x methods

This commit is contained in:
Fredrik Johansson 2016-05-16 12:33:16 +02:00
parent 5810ef58da
commit 6f294eab35
4 changed files with 71 additions and 15 deletions

View file

@ -69,6 +69,25 @@ ACB_POLY_INLINE slong acb_poly_degree(const acb_poly_t poly)
return poly->length - 1;
}
ACB_POLY_INLINE int
acb_poly_is_zero(const acb_poly_t z)
{
return acb_poly_length(z) == 0;
}
ACB_POLY_INLINE int
acb_poly_is_one(const acb_poly_t z)
{
return (acb_poly_length(z) == 1) && acb_is_one(z->coeffs);
}
ACB_POLY_INLINE int
acb_poly_is_x(const acb_poly_t z)
{
return (acb_poly_length(z) == 2) && acb_is_zero(z->coeffs)
&& acb_is_one(z->coeffs + 1);
}
ACB_POLY_INLINE void acb_poly_zero(acb_poly_t poly)
{
poly->length = 0;

View file

@ -77,6 +77,25 @@ ARB_POLY_INLINE slong arb_poly_degree(const arb_poly_t poly)
return poly->length - 1;
}
ARB_POLY_INLINE int
arb_poly_is_zero(const arb_poly_t z)
{
return arb_poly_length(z) == 0;
}
ARB_POLY_INLINE int
arb_poly_is_one(const arb_poly_t z)
{
return (arb_poly_length(z) == 1) && arb_is_one(z->coeffs);
}
ARB_POLY_INLINE int
arb_poly_is_x(const arb_poly_t z)
{
return (arb_poly_length(z) == 2) && arb_is_zero(z->coeffs)
&& arb_is_one(z->coeffs + 1);
}
ARB_POLY_INLINE void arb_poly_zero(arb_poly_t poly)
{
poly->length = 0;

View file

@ -76,6 +76,15 @@ Basic properties and manipulation
so the return value of this function is effectively
an upper bound.
.. function:: int acb_poly_is_zero(const acb_poly_t poly)
.. function:: int acb_poly_is_one(const acb_poly_t poly)
.. function:: int acb_poly_is_x(const acb_poly_t poly)
Returns 1 if *poly* is exactly the polynomial 0, 1 or *x*
respectively. Returns 0 otherwise.
.. function:: void acb_poly_zero(acb_poly_t poly)
Sets *poly* to the zero polynomial.

View file

@ -57,6 +57,30 @@ Memory management
Basic manipulation
-------------------------------------------------------------------------------
.. function:: slong arb_poly_length(const arb_poly_t poly)
Returns the length of *poly*, i.e. zero if *poly* is
identically zero, and otherwise one more than the index
of the highest term that is not identically zero.
.. function:: slong arb_poly_degree(const arb_poly_t poly)
Returns the degree of *poly*, defined as one less than its length.
Note that if one or several leading coefficients are balls
containing zero, this value can be larger than the true
degree of the exact polynomial represented by *poly*,
so the return value of this function is effectively
an upper bound.
.. function:: int arb_poly_is_zero(const arb_poly_t poly)
.. function:: int arb_poly_is_one(const arb_poly_t poly)
.. function:: int arb_poly_is_x(const arb_poly_t poly)
Returns 1 if *poly* is exactly the polynomial 0, 1 or *x*
respectively. Returns 0 otherwise.
.. function:: void arb_poly_zero(arb_poly_t poly)
.. function:: void arb_poly_one(arb_poly_t poly)
@ -107,21 +131,6 @@ Basic manipulation
Truncates *poly* to have length at most *n*, i.e. degree
strictly smaller than *n*.
.. function:: slong arb_poly_length(const arb_poly_t poly)
Returns the length of *poly*, i.e. zero if *poly* is
identically zero, and otherwise one more than the index
of the highest term that is not identically zero.
.. function:: slong arb_poly_degree(const arb_poly_t poly)
Returns the degree of *poly*, defined as one less than its length.
Note that if one or several leading coefficients are balls
containing zero, this value can be larger than the true
degree of the exact polynomial represented by *poly*,
so the return value of this function is effectively
an upper bound.
Conversions
-------------------------------------------------------------------------------