add polynomial valuation functions

This commit is contained in:
Fredrik Johansson 2016-09-07 16:25:32 +02:00
parent b6be51978f
commit a357181b71
6 changed files with 64 additions and 0 deletions

View file

@ -69,6 +69,8 @@ ACB_POLY_INLINE slong acb_poly_degree(const acb_poly_t poly)
return poly->length - 1; return poly->length - 1;
} }
slong acb_poly_valuation(const acb_poly_t poly);
ACB_POLY_INLINE int ACB_POLY_INLINE int
acb_poly_is_zero(const acb_poly_t z) acb_poly_is_zero(const acb_poly_t z)
{ {

25
acb_poly/valuation.c Normal file
View file

@ -0,0 +1,25 @@
/*
Copyright (C) 2016 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#include "acb_poly.h"
slong
acb_poly_valuation(const acb_poly_t poly)
{
slong i, len = poly->length;
for (i = 0; i < len; i++)
if (!acb_is_zero(poly->coeffs + i))
return i;
return -1;
}

View file

@ -81,6 +81,8 @@ ARB_POLY_INLINE slong arb_poly_degree(const arb_poly_t poly)
return poly->length - 1; return poly->length - 1;
} }
slong arb_poly_valuation(const arb_poly_t poly);
ARB_POLY_INLINE int ARB_POLY_INLINE int
arb_poly_is_zero(const arb_poly_t z) arb_poly_is_zero(const arb_poly_t z)
{ {

25
arb_poly/valuation.c Normal file
View file

@ -0,0 +1,25 @@
/*
Copyright (C) 2016 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#include "arb_poly.h"
slong
arb_poly_valuation(const arb_poly_t poly)
{
slong i, len = poly->length;
for (i = 0; i < len; i++)
if (!arb_is_zero(poly->coeffs + i))
return i;
return -1;
}

View file

@ -143,6 +143,11 @@ Basic properties and manipulation
Truncates *poly* to have length at most *n*, i.e. degree Truncates *poly* to have length at most *n*, i.e. degree
strictly smaller than *n*. strictly smaller than *n*.
.. function:: slong acb_poly_valuation(const acb_poly_t poly)
Returns the degree of the lowest term that is not exactly zero in *poly*.
Returns -1 if *poly* is the zero polynomial.
Input and output Input and output
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View file

@ -137,6 +137,11 @@ Basic manipulation
Truncates *poly* to have length at most *n*, i.e. degree Truncates *poly* to have length at most *n*, i.e. degree
strictly smaller than *n*. strictly smaller than *n*.
.. function:: slong arb_poly_valuation(const arb_poly_t poly)
Returns the degree of the lowest term that is not exactly zero in *poly*.
Returns -1 if *poly* is the zero polynomial.
Conversions Conversions
------------------------------------------------------------------------------- -------------------------------------------------------------------------------