@@ -50,6 +50,12 @@ substitute(st::AST, m::AbstractMonomial, s::Substitutions) = powersubstitute(st,
5050# # Terms
5151substitute (st:: AST , t:: AbstractTerm , s:: Substitutions ) = coefficient (t) * substitute (st, monomial (t), s)
5252
53+ function MA. promote_operation (:: typeof (substitute), :: Type{Subs} , :: Type{T} , args:: Vararg{Type,N} ) where {T<: AbstractTerm ,N}
54+ M = MA. promote_operation (substitute, Subs, monomialtype (T), args... )
55+ U = coefficienttype (T)
56+ return MA. promote_operation (* , U, M)
57+ end
58+
5359# # Polynomials
5460_polynomial (α) = α
5561_polynomial (p:: APL ) = polynomial (p)
@@ -59,7 +65,7 @@ function substitute(st::AST, p::AbstractPolynomial, s::Substitutions)
5965 else
6066 ts = terms (p)
6167 r1 = substitute (st, ts[1 ], s)
62- R = Base . promote_op (+ , typeof (r1), typeof (r1))
68+ R = MA . promote_operation (+ , typeof (r1), typeof (r1))
6369 result:: R = convert (R, r1)
6470 for i in 2 : length (ts)
6571 result += substitute (st, ts[i], s)
@@ -68,6 +74,11 @@ function substitute(st::AST, p::AbstractPolynomial, s::Substitutions)
6874 end
6975end
7076
77+ function MA. promote_operation (:: typeof (substitute), :: Type{Subs} , :: Type{P} , args:: Vararg{Type,N} ) where {P<: AbstractPolynomial ,N}
78+ T = MA. promote_operation (substitute, Subs, termtype (P), args... )
79+ return MA. promote_operation (+ , T, T)
80+ end
81+
7182# # Fallbacks
7283substitute (st:: AST , p:: APL , s:: Substitutions ) = substitute (st, polynomial (p), s)
7384substitute (st:: AST , q:: RationalPoly , s:: Substitutions ) = substitute (st, q. num, s) / substitute (st, q. den, s)
0 commit comments