Changeset 4395
- Timestamp:
- 2016-06-07T14:56:27-07:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/polynomial.lisp
r4385 r4395 299 299 ))) 300 300 301 (defun fast-add (p q order-fn add-fn) 302 (macrolet ((lc (x) `(term-coeff (car ,x)))) 303 (do (r) 304 ((or (endp p) (endp q)) 305 ;; NOTE: R contains the result in reverse order. Can it 306 ;; be more efficient to produce the terms in correct order? 307 (unless (endp q) 308 (setf r (nreconc r q))) 309 (unless (endp p) 310 (setf r (nreconc r p))) 311 r) 312 (multiple-value-bind 313 (greater-p equal-p) 314 (funcall order-fn (car p) (car q)) 315 (cond 316 (greater-p 317 (rotatef (cdr p) r p) 318 ) 319 (equal-p 320 (let ((s (funcall add-fn (lc p) (lc q)))) 321 (cond 322 ((universal-zerop s) 323 (setf p (cdr p)) 324 ) 325 (t 326 (setf (lc p) s) 327 (rotatef (cdr p) r p)))) 328 (setf q (cdr q)) 329 ) 330 (t 331 (rotatef (cdr q) r q))))))) 332 301 333 #| 302 334 ;; NOTE: The stuff below works, but may not be worth the trouble. … … 343 375 (defun add-termlists (p q order-fn) 344 376 "Destructively adds two termlists P and Q ordered according to ORDER-FN." 345 (fast-add /subtract p q order-fn #'add-to nil))377 (fast-add p q order-fn #'add-to)) 346 378 347 379 (defun subtract-termlists (p q order-fn) 348 380 "Destructively subtracts two termlists P and Q ordered according to ORDER-FN." 349 (fast-add/subtract p q order-fn #'subtract-from #'unary-minus)) 381 (setf q (mapc #'unary-minus q)) 382 (add-termlists p q order-fn)) 350 383 351 384 (defmethod add-to ((self poly) (other poly) &aux (other-copy (copy-instance other)))
Note:
See TracChangeset
for help on using the changeset viewer.