Skip to content

Commit

Permalink
Allow variables of same positive degree in monomials_of_degree (#4497)
Browse files Browse the repository at this point in the history
  • Loading branch information
paemurru authored Jan 24, 2025
1 parent 3e86180 commit f329ec4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/InvariantTheory/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ end

function AllMonomials(R::MPolyDecRing, d::Int, vars::Vector{Int})
@req is_z_graded(R) "Iterator only implemented when the grading group is Z"
@req all(isequal(ZZ(1)), map(i -> degree(R[i])[1], vars)) "Iterator only implemented for variables of degree 1"
return AllMonomials{typeof(R)}(R, d, vars)
isempty(vars) && d !== 0 && return AllMonomials{typeof(R)}(R, 1, Int[])
isempty(vars) && return AllMonomials{typeof(R)}(R, 0, Int[])
deg_ZZ = degree(R[vars[1]])[1]
@req all(isequal(deg_ZZ), map(i -> degree(R[i])[1], vars)) "Iterator only implemented when all the given variables have the same nonzero degree"
deg = Int(deg_ZZ)
d == 0 && return AllMonomials{typeof(R)}(R, 0, Int[])
does_divide, quot = divides(d, deg)
does_divide || return AllMonomials{typeof(R)}(R, 1, Int[])
quot > 0 || return AllMonomials{typeof(R)}(R, 1, Int[])
return AllMonomials{typeof(R)}(R, quot, vars)
end

Base.eltype(::Type{AllMonomials{PolyRingT}}) where {PolyRingT} = elem_type(PolyRingT)
Expand Down
7 changes: 5 additions & 2 deletions test/InvariantTheory/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
@test isempty(monomials_of_degree(R, 2, Int[]))
end

R = graded_polynomial_ring(QQ, [:x, :y, :z], [1, 1, 3])[1]
x, y, z = gens(R)
R, (x, y, z, t) = graded_polynomial_ring(QQ, [:x, :y, :z, :t], [1, 1, 3, 3])
@test collect(monomials_of_degree(R, 3, [1, 2])) == [x^3, x^2 * y, x * y^2, y^3]
@test collect(monomials_of_degree(R, 6, [3, 4])) == [z^2, z * t, t^2]
@test collect(monomials_of_degree(R, -1, [3, 4])) == Vector{elem_type(R)}[]
@test collect(monomials_of_degree(R, 2, [3, 4])) == Vector{elem_type(R)}[]
@test collect(monomials_of_degree(R, 0, [3, 4])) == [R(1)]
end

0 comments on commit f329ec4

Please sign in to comment.