Skip to content

Commit

Permalink
Merge pull request #2115 from thofma/main
Browse files Browse the repository at this point in the history
fix: fmpz_mod_poly for modulus 1
  • Loading branch information
albinahlback authored Nov 24, 2024
2 parents 487785c + 4b84512 commit cb7513b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/fmpz_mod_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,7 @@ int fmpz_mod_poly_is_one(const fmpz_mod_poly_t poly, const fmpz_mod_ctx_t FLINT_
return poly->length == 1 && poly->coeffs[0] == WORD(1);
}

FMPZ_MOD_POLY_INLINE
int fmpz_mod_poly_is_gen(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t FLINT_UNUSED(ctx))
{
return op->length == 2 && op->coeffs[1] == WORD(1) && op->coeffs[0] == WORD(0);
}
int fmpz_mod_poly_is_gen(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx);

int fmpz_mod_poly_is_unit(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx);

Expand Down
9 changes: 8 additions & 1 deletion src/fmpz_mod_poly/attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
#include "fmpz_mod.h"
#include "fmpz_mod_poly.h"

int fmpz_mod_poly_is_gen(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx)
{
return (*fmpz_mod_ctx_modulus(ctx) == UWORD(1)) ||
(op->length == 2 && op->coeffs[1] == WORD(1) && op->coeffs[0] == WORD(0));
}

/* bogus for non-prime modulus */
int fmpz_mod_poly_is_unit(const fmpz_mod_poly_t op, const fmpz_mod_ctx_t ctx)
{
return (op->length == 1) && fmpz_mod_is_invertible(op->coeffs + 0, ctx);
return (*fmpz_mod_ctx_modulus(ctx) == UWORD(1)) ||
(op->length == 1 && fmpz_mod_is_invertible(op->coeffs + 0, ctx));
}

0 comments on commit cb7513b

Please sign in to comment.