15
15
Base.:(+ )(x:: DMonomialLike , y:: DMonomialLike ) = Term (x) + Term (y)
16
16
Base.:(- )(x:: DMonomialLike , y:: DMonomialLike ) = Term (x) - Term (y)
17
17
18
- # `+(::UniformScaling)` is not defined...
19
- _unary (:: typeof (+ ), x) = MA. copy_if_mutable (x)
20
- _unary (:: typeof (- ), x) = - x
21
-
22
18
_getindex (p:: Polynomial , i) = p[i]
23
19
_getindex (t:: Term , i) = t
24
20
function _plusorminus_to! (a:: Vector{U} , Z:: Vector{Vector{Int}} , op:: Function , p:: TermPoly{C} , q:: TermPoly{C} , maps, nvars) where {C, U}
@@ -72,6 +68,11 @@ function MA.mutable_operate_to!(output::Polynomial{C}, op::Union{typeof(+), type
72
68
return output
73
69
end
74
70
71
+ # TODO replace by MA.operate with MA v0.2
72
+ # `+(::UniformScaling)` is not defined...
73
+ _unary (:: typeof (+ ), x) = MA. copy_if_mutable (x)
74
+ _unary (:: typeof (- ), x) = - x
75
+
75
76
function MA. mutable_operate! (op:: Union{typeof(+), typeof(-)} , p:: Polynomial ,
76
77
q:: Union{PolyVar, Monomial, Term} )
77
78
return MA. mutable_operate! (op, p, polynomial (q))
@@ -98,7 +99,7 @@ function MA.mutable_operate!(op::Union{typeof(+), typeof(-)}, p::Polynomial{true
98
99
return MA. mutable_operate! (op, p, rhs)
99
100
end
100
101
get1 (i) = (p. a[i], p. x. Z[i])
101
- get2 (i) = (MA. scaling_convert (eltype (p. a), MA . copy_if_mutable ( q. a[i])), copy (q. x. Z[i]))
102
+ get2 (i) = (MA. scaling_convert (eltype (p. a), _unary (op, q. a[i])), copy (q. x. Z[i]))
102
103
function set (i, t:: _NoVarTerm )
103
104
p. a[i] = t[1 ]
104
105
p. x. Z[i] = t[2 ]
@@ -133,6 +134,11 @@ Base.:(+)(x::Union{Monomial,PolyVar}, y::TermPoly{C}) where C = Term{C}(x) + y
133
134
Base.:(- )(x:: TermPoly{T} , y:: DMonomialLike ) where T = x - Term {T} (y)
134
135
Base.:(- )(x:: DMonomialLike , y:: TermPoly{T} ) where T = Term {T} (x) - y
135
136
136
- Base.:(- )(p:: Polynomial ) = Polynomial (- p. a, p. x)
137
+ # `MA.operate(-, p)` redirects to `-p` as it assumes that `-p` can be modified
138
+ # through the MA API without modifying `p`. We should either copy `p.x` here
139
+ # or implement a `MA.operate(-, p)` that copies it. We choose the first option.
140
+ Base.:(- )(p:: Polynomial ) = Polynomial (- p. a, copy (p. x))
141
+ # TODO use that with MA v0.2
142
+ # Base.:(-)(p::Polynomial) = Polynomial(map(α -> MA.operate(-, α), p.a), copy(p.x))
137
143
138
144
include (" mult.jl" )
0 commit comments