diff --git a/src/default_term.jl b/src/default_term.jl index 5e7b7990..2ed44b7c 100644 --- a/src/default_term.jl +++ b/src/default_term.jl @@ -31,6 +31,13 @@ monomial_type(::Type{<:Term{C,M}}) where {C,M} = M function Base.convert(::Type{Term{T,M}}, m::AbstractMonomialLike) where {T,M} return Term(one(T), convert(M, m)) end +function Base.convert(::Type{Term{T,M}}, t::AbstractTerm) where {T,M} + return Term{T,M}(convert(T, coefficient(t)), convert(M, monomial(t))) +end +function Base.convert(::Type{Term{T,M}}, t::Term{T,M}) where {T,M} + return t +end + function convert_constant(::Type{Term{C,M} where C}, α) where {M} return convert(Term{typeof(α),M}, α) end diff --git a/test/commutative/term.jl b/test/commutative/term.jl index 6da09258..08732ccb 100644 --- a/test/commutative/term.jl +++ b/test/commutative/term.jl @@ -63,6 +63,10 @@ MP.term_type(::Type{Term2{T,M}}) where {T,M} = MP.Term{T,M} @test_throws InexactError push!([1], 2x) @test_throws InexactError push!([x^2], 2x) + t = MP.term(1, x) + @test convert(MP.Term{Number,MP.monomial_type(t)}, t) isa + MP.Term{Number,MP.monomial_type(t)} + @testset "Effective variables" begin T = variable_union_type(x) @test x isa T