diff --git a/Project.toml b/Project.toml index decd4e0..8889cef 100644 --- a/Project.toml +++ b/Project.toml @@ -12,8 +12,8 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -MultivariatePolynomials = "0.5.9" -MutableArithmetics = "1" +MultivariatePolynomials = "0.5.12" +MutableArithmetics = "1.6.5" Reexport = "1" julia = "1" diff --git a/src/operators.jl b/src/operators.jl index dd27226..cbe67b7 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -183,9 +183,9 @@ end # TODO need to check that this also works for non-commutative function MA.operate!( op::Union{typeof(+),typeof(-)}, - p::Polynomial{V}, - q::Polynomial{V}, -) where {V<:Commutative} + p::Polynomial{V, M1, T1}, + q::Polynomial{V, M2, T2}, +) where {V<:Commutative, M1, M2, T1, T2} if MP.variables(p) != MP.variables(q) allvars, maps = ___add_variables!(p, q) if length(allvars) == length(MP.variables(q)) @@ -239,6 +239,7 @@ function MA.operate!( combine, keep, resize, + Tuple{MA.promote_operation(op, T1, T2), Vector{Int}}, ) return p end diff --git a/test/mutable_arithmetics.jl b/test/mutable_arithmetics.jl index 5529013..f5959d7 100644 --- a/test/mutable_arithmetics.jl +++ b/test/mutable_arithmetics.jl @@ -2,6 +2,7 @@ using Test import MutableArithmetics const MA = MutableArithmetics +import MultivariatePolynomials as MP using DynamicPolynomials @@ -100,3 +101,15 @@ end @test (@allocated MA.operate!(-, poly2, x)) <= 144 end end + +@testset "Non-concrete in-place polynomial addition" begin + @polyvar p q r s + p1 = MP.polynomial(r - q, Number) + MP.polynomial(3//5 * p^2, Number) + p2 = MP.polynomial(1//2 + s, Number) + MP.polynomial(p^2, Number) + result = p1 + p2 + @test isequal(result, MA.operate!(+, p1, p2)) + + p1 = MP.polynomial(r - q, Number) + MP.polynomial(3//5 * p^2, Number) + p2 = MP.polynomial(1//2 + s, Number) + MP.polynomial(p^2, Number) + @test isequal(result, MA.operate!(+, p2, p1)) +end