Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/comparison.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,23 @@ end

nvariables(it::ExponentsIterator) = length(it.object)

function Base.in(x, it::ExponentsIterator)
if length(x) != nvariables(it)
return false
end
if any(xi -> xi < 0, x)
return false
end
deg = sum(x)
if deg < it.mindegree
return false
end
if it.maxdegree !== nothing && deg > it.maxdegree
return false
end
return true
end

_last_lex_index(n, ::Type{LexOrder}) = n
_prev_lex_index(i, ::Type{LexOrder}) = i - 1
_not_first_indices(n, ::Type{LexOrder}) = n:-1:2
Expand Down
15 changes: 15 additions & 0 deletions test/comparison.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ function test_equal()
@test exp != ExponentsIterator{LexOrder}([0], maxdegree = 2)
end

function test_in()
# Unbounded iterator (no maxdegree)
it = ExponentsIterator{Graded{LexOrder}}([0, 0])
@test [0, 0] in it
@test [1, 2] in it
@test [3] ∉ it # wrong number of variables
@test [0, 0, 0] ∉ it # wrong number of variables
# Bounded iterator
it2 = ExponentsIterator{LexOrder}([0, 0], mindegree = 1, maxdegree = 3)
@test [1, 0] in it2
@test [1, 2] in it2
@test [0, 0] ∉ it2 # degree too low
@test [2, 2] ∉ it2 # degree too high
end

function test_errors()
err = ArgumentError(
"The `mindegree` of `ExponentsIterator` cannot be negative.",
Expand Down
Loading