diff --git a/Project.toml b/Project.toml index 2cfde91..968586b 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -MultivariatePolynomials = "0.5.3" +MultivariatePolynomials = "0.5.6" MutableArithmetics = "1" Reexport = "1" julia = "1" diff --git a/src/comp.jl b/src/comp.jl index 62e7edd..a74c019 100644 --- a/src/comp.jl +++ b/src/comp.jl @@ -1,8 +1,5 @@ import Base.== -#Base.iszero(t::Term) = iszero(MP.coefficient(t)) -Base.iszero(p::Polynomial) = isempty(p) - # TODO This should be in Base with T instead of Variable{V,M}. # See https://github.com/blegat/MultivariatePolynomials.jl/issues/3 function (==)(x::Vector{Variable{V,M}}, y::Vector{Variable{V,M}}) where {V,M} @@ -162,10 +159,10 @@ end # Comparison of Term function (==)(p::Polynomial{V,M}, q::Polynomial{V,M}) where {V,M} # terms should be sorted and without zeros - if length(p) != length(q) + if MP.nterms(p) != MP.nterms(q) return false end - for i in 1:length(p) + for i in eachindex(p.a) if p.x[i] != q.x[i] # There should not be zero terms @assert p.a[i] != 0 diff --git a/src/mult.jl b/src/mult.jl index 929a22a..bd63732 100644 --- a/src/mult.jl +++ b/src/mult.jl @@ -101,12 +101,12 @@ function _mul( else allvars, maps = mergevars([MP.variables(p), MP.variables(q)]) end - N = length(p) * length(q) + N = MP.nterms(p) * MP.nterms(q) Z = Vector{Vector{Int}}(undef, N) a = Vector{T}(undef, N) i = 0 - for u in p - for v in q + for u in MP.terms(p) + for v in MP.terms(q) if samevars z = MP.monomial(u).z + MP.monomial(v).z else diff --git a/src/operators.jl b/src/operators.jl index aa14e65..539d1bc 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -15,7 +15,7 @@ end Base.:(+)(x::DMonomialLike, y::DMonomialLike) = MP.term(x) + MP.term(y) Base.:(-)(x::DMonomialLike, y::DMonomialLike) = MP.term(x) - MP.term(y) -_getindex(p::Polynomial, i::Int) = p[i] +_getindex(p::Polynomial, i::Int) = MP.terms(p)[i] _getindex(t::_Term, ::Int) = t function _plusorminus_to!( a::Vector{U}, diff --git a/src/poly.jl b/src/poly.jl index 0c8f727..8334416 100644 --- a/src/poly.jl +++ b/src/poly.jl @@ -137,14 +137,6 @@ end #Base.convert(::Type{term_type{V,M}}, p::TermContainer{V,M}) where {V,M} = p #Base.convert(::Type{term_type{V,M,T}}, p::TermContainer{V,M,T}) where {V,M,T} = p -Base.length(p::Polynomial) = length(p.a) -Base.isempty(p::Polynomial) = isempty(p.a) -Base.iterate(p::Polynomial) = isempty(p) ? nothing : (p[1], 1) -function Base.iterate(p::Polynomial, state::Int) - return state < length(p) ? (p[state+1], state + 1) : nothing -end -#eltype(::Type{Polynomial{V,M,T}}) where {V,M,T} = T -Base.getindex(p::Polynomial, I::Int) = MP.term(p.a[I[1]], p.x[I[1]]) #Base.transpose(p::Polynomial) = Polynomial(map(transpose, p.a), p.x) # FIXME invalid age range update @@ -192,7 +184,7 @@ function MP.remove_monomials(p::Polynomial, x::MonomialVector) # use the fact that monomials are sorted to do this O(n) instead of O(n^2) j = 1 I = Int[] - for (i, t) in enumerate(p) + for (i, t) in enumerate(MP.terms(p)) while j <= length(x) && x[j] < MP.monomial(t) j += 1 end