Skip to content

Commit

Permalink
Fix division by zero in monomials_deflate.c.
Browse files Browse the repository at this point in the history
The documentation for `fmpz_mpoly_deflate` (and similar) states

> If any `stride[v]` is zero, the corresponding numerator `e - shift[v]` is assumed to
> be zero, and the quotient is defined as zero. This allows the function to undo the
> operation performed by `fmpz_mpoly_inflate()` when possible.

The previous comment and if-statement did not align meaning that the denominator was not
being checked leading to divisions by zero when `stride[v]` is 0.
  • Loading branch information
Jake-Moss committed Sep 8, 2024
1 parent 6c38679 commit 6007dd7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mpoly/monomials_deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ void mpoly_monomials_deflate(ulong * Aexps, flint_bitcnt_t Abits,
for (j = 0; j < nvars; j++)
{
fmpz_sub(exps + j, exps + j, shift + j);
/* stride + j is allowed to be zero */
if (!fmpz_is_zero(exps + j))
/* stride + j is allowed to be zero, if it is then exps + j is
assumed to be zero, and the quotient is defined as zero */
if (!fmpz_is_zero(exps + j) && !fmpz_is_zero(stride + j))
{
FLINT_ASSERT(fmpz_divisible(exps + j, stride + j));
fmpz_divexact(exps + j, exps + j, stride + j);
}
else
{
fmpz_zero(exps + j);
}

}
FLINT_ASSERT(Abits >= mpoly_exp_bits_required_ffmpz(exps, mctx));
mpoly_set_monomial_ffmpz(Aexps + NA*i, exps, Abits, mctx);
Expand Down

0 comments on commit 6007dd7

Please sign in to comment.