[1201] | 1 | ;;; -*- Mode: Lisp -*-
|
---|
[98] | 2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 3 | ;;;
|
---|
| 4 | ;;; Copyright (C) 1999, 2002, 2009, 2015 Marek Rychlik <rychlik@u.arizona.edu>
|
---|
| 5 | ;;;
|
---|
| 6 | ;;; This program is free software; you can redistribute it and/or modify
|
---|
| 7 | ;;; it under the terms of the GNU General Public License as published by
|
---|
| 8 | ;;; the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | ;;; (at your option) any later version.
|
---|
| 10 | ;;;
|
---|
| 11 | ;;; This program is distributed in the hope that it will be useful,
|
---|
| 12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | ;;; GNU General Public License for more details.
|
---|
| 15 | ;;;
|
---|
| 16 | ;;; You should have received a copy of the GNU General Public License
|
---|
| 17 | ;;; along with this program; if not, write to the Free Software
|
---|
| 18 | ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 19 | ;;;
|
---|
| 20 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 21 |
|
---|
[133] | 22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 23 | ;;
|
---|
[268] | 24 | ;; Load this file into Maxima to bootstrap the Grobner package.
|
---|
[390] | 25 | ;; NOTE: This file does use symbols defined by Maxima, so it
|
---|
| 26 | ;; will not work when loaded in Common Lisp.
|
---|
[133] | 27 | ;;
|
---|
[268] | 28 | ;; DETAILS: This file implements an interface between the Grobner
|
---|
[374] | 29 | ;; basis package NGROBNER, which is a pure Common Lisp package, and
|
---|
| 30 | ;; Maxima. NGROBNER for efficiency uses its own representation of
|
---|
| 31 | ;; polynomials. Thus, it is necessary to convert Maxima representation
|
---|
| 32 | ;; to the internal representation and back. The facilities to do so
|
---|
| 33 | ;; are implemented in this file.
|
---|
[268] | 34 | ;;
|
---|
[270] | 35 | ;; Also, since the NGROBNER package consists of many Lisp files, it is
|
---|
[375] | 36 | ;; necessary to load the files. It is possible and preferrable to use
|
---|
| 37 | ;; ASDF for this purpose. The default is ASDF. It is also possible to
|
---|
| 38 | ;; simply used LOAD and COMPILE-FILE to accomplish this task.
|
---|
[270] | 39 | ;;
|
---|
[133] | 40 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 41 |
|
---|
[98] | 42 | (in-package :maxima)
|
---|
| 43 |
|
---|
[568] | 44 | (macsyma-module cgb-maxima)
|
---|
[98] | 45 |
|
---|
[568] | 46 |
|
---|
[98] | 47 | (eval-when
|
---|
| 48 | #+gcl (load eval)
|
---|
| 49 | #-gcl (:load-toplevel :execute)
|
---|
| 50 | (format t "~&Loading maxima-grobner ~a ~a~%"
|
---|
| 51 | "$Revision: 2.0 $" "$Date: 2015/06/02 0:34:17 $"))
|
---|
| 52 |
|
---|
| 53 | ;;FUNCTS is loaded because it contains the definition of LCM
|
---|
[995] | 54 | ($load "functs")
|
---|
[568] | 55 | #+sbcl(progn (require 'asdf) (load "ngrobner.asd")(asdf:load-system :ngrobner))
|
---|
[152] | 56 |
|
---|
[571] | 57 | (use-package :ngrobner)
|
---|
[274] | 58 |
|
---|
[571] | 59 |
|
---|
[98] | 60 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 61 | ;;
|
---|
| 62 | ;; Maxima expression ring
|
---|
| 63 | ;;
|
---|
| 64 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
[521] | 65 | ;;
|
---|
| 66 | ;; This is how we perform operations on coefficients
|
---|
| 67 | ;; using Maxima functions.
|
---|
| 68 | ;;
|
---|
| 69 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 70 |
|
---|
[230] | 71 | (defparameter *maxima-ring*
|
---|
| 72 | (make-ring
|
---|
[98] | 73 | ;;(defun coeff-zerop (expr) (meval1 `(($is) (($equal) ,expr 0))))
|
---|
| 74 | :parse #'(lambda (expr)
|
---|
| 75 | (when modulus (setf expr ($rat expr)))
|
---|
| 76 | expr)
|
---|
| 77 | :unit #'(lambda () (if modulus ($rat 1) 1))
|
---|
| 78 | :zerop #'(lambda (expr)
|
---|
| 79 | ;;When is exactly a maxima expression equal to 0?
|
---|
| 80 | (cond ((numberp expr)
|
---|
| 81 | (= expr 0))
|
---|
| 82 | ((atom expr) nil)
|
---|
| 83 | (t
|
---|
| 84 | (case (caar expr)
|
---|
| 85 | (mrat (eql ($ratdisrep expr) 0))
|
---|
| 86 | (otherwise (eql ($totaldisrep expr) 0))))))
|
---|
| 87 | :add #'(lambda (x y) (m+ x y))
|
---|
| 88 | :sub #'(lambda (x y) (m- x y))
|
---|
| 89 | :uminus #'(lambda (x) (m- x))
|
---|
| 90 | :mul #'(lambda (x y) (m* x y))
|
---|
| 91 | ;;(defun coeff-div (x y) (cadr ($divide x y)))
|
---|
| 92 | :div #'(lambda (x y) (m// x y))
|
---|
| 93 | :lcm #'(lambda (x y) (meval1 `((|$LCM|) ,x ,y)))
|
---|
| 94 | :ezgcd #'(lambda (x y) (apply #'values (cdr ($ezgcd ($totaldisrep x) ($totaldisrep y)))))
|
---|
| 95 | ;; :gcd #'(lambda (x y) (second ($ezgcd x y)))))
|
---|
| 96 | :gcd #'(lambda (x y) ($gcd x y))))
|
---|
| 97 |
|
---|
[619] | 98 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 99 | ;;
|
---|
| 100 | ;; Maxima expression parsing
|
---|
| 101 | ;;
|
---|
| 102 | ;;
|
---|
| 103 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 104 | ;;
|
---|
| 105 | ;; Functions and macros dealing with internal representation
|
---|
| 106 | ;; structure.
|
---|
| 107 | ;;
|
---|
| 108 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
[114] | 109 |
|
---|
[619] | 110 | (defun equal-test-p (expr1 expr2)
|
---|
| 111 | (alike1 expr1 expr2))
|
---|
| 112 |
|
---|
| 113 | (defun coerce-maxima-list (expr)
|
---|
| 114 | "Convert a Maxima list to Lisp list."
|
---|
| 115 | (cond
|
---|
| 116 | ((and (consp (car expr)) (eql (caar expr) 'mlist)) (cdr expr))
|
---|
| 117 | (t expr)))
|
---|
| 118 |
|
---|
| 119 | (defun free-of-vars (expr vars) (apply #'$freeof `(,@vars ,expr)))
|
---|
| 120 |
|
---|
[1642] | 121 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 122 | ;;
|
---|
| 123 | ;; Order utilities
|
---|
| 124 | ;;
|
---|
| 125 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 126 |
|
---|
[1644] | 127 | (defun find-ring (ring)
|
---|
| 128 | "This function returns the ring structure bases on input symbol."
|
---|
| 129 | (cond
|
---|
| 130 | ((null ring) nil)
|
---|
| 131 | ((symbolp ring)
|
---|
| 132 | (case ring
|
---|
| 133 | ((maxima-ring :maxima-ring $expression_ring) *maxima-ring*)
|
---|
| 134 | ((ring-of-integers :ring-of-integers $ring_of_integers) *ring-of-integers*)
|
---|
| 135 | (otherwise
|
---|
| 136 | (mtell "~%Warning: Ring ~M not found. Using default.~%" ring))))
|
---|
| 137 | (t
|
---|
| 138 | (mtell "~%Ring specification ~M is not recognized. Using default.~%" ring)
|
---|
| 139 | nil)))
|
---|
| 140 |
|
---|
[1642] | 141 | (defun find-order (order)
|
---|
| 142 | "This function returns the order function bases on its name."
|
---|
| 143 | (cond
|
---|
| 144 | ((null order) nil)
|
---|
| 145 | ((symbolp order)
|
---|
| 146 | (case order
|
---|
| 147 | ((lex :lex $lex) #'lex>)
|
---|
| 148 | ((grlex :grlex $grlex) #'grlex>)
|
---|
| 149 | ((grevlex :grevlex $grevlex) #'grevlex>)
|
---|
| 150 | ((invlex :invlex $invlex) #'invlex>)
|
---|
| 151 | (otherwise
|
---|
| 152 | (mtell "~%Warning: Order ~M not found. Using default.~%" order))))
|
---|
| 153 | (t
|
---|
| 154 | (mtell "~%Order specification ~M is not recognized. Using default.~%" order)
|
---|
| 155 | nil)))
|
---|
| 156 |
|
---|
| 157 |
|
---|
[1644] | 158 | (defun maxima->poly (expr vars
|
---|
| 159 | &optional
|
---|
| 160 | (ring $poly_coefficient_ring)
|
---|
| 161 | (order $poly_monomial_order)
|
---|
| 162 | &aux
|
---|
| 163 | (vars (coerce-maxima-list vars))
|
---|
| 164 | (ring-and-order (make-ring-and-order (find-ring) (find-order))))
|
---|
[619] | 165 | "Convert a maxima polynomial expression EXPR in variables VARS to internal form."
|
---|
[1641] | 166 | (labels ((parse (arg) (maxima->poly arg vars))
|
---|
[619] | 167 | (parse-list (args) (mapcar #'parse args)))
|
---|
| 168 | (cond
|
---|
| 169 | ((eql expr 0) (make-poly-zero))
|
---|
| 170 | ((member expr vars :test #'equal-test-p)
|
---|
| 171 | (let ((pos (position expr vars :test #'equal-test-p)))
|
---|
[1002] | 172 | (make-variable *maxima-ring* (length vars) pos)))
|
---|
[619] | 173 | ((free-of-vars expr vars)
|
---|
| 174 | ;;This means that variable-free CRE and Poisson forms will be converted
|
---|
| 175 | ;;to coefficients intact
|
---|
[1002] | 176 | (coerce-coeff *maxima-ring* expr vars))
|
---|
[619] | 177 | (t
|
---|
| 178 | (case (caar expr)
|
---|
[1002] | 179 | (mplus (reduce #'(lambda (x y) (poly-add *maxima-ring* x y)) (parse-list (cdr expr))))
|
---|
| 180 | (mminus (poly-uminus *maxima-ring* (parse (cadr expr))))
|
---|
[619] | 181 | (mtimes
|
---|
| 182 | (if (endp (cddr expr)) ;unary
|
---|
| 183 | (parse (cdr expr))
|
---|
[1002] | 184 | (reduce #'(lambda (p q) (poly-mul *maxima-ring* p q)) (parse-list (cdr expr)))))
|
---|
[619] | 185 | (mexpt
|
---|
| 186 | (cond
|
---|
| 187 | ((member (cadr expr) vars :test #'equal-test-p)
|
---|
| 188 | ;;Special handling of (expt var pow)
|
---|
| 189 | (let ((pos (position (cadr expr) vars :test #'equal-test-p)))
|
---|
[1002] | 190 | (make-variable *maxima-ring* (length vars) pos (caddr expr))))
|
---|
[619] | 191 | ((not (and (integerp (caddr expr)) (plusp (caddr expr))))
|
---|
| 192 | ;; Negative power means division in coefficient ring
|
---|
| 193 | ;; Non-integer power means non-polynomial coefficient
|
---|
| 194 | (mtell "~%Warning: Expression ~%~M~%contains power which is not a positive integer. Parsing as coefficient.~%"
|
---|
| 195 | expr)
|
---|
[1002] | 196 | (coerce-coeff *maxima-ring* expr vars))
|
---|
| 197 | (t (poly-expt *maxima-ring* (parse (cadr expr)) (caddr expr)))))
|
---|
[619] | 198 | (mrat (parse ($ratdisrep expr)))
|
---|
| 199 | (mpois (parse ($outofpois expr)))
|
---|
| 200 | (otherwise
|
---|
[1002] | 201 | (coerce-coeff *maxima-ring* expr vars)))))))
|
---|
[619] | 202 |
|
---|
[1640] | 203 | #|
|
---|
| 204 |
|
---|
[619] | 205 | (defun parse-poly-list (expr vars)
|
---|
| 206 | "Parse a Maxima representation of a list of polynomials."
|
---|
| 207 | (case (caar expr)
|
---|
| 208 | (mlist (mapcar #'(lambda (p) (parse-poly p vars)) (cdr expr)))
|
---|
| 209 | (t (merror "Expression ~M is not a list of polynomials in variables ~M."
|
---|
| 210 | expr vars))))
|
---|
| 211 |
|
---|
| 212 | (defun parse-poly-list-list (poly-list-list vars)
|
---|
| 213 | "Parse a Maxima representation of a list of lists of polynomials."
|
---|
| 214 | (mapcar #'(lambda (g) (parse-poly-list g vars)) (coerce-maxima-list poly-list-list)))
|
---|
| 215 |
|
---|
| 216 |
|
---|
[111] | 217 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 218 | ;;
|
---|
[241] | 219 | ;; Conversion from internal form to Maxima general form
|
---|
| 220 | ;;
|
---|
| 221 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 222 |
|
---|
| 223 | (defun maxima-head ()
|
---|
| 224 | (if $poly_return_term_list
|
---|
| 225 | '(mlist)
|
---|
| 226 | '(mplus)))
|
---|
| 227 |
|
---|
| 228 | (defun coerce-to-maxima (poly-type object vars)
|
---|
| 229 | (case poly-type
|
---|
| 230 | (:polynomial
|
---|
| 231 | `(,(maxima-head) ,@(mapcar #'(lambda (term) (coerce-to-maxima :term term vars)) (poly-termlist object))))
|
---|
| 232 | (:poly-list
|
---|
| 233 | `((mlist) ,@(mapcar #'(lambda (p) (funcall *ratdisrep-fun* (coerce-to-maxima :polynomial p vars))) object)))
|
---|
| 234 | (:term
|
---|
| 235 | `((mtimes) ,(funcall *ratdisrep-fun* (term-coeff object))
|
---|
| 236 | ,@(mapcar #'(lambda (var power) `((mexpt) ,var ,power))
|
---|
[882] | 237 | vars (coerce (term-monom object) 'list))))
|
---|
[241] | 238 | ;; Assumes that Lisp and Maxima logicals coincide
|
---|
| 239 | (:logical object)
|
---|
| 240 | (otherwise
|
---|
| 241 | object)))
|
---|
| 242 |
|
---|
| 243 |
|
---|
| 244 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 245 | ;;
|
---|
[111] | 246 | ;; Unary and binary operation definition facility
|
---|
| 247 | ;;
|
---|
| 248 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
[98] | 249 |
|
---|
[111] | 250 | (defmacro define-unop (maxima-name fun-name
|
---|
| 251 | &optional (documentation nil documentation-supplied-p))
|
---|
| 252 | "Define a MAXIMA-level unary operator MAXIMA-NAME corresponding to unary function FUN-NAME."
|
---|
| 253 | `(defun ,maxima-name (p vars
|
---|
| 254 | &aux
|
---|
| 255 | (vars (coerce-maxima-list vars))
|
---|
| 256 | (p (parse-poly p vars)))
|
---|
| 257 | ,@(when documentation-supplied-p (list documentation))
|
---|
[1002] | 258 | (coerce-to-maxima :polynomial (,fun-name *maxima-ring* p) vars)))
|
---|
[111] | 259 |
|
---|
| 260 | (defmacro define-binop (maxima-name fun-name
|
---|
| 261 | &optional (documentation nil documentation-supplied-p))
|
---|
| 262 | "Define a MAXIMA-level binary operator MAXIMA-NAME corresponding to binary function FUN-NAME."
|
---|
| 263 | `(defmfun ,maxima-name (p q vars
|
---|
| 264 | &aux
|
---|
| 265 | (vars (coerce-maxima-list vars))
|
---|
| 266 | (p (parse-poly p vars))
|
---|
| 267 | (q (parse-poly q vars)))
|
---|
| 268 | ,@(when documentation-supplied-p (list documentation))
|
---|
[1002] | 269 | (coerce-to-maxima :polynomial (,fun-name *maxima-ring* p q) vars)))
|
---|
[111] | 270 |
|
---|
| 271 |
|
---|
[219] | 272 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 273 | ;;
|
---|
| 274 | ;; Facilities for evaluating Grobner package expressions
|
---|
| 275 | ;; within a prepared environment
|
---|
| 276 | ;;
|
---|
| 277 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 278 |
|
---|
| 279 | (defmacro with-monomial-order ((order) &body body)
|
---|
| 280 | "Evaluate BODY with monomial order set to ORDER."
|
---|
| 281 | `(let ((*monomial-order* (or (find-order ,order) *monomial-order*)))
|
---|
| 282 | . ,body))
|
---|
| 283 |
|
---|
| 284 | (defmacro with-coefficient-ring ((ring) &body body)
|
---|
| 285 | "Evaluate BODY with coefficient ring set to RING."
|
---|
[1002] | 286 | `(let ((*maxima-ring* (or (find-ring ,ring) *maxima-ring*)))
|
---|
[219] | 287 | . ,body))
|
---|
| 288 |
|
---|
[863] | 289 | (defmacro with-ring-and-order ((ring order) &body body)
|
---|
[830] | 290 | "Evaluate BODY with monomial order set to ORDER and coefficient ring set to RING."
|
---|
| 291 | `(let ((*monomial-order* (or (find-order ,order) *monomial-order*))
|
---|
[1002] | 292 | (*maxima-ring* (or (find-ring ,ring) *maxima-ring*)))
|
---|
[830] | 293 | . ,body))
|
---|
| 294 |
|
---|
[219] | 295 | (defmacro with-elimination-orders ((primary secondary elimination-order)
|
---|
| 296 | &body body)
|
---|
| 297 | "Evaluate BODY with primary and secondary elimination orders set to PRIMARY and SECONDARY."
|
---|
| 298 | `(let ((*primary-elimination-order* (or (find-order ,primary) *primary-elimination-order*))
|
---|
| 299 | (*secondary-elimination-order* (or (find-order ,secondary) *secondary-elimination-order*))
|
---|
| 300 | (*elimination-order* (or (find-order ,elimination-order) *elimination-order*)))
|
---|
| 301 | . ,body))
|
---|
| 302 |
|
---|
| 303 |
|
---|
[98] | 304 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 305 | ;;
|
---|
| 306 | ;; Maxima-level interface functions
|
---|
| 307 | ;;
|
---|
| 308 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 309 |
|
---|
| 310 | ;; Auxillary function for removing zero polynomial
|
---|
| 311 | (defun remzero (plist) (remove #'poly-zerop plist))
|
---|
| 312 |
|
---|
| 313 | ;;Simple operators
|
---|
| 314 |
|
---|
| 315 | (define-binop $poly_add poly-add
|
---|
| 316 | "Adds two polynomials P and Q")
|
---|
| 317 |
|
---|
| 318 | (define-binop $poly_subtract poly-sub
|
---|
| 319 | "Subtracts a polynomial Q from P.")
|
---|
| 320 |
|
---|
| 321 | (define-binop $poly_multiply poly-mul
|
---|
| 322 | "Returns the product of polynomials P and Q.")
|
---|
| 323 |
|
---|
| 324 | (define-binop $poly_s_polynomial spoly
|
---|
| 325 | "Returns the syzygy polynomial (S-polynomial) of two polynomials P and Q.")
|
---|
| 326 |
|
---|
| 327 | (define-unop $poly_primitive_part poly-primitive-part
|
---|
| 328 | "Returns the polynomial P divided by GCD of its coefficients.")
|
---|
| 329 |
|
---|
| 330 | (define-unop $poly_normalize poly-normalize
|
---|
| 331 | "Returns the polynomial P divided by the leading coefficient.")
|
---|
| 332 |
|
---|
[222] | 333 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 334 | ;;
|
---|
| 335 | ;; Macro facility for writing Maxima-level wrappers for
|
---|
| 336 | ;; functions operating on internal representation
|
---|
| 337 | ;;
|
---|
| 338 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 339 |
|
---|
| 340 | (defmacro with-parsed-polynomials (((maxima-vars &optional (maxima-new-vars nil new-vars-supplied-p))
|
---|
| 341 | &key (polynomials nil)
|
---|
[1288] | 342 | (poly-lists nil)
|
---|
| 343 | (poly-list-lists nil)
|
---|
| 344 | (value-type nil))
|
---|
[222] | 345 | &body body
|
---|
| 346 | &aux (vars (gensym))
|
---|
[1288] | 347 | (new-vars (gensym)))
|
---|
[222] | 348 | `(let ((,vars (coerce-maxima-list ,maxima-vars))
|
---|
| 349 | ,@(when new-vars-supplied-p
|
---|
[1288] | 350 | (list `(,new-vars (coerce-maxima-list ,maxima-new-vars)))))
|
---|
[222] | 351 | (coerce-to-maxima
|
---|
| 352 | ,value-type
|
---|
| 353 | (with-coefficient-ring ($poly_coefficient_ring)
|
---|
| 354 | (with-monomial-order ($poly_monomial_order)
|
---|
| 355 | (with-elimination-orders ($poly_primary_elimination_order
|
---|
| 356 | $poly_secondary_elimination_order
|
---|
| 357 | $poly_elimination_order)
|
---|
| 358 | (let ,(let ((args nil))
|
---|
[1288] | 359 | (dolist (p polynomials args)
|
---|
| 360 | (setf args (cons `(,p (parse-poly ,p ,vars)) args)))
|
---|
| 361 | (dolist (p poly-lists args)
|
---|
| 362 | (setf args (cons `(,p (parse-poly-list ,p ,vars)) args)))
|
---|
| 363 | (dolist (p poly-list-lists args)
|
---|
| 364 | (setf args (cons `(,p (parse-poly-list-list ,p ,vars)) args))))
|
---|
[222] | 365 | . ,body))))
|
---|
| 366 | ,(if new-vars-supplied-p
|
---|
| 367 | `(append ,vars ,new-vars)
|
---|
[1288] | 368 | vars))))
|
---|
[222] | 369 |
|
---|
| 370 |
|
---|
[98] | 371 | ;;Functions
|
---|
| 372 |
|
---|
| 373 | (defmfun $poly_expand (p vars)
|
---|
| 374 | "This function is equivalent to EXPAND(P) if P parses correctly to a polynomial.
|
---|
| 375 | If the representation is not compatible with a polynomial in variables VARS,
|
---|
| 376 | the result is an error."
|
---|
| 377 | (with-parsed-polynomials ((vars) :polynomials (p)
|
---|
| 378 | :value-type :polynomial)
|
---|
| 379 | p))
|
---|
| 380 |
|
---|
| 381 | (defmfun $poly_expt (p n vars)
|
---|
| 382 | (with-parsed-polynomials ((vars) :polynomials (p) :value-type :polynomial)
|
---|
[1002] | 383 | (poly-expt *maxima-ring* p n)))
|
---|
[98] | 384 |
|
---|
| 385 | (defmfun $poly_content (p vars)
|
---|
| 386 | (with-parsed-polynomials ((vars) :polynomials (p))
|
---|
[1002] | 387 | (poly-content *maxima-ring* p)))
|
---|
[98] | 388 |
|
---|
| 389 | (defmfun $poly_pseudo_divide (f fl vars
|
---|
| 390 | &aux (vars (coerce-maxima-list vars))
|
---|
| 391 | (f (parse-poly f vars))
|
---|
| 392 | (fl (parse-poly-list fl vars)))
|
---|
| 393 | (multiple-value-bind (quot rem c division-count)
|
---|
[1002] | 394 | (poly-pseudo-divide *maxima-ring* f fl)
|
---|
[98] | 395 | `((mlist)
|
---|
| 396 | ,(coerce-to-maxima :poly-list quot vars)
|
---|
| 397 | ,(coerce-to-maxima :polynomial rem vars)
|
---|
| 398 | ,c
|
---|
| 399 | ,division-count)))
|
---|
| 400 |
|
---|
| 401 | (defmfun $poly_exact_divide (f g vars)
|
---|
| 402 | (with-parsed-polynomials ((vars) :polynomials (f g) :value-type :polynomial)
|
---|
[1002] | 403 | (poly-exact-divide *maxima-ring* f g)))
|
---|
[98] | 404 |
|
---|
| 405 | (defmfun $poly_normal_form (f fl vars)
|
---|
| 406 | (with-parsed-polynomials ((vars) :polynomials (f)
|
---|
| 407 | :poly-lists (fl)
|
---|
| 408 | :value-type :polynomial)
|
---|
[1002] | 409 | (normal-form *maxima-ring* f (remzero fl) nil)))
|
---|
[98] | 410 |
|
---|
| 411 | (defmfun $poly_buchberger_criterion (g vars)
|
---|
| 412 | (with-parsed-polynomials ((vars) :poly-lists (g) :value-type :logical)
|
---|
[1002] | 413 | (buchberger-criterion *maxima-ring* g)))
|
---|
[98] | 414 |
|
---|
| 415 | (defmfun $poly_buchberger (fl vars)
|
---|
| 416 | (with-parsed-polynomials ((vars) :poly-lists (fl) :value-type :poly-list)
|
---|
[1002] | 417 | (buchberger *maxima-ring* (remzero fl) 0 nil)))
|
---|
[98] | 418 |
|
---|
| 419 | (defmfun $poly_reduction (plist vars)
|
---|
| 420 | (with-parsed-polynomials ((vars) :poly-lists (plist)
|
---|
| 421 | :value-type :poly-list)
|
---|
[1002] | 422 | (reduction *maxima-ring* plist)))
|
---|
[98] | 423 |
|
---|
| 424 | (defmfun $poly_minimization (plist vars)
|
---|
| 425 | (with-parsed-polynomials ((vars) :poly-lists (plist)
|
---|
| 426 | :value-type :poly-list)
|
---|
| 427 | (minimization plist)))
|
---|
| 428 |
|
---|
| 429 | (defmfun $poly_normalize_list (plist vars)
|
---|
| 430 | (with-parsed-polynomials ((vars) :poly-lists (plist)
|
---|
| 431 | :value-type :poly-list)
|
---|
[1002] | 432 | (poly-normalize-list *maxima-ring* plist)))
|
---|
[98] | 433 |
|
---|
| 434 | (defmfun $poly_grobner (f vars)
|
---|
| 435 | (with-parsed-polynomials ((vars) :poly-lists (f)
|
---|
| 436 | :value-type :poly-list)
|
---|
[1002] | 437 | (grobner *maxima-ring* (remzero f))))
|
---|
[98] | 438 |
|
---|
| 439 | (defmfun $poly_reduced_grobner (f vars)
|
---|
| 440 | (with-parsed-polynomials ((vars) :poly-lists (f)
|
---|
| 441 | :value-type :poly-list)
|
---|
[1002] | 442 | (reduced-grobner *maxima-ring* (remzero f))))
|
---|
[98] | 443 |
|
---|
| 444 | (defmfun $poly_depends_p (p var mvars
|
---|
| 445 | &aux (vars (coerce-maxima-list mvars))
|
---|
| 446 | (pos (position var vars)))
|
---|
| 447 | (if (null pos)
|
---|
| 448 | (merror "~%Variable ~M not in the list of variables ~M." var mvars)
|
---|
| 449 | (poly-depends-p (parse-poly p vars) pos)))
|
---|
| 450 |
|
---|
| 451 | (defmfun $poly_elimination_ideal (flist k vars)
|
---|
| 452 | (with-parsed-polynomials ((vars) :poly-lists (flist)
|
---|
| 453 | :value-type :poly-list)
|
---|
[1002] | 454 | (elimination-ideal *maxima-ring* flist k nil 0)))
|
---|
[98] | 455 |
|
---|
| 456 | (defmfun $poly_colon_ideal (f g vars)
|
---|
| 457 | (with-parsed-polynomials ((vars) :poly-lists (f g) :value-type :poly-list)
|
---|
[1002] | 458 | (colon-ideal *maxima-ring* f g nil)))
|
---|
[98] | 459 |
|
---|
| 460 | (defmfun $poly_ideal_intersection (f g vars)
|
---|
| 461 | (with-parsed-polynomials ((vars) :poly-lists (f g) :value-type :poly-list)
|
---|
[1002] | 462 | (ideal-intersection *maxima-ring* f g nil)))
|
---|
[98] | 463 |
|
---|
| 464 | (defmfun $poly_lcm (f g vars)
|
---|
| 465 | (with-parsed-polynomials ((vars) :polynomials (f g) :value-type :polynomial)
|
---|
[1002] | 466 | (poly-lcm *maxima-ring* f g)))
|
---|
[98] | 467 |
|
---|
| 468 | (defmfun $poly_gcd (f g vars)
|
---|
| 469 | ($first ($divide (m* f g) ($poly_lcm f g vars))))
|
---|
| 470 |
|
---|
| 471 | (defmfun $poly_grobner_equal (g1 g2 vars)
|
---|
| 472 | (with-parsed-polynomials ((vars) :poly-lists (g1 g2))
|
---|
[1002] | 473 | (grobner-equal *maxima-ring* g1 g2)))
|
---|
[98] | 474 |
|
---|
| 475 | (defmfun $poly_grobner_subsetp (g1 g2 vars)
|
---|
| 476 | (with-parsed-polynomials ((vars) :poly-lists (g1 g2))
|
---|
[1002] | 477 | (grobner-subsetp *maxima-ring* g1 g2)))
|
---|
[98] | 478 |
|
---|
| 479 | (defmfun $poly_grobner_member (p g vars)
|
---|
| 480 | (with-parsed-polynomials ((vars) :polynomials (p) :poly-lists (g))
|
---|
[1002] | 481 | (grobner-member *maxima-ring* p g)))
|
---|
[98] | 482 |
|
---|
| 483 | (defmfun $poly_ideal_saturation1 (f p vars)
|
---|
| 484 | (with-parsed-polynomials ((vars) :poly-lists (f) :polynomials (p)
|
---|
| 485 | :value-type :poly-list)
|
---|
[1002] | 486 | (ideal-saturation-1 *maxima-ring* f p 0)))
|
---|
[98] | 487 |
|
---|
| 488 | (defmfun $poly_saturation_extension (f plist vars new-vars)
|
---|
| 489 | (with-parsed-polynomials ((vars new-vars)
|
---|
| 490 | :poly-lists (f plist)
|
---|
| 491 | :value-type :poly-list)
|
---|
[1002] | 492 | (saturation-extension *maxima-ring* f plist)))
|
---|
[98] | 493 |
|
---|
| 494 | (defmfun $poly_polysaturation_extension (f plist vars new-vars)
|
---|
| 495 | (with-parsed-polynomials ((vars new-vars)
|
---|
| 496 | :poly-lists (f plist)
|
---|
| 497 | :value-type :poly-list)
|
---|
[1002] | 498 | (polysaturation-extension *maxima-ring* f plist)))
|
---|
[98] | 499 |
|
---|
| 500 | (defmfun $poly_ideal_polysaturation1 (f plist vars)
|
---|
| 501 | (with-parsed-polynomials ((vars) :poly-lists (f plist)
|
---|
| 502 | :value-type :poly-list)
|
---|
[1002] | 503 | (ideal-polysaturation-1 *maxima-ring* f plist 0 nil)))
|
---|
[98] | 504 |
|
---|
| 505 | (defmfun $poly_ideal_saturation (f g vars)
|
---|
| 506 | (with-parsed-polynomials ((vars) :poly-lists (f g)
|
---|
| 507 | :value-type :poly-list)
|
---|
[1002] | 508 | (ideal-saturation *maxima-ring* f g 0 nil)))
|
---|
[98] | 509 |
|
---|
| 510 | (defmfun $poly_ideal_polysaturation (f ideal-list vars)
|
---|
| 511 | (with-parsed-polynomials ((vars) :poly-lists (f)
|
---|
| 512 | :poly-list-lists (ideal-list)
|
---|
| 513 | :value-type :poly-list)
|
---|
[1002] | 514 | (ideal-polysaturation *maxima-ring* f ideal-list 0 nil)))
|
---|
[98] | 515 |
|
---|
| 516 | (defmfun $poly_lt (f vars)
|
---|
| 517 | (with-parsed-polynomials ((vars) :polynomials (f) :value-type :polynomial)
|
---|
| 518 | (make-poly-from-termlist (list (poly-lt f)))))
|
---|
| 519 |
|
---|
| 520 | (defmfun $poly_lm (f vars)
|
---|
| 521 | (with-parsed-polynomials ((vars) :polynomials (f) :value-type :polynomial)
|
---|
[1002] | 522 | (make-poly-from-termlist (list (make-term (poly-lm f) (funcall (ring-unit *maxima-ring*)))))))
|
---|
[98] | 523 |
|
---|
[1640] | 524 | |#
|
---|