Changeset 2603
- Timestamp:
- 2015-06-20T01:10:34-07:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/polynomial.lisp
r2602 r2603 91 91 self) 92 92 93 (defun fast-add-to (p q order-fn)94 "Fast destructive addition of termlists95 Note that this assumes the presence of a96 dummy header."97 (macrolet ((lt (x) `(cadr ,x))98 (lc (x) `(r-coeff (cadr ,x))))99 (do ((p p)100 (q q))101 ((or (endp (cdr p)) (endp (cdr q)))102 p)103 (multiple-value-bind104 (greater-p equal-p)105 (funcall order-fn (lt q) (lt p))106 (cond107 (greater-p108 (rotatef (cdr p) (cdr q)))109 (equal-p110 (let ((s (add-to (lc p) (lc q))))111 (if (r-zerop s)112 (setf (cdr p) (cddr p))113 (setf (lc p) s114 q (cdr q)))))))115 (setf p (cdr p)))))116 93 117 94 (defmethod add-to ((self poly) (other poly)) … … 120 97 The result is stored in SELF. This implementation does 121 98 no consing, entirely reusing the sells of SELF and OTHER." 122 (with-slots ((termlist1 termlist) (order1 order)) 123 self 124 (with-slots ((termlist2 termlist) (order2 order)) 125 other 126 ;; Ensure orders are compatible 127 (unless (eq order1 order2) 128 (setf termlist2 (sort termlist2 order1) 129 order2 order1)) 130 ;; Create dummy head 131 (push nil termlist1) 132 (push nil termlist2) 133 (fast-add-to termlist1 termlist2 order1) 134 ;; Remove dummy head 135 (pop termlist1))) 99 (flet ((fast-add-to (p q order-fn) 100 ;; Fast destructive addition of termlists Note that this 101 ;; assumes the presence of a dummy header." 102 (macrolet ((lt (x) `(cadr ,x)) 103 (lc (x) `(r-coeff (cadr ,x)))) 104 (do ((p p) 105 (q q)) 106 ((or (endp (cdr p)) (endp (cdr q))) 107 p) 108 (multiple-value-bind 109 (greater-p equal-p) 110 (funcall order-fn (lt q) (lt p)) 111 (cond 112 (greater-p 113 (rotatef (cdr p) (cdr q))) 114 (equal-p 115 (let ((s (add-to (lc p) (lc q)))) 116 (if (r-zerop s) 117 (setf (cdr p) (cddr p)) 118 (setf (lc p) s 119 q (cdr q))))))) 120 (setf p (cdr p)))))) 121 (with-slots ((termlist1 termlist) (order1 order)) 122 self 123 (with-slots ((termlist2 termlist) (order2 order)) 124 other 125 ;; Ensure orders are compatible 126 (unless (eq order1 order2) 127 (setf termlist2 (sort termlist2 order1) 128 order2 order1)) 129 ;; Create dummy head 130 (push nil termlist1) 131 (push nil termlist2) 132 (fast-add-to termlist1 termlist2 order1) 133 ;; Remove dummy head 134 (pop termlist1)))) 136 135 self) 137 136
Note:
See TracChangeset
for help on using the changeset viewer.