Skip to content

Commit

Permalink
Define is_homogeneous for MPolyRingElem
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Apr 3, 2024
1 parent bae82ed commit de4a969
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ import .Generic: inverse_mat
import .Generic: invmod
import .Generic: is_compatible
import .Generic: is_divisible_by
import .Generic: is_homogeneous
import .Generic: is_power
import .Generic: is_rimhook
import .Generic: is_submodule
Expand Down
23 changes: 23 additions & 0 deletions src/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,29 @@ function is_monomial(x::MPolyRingElem{T}) where T <: RingElement
return length(x) == 1 && isone(first(coefficients(x)))
end

@doc raw"""
is_homogeneous(x::MPolyRingElem{T}) where {T <: RingElement}
Return `true` if the given polynomial is homogeneous with respect to the standard grading and `false` otherwise.
"""
function is_homogeneous(x::MPolyRingElem{T}) where {T <: RingElement}
last_deg = 0
is_first = true

for e in exponent_vectors(x)
d = sum(e)
if !is_first
if d != last_deg
return false
end
else
is_first = false
last_deg = d
end
end
return true
end

###############################################################################
#
# Iterators
Expand Down
25 changes: 0 additions & 25 deletions src/generic/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -642,31 +642,6 @@ function is_gen(x::MPoly{T}) where {T <: RingElement}
return is_gen(x, Val{parent(x).ord})
end

@doc raw"""
is_homogeneous(x::MPoly{T}) where {T <: RingElement}
Return `true` if the given polynomial is homogeneous with respect to the standard grading and `false` otherwise.
"""
function is_homogeneous(x::MPoly{T}) where {T <: RingElement}
last_deg = 0
is_first = true

for e in exponent_vectors(x)
d = sum(e)
if !is_first
if d != last_deg
return false
else
last_deg = d
end
else
is_first = false
last_deg = d
end
end
return true
end

@doc raw"""
coeff(x::MPoly, i::Int)
Expand Down

0 comments on commit de4a969

Please sign in to comment.