Skip to content

Commit b90fb4e

Browse files
committed
Fix is_unit for MPolyRingElem
1 parent dc96201 commit b90fb4e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/MPoly.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,19 +426,18 @@ end
426426
iszero(x::MPolyRingElem{T}) where T <: RingElement = length(x) == 0
427427

428428
function is_unit(f::T) where {T <: MPolyRingElem}
429-
# for constant polynomials we delegate to the coefficient ring:
430-
is_constant(f) && return is_unit(constant_coefficient(f))
431-
# Here deg(f) > 0; over an integral domain, non-constant polynomials are never units:
432-
is_domain_type(T) && return false
433429
# A polynomial over a commutative ring is a unit iff its
434430
# constant term is a unit and all other coefficients are nilpotent:
435431
# see e.g. <https://kconrad.math.uconn.edu/blurbs/ringtheory/polynomial-properties.pdf> for a proof.
432+
!is_unit(constant_coefficient(f)) && return false
433+
# for constant polynomials we are done now
434+
is_constant(f) && return true
435+
# over a domain, non-constant polynomials are never units
436+
is_domain_type(T) && return false
437+
# remains to check the non-constant non-zero terms have nilpotent coefficients
436438
for (c, expv) in zip(coefficients(f), exponent_vectors(f))
437-
if is_zero(expv)
438-
is_unit(c) || return false
439-
else
440-
is_nilpotent(c) || return false
441-
end
439+
is_zero(expv) && continue # skip constant term
440+
is_nilpotent(c) || return false
442441
end
443442
return true
444443
end

0 commit comments

Comments
 (0)