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 | (load "boot")
|
---|
2 |
|
---|
3 | (use-package :polynomial)
|
---|
4 | (use-package :monom)
|
---|
5 |
|
---|
6 | ;;(shadow '(fast-add) "POLYNOMIAL")
|
---|
7 |
|
---|
8 | ;; Getter/setter of leading coefficient
|
---|
9 | (defun lc (x) (term-coeff (car x)))
|
---|
10 | (defun (setf lc) (new-value x) (setf (term-coeff (car x)) new-value))
|
---|
11 |
|
---|
12 | (defvar order-fn #'lex>)
|
---|
13 | (defvar add-fn #'add-to)
|
---|
14 |
|
---|
15 | (defun fast-add-helper (p q)
|
---|
16 | (do ((h p))
|
---|
17 | ((endp q) p)
|
---|
18 | (multiple-value-bind
|
---|
19 | (greater-p equal-p)
|
---|
20 | (funcall order-fn (car h) (car q))
|
---|
21 | (cond
|
---|
22 | (greater-p ; (> (lm h) (lm q))
|
---|
23 | (setf h (cdr h))
|
---|
24 | )
|
---|
25 | (equal-p ; (= (lm h) (lm q))
|
---|
26 | (let ((s (funcall add-fn (lc h) (lc q))))
|
---|
27 | (cond
|
---|
28 | ((universal-zerop s)
|
---|
29 | (cond
|
---|
30 | (setf h (cdr h)
|
---|
31 | q (cdr q))))
|
---|
32 | (t
|
---|
33 | ;; Adjust the lc of p
|
---|
34 | (setf (lc h) s)
|
---|
35 | (setf h (cdr h)
|
---|
36 | q (cdr q))))))
|
---|
37 |
|
---|
38 | (t ;(< (lm h) (lm q))
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.
Download in other formats: