Skip to content

Commit ba9479f

Browse files
authored
Improve promote_operation for substitution (#84)
1 parent 405cbed commit ba9479f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/substitution.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ MP.substitute(st::MP.AbstractSubstitutionType, v::Variable, s::Substitution) = v
77
MP.substitute(st::MP.AbstractSubstitutionType, v::Variable{Name}, s::Substitution{Name}, ::MP.AbstractSubstitution...) where {Name} = s.second
88

99
_remove_variable(t::Tuple{}, ::Type) = t
10-
_remove_variable(t::Tuple{V,Vararg{Variable,N}}, ::Type{V}) where {V,N} = Base.tail(t)
11-
_remove_variable(t::Tuple{V,Vararg{Variable,N}}, ::Type{W}) where {V,W,N} = tuple(first(t), _remove_variable(Base.tail(t), V)...)
10+
function _remove_variable(t::Tuple{V,Vararg{Variable,N}}, ::Type{V}) where {V,N}
11+
Base.tail(t)
12+
end
13+
function _remove_variable(t::Tuple{V,Vararg{Variable,N}}, ::Type{W}) where {V,W,N}
14+
tuple(first(t), _remove_variable(Base.tail(t), W)...)
15+
end
16+
17+
_mult_monomial_type(::Type{U}, ::Tuple{}) where {U} = U
18+
_mult_monomial_type(::Type{U}, V::Tuple) where {U} = MA.promote_operation(*, U, Monomial{V,length(V)})
1219

1320
function MA.promote_operation(::typeof(MP.substitute), ::Type{MP.Subs}, ::Type{Monomial{V,N}}, ::Type{Pair{Variable{Name},T}}) where {V,N,Name,T}
14-
U = MA.promote_operation(^, T, Int)
21+
U = MA.promote_operation(*, T, T)
1522
VV = _remove_variable(V, Variable{Name})
16-
return Term{U,Monomial{VV,length(VV)}}
23+
return _mult_monomial_type(U, VV)
1724
end

0 commit comments

Comments
 (0)