|
1 | 1 | # Graded Lexicographic order |
2 | | -# First compare total degree, then lexicographic order |
3 | | -function Base.isless(m1::Monomial{V}, m2::Monomial{V}) where {V} |
4 | | - d1 = degree(m1) |
5 | | - d2 = degree(m2) |
6 | | - if d1 < d2 |
7 | | - return true |
8 | | - elseif d1 > d2 |
9 | | - return false |
10 | | - else |
11 | | - return exponents(m1) < exponents(m2) |
12 | | - end |
13 | | -end |
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 |
20 | | - else |
21 | | - return 1 |
22 | | - end |
23 | | -end |
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 | | - |
40 | | - |
41 | 2 | (==)(::Variable{N}, ::Variable{N}) where {N} = true |
42 | 3 | (==)(::Variable, ::Variable) = false |
43 | 4 | (==)(m1::Monomial{V}, m2::Monomial{V}) where {V} = exponents(m1) == exponents(m2) |
44 | 5 |
|
45 | 6 | # Multiplication is handled as a special case so that we can write these |
46 | 7 | # definitions without resorting to promotion: |
47 | 8 |
|
48 | | -(*)(v1::V, v2::V) where {V <: Variable} = Monomial{(V(),), 1}((2,)) |
| 9 | +(*)(::V, ::V) where {V <: Variable} = Monomial{(V(),), 1}((2,)) |
49 | 10 | (*)(v1::Variable, v2::Variable) = (*)(promote(v1, v2)...) |
50 | 11 |
|
51 | 12 | function MP.divides(m1::Monomial{V, N}, m2::Monomial{V, N}) where {V, N} |
|
68 | 29 | # We could remove these methods since it is the default. |
69 | 30 | MA.mutability(::Type{<:Monomial}) = MA.IsNotMutable() |
70 | 31 |
|
71 | | -^(v::V, x::Integer) where {V <: Variable} = Monomial{(V(),), 1}((x,)) |
| 32 | +^(::V, x::Integer) where {V <: Variable} = Monomial{(V(),), 1}((x,)) |
72 | 33 |
|
73 | 34 | # dot(v1::AbstractVector{<:TermLike}, v2::AbstractVector) = dot(v1, v2) |
74 | 35 | # dot(v1::AbstractVector, v2::AbstractVector{<:TermLike}) = dot(v1, v2) |
|
0 commit comments