diff --git a/src/comp.jl b/src/comp.jl index a687949..a74c019 100644 --- a/src/comp.jl +++ b/src/comp.jl @@ -159,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 8521190..bd63732 100644 --- a/src/mult.jl +++ b/src/mult.jl @@ -101,7 +101,7 @@ 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 diff --git a/src/poly.jl b/src/poly.jl index 3195c56..8334416 100644 --- a/src/poly.jl +++ b/src/poly.jl @@ -184,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