From a357181b71bee000723d57abec2cfb796a6e4836 Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Wed, 7 Sep 2016 16:25:32 +0200 Subject: [PATCH] add polynomial valuation functions --- acb_poly.h | 2 ++ acb_poly/valuation.c | 25 +++++++++++++++++++++++++ arb_poly.h | 2 ++ arb_poly/valuation.c | 25 +++++++++++++++++++++++++ doc/source/acb_poly.rst | 5 +++++ doc/source/arb_poly.rst | 5 +++++ 6 files changed, 64 insertions(+) create mode 100644 acb_poly/valuation.c create mode 100644 arb_poly/valuation.c diff --git a/acb_poly.h b/acb_poly.h index 0b1cd0ec..03d4140e 100644 --- a/acb_poly.h +++ b/acb_poly.h @@ -69,6 +69,8 @@ ACB_POLY_INLINE slong acb_poly_degree(const acb_poly_t poly) return poly->length - 1; } +slong acb_poly_valuation(const acb_poly_t poly); + ACB_POLY_INLINE int acb_poly_is_zero(const acb_poly_t z) { diff --git a/acb_poly/valuation.c b/acb_poly/valuation.c new file mode 100644 index 00000000..76872387 --- /dev/null +++ b/acb_poly/valuation.c @@ -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 . +*/ + +#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; +} + diff --git a/arb_poly.h b/arb_poly.h index 64b738b2..8002f59c 100644 --- a/arb_poly.h +++ b/arb_poly.h @@ -81,6 +81,8 @@ ARB_POLY_INLINE slong arb_poly_degree(const arb_poly_t poly) return poly->length - 1; } +slong arb_poly_valuation(const arb_poly_t poly); + ARB_POLY_INLINE int arb_poly_is_zero(const arb_poly_t z) { diff --git a/arb_poly/valuation.c b/arb_poly/valuation.c new file mode 100644 index 00000000..509feca2 --- /dev/null +++ b/arb_poly/valuation.c @@ -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 . +*/ + +#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; +} + diff --git a/doc/source/acb_poly.rst b/doc/source/acb_poly.rst index 5ad90343..a4792017 100644 --- a/doc/source/acb_poly.rst +++ b/doc/source/acb_poly.rst @@ -143,6 +143,11 @@ Basic properties and manipulation Truncates *poly* to have length at most *n*, i.e. degree 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 ------------------------------------------------------------------------------- diff --git a/doc/source/arb_poly.rst b/doc/source/arb_poly.rst index 4b7a1df5..0388b192 100644 --- a/doc/source/arb_poly.rst +++ b/doc/source/arb_poly.rst @@ -137,6 +137,11 @@ Basic manipulation Truncates *poly* to have length at most *n*, i.e. degree 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 -------------------------------------------------------------------------------