Skip to content

Commit 405cbed

Browse files
authored
Preliminary support for other monomial ordering (#83)
* Preliminary support for other monomial ordering * Fix
1 parent c14d479 commit 405cbed

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/operators.jl

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@ function Base.isless(m1::Monomial{V}, m2::Monomial{V}) where {V}
1111
return exponents(m1) < exponents(m2)
1212
end
1313
end
14-
function MP.grlex(m1::Monomial{V}, m2::Monomial{V}) where {V}
15-
d1 = degree(m1)
16-
d2 = degree(m2)
17-
if d1 != d2
18-
return d1 - d2
14+
15+
function _compare(a::Tuple, b::Tuple, ::Type{MP.LexOrder})
16+
if a == b
17+
return 0
18+
elseif a < b
19+
return -1
1920
else
20-
if exponents(m1) == exponents(m2)
21-
return 0
22-
elseif exponents(m1) < exponents(m2)
23-
return -1
24-
else
25-
return 1
26-
end
21+
return 1
2722
end
2823
end
29-
MP.grlex(m1::Monomial, m2::Monomial) = MP.grlex(promote(m1, m2)...)
24+
function _compare(a::Tuple, b::Tuple, ::Type{MP.InverseLexOrder})
25+
return _compare(reverse(a), reverse(b), MP.LexOrder)
26+
end
27+
28+
function MP.compare(m1::Monomial{V}, m2::Monomial{V}, ::Type{O}) where {V,O<:Union{MP.LexOrder,MP.InverseLexOrder}}
29+
return _compare(MP.exponents(m1), MP.exponents(m2), O)
30+
end
31+
32+
function MP.compare(m1::Monomial, m2::Monomial, ::Type{O}) where {O<:Union{MP.LexOrder,MP.InverseLexOrder}}
33+
return MP.compare(promote(m1, m2)..., O)
34+
end
35+
36+
function MP.compare(m1::Monomial, m2::Monomial)
37+
return MP.compare(m1, m2, MP.Graded{MP.LexOrder})
38+
end
39+
3040

3141
(==)(::Variable{N}, ::Variable{N}) where {N} = true
3242
(==)(::Variable, ::Variable) = false

0 commit comments

Comments
 (0)