@@ -6,19 +6,37 @@ MP.substitute(st::MP.AbstractSubstitutionType, v::Variable, s::Substitution) = v
6
6
# subs(x, x=>y, y=>1) should be y, not 1 so as soon as we see the right variable, we stop, in subs(x, x=>y, x=>1), "x=>1" is ignored.
7
7
MP. substitute (st:: MP.AbstractSubstitutionType , v:: Variable{Name} , s:: Substitution{Name} , :: MP.AbstractSubstitution... ) where {Name} = s. second
8
8
9
- _remove_variable (t :: Tuple{} , :: Type ) = t
9
+ _remove_variable (:: Tuple{} , :: Type ) = nothing
10
10
function _remove_variable (t:: Tuple{V,Vararg{Variable,N}} , :: Type{V} ) where {V,N}
11
11
Base. tail (t)
12
12
end
13
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)... )
14
+ tail = _remove_variable (Base. tail (t), W)
15
+ if isnothing (tail)
16
+ return
17
+ else
18
+ return tuple (first (t), tail... )
19
+ end
15
20
end
16
21
17
22
_mult_monomial_type (:: Type{U} , :: Tuple{} ) where {U} = U
18
23
_mult_monomial_type (:: Type{U} , V:: Tuple ) where {U} = MA. promote_operation (* , U, Monomial{V,length (V)})
19
24
20
- function MA . promote_operation ( :: typeof (MP . substitute), :: Type{MP.Subs} , :: Type{Monomial{V,N}} , :: Type{Pair{Variable{Name},T}} ) where {V,N,Name,T}
25
+ function _promote_subs ( :: Type{Monomial{V,N}} , :: Type{Pair{Variable{Name},T}} ) where {V,N,Name,T}
21
26
U = MA. promote_operation (* , T, T)
22
27
VV = _remove_variable (V, Variable{Name})
23
- return _mult_monomial_type (U, VV)
28
+ if isnothing (VV)
29
+ # Variable not present
30
+ return Monomial{V,N}
31
+ else
32
+ return _mult_monomial_type (U, VV)
33
+ end
34
+ end
35
+
36
+ function MA. promote_operation (:: typeof (MP. substitute), :: Type{MP.Subs} , :: Type{Monomial{V,N}} , :: Type{Pair{Variable{Name},T}} ) where {V,N,Name,T}
37
+ return _promote_subs (Monomial{V,N}, Pair{Variable{Name},T})
38
+ end
39
+
40
+ function MA. promote_operation (:: typeof (MP. substitute), :: Type{MP.Eval} , :: Type{Monomial{V,N}} , :: Type{Pair{Variable{Name},T}} ) where {V,N,Name,T}
41
+ return _promote_subs (Monomial{V,N}, Pair{Variable{Name},T})
24
42
end
0 commit comments