Changeset 1201 for branches/f4grobner/.junk/parse.lisp
- Timestamp:
- 2015-06-11T10:48:54-07:00 (9 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/.junk/parse.lisp
r1061 r1201 115 115 116 116 117 (defun parse-string-to-alist (str vars)118 "Parse string STR and return a polynomial as a sorted association119 list of pairs (MONOM . COEFFICIENT). For example:120 (parse-string-to-alist \"[x^2-y^2+(-4/3)*u^2*w^3-5,y]\" '(x y u w))121 ([ (((0 0 2 3) . -4/3) ((0 2 0 0) . -1) ((2 0 0 0) . 1)122 ((0 0 0 0) . -5))123 (((0 1 0 0) . 1)))124 The functions PARSE-TO-SORTED-ALIST and PARSE-STRING-TO-SORTED-ALIST125 sort terms by the predicate defined in the ORDER package."126 (with-input-from-string (stream str)127 (parse-to-alist vars stream)))128 117 129 118 130 (defun parse-to-sorted-alist (vars &optional (order #'lex>) (stream t))131 "Parses streasm STREAM and returns a polynomial represented as132 a sorted alist. For example:133 (WITH-INPUT-FROM-STRING (S \"X^2-Y^2+(-4/3)*U^2*W^3-5\")134 (PARSE-TO-SORTED-ALIST '(X Y U W) S))135 returns136 (((2 0 0 0) . 1) ((0 2 0 0) . -1) ((0 0 2 3) . -4/3) ((0 0 0 0) . -5))137 and138 (WITH-INPUT-FROM-STRING (S \"X^2-Y^2+(-4/3)*U^2*W^3-5\")139 (PARSE-TO-SORTED-ALIST '(X Y U W) T #'GRLEX>) S)140 returns141 (((0 0 2 3) . -4/3) ((2 0 0 0) . 1) ((0 2 0 0) . -1) ((0 0 0 0) . -5))"142 (sort-poly (parse-to-alist vars stream) order))143 144 (defun parse-string-to-sorted-alist (str vars &optional (order #'lex>))145 "Parse a string to a sorted alist form, the internal representation146 of polynomials used by our system."147 (with-input-from-string (stream str)148 (parse-to-sorted-alist vars order stream)))149 150 (defun sort-poly-1 (p order)151 "Sort the terms of a single polynomial P using an admissible monomial order ORDER.152 Returns the sorted polynomial. Destructively modifies P."153 (sort p order :key #'first))154 155 ;; Sort a polynomial or polynomial list156 (defun sort-poly (poly-or-poly-list &optional (order #'lex>))157 "Sort POLY-OR-POLY-LIST, which could be either a single polynomial158 or a list of polynomials in internal alist representation, using159 admissible monomial order ORDER. Each polynomial is sorted using160 SORT-POLY-1."161 (cond162 ((eql poly-or-poly-list :syntax-error) nil)163 ((null poly-or-poly-list) nil)164 ((eql (car poly-or-poly-list) '[)165 (cons '[ (mapcar #'(lambda (p) (sort-poly-1 p order))166 (rest poly-or-poly-list))))167 (t (sort-poly-1 poly-or-poly-list order))))168 169 170
Note:
See TracChangeset
for help on using the changeset viewer.