From f9c8109f1468783084ae21ae3a5b19758f17d1a1 Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Tue, 29 Aug 2023 18:02:02 +0200 Subject: [PATCH] add gr_poly_is_scalar --- doc/source/gr_poly.rst | 1 + src/gr_poly.h | 1 + src/gr_poly/is_scalar.c | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 src/gr_poly/is_scalar.c diff --git a/doc/source/gr_poly.rst b/doc/source/gr_poly.rst index ecc4cbe1f8..8813f96830 100644 --- a/doc/source/gr_poly.rst +++ b/doc/source/gr_poly.rst @@ -110,6 +110,7 @@ Basic manipulation .. function:: truth_t gr_poly_is_zero(const gr_poly_t poly, gr_ctx_t ctx) truth_t gr_poly_is_one(const gr_poly_t poly, gr_ctx_t ctx) truth_t gr_poly_is_gen(const gr_poly_t poly, gr_ctx_t ctx) + truth_t gr_poly_is_scalar(const gr_poly_t poly, gr_ctx_t ctx) .. function:: int gr_poly_set_scalar(gr_poly_t poly, gr_srcptr c, gr_ctx_t ctx) int gr_poly_set_si(gr_poly_t poly, slong c, gr_ctx_t ctx) diff --git a/src/gr_poly.h b/src/gr_poly.h index 7ef8d28548..7c83fab2cb 100644 --- a/src/gr_poly.h +++ b/src/gr_poly.h @@ -93,6 +93,7 @@ truth_t gr_poly_equal(const gr_poly_t poly1, const gr_poly_t poly2, gr_ctx_t ctx truth_t gr_poly_is_zero(const gr_poly_t poly, gr_ctx_t ctx); truth_t gr_poly_is_one(const gr_poly_t poly, gr_ctx_t ctx); truth_t gr_poly_is_gen(const gr_poly_t poly, gr_ctx_t ctx); +truth_t gr_poly_is_scalar(const gr_poly_t poly, gr_ctx_t ctx); WARN_UNUSED_RESULT int gr_poly_set_scalar(gr_poly_t poly, gr_srcptr x, gr_ctx_t ctx); WARN_UNUSED_RESULT int gr_poly_set_si(gr_poly_t poly, slong x, gr_ctx_t ctx); diff --git a/src/gr_poly/is_scalar.c b/src/gr_poly/is_scalar.c new file mode 100644 index 0000000000..429cb6517e --- /dev/null +++ b/src/gr_poly/is_scalar.c @@ -0,0 +1,23 @@ +/* + Copyright (C) 2023 Fredrik Johansson + + This file is part of FLINT. + + FLINT 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 "gr_poly.h" + +truth_t +gr_poly_is_scalar(const gr_poly_t poly, gr_ctx_t ctx) +{ + slong len = poly->length; + + if (len <= 1) + return T_TRUE; + + return _gr_vec_is_zero(GR_ENTRY(poly->coeffs, 1, ctx->sizeof_elem), len - 1, ctx); +}