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.
| Line | |
|---|
| 1 |
|
|---|
| 2 | ;; Getter/setter of leading coefficient
|
|---|
| 3 | (defun lc (x) (term-coeff (car x)))
|
|---|
| 4 | (defun (setf lc) (new-value x) (setf (term-coeff (car x)) new-value))
|
|---|
| 5 |
|
|---|
| 6 | (defun fast-add-helper (p q)
|
|---|
| 7 | "It assumes that p and q are non-zero polynomials, i.e. non-empty lists of terms."
|
|---|
| 8 | (multiple-value-bind
|
|---|
| 9 | (greater-p equal-p)
|
|---|
| 10 | (funcall order-fn (car p) (car q))
|
|---|
| 11 | (cond
|
|---|
| 12 | (greater-p
|
|---|
| 13 | (fast-add-helper (cdr p) q))
|
|---|
| 14 | (equal-p
|
|---|
| 15 | (let ((s (funcall add-fn (lc p) (lc q))))
|
|---|
| 16 | (cond
|
|---|
| 17 | ((universal-zerop s)
|
|---|
| 18 | (setf p (cdr p))
|
|---|
| 19 | )
|
|---|
| 20 | (t
|
|---|
| 21 | (setf (lc p) s)
|
|---|
| 22 | (fast-add-helper (cdr p) (cdr q)))))
|
|---|
| 23 | (setf q (cdr q))
|
|---|
| 24 | )
|
|---|
| 25 | (t
|
|---|
| 26 | (fast-add-helper (cdr q) p)))))
|
|---|
| 27 |
|
|---|
| 28 | (defun fast-add (p q order-fn add-fn &aux r)
|
|---|
| 29 | "Add two polynomials, P and Q, represented as lists of terms.
|
|---|
| 30 | The operation is destructive to both polynomials, as the terms
|
|---|
| 31 | of both lists are combined into the result. The operation does not
|
|---|
| 32 | create any new instance of TERM."
|
|---|
| 33 | (cond ((endp p) q)
|
|---|
| 34 | ((endp q) p)
|
|---|
| 35 | (t (fast-add-helper p q))))
|
|---|
| 36 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.
Download in other formats: