Skip to content

Commit

Permalink
More fallbacks (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Jul 3, 2024
1 parent 1046d55 commit 1027a0b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1027a0b

Please sign in to comment.