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.

Ignore:
Timestamp:
2016-06-14T19:35:34-07:00 (8 years ago)
Author:
Marek Rychlik
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/division.lisp

    r4434 r4463  
    4343
    4444(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)))
    6248
    6349(defun check-loop-invariant (c f a fl r p &aux (p-zero (make-zero-for f)))
     
    7460  |#
    7561  (let* ((prod (inner-product a fl add multiply p-zero))
    76          (succeeded-p (universal-zerop (subtract (multiply f c) (add prod r p)))))
     62         (succeeded-p (universal-zerop (subtract (multiply f c) (add prod (make-instance 'poly :termlist (reverse r)) p)))))
    7763    (unless succeeded-p
    7864      (error "#### Polynomial division Loop invariant failed ####:~%C=~A~%F=~A~%A=~A~%FL=~A~%R=~A~%P=~A~%"
     
    9278  (declare (type poly f) (list fl))
    9379  ;; 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)
    9581       (c (make-unit-for (leading-coefficient f)))
    9682       (a (make-list (length fl) :initial-element (make-zero-for f)))
     
    10086       #+grobner-check(check-loop-invariant c f a fl r p)
    10187       (debug-cgb "~&~3T~d reduction~:p" division-count)
    102        (when (universal-zerop r) (debug-cgb " ---> 0"))
    103        (values a r c division-count))
     88       (when (null r) (debug-cgb " ---> 0"))
     89       (values a (make-instance 'poly :termlist r) c division-count))
    10490    (declare (fixnum division-count))
    10591    ;; Check the loop invariant here
     
    10894         (b a (rest b)))
    10995        ((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
    11398            t)
    11499           ((divides-p (leading-monomial (car fl)) (leading-monomial p)) ;division occurred
     
    122107                          (setf (car x) (multiply-by (car x) c1)))
    123108                      a)
    124                 (setf r (multiply-by r c1)
     109                (setf r (mapc #'multiply-by r c1)
    125110                      c (multiply-by c c1)
    126111                      p (grobner-op c2 c1 m p (car fl)))
     
    154139                                    :test #'divisible-by-p
    155140                                    :key #'leading-monomial)))
     141  ;; NOTE: Currently R is a list of terms of the remainder
    156142  (cond
    157143   (g                                   ;division possible
     
    162148      (let ((m (divide (leading-monomial p) (leading-monomial g))))
    163149        ;; Multiply the equation c*f=sum ai*fi+r+p by cg.
    164         (setf r (multiply-by r cg)
     150        (setf r (mapc #'(lambda (trm) (multiply-by trm cg)) r)
    165151              c (multiply-by c cg)
    166152              ;; p := cg*p-cp*m*g
    167153              p (grobner-op cp cg m p g))))
    168154    (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
    172157    (debug-cgb "+")))
    173158  (values p r c division-count))
     
    187172    ;; unit in the coefficient field.
    188173    (return-from normal-form (values f nil 0)))
    189   (do ((r (make-zero-for f))
     174  (do ((r nil)
    190175       (c (make-unit-for (leading-coefficient f)))
    191176       (division-count 0))
    192177      ((or (universal-zerop f)
    193178           ;;(endp fl)
    194            (and top-reduction-only (not (universal-zerop r))))
     179           (and top-reduction-only (not (null r))))
    195180       (progn
    196181         (debug-cgb "~&~3T~D reduction~:P" division-count)
    197          (when (universal-zerop r)
     182         (when (null r)
    198183           (debug-cgb " ---> 0")))
    199        (setf f (add-to f r))
     184       (setf (poly-termlist f) (nreconc r (poly-termlist f)))
    200185       (values f c division-count))
    201     (declare (fixnum division-count)
    202              (type poly r))
     186    (declare (fixnum division-count))
    203187    (multiple-value-setq (f r c division-count)
    204188      (normal-form-step fl f r c division-count))))
Note: See TracChangeset for help on using the changeset viewer.