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 1063


Ignore:
Timestamp:
2015-06-10T09:08:15-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

    r1062 r1063  
    163163
    164164
     165(defun parse-string-to-alist (str vars)
     166  "Parse string STR and return a polynomial as a sorted association
     167list of pairs (MONOM . COEFFICIENT). For example:
     168(parse-string-to-alist \"[x^2-y^2+(-4/3)*u^2*w^3-5,y]\" '(x y u w))
     169 ([ (((0 0 2 3) . -4/3) ((0 2 0 0) . -1) ((2 0 0 0) . 1)
     170     ((0 0 0 0) . -5))
     171    (((0 1 0 0) . 1)))
     172The functions PARSE-TO-SORTED-ALIST and PARSE-STRING-TO-SORTED-ALIST
     173sort terms by the predicate defined in the ORDER package."
     174  (with-input-from-string (stream str)
     175    (parse-to-alist vars stream)))
     176
     177
     178(defun parse-to-sorted-alist (vars &optional (order #'lex>) (stream t))
     179  "Parses streasm STREAM and returns a polynomial represented as
     180a sorted alist. For example:
     181(WITH-INPUT-FROM-STRING (S \"X^2-Y^2+(-4/3)*U^2*W^3-5\")
     182  (PARSE-TO-SORTED-ALIST '(X Y U W) S))
     183returns
     184(((2 0 0 0) . 1) ((0 2 0 0) . -1) ((0 0 2 3) . -4/3) ((0 0 0 0) . -5))
     185and
     186(WITH-INPUT-FROM-STRING (S \"X^2-Y^2+(-4/3)*U^2*W^3-5\")
     187  (PARSE-TO-SORTED-ALIST '(X Y U W) T #'GRLEX>) S)
     188returns
     189(((0 0 2 3) . -4/3) ((2 0 0 0) . 1) ((0 2 0 0) . -1) ((0 0 0 0) . -5))"
     190  (sort-poly (parse-to-alist vars stream) order))
     191
     192(defun parse-string-to-sorted-alist (str vars &optional (order #'lex>))
     193  "Parse a string to a sorted alist form, the internal representation
     194of polynomials used by our system."
     195  (with-input-from-string (stream str)
     196    (parse-to-sorted-alist vars order stream)))
     197
     198(defun sort-poly-1 (p order)
     199  "Sort the terms of a single polynomial P using an admissible monomial order ORDER.
     200Returns the sorted polynomial. Destructively modifies P."
     201  (sort p order :key #'first))
     202
     203;; Sort a polynomial or polynomial list
     204(defun sort-poly (poly-or-poly-list &optional (order #'lex>))
     205  "Sort POLY-OR-POLY-LIST, which could be either a single polynomial
     206or a list of polynomials in internal alist representation, using
     207admissible monomial order ORDER. Each polynomial is sorted using
     208SORT-POLY-1."
     209  (cond
     210   ((eql poly-or-poly-list :syntax-error) nil)
     211   ((null poly-or-poly-list) nil)
     212   ((eql (car poly-or-poly-list) '[)
     213    (cons '[ (mapcar #'(lambda (p) (sort-poly-1 p order))
     214                     (rest poly-or-poly-list))))
     215   (t (sort-poly-1 poly-or-poly-list order))))
     216
Note: See TracChangeset for help on using the changeset viewer.