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 1059 for branches


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

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/parse.lisp

    r1058 r1059  
    106106;; assuming variables are VARS
    107107
    108 (defun alist-form (plist vars)
    109   "Translates an expression PLIST, which should be a list of polynomials
    110 in variables VARS, to an alist representation of a polynomial.
    111 It returns the alist. See also PARSE-TO-ALIST."
    112   (cond
    113    ((endp plist) nil)
    114    ((eql (first plist) '[)
    115     (cons '[ (mapcar #'(lambda (x) (alist-form x vars)) (rest plist))))
    116    (t
    117     (assert (eql (car plist) '+))
    118     (alist-form-1 (rest plist) vars))))
    119 
    120 (defun alist-form-1 (p vars
    121                          &aux (ht (make-hash-table
    122                                    :test #'equal :size 16))
    123                          stack)
    124   (dolist (term p)
    125     (assert (eql (car term) '*))
    126     (incf  (gethash (powers (cddr term) vars) ht 0) (second term)))
    127   (maphash #'(lambda (key value) (unless (zerop value)
    128                                    (push (cons key value) stack))) ht)
    129   stack)
    130    
    131 (defun powers (monom vars
    132                      &aux (tab (pairlis vars (make-list (length vars)
    133                                                         :initial-element 0))))
    134   (dolist (e monom (mapcar #'(lambda (v) (cdr (assoc v tab))) vars))
    135     (assert (equal (first e) '^))
    136     (assert (integerp (third e)))
    137     (assert (= (length e) 3))
    138     (let ((x (assoc (second e) tab)))
    139       (if (null x) (error "Variable ~a not in the list of variables."
    140                          (second e))
    141         (incf (cdr x) (third e))))))
    142  
    143108
    144109;; New implementation based on the INFIX package of Mark Kantorowitz
Note: See TracChangeset for help on using the changeset viewer.