Skip to content

Commit 2668e1e

Browse files
committed
Fixes
1 parent b2d50f6 commit 2668e1e

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/comp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function (==)(x::MonomialVector{V,M}, y::MonomialVector{V,M}) where {V,M}
4040
# Should be sorted in the same order since the non-common
4141
# polyvar should have exponent 0
4242
for (a, b) in zip(x.Z, y.Z)
43-
A = zeros(length(allvars))
44-
B = zeros(length(allvars))
43+
A = zeros(Int, length(allvars))
44+
B = zeros(Int, length(allvars))
4545
A[maps[1]] = a
4646
B[maps[2]] = b
4747
if A != B

src/monomial_vector.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
export MonomialVector
22

3-
struct AllMonomials{V,M} <: AbstractVector{Monomial{V,M}}
4-
vars::Vector{Variable{V,M}}
5-
end
6-
Base.IteratorSize(::Type{<:AllMonomials}) = Base.IsInfinite()
7-
83
# Invariant: Always sorted and no zero vector
94
struct MonomialVector{V,M} <: AbstractVector{Monomial{V,M}}
105
vars::Vector{Variable{V,M}}
@@ -153,6 +148,15 @@ function _error_for_negative_degree(deg)
153148
end
154149
end
155150

151+
const _Lex = Union{MP.LexOrder,MP.InverseLexOrder}
152+
153+
_last_lex_index(n, ::Type{MP.LexOrder}) = n
154+
_prev_lex_index(i, ::Type{MP.LexOrder}) = i - 1
155+
_not_first_indices(n, ::Type{MP.LexOrder}) = n:-1:2
156+
_last_lex_index(_, ::Type{MP.InverseLexOrder}) = 1
157+
_prev_lex_index(i, ::Type{MP.InverseLexOrder}) = i + 1
158+
_not_first_indices(n, ::Type{MP.InverseLexOrder}) = 1:(n-1)
159+
156160
function _fill_exponents!(Z, n, degs, ::Type{Commutative}, M::Type{<:_Lex}, filter::Function)
157161
_error_for_negative_degree.(degs)
158162
maxdeg = maximum(degs, init = 0)

src/var.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,15 @@ function mergevars_of(::Type{Variable{V,M}}, polys::AbstractVector) where {V,M}
291291
# TODO avoid computing `maps`
292292
return mergevars(varsvec)
293293
end
294+
295+
function MP.promote_variables(m1::Monomial, m2::Monomial)
296+
if MP.variables(m1) == MP.variables(m2)
297+
return m1, m2
298+
end
299+
allvars, maps = mergevars([MP.variables(m1), MP.variables(m2)])
300+
z1 = zeros(Int, length(allvars))
301+
z1[maps[1]] = m1.z
302+
z2 = zeros(Int, length(allvars))
303+
z2[maps[2]] = m2.z
304+
return Monomial(allvars, z1), Monomial(allvars, z2)
305+
end

0 commit comments

Comments
 (0)