Skip to content

Commit 64b0709

Browse files
authored
Simplify comparison (#89)
* Simplify comparison * Update ci * Remove ordering
1 parent 133520c commit 64b0709

File tree

3 files changed

+16
-54
lines changed

3 files changed

+16
-54
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,25 @@ jobs:
2727
os: ubuntu-latest
2828
arch: x64
2929
steps:
30-
- uses: actions/checkout@v3
31-
- uses: julia-actions/setup-julia@v1
30+
- uses: actions/checkout@v4
31+
- uses: julia-actions/setup-julia@v2
3232
with:
3333
version: ${{ matrix.version }}
3434
arch: ${{ matrix.arch }}
35-
- uses: actions/cache@v1
36-
env:
37-
cache-name: cache-artifacts
38-
with:
39-
path: ~/.julia/artifacts
40-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
41-
restore-keys: |
42-
${{ runner.os }}-test-${{ env.cache-name }}-
43-
${{ runner.os }}-test-
44-
${{ runner.os }}-
35+
- uses: julia-actions/cache@v2
36+
- name: MP
37+
shell: julia --project=@. {0}
38+
run: |
39+
using Pkg
40+
Pkg.add([
41+
PackageSpec(name="MultivariatePolynomials", rev="master"),
42+
])
4543
- uses: julia-actions/julia-buildpkg@v1
4644
- uses: julia-actions/julia-runtest@v1
4745
with:
4846
depwarn: error
4947
- uses: julia-actions/julia-processcoverage@v1
50-
- uses: codecov/codecov-action@v3
48+
- uses: codecov/codecov-action@v4
5149
with:
5250
file: lcov.info
51+
token: ${{ secrets.CODECOV_TOKEN }}

src/operators.jl

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,12 @@
11
# 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-
412
(==)(::Variable{N}, ::Variable{N}) where {N} = true
423
(==)(::Variable, ::Variable) = false
434
(==)(m1::Monomial{V}, m2::Monomial{V}) where {V} = exponents(m1) == exponents(m2)
445

456
# Multiplication is handled as a special case so that we can write these
467
# definitions without resorting to promotion:
478

48-
(*)(v1::V, v2::V) where {V <: Variable} = Monomial{(V(),), 1}((2,))
9+
(*)(::V, ::V) where {V <: Variable} = Monomial{(V(),), 1}((2,))
4910
(*)(v1::Variable, v2::Variable) = (*)(promote(v1, v2)...)
5011

5112
function MP.divides(m1::Monomial{V, N}, m2::Monomial{V, N}) where {V, N}
@@ -68,7 +29,7 @@ end
6829
# We could remove these methods since it is the default.
6930
MA.mutability(::Type{<:Monomial}) = MA.IsNotMutable()
7031

71-
^(v::V, x::Integer) where {V <: Variable} = Monomial{(V(),), 1}((x,))
32+
^(::V, x::Integer) where {V <: Variable} = Monomial{(V(),), 1}((x,))
7233

7334
# dot(v1::AbstractVector{<:TermLike}, v2::AbstractVector) = dot(v1, v2)
7435
# dot(v1::AbstractVector, v2::AbstractVector{<:TermLike}) = dot(v1, v2)

src/types.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ function MP.monomials(vars::Tuple{Vararg{Variable}}, degrees::AbstractArray, fil
113113
for p in monomial_powers(Val{length(vars)}(), d) if filter(Monomial{vars}(p))]
114114
end
115115
end
116+
117+
MP.promote_variables(a::MonomialLike, b::MonomialLike) = promote(a, b)

0 commit comments

Comments
 (0)