Changeset 4463 for branches/f4grobner/division.lisp
- Timestamp:
- 2016-06-14T19:35:34-07:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/division.lisp
r4434 r4463 43 43 44 44 (defun grobner-op (c1 c2 m f g) 45 "Returns C2*F-C1*M*G, where F and G are polynomials M is a monomial. 46 Assume that the leading terms will cancel." 47 (declare (type monom m) 48 (type poly f g)) 49 (assert (universal-zerop 50 (subtract 51 (multiply c2 (leading-coefficient f)) 52 (multiply c1 (leading-coefficient g))))) 53 (assert (universal-equalp (leading-monomial f) (multiply m (leading-monomial g)))) 54 ;; Note that below we can drop the leading terms of f ang g for the 55 ;; purpose of polynomial arithmetic. 56 ;; 57 ;; TODO: Make sure that the sugar calculation is correct if leading 58 ;; terms are dropped. 59 (subtract 60 (multiply f c2) 61 (multiply g m c1))) 45 "Returns C2*F-C1*M*G, where F and G are polynomials M is a monomial." 46 (declare (type monom m) (type poly f g)) 47 (subtract (multiply f c2) (multiply g m c1))) 62 48 63 49 (defun check-loop-invariant (c f a fl r p &aux (p-zero (make-zero-for f))) … … 74 60 |# 75 61 (let* ((prod (inner-product a fl add multiply p-zero)) 76 (succeeded-p (universal-zerop (subtract (multiply f c) (add prod rp)))))62 (succeeded-p (universal-zerop (subtract (multiply f c) (add prod (make-instance 'poly :termlist (reverse r)) p))))) 77 63 (unless succeeded-p 78 64 (error "#### Polynomial division Loop invariant failed ####:~%C=~A~%F=~A~%A=~A~%FL=~A~%R=~A~%P=~A~%" … … 92 78 (declare (type poly f) (list fl)) 93 79 ;; Loop invariant: c*f=sum ai*fi+r+p, where p must eventually become 0 94 (do ((r (make-zero-for f))80 (do ((r nil) 95 81 (c (make-unit-for (leading-coefficient f))) 96 82 (a (make-list (length fl) :initial-element (make-zero-for f))) … … 100 86 #+grobner-check(check-loop-invariant c f a fl r p) 101 87 (debug-cgb "~&~3T~d reduction~:p" division-count) 102 (when ( universal-zeropr) (debug-cgb " ---> 0"))103 (values a rc division-count))88 (when (null r) (debug-cgb " ---> 0")) 89 (values a (make-instance 'poly :termlist r) c division-count)) 104 90 (declare (fixnum division-count)) 105 91 ;; Check the loop invariant here … … 108 94 (b a (rest b))) 109 95 ((cond 110 ((endp fl) ;no division occurred 111 (setf r (add-to r (leading-term p)) ;move lt(p) to remainder 112 p (subtract-from p (leading-term p))) ;remove lt(p) from p 96 ((endp fl) ;no division occurred 97 (push (poly-remove-term p) r) ;move lt(p) to remainder 113 98 t) 114 99 ((divides-p (leading-monomial (car fl)) (leading-monomial p)) ;division occurred … … 122 107 (setf (car x) (multiply-by (car x) c1))) 123 108 a) 124 (setf r (m ultiply-by r c1)109 (setf r (mapc #'multiply-by r c1) 125 110 c (multiply-by c c1) 126 111 p (grobner-op c2 c1 m p (car fl))) … … 154 139 :test #'divisible-by-p 155 140 :key #'leading-monomial))) 141 ;; NOTE: Currently R is a list of terms of the remainder 156 142 (cond 157 143 (g ;division possible … … 162 148 (let ((m (divide (leading-monomial p) (leading-monomial g)))) 163 149 ;; Multiply the equation c*f=sum ai*fi+r+p by cg. 164 (setf r (m ultiply-by r cg)150 (setf r (mapc #'(lambda (trm) (multiply-by trm cg)) r) 165 151 c (multiply-by c cg) 166 152 ;; p := cg*p-cp*m*g 167 153 p (grobner-op cp cg m p g)))) 168 154 (debug-cgb "/")) 169 (t ;no division possible 170 (setf r (add-to r (leading-term p))) ;move lt(p) to remainder 171 (setf p (subtract-from p (leading-term p))) ;move lt(p) to remainder 155 (t ;no division possible 156 (setf r (push (poly-remove-term p) r)) ;move lt(p) to remainder 172 157 (debug-cgb "+"))) 173 158 (values p r c division-count)) … … 187 172 ;; unit in the coefficient field. 188 173 (return-from normal-form (values f nil 0))) 189 (do ((r (make-zero-for f))174 (do ((r nil) 190 175 (c (make-unit-for (leading-coefficient f))) 191 176 (division-count 0)) 192 177 ((or (universal-zerop f) 193 178 ;;(endp fl) 194 (and top-reduction-only (not ( universal-zeropr))))179 (and top-reduction-only (not (null r)))) 195 180 (progn 196 181 (debug-cgb "~&~3T~D reduction~:P" division-count) 197 (when ( universal-zeropr)182 (when (null r) 198 183 (debug-cgb " ---> 0"))) 199 (setf f (add-to f r))184 (setf (poly-termlist f) (nreconc r (poly-termlist f))) 200 185 (values f c division-count)) 201 (declare (fixnum division-count) 202 (type poly r)) 186 (declare (fixnum division-count)) 203 187 (multiple-value-setq (f r c division-count) 204 188 (normal-form-step fl f r c division-count))))
Note:
See TracChangeset
for help on using the changeset viewer.