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.

Changeset 1060 for branches/f4grobner


Ignore:
Timestamp:
2015-06-10T09:01:41-07:00 (9 years ago)
Author:
Marek Rychlik
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/.junk/poly-eval.lisp

    r1057 r1060  
     1(defun alist-form (plist vars)
     2  "Translates an expression PLIST, which should be a list of polynomials
     3in variables VARS, to an alist representation of a polynomial.
     4It returns the alist. See also PARSE-TO-ALIST."
     5  (cond
     6   ((endp plist) nil)
     7   ((eql (first plist) '[)
     8    (cons '[ (mapcar #'(lambda (x) (alist-form x vars)) (rest plist))))
     9   (t
     10    (assert (eql (car plist) '+))
     11    (alist-form-1 (rest plist) vars))))
     12
     13(defun alist-form-1 (p vars
     14                         &aux (ht (make-hash-table
     15                                   :test #'equal :size 16))
     16                         stack)
     17  (dolist (term p)
     18    (assert (eql (car term) '*))
     19    (incf  (gethash (powers (cddr term) vars) ht 0) (second term)))
     20  (maphash #'(lambda (key value) (unless (zerop value)
     21                                   (push (cons key value) stack))) ht)
     22  stack)
     23   
     24(defun powers (monom vars
     25                     &aux (tab (pairlis vars (make-list (length vars)
     26                                                        :initial-element 0))))
     27  (dolist (e monom (mapcar #'(lambda (v) (cdr (assoc v tab))) vars))
     28    (assert (equal (first e) '^))
     29    (assert (integerp (third e)))
     30    (assert (= (length e) 3))
     31    (let ((x (assoc (second e) tab)))
     32      (if (null x) (error "Variable ~a not in the list of variables."
     33                         (second e))
     34        (incf (cdr x) (third e))))))
     35 
     36
     37
    138(defun convert-number (number-or-poly n)
    239  "Returns NUMBER-OR-POLY, if it is a polynomial. If it is a number,
Note: See TracChangeset for help on using the changeset viewer.