Skip to content

Commit

Permalink
fixup! Fix is_unit for MPolyRingElem
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jan 6, 2025
1 parent 0ed1bf9 commit 04625b5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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. <https://kconrad.math.uconn.edu/blurbs/ringtheory/polynomial-properties.pdf> 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
Expand Down

0 comments on commit 04625b5

Please sign in to comment.