Changeset 1051 for branches/f4grobner
- Timestamp:
- 2015-06-10T08:53:27-07:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/polynomial.lisp
r1050 r1051 329 329 (setf (elt basis i) (make-variable ring n i)))) 330 330 331 #|332 (defun poly-eval-1 (expr vars &optional (ring *ring-of-integers*) (order #'lex>)333 &aux334 (ring-and-order (make-ring-and-order :ring ring :order order))335 (n (length vars))336 (basis (variable-basis ring (length vars))))337 "Evaluate an expression EXPR as polynomial by substituting operators338 + - * expt with corresponding polynomial operators and variables VARS339 with the corresponding polynomials in internal form. We use special340 versions of binary operators $poly+, $poly-, $minus-poly, $poly* and341 $poly-expt which work like the corresponding functions in the POLY342 package, but accept scalars as arguments as well. The result is a343 polynomial in internal form. This operation is somewhat similar to344 the function EXPAND in CAS."345 (cond346 ((numberp expr)347 (cond348 ((zerop expr) NIL)349 (t (make-poly-from-termlist (list (make-term (make-monom :dimension n) expr))))))350 ((symbolp expr)351 (nth (position expr vars) basis))352 ((consp expr)353 (case (car expr)354 (expt355 (if (= (length expr) 3)356 ($poly-expt ring-and-order357 (poly-eval-1 (cadr expr) vars ring order)358 (caddr expr)359 n)360 (error "Too many arguments to EXPT")))361 (/362 (if (and (= (length expr) 3)363 (numberp (caddr expr)))364 ($poly/ ring (cadr expr) (caddr expr))365 (error "The second argument to / must be a number")))366 (otherwise367 (let ((r (mapcar368 #'(lambda (e) (poly-eval-1 e vars ring order))369 (cdr expr))))370 (ecase (car expr)371 (+ (reduce #'(lambda (p q) ($poly+ ring-and-order p q n)) r))372 (-373 (if (endp (cdr r))374 ($minus-poly ring (car r) n)375 ($poly- ring-and-order376 (car r)377 (reduce #'(lambda (p q) ($poly+ ring-and-order p q n)) (cdr r))378 n)))379 (*380 (reduce #'(lambda (p q) ($poly* ring-and-order p q n)) r))381 )))))))382 383 384 385 (defun poly-eval (expr vars &optional (order #'lex>) (ring *ring-of-integers*))386 "Evaluate an expression EXPR, which should be a polynomial387 expression or a list of polynomial expressions (a list of expressions388 marked by prepending keyword :[ to it) given in Lisp prefix notation,389 in variables VARS, which should be a list of symbols. The result of390 the evaluation is a polynomial or a list of polynomials (marked by391 prepending symbol '[) in the internal alist form. This evaluator is392 used by the PARSE package to convert input from strings directly to393 internal form."394 (cond395 ((numberp expr)396 (unless (zerop expr)397 (make-poly-from-termlist398 (list (make-term (make-monom :dimension (length vars)) expr)))))399 ((or (symbolp expr) (not (eq (car expr) :[)))400 (poly-eval-1 expr vars ring order))401 (t (cons '[ (mapcar #'(lambda (p) (poly-eval-1 p vars ring order)) (rest expr))))))402 403 |#
Note:
See TracChangeset
for help on using the changeset viewer.