From 14c1be8704a70e3618ae2d11443b5eb4da3aedac Mon Sep 17 00:00:00 2001 From: Tommy Hofmann Date: Sun, 24 Nov 2024 19:42:47 +0100 Subject: [PATCH] fix: nmod_mpoly with modulus 1 --- src/nmod_mpoly/gen.c | 6 ++++++ src/nmod_mpoly/is_gen.c | 3 +++ src/nmod_mpoly/test/t-gen.c | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/nmod_mpoly/gen.c b/src/nmod_mpoly/gen.c index b7c3d209ef..9d65a84559 100644 --- a/src/nmod_mpoly/gen.c +++ b/src/nmod_mpoly/gen.c @@ -16,6 +16,12 @@ void nmod_mpoly_gen(nmod_mpoly_t A, slong var, const nmod_mpoly_ctx_t ctx) { flint_bitcnt_t bits; + if (ctx->mod.n == UWORD(1)) + { + nmod_mpoly_zero(A, ctx); + return; + } + bits = mpoly_gen_bits_required(var, ctx->minfo); bits = mpoly_fix_bits(bits, ctx->minfo); nmod_mpoly_fit_length_reset_bits(A, 1, bits, ctx); diff --git a/src/nmod_mpoly/is_gen.c b/src/nmod_mpoly/is_gen.c index daab1cbf43..f5fae4e260 100644 --- a/src/nmod_mpoly/is_gen.c +++ b/src/nmod_mpoly/is_gen.c @@ -15,6 +15,9 @@ int nmod_mpoly_is_gen(const nmod_mpoly_t A, slong var, const nmod_mpoly_ctx_t ctx) { + if (ctx->mod.n == UWORD(1)) + return 1; + if (A->length != WORD(1)) return 0; diff --git a/src/nmod_mpoly/test/t-gen.c b/src/nmod_mpoly/test/t-gen.c index e74d86de6c..1f29ac5f09 100644 --- a/src/nmod_mpoly/test/t-gen.c +++ b/src/nmod_mpoly/test/t-gen.c @@ -23,7 +23,7 @@ TEST_FUNCTION_START(nmod_mpoly_gen, state) slong len, exp_bits, k1, k2; ulong modulus; - modulus = UWORD(2) + n_randint(state, -UWORD(2)); + modulus = UWORD(1) + n_randint(state, -UWORD(2)); nmod_mpoly_ctx_init_rand(ctx, state, 20, modulus); if (ctx->minfo->nvars < 1) {