Skip to content

Commit

Permalink
add gr_poly_is_scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-johansson committed Aug 29, 2023
1 parent 8b4b3ff commit f9c8109
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/gr_poly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/gr_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions src/gr_poly/is_scalar.c
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#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);
}

0 comments on commit f9c8109

Please sign in to comment.