@@ -81,8 +81,39 @@ function powersubstitute(
8181)
8282 return powersubstitute (st, s, p) * powersubstitute (st, s, p2... )
8383end
84+
85+ function _promote_subs (S, T, s:: Substitution )
86+ # `T` is a constant
87+ return T
88+ end
89+
90+ function _promote_subs (S, T:: Type{<:Union{RationalPoly,_APL}} , s:: Substitution )
91+ return MA. promote_operation (substitute, S, T, typeof (s))
92+ end
93+
94+ function _promote_subs (S, T, s:: AbstractMultiSubstitution )
95+ return _promote_subs (
96+ S,
97+ T,
98+ pair_zip (_monomial_vector_to_variable_tuple (s))... ,
99+ )
100+ end
101+
102+ function _promote_subs (
103+ S,
104+ T,
105+ head:: AbstractSubstitution ,
106+ tail:: Vararg{AbstractSubstitution,N} ,
107+ ) where {N}
108+ return _promote_subs (S, _promote_subs (S, T, head), tail... )
109+ end
110+
84111function substitute (st:: _AST , m:: AbstractMonomial , s:: Substitutions )
85- return powersubstitute (st, s, powers (m)... )
112+ if isconstant (m)
113+ return one (_promote_subs (typeof (st), typeof (m), s... ))
114+ else
115+ return powersubstitute (st, s, powers (m)... )
116+ end
86117end
87118
88119# # Terms
92123
93124function MA. promote_operation (
94125 :: typeof (substitute),
95- :: Type{Subs} ,
126+ :: Type{Eval} ,
127+ :: Type{M} ,
128+ :: Type{Pair{V,T}} ,
129+ ) where {M<: AbstractMonomial ,V<: AbstractVariable ,T}
130+ return MA. promote_operation (* , T, T)
131+ end
132+
133+ function MA. promote_operation (
134+ :: typeof (substitute),
135+ :: Type{S} ,
96136 :: Type{T} ,
97137 args:: Vararg{Type,N} ,
98- ) where {T<: AbstractTerm ,N}
99- M = MA. promote_operation (substitute, Subs , monomial_type (T), args... )
138+ ) where {S <: AbstractSubstitutionType , T<: AbstractTerm ,N}
139+ M = MA. promote_operation (substitute, S , monomial_type (T), args... )
100140 U = coefficient_type (T)
101141 return MA. promote_operation (* , U, M)
102142end
@@ -121,11 +161,11 @@ end
121161
122162function MA. promote_operation (
123163 :: typeof (substitute),
124- :: Type{Subs } ,
164+ :: Type{S } ,
125165 :: Type{P} ,
126166 args:: Vararg{Type,N} ,
127- ) where {P<: AbstractPolynomial ,N}
128- T = MA. promote_operation (substitute, Subs , term_type (P), args... )
167+ ) where {S <: AbstractSubstitutionType , P<: AbstractPolynomial ,N}
168+ T = MA. promote_operation (substitute, S , term_type (P), args... )
129169 return MA. promote_operation (+ , T, T)
130170end
131171
0 commit comments