51
51
(+ )(p1:: Polynomial , p2:: Polynomial{<:UniformScaling} ) = p1 + MP. mapcoefficientsnz (J -> J. λ, p2)
52
52
(+ )(p1:: Polynomial{<:UniformScaling} , p2:: Polynomial ) = MP. mapcoefficientsnz (J -> J. λ, p1) + p2
53
53
(+ )(p1:: Polynomial{<:UniformScaling} , p2:: Polynomial{<:UniformScaling} ) = MP. mapcoefficientsnz (J -> J. λ, p1) + p2
54
- function MA. mutable_operate_to ! (result:: Polynomial , :: typeof (+ ), p1:: Polynomial , p2:: Polynomial )
54
+ function MA. operate_to ! (result:: Polynomial , :: typeof (+ ), p1:: Polynomial , p2:: Polynomial )
55
55
if result === p1 || result === p2
56
- error (" Cannot call `mutable_operate_to !(output, +, p, q)` with `output` equal to `p` or `q`, call `mutable_operate !` instead." )
56
+ error (" Cannot call `operate_to !(output, +, p, q)` with `output` equal to `p` or `q`, call `operate !` instead." )
57
57
end
58
58
jointerms! (result. terms, terms (p1), terms (p2))
59
59
result
60
60
end
61
- function MA. mutable_operate_to ! (result:: Polynomial , :: typeof (* ), p:: Polynomial , t:: AbstractTermLike )
61
+ function MA. operate_to ! (result:: Polynomial , :: typeof (* ), p:: Polynomial , t:: AbstractTermLike )
62
62
if iszero (t)
63
- MA. mutable_operate ! (zero, result)
63
+ MA. operate ! (zero, result)
64
64
else
65
65
resize! (result. terms, nterms (p))
66
66
for i in eachindex (p. terms)
67
- # TODO could use MA.mul_to! for indices that were presents in `result` before the `resize!`.
67
+ # TODO could use MA.mul_to!! for indices that were presents in `result` before the `resize!`.
68
68
result. terms[i] = p. terms[i] * t
69
69
end
70
70
return result
71
71
end
72
72
end
73
- function MA. mutable_operate_to ! (result:: Polynomial , :: typeof (* ), t:: AbstractTermLike , p:: Polynomial )
73
+ function MA. operate_to ! (result:: Polynomial , :: typeof (* ), t:: AbstractTermLike , p:: Polynomial )
74
74
if iszero (t)
75
- MA. mutable_operate ! (zero, result)
75
+ MA. operate ! (zero, result)
76
76
else
77
77
resize! (result. terms, nterms (p))
78
78
for i in eachindex (p. terms)
79
- # TODO could use MA.mul_to! for indices that were presents in `result` before the `resize!`.
79
+ # TODO could use MA.mul_to!! for indices that were presents in `result` before the `resize!`.
80
80
result. terms[i] = t * p. terms[i]
81
81
end
82
82
return result
87
87
(- )(p1:: Polynomial{<:UniformScaling} , p2:: Polynomial ) = MP. mapcoefficientsnz (J -> J. λ, p1) - p2
88
88
(- )(p1:: Polynomial{<:UniformScaling} , p2:: Polynomial{<:UniformScaling} ) = MP. mapcoefficientsnz (J -> J. λ, p1) - p2
89
89
90
- function MA. mutable_operate ! (op:: Union{typeof(+), typeof(-)} , p:: Polynomial{T} , q:: Polynomial ) where T
90
+ function MA. operate ! (op:: Union{typeof(+), typeof(-)} , p:: Polynomial{T} , q:: Polynomial ) where T
91
91
get1 (i) = p. terms[i]
92
92
function get2 (i)
93
93
t = q. terms[i]
@@ -97,12 +97,12 @@ function MA.mutable_operate!(op::Union{typeof(+), typeof(-)}, p::Polynomial{T},
97
97
push (t:: Term ) = push! (p. terms, t)
98
98
compare_monomials (t:: Term , j:: Int ) = grlex (q. terms[j]. monomial, t. monomial)
99
99
compare_monomials (i:: Int , j:: Int ) = compare_monomials (get1 (i), j)
100
- combine (i:: Int , j:: Int ) = p. terms[i] = Term (MA. operate! (op, p. terms[i]. coefficient, q. terms[j]. coefficient), p. terms[i]. monomial)
101
- combine (t:: Term , j:: Int ) = Term (MA. operate! (op, t. coefficient, q. terms[j]. coefficient), t. monomial)
100
+ combine (i:: Int , j:: Int ) = p. terms[i] = Term (MA. operate!! (op, p. terms[i]. coefficient, q. terms[j]. coefficient), p. terms[i]. monomial)
101
+ combine (t:: Term , j:: Int ) = Term (MA. operate!! (op, t. coefficient, q. terms[j]. coefficient), t. monomial)
102
102
resize (n) = resize! (p. terms, n)
103
103
# We can modify the coefficient since it's the result of `combine`.
104
- keep (t:: Term ) = ! MA. iszero! (t. coefficient)
105
- keep (i:: Int ) = ! MA. iszero! (p. terms[i]. coefficient)
104
+ keep (t:: Term ) = ! MA. iszero!! (t. coefficient)
105
+ keep (i:: Int ) = ! MA. iszero!! (p. terms[i]. coefficient)
106
106
MP. polynomial_merge! (
107
107
nterms (p), nterms (q), get1, get2, set, push,
108
108
compare_monomials, combine, keep, resize
@@ -138,36 +138,36 @@ function MP.mapexponents!(op::F, m1::Monomial, m2::Monomial) where {F<:Function}
138
138
return MP. mapexponents (op, m1, m2)
139
139
end
140
140
141
- function MA. mutable_operate_to ! (output:: Polynomial , :: typeof (* ), p:: Polynomial , q:: Polynomial )
141
+ function MA. operate_to ! (output:: Polynomial , :: typeof (* ), p:: Polynomial , q:: Polynomial )
142
142
empty! (output. terms)
143
143
MP. mul_to_terms! (output. terms, p, q)
144
144
sort! (output. terms, lt= (> ))
145
145
MP. uniqterms! (output. terms)
146
146
return output
147
147
end
148
- function MA. mutable_operate ! (:: typeof (* ), p:: Polynomial , q:: Polynomial )
149
- return MA. mutable_operate_to ! (p, * , MA. mutable_copy (p), q)
148
+ function MA. operate ! (:: typeof (* ), p:: Polynomial , q:: Polynomial )
149
+ return MA. operate_to ! (p, * , MA. mutable_copy (p), q)
150
150
end
151
151
152
- function MA. mutable_operate ! (:: typeof (zero), p:: Polynomial )
152
+ function MA. operate ! (:: typeof (zero), p:: Polynomial )
153
153
empty! (p. terms)
154
154
return p
155
155
end
156
- function MA. mutable_operate ! (:: typeof (one), p:: Polynomial{T} ) where T
156
+ function MA. operate ! (:: typeof (one), p:: Polynomial{T} ) where T
157
157
if isempty (p. terms)
158
158
push! (p. terms, constantterm (one (T), p))
159
159
else
160
160
t = p. terms[1 ]
161
- p. terms[1 ] = Term (MA. one! (coefficient (t)), constantmonomial (t))
161
+ p. terms[1 ] = Term (MA. one!! (coefficient (t)), constantmonomial (t))
162
162
resize! (p. terms, 1 )
163
163
end
164
164
return p
165
165
end
166
166
167
167
# The exponents are stored in a tuple, this is not mutable.
168
168
# We could remove these methods since it is the default.
169
- MA. mutability (:: Type{<:Monomial} ) = MA. NotMutable ()
170
- MA. mutability (:: Type{<:Term} ) = MA. NotMutable ()
169
+ MA. mutability (:: Type{<:Monomial} ) = MA. IsNotMutable ()
170
+ MA. mutability (:: Type{<:Term} ) = MA. IsNotMutable ()
171
171
# The polynomials can be mutated.
172
172
MA. mutability (:: Type{<:Polynomial} ) = MA. IsMutable ()
173
173
@@ -202,7 +202,7 @@ function MP.mapcoefficientsnz_to!(output::Polynomial, f::Function, p::AbstractPo
202
202
return MP. mapcoefficientsnz_to! (output, f, polynomial (p))
203
203
end
204
204
205
- function MA. mutable_operate ! (:: typeof (MP. removeleadingterm), p:: Polynomial )
205
+ function MA. operate ! (:: typeof (MP. removeleadingterm), p:: Polynomial )
206
206
deleteat! (p. terms, 1 )
207
207
return p
208
208
end
0 commit comments