@@ -151,21 +151,53 @@ Base.copy(p::VectorPolynomial) = MA.mutable_copy(p)
151
151
152
152
function grlex end
153
153
function MA. operate! (op:: Union{typeof(+), typeof(-)} , p:: Polynomial{T,TT} , q:: Polynomial ) where {T,TT}
154
- get1 (i) = p. terms[i]
155
- function get2 (i)
156
- t = q. terms[i]
157
- TT (MA. scaling_convert (T, MA. operate (op, coefficient (t))), monomial (t))
158
- end
159
- set (i, t:: TT ) = p. terms[i] = t
160
- push (t:: TT ) = push! (p. terms, t)
161
- compare_monomials (t:: TT , j:: Int ) = grlex (monomial (q. terms[j]), monomial (t))
162
- compare_monomials (i:: Int , j:: Int ) = compare_monomials (get1 (i), j)
163
- combine (i:: Int , j:: Int ) = p. terms[i] = Term (MA. operate!! (op, coefficient (p. terms[i]), coefficient (q. terms[j])), monomial (p. terms[i]))
164
- combine (t:: TT , j:: Int ) = TT (MA. operate!! (op, coefficient (t), coefficient (q. terms[j])), monomial (t))
165
- resize (n) = resize! (p. terms, n)
154
+ get1 = let p= p
155
+ i -> p. terms[i]
156
+ end
157
+ get2 = let p= p
158
+ i -> begin
159
+ t = q. terms[i]
160
+ TT (MA. scaling_convert (T, MA. operate (op, coefficient (t))), monomial (t))
161
+ end
162
+ end
163
+ set = let p= p
164
+ (i, t) -> begin
165
+ p. terms[i] = t
166
+ end
167
+ end
168
+ push = let p= p
169
+ t -> push! (p. terms, t)
170
+ end
171
+ compare_monomials = let q= q
172
+ (t, j) -> begin
173
+ if t isa Int && j isa Int
174
+ t = get1 (t)
175
+ end
176
+ grlex (monomial (q. terms[j]), monomial (t))
177
+ end
178
+ end
179
+ combine = let p= p, q= q
180
+ (i, j) -> begin
181
+ if i isa Int
182
+ p. terms[i] = Term (MA. operate!! (op, coefficient (p. terms[i]), coefficient (q. terms[j])), monomial (p. terms[i]))
183
+ else
184
+ typeof (i)(MA. operate!! (op, coefficient (i), coefficient (q. terms[j])), monomial (i))
185
+ end
186
+ end
187
+ end
188
+ resize = let p= p
189
+ (n) -> resize! (p. terms, n)
190
+ end
166
191
# We can modify the coefficient since it's the result of `combine`.
167
- keep (t:: Term ) = ! MA. iszero!! (coefficient (t))
168
- keep (i:: Int ) = ! MA. iszero!! (coefficient (p. terms[i]))
192
+ keep = let p= p
193
+ i -> begin
194
+ if i isa Int
195
+ ! MA. iszero!! (coefficient (p. terms[i]))
196
+ else
197
+ ! MA. iszero!! (coefficient (i))
198
+ end
199
+ end
200
+ end
169
201
polynomial_merge! (
170
202
nterms (p), nterms (q), get1, get2, set, push,
171
203
compare_monomials, combine, keep, resize
0 commit comments