close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

Changeset 4395 for branches


Ignore:
Timestamp:
2016-06-07T14:56:27-07:00 (9 years ago)
Author:
Marek Rychlik
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/polynomial.lisp

    r4385 r4395  
    299299       )))
    300300
     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
    301333#|
    302334;; NOTE: The stuff below works, but may not be worth the trouble.
     
    343375(defun add-termlists (p q order-fn)
    344376  "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))
    346378
    347379(defun subtract-termlists (p q order-fn)
    348380  "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))
    350383
    351384(defmethod add-to ((self poly) (other poly) &aux (other-copy (copy-instance other)))
Note: See TracChangeset for help on using the changeset viewer.