Skip to content

Commit 1027a0b

Browse files
authored
More fallbacks (#38)
1 parent 1046d55 commit 1027a0b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/arithmetic.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,30 @@ for op in [:+, :-]
7575
end
7676
end
7777
end
78+
79+
function MA.operate!(op::Union{typeof(+),typeof(-),typeof(*)}, p::_APL, q::_AE)
80+
return MA.operate!(op, p, MP.polynomial(q))
81+
end
82+
83+
# These are not implemented yet for arbitrary bases so we
84+
# fall back to polynomials
85+
86+
function MP.substitute(
87+
s::MP.AbstractSubstitutionType,
88+
p::_AE,
89+
args::MP.AbstractSubstitution...,
90+
)
91+
return MP.substitute(s, MP.polynomial(p), args...)
92+
end
93+
94+
function MP.subs(p::_AE, args::MP.AbstractSubstitution...)
95+
return MP.substitute(MP.Subs(), p, args...)
96+
end
97+
98+
function (p::_AE)(args::MP.AbstractSubstitution...)
99+
return MP.substitute(MP.Eval(), p, args...)
100+
end
101+
102+
function MP.differentiate(p::_AE, args...)
103+
return MP.differentiate(MP.polynomial(p), args...)
104+
end

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
9595
@test iszero(_test_op(-, other, const_alg_el))
9696
@test iszero(_test_op(-, const_alg_el, other))
9797
end
98+
@test iszero(MA.operate!(-, polynomial(const_alg_el), const_alg_el))
99+
@test iszero(MA.operate!(+, -polynomial(const_alg_el), const_alg_el))
98100
@test typeof(MB.sparse_coefficients(sum(x))) ==
99101
MA.promote_operation(MB.sparse_coefficients, typeof(sum(x)))
100102
@test typeof(MB.algebra_element(sum(x))) ==
101103
MA.promote_operation(MB.algebra_element, typeof(sum(x)))
104+
@test const_alg_el(x => ones(length(x))) == const_mono
105+
@test subs(const_alg_el, x => ones(length(x))) == const_mono
106+
@test differentiate(const_alg_el, x) == differentiate(const_mono, x)
102107
end
103108

104109
function univ_orthogonal_test(

0 commit comments

Comments
 (0)