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-10T19:45:42-07:00 (8 years ago)
Author:
Marek Rychlik
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/polynomial.lisp

    r4436 r4442  
    4646           "SATURATION-EXTENSION"
    4747           "ALIST->POLY"
     48           "POLY->ALIST"
    4849           "->INFIX"
    4950           "UNIVERSAL-EZGCD"
     
    140141
    141142can be entered as
    142 (ALIST->POLY '(((2 3) . 3) ((0 1) . 2) ((0 0) . 7))).
     143(ALIST->POLY '(((0 0) . 7) ((0 1) . 2) ((2 3) . 3) )). NOTE: the
     144terms are entered in the increasing order.
    143145
    144146NOTE: The primary use is for low-level debugging of the package."
    145147  (dolist (x alist poly)
    146148    (poly-insert-term poly (make-instance 'term :exponents (car x) :coeff (cdr x)))))
     149
     150(defun poly->alist (p)
     151  "Convert a polynomial P to an association list. Thus, the format of the
     152returned value is  ((MONOM[0] . COEFF[0]) (MONOM[1] . COEFF[1]) ...), where
     153MONOM[I] is a list of exponents in the monomial and COEFF[I] is the
     154corresponding coefficient in the ring."
     155  (cond
     156    ((poly-p p)
     157     (mapcar #'->list (poly-termlist p)))
     158    ((and (consp p) (eq (car p) :[))
     159     (cons :[ (mapcar #'poly->alist (cdr p))))))
     160
     161
    147162
    148163(defmethod update-instance-for-different-class :after ((old term) (new poly) &key)
     
    346361(defun (setf lc) (new-value x) (setf (term-coeff (car x)) new-value))
    347362
     363
    348364(defun fast-add (p q order-fn add-fn)
    349365  (cond
     
    355371         (funcall order-fn (car p) (car q))
    356372       (cond
    357          (greater-p                     ; (> (cadr h) (car q))
     373         (greater-p                     ; (> (car p) (car q))
    358374          (cons (car p) (fast-add (cdr p) q order-fn add-fn))
    359375          )
    360          (equal-p                       ; (= (cadr h)) (car q))
     376         (equal-p                       ; (= (car p)) (car q))
    361377          (let ((s (funcall add-fn (lc p) (lc q))))
    362378            (cond
     
    368384               (cons (car p) (fast-add (cdr p) (cdr q) order-fn add-fn))
    369385               ))))
    370          (t                    ;(< (cadr h) (car q))                   
     386         (t                    ;(< (car p) (car q))                     
    371387          (cons (car q) (fast-add p (cdr q) order-fn add-fn))
    372388          ))))))
    373 
    374389
    375390
Note: See TracChangeset for help on using the changeset viewer.