diff --git a/src/arithmetic.jl b/src/arithmetic.jl index e613c3d..e806d82 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -75,3 +75,30 @@ for op in [:+, :-] end end end + +function MA.operate!(op::Union{typeof(+),typeof(-),typeof(*)}, p::_APL, q::_AE) + return MA.operate!(op, p, MP.polynomial(q)) +end + +# These are not implemented yet for arbitrary bases so we +# fall back to polynomials + +function MP.substitute( + s::MP.AbstractSubstitutionType, + p::_AE, + args::MP.AbstractSubstitution..., +) + return MP.substitute(s, MP.polynomial(p), args...) +end + +function MP.subs(p::_AE, args::MP.AbstractSubstitution...) + return MP.substitute(MP.Subs(), p, args...) +end + +function (p::_AE)(args::MP.AbstractSubstitution...) + return MP.substitute(MP.Eval(), p, args...) +end + +function MP.differentiate(p::_AE, args...) + return MP.differentiate(MP.polynomial(p), args...) +end diff --git a/test/runtests.jl b/test/runtests.jl index 569f942..763c2c0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -95,10 +95,15 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree) @test iszero(_test_op(-, other, const_alg_el)) @test iszero(_test_op(-, const_alg_el, other)) end + @test iszero(MA.operate!(-, polynomial(const_alg_el), const_alg_el)) + @test iszero(MA.operate!(+, -polynomial(const_alg_el), const_alg_el)) @test typeof(MB.sparse_coefficients(sum(x))) == MA.promote_operation(MB.sparse_coefficients, typeof(sum(x))) @test typeof(MB.algebra_element(sum(x))) == MA.promote_operation(MB.algebra_element, typeof(sum(x))) + @test const_alg_el(x => ones(length(x))) == const_mono + @test subs(const_alg_el, x => ones(length(x))) == const_mono + @test differentiate(const_alg_el, x) == differentiate(const_mono, x) end function univ_orthogonal_test(