Changeset 3902 for branches/f4grobner
- Timestamp:
- 2016-05-29T14:30:37-07:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/symbolic-polynomial.lisp
r3898 r3902 22 22 (defpackage "SYMBOLIC-POLYNOMIAL" 23 23 (:use :cl :utils :monom :polynomial :infix :infix-printer) 24 (:export "SYMBOLIC-POLY" "READ-INFIX-FORM" "STRING->POLY" "POLY->STRING" "->INFIX" "+LIST-MARKER+")24 (:export "SYMBOLIC-POLY" "READ-INFIX-FORM" "STRING->POLY" "POLY->STRING" "->INFIX") 25 25 (:documentation "Implements symbolic polynomials. A symbolic 26 26 polynomial is polynomial which uses symbolic variables for reading and … … 28 28 29 29 (in-package :symbolic-polynomial) 30 31 (defparameter +list-marker+ :[32 "A sexp with this head is considered a list of polynomials.")33 30 34 31 (defclass symbolic-poly (poly) … … 62 59 (assert (= (length (symbolic-poly-vars new)) (poly-dimension new)))) 63 60 64 (defun poly-eval (expr vars order)65 "Evaluate Lisp form EXPR to a polynomial or a list of polynomials in66 variables VARS. Return the resulting polynomial or list of67 polynomials. Standard arithmetical operators in form EXPR are68 replaced with their analogues in the ring of polynomials, and the69 resulting expression is evaluated, resulting in a polynomial or a list70 of polynomials in internal form. A similar operation in another computer71 algebra system could be called 'expand' or so."72 (labels ((p-eval (p) (poly-eval p vars order))73 (p-eval-scalar (p) (poly-eval p '() order))74 (p-eval-list (plist) (mapcar #'p-eval plist)))75 (cond76 ((eq expr 0)77 (make-instance 'poly :dimension (length vars)))78 ((member expr vars :test #'equalp)79 (let ((pos (position expr vars :test #'equalp)))80 (make-poly-variable (length vars) pos)))81 ((atom expr)82 expr)83 ((eq (car expr) +list-marker+)84 (cons +list-marker+ (p-eval-list (cdr expr))))85 (t86 (case (car expr)87 (+ (reduce #'add (p-eval-list (cdr expr))))88 (- (apply #'subtract (p-eval-list (cdr expr))))89 (*90 (if (endp (cddr expr)) ;unary91 (p-eval (cadr expr))92 (reduce #'multiply (p-eval-list (cdr expr)))))93 (/94 ;; A polynomial can be divided by a scalar95 (cond96 ((endp (cddr expr))97 ;; A special case (/ ?), the inverse98 (divide (cadr expr)))99 (t100 (let ((num (p-eval (cadr expr)))101 (denom-inverse (apply #'divide (mapcar #'p-eval-scalar (cddr expr)))))102 (multiply denom-inverse num)))))103 (expt104 (cond105 ((member (cadr expr) vars :test #'equalp)106 ;;Special handling of (expt var pow)107 (let ((pos (position (cadr expr) vars :test #'equalp)))108 (make-poly-variable (length vars) pos (caddr expr))))109 ((not (and (integerp (caddr expr)) (plusp (caddr expr))))110 ;; Negative power means division in coefficient ring111 ;; Non-integer power means non-polynomial coefficient112 expr)113 (t (universal-expt (p-eval (cadr expr)) (caddr expr)))))114 (otherwise115 expr))))))116 61 117 62 #|
Note:
See TracChangeset
for help on using the changeset viewer.