- Timestamp:
- 2015-06-10T09:01:30-07:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/parse.lisp
r1058 r1059 106 106 ;; assuming variables are VARS 107 107 108 (defun alist-form (plist vars)109 "Translates an expression PLIST, which should be a list of polynomials110 in variables VARS, to an alist representation of a polynomial.111 It returns the alist. See also PARSE-TO-ALIST."112 (cond113 ((endp plist) nil)114 ((eql (first plist) '[)115 (cons '[ (mapcar #'(lambda (x) (alist-form x vars)) (rest plist))))116 (t117 (assert (eql (car plist) '+))118 (alist-form-1 (rest plist) vars))))119 120 (defun alist-form-1 (p vars121 &aux (ht (make-hash-table122 :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 vars132 &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 143 108 144 109 ;; New implementation based on the INFIX package of Mark Kantorowitz
Note:
See TracChangeset
for help on using the changeset viewer.