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.

source: branches/f4grobner/fast-add.lisp@ 4435

Last change on this file since 4435 was 4434, checked in by Marek Rychlik, 9 years ago
File size: 893 bytes
RevLine 
[4434]1(in-package :polynomial)
[4430]2
3;; Getter/setter of leading coefficient
4(defun lc (x) (term-coeff (car x)))
5(defun (setf lc) (new-value x) (setf (term-coeff (car x)) new-value))
6
[4434]7(defun fast-add (p q order-fn add-fn)
8 (cond
9 ((endp p) p)
10 ((endp q) q)
11 (t
12 (multiple-value-bind
13 (greater-p equal-p)
14 (funcall order-fn (car p) (car q))
15 (cond
16 (greater-p ; (> (cadr h) (car q))
17 (cons (car p) (fast-add (cdr p) q order-fn add-fn))
18 )
19 (equal-p ; (= (cadr h)) (car q))
20 (let ((s (funcall add-fn (lc p) (lc q))))
21 (cond
22 ((universal-zerop s)
23 (fast-add (cdr p) (cdr q) order-fn add-fn))
24 (t
25 ;; Adjust the lc of p
26 (setf (lc p) s)
27 (cons (car p) (fast-add (cdr p) (cdr q) order-fn add-fn))
28 ))))
29 (t ;(< (cadr h) (car q))
30 (cons (car q) (fast-add p (cdr q) order-fn add-fn))
31 ))))))
[4431]32
[4430]33
34
[4431]35
36
37
[4434]38
[4431]39
Note: See TracBrowser for help on using the repository browser.