From 04625b55fb72e0ec053ed4524dd6f12c9caa6213 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 6 Jan 2025 18:03:31 +0100 Subject: [PATCH] fixup! Fix is_unit for MPolyRingElem --- src/MPoly.jl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/MPoly.jl b/src/MPoly.jl index f149dc37c..17e7f6cd2 100644 --- a/src/MPoly.jl +++ b/src/MPoly.jl @@ -426,20 +426,23 @@ end iszero(x::MPolyRingElem{T}) where T <: RingElement = length(x) == 0 function is_unit(f::T) where {T <: MPolyRingElem} + # for constant polynomials we delegate to the coefficient ring: + is_constant(f) && return is_unit(constant_coefficient(f)) + # Here deg(f) > 0; over an integral domain, non-constant polynomials are never units: + is_domain_type(T) && return false # A polynomial over a commutative ring is a unit iff its # constant term is a unit and all other coefficients are nilpotent: # see e.g. for a proof. - !is_unit(constant_coefficient(f)) && return false - # for constant polynomials we are done now - is_constant(f) && return true - # over a domain, non-constant polynomials are never units - is_domain_type(T) && return false - # remains to check the non-constant non-zero terms have nilpotent coefficients + constant_term_is_unit = false for (c, expv) in zip(coefficients(f), exponent_vectors(f)) - is_zero(expv) && continue # skip constant term - is_nilpotent(c) || return false + if is_zero(expv) + is_unit(c) || return false + constant_term_is_unit = true + else + is_nilpotent(c) || return false + end end - return true + return constant_term_is_unit end function content(a::MPolyRingElem{T}) where T <: RingElement