[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 |
|
---|
| 121 | (defun parse-poly (expr vars &aux (vars (coerce-maxima-list vars)))
|
---|
| 122 | "Convert a maxima polynomial expression EXPR in variables VARS to internal form."
|
---|
| 123 | (labels ((parse (arg) (parse-poly arg vars))
|
---|
| 124 | (parse-list (args) (mapcar #'parse args)))
|
---|
| 125 | (cond
|
---|
| 126 | ((eql expr 0) (make-poly-zero))
|
---|
| 127 | ((member expr vars :test #'equal-test-p)
|
---|
| 128 | (let ((pos (position expr vars :test #'equal-test-p)))
|
---|
[1002] | 129 | (make-variable *maxima-ring* (length vars) pos)))
|
---|
[619] | 130 | ((free-of-vars expr vars)
|
---|
| 131 | ;;This means that variable-free CRE and Poisson forms will be converted
|
---|
| 132 | ;;to coefficients intact
|
---|
[1002] | 133 | (coerce-coeff *maxima-ring* expr vars))
|
---|
[619] | 134 | (t
|
---|
| 135 | (case (caar expr)
|
---|
[1002] | 136 | (mplus (reduce #'(lambda (x y) (poly-add *maxima-ring* x y)) (parse-list (cdr expr))))
|
---|
| 137 | (mminus (poly-uminus *maxima-ring* (parse (cadr expr))))
|
---|
[619] | 138 | (mtimes
|
---|
| 139 | (if (endp (cddr expr)) ;unary
|
---|
| 140 | (parse (cdr expr))
|
---|
[1002] | 141 | (reduce #'(lambda (p q) (poly-mul *maxima-ring* p q)) (parse-list (cdr expr)))))
|
---|
[619] | 142 | (mexpt
|
---|
| 143 | (cond
|
---|
| 144 | ((member (cadr expr) vars :test #'equal-test-p)
|
---|
| 145 | ;;Special handling of (expt var pow)
|
---|
| 146 | (let ((pos (position (cadr expr) vars :test #'equal-test-p)))
|
---|
[1002] | 147 | (make-variable *maxima-ring* (length vars) pos (caddr expr))))
|
---|
[619] | 148 | ((not (and (integerp (caddr expr)) (plusp (caddr expr))))
|
---|
| 149 | ;; Negative power means division in coefficient ring
|
---|
| 150 | ;; Non-integer power means non-polynomial coefficient
|
---|
| 151 | (mtell "~%Warning: Expression ~%~M~%contains power which is not a positive integer. Parsing as coefficient.~%"
|
---|
| 152 | expr)
|
---|
[1002] | 153 | (coerce-coeff *maxima-ring* expr vars))
|
---|
| 154 | (t (poly-expt *maxima-ring* (parse (cadr expr)) (caddr expr)))))
|
---|
[619] | 155 | (mrat (parse ($ratdisrep expr)))
|
---|
| 156 | (mpois (parse ($outofpois expr)))
|
---|
| 157 | (otherwise
|
---|
[1002] | 158 | (coerce-coeff *maxima-ring* expr vars)))))))
|
---|
[619] | 159 |
|
---|
[1640] | 160 | #|
|
---|
| 161 |
|
---|
[619] | 162 | (defun parse-poly-list (expr vars)
|
---|
| 163 | "Parse a Maxima representation of a list of polynomials."
|
---|
| 164 | (case (caar expr)
|
---|
| 165 | (mlist (mapcar #'(lambda (p) (parse-poly p vars)) (cdr expr)))
|
---|
| 166 | (t (merror "Expression ~M is not a list of polynomials in variables ~M."
|
---|
| 167 | expr vars))))
|
---|
| 168 |
|
---|
| 169 | (defun parse-poly-list-list (poly-list-list vars)
|
---|
| 170 | "Parse a Maxima representation of a list of lists of polynomials."
|
---|
| 171 | (mapcar #'(lambda (g) (parse-poly-list g vars)) (coerce-maxima-list poly-list-list)))
|
---|
| 172 |
|
---|
| 173 |
|
---|
[111] | 174 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 175 | ;;
|
---|
[241] | 176 | ;; Conversion from internal form to Maxima general form
|
---|
| 177 | ;;
|
---|
| 178 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 179 |
|
---|
| 180 | (defun maxima-head ()
|
---|
| 181 | (if $poly_return_term_list
|
---|
| 182 | '(mlist)
|
---|
| 183 | '(mplus)))
|
---|
| 184 |
|
---|
| 185 | (defun coerce-to-maxima (poly-type object vars)
|
---|
| 186 | (case poly-type
|
---|
| 187 | (:polynomial
|
---|
| 188 | `(,(maxima-head) ,@(mapcar #'(lambda (term) (coerce-to-maxima :term term vars)) (poly-termlist object))))
|
---|
| 189 | (:poly-list
|
---|
| 190 | `((mlist) ,@(mapcar #'(lambda (p) (funcall *ratdisrep-fun* (coerce-to-maxima :polynomial p vars))) object)))
|
---|
| 191 | (:term
|
---|
| 192 | `((mtimes) ,(funcall *ratdisrep-fun* (term-coeff object))
|
---|
| 193 | ,@(mapcar #'(lambda (var power) `((mexpt) ,var ,power))
|
---|
[882] | 194 | vars (coerce (term-monom object) 'list))))
|
---|
[241] | 195 | ;; Assumes that Lisp and Maxima logicals coincide
|
---|
| 196 | (:logical object)
|
---|
| 197 | (otherwise
|
---|
| 198 | object)))
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 202 | ;;
|
---|
[111] | 203 | ;; Unary and binary operation definition facility
|
---|
| 204 | ;;
|
---|
| 205 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
[98] | 206 |
|
---|
[111] | 207 | (defmacro define-unop (maxima-name fun-name
|
---|
| 208 | &optional (documentation nil documentation-supplied-p))
|
---|
| 209 | "Define a MAXIMA-level unary operator MAXIMA-NAME corresponding to unary function FUN-NAME."
|
---|
| 210 | `(defun ,maxima-name (p vars
|
---|
| 211 | &aux
|
---|
| 212 | (vars (coerce-maxima-list vars))
|
---|
| 213 | (p (parse-poly p vars)))
|
---|
| 214 | ,@(when documentation-supplied-p (list documentation))
|
---|
[1002] | 215 | (coerce-to-maxima :polynomial (,fun-name *maxima-ring* p) vars)))
|
---|
[111] | 216 |
|
---|
| 217 | (defmacro define-binop (maxima-name fun-name
|
---|
| 218 | &optional (documentation nil documentation-supplied-p))
|
---|
| 219 | "Define a MAXIMA-level binary operator MAXIMA-NAME corresponding to binary function FUN-NAME."
|
---|
| 220 | `(defmfun ,maxima-name (p q vars
|
---|
| 221 | &aux
|
---|
| 222 | (vars (coerce-maxima-list vars))
|
---|
| 223 | (p (parse-poly p vars))
|
---|
| 224 | (q (parse-poly q vars)))
|
---|
| 225 | ,@(when documentation-supplied-p (list documentation))
|
---|
[1002] | 226 | (coerce-to-maxima :polynomial (,fun-name *maxima-ring* p q) vars)))
|
---|
[111] | 227 |
|
---|
| 228 |
|
---|
[998] | 229 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 230 | ;;
|
---|
| 231 | ;; Order utilities
|
---|
| 232 | ;;
|
---|
| 233 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 234 |
|
---|
| 235 | (defun find-order (order)
|
---|
| 236 | "This function returns the order function bases on its name."
|
---|
| 237 | (cond
|
---|
| 238 | ((null order) nil)
|
---|
| 239 | ((symbolp order)
|
---|
| 240 | (case order
|
---|
| 241 | ((lex :lex $lex) #'lex>)
|
---|
| 242 | ((grlex :grlex $grlex) #'grlex>)
|
---|
| 243 | ((grevlex :grevlex $grevlex) #'grevlex>)
|
---|
| 244 | ((invlex :invlex $invlex) #'invlex>)
|
---|
| 245 | ((elimination-order-1 :elimination-order-1 elimination_order_1) #'elimination-order-1)
|
---|
| 246 | (otherwise
|
---|
| 247 | (mtell "~%Warning: Order ~M not found. Using default.~%" order))))
|
---|
| 248 | (t
|
---|
| 249 | (mtell "~%Order specification ~M is not recognized. Using default.~%" order)
|
---|
| 250 | nil)))
|
---|
| 251 |
|
---|
| 252 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 253 | ;;
|
---|
| 254 | ;; Ring utilities
|
---|
| 255 | ;;
|
---|
| 256 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 257 |
|
---|
| 258 | (defun find-ring (ring)
|
---|
| 259 | "This function returns the ring structure bases on input symbol."
|
---|
| 260 | (cond
|
---|
| 261 | ((null ring) nil)
|
---|
| 262 | ((symbolp ring)
|
---|
| 263 | (case ring
|
---|
[1002] | 264 | ((maxima-ring :maxima-ring $expression_ring) *maxima-ring*)
|
---|
[998] | 265 | ((ring-of-integers :ring-of-integers $ring_of_integers) *ring-of-integers*)
|
---|
| 266 | (otherwise
|
---|
| 267 | (mtell "~%Warning: Ring ~M not found. Using default.~%" ring))))
|
---|
| 268 | (t
|
---|
[999] | 269 | (mtell "~%Ring specification ~M is not recognized. Using default.~%" ring)
|
---|
[998] | 270 | nil)))
|
---|
| 271 |
|
---|
| 272 |
|
---|
[219] | 273 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 274 | ;;
|
---|
| 275 | ;; Facilities for evaluating Grobner package expressions
|
---|
| 276 | ;; within a prepared environment
|
---|
| 277 | ;;
|
---|
| 278 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 279 |
|
---|
| 280 | (defmacro with-monomial-order ((order) &body body)
|
---|
| 281 | "Evaluate BODY with monomial order set to ORDER."
|
---|
| 282 | `(let ((*monomial-order* (or (find-order ,order) *monomial-order*)))
|
---|
| 283 | . ,body))
|
---|
| 284 |
|
---|
| 285 | (defmacro with-coefficient-ring ((ring) &body body)
|
---|
| 286 | "Evaluate BODY with coefficient ring set to RING."
|
---|
[1002] | 287 | `(let ((*maxima-ring* (or (find-ring ,ring) *maxima-ring*)))
|
---|
[219] | 288 | . ,body))
|
---|
| 289 |
|
---|
[863] | 290 | (defmacro with-ring-and-order ((ring order) &body body)
|
---|
[830] | 291 | "Evaluate BODY with monomial order set to ORDER and coefficient ring set to RING."
|
---|
| 292 | `(let ((*monomial-order* (or (find-order ,order) *monomial-order*))
|
---|
[1002] | 293 | (*maxima-ring* (or (find-ring ,ring) *maxima-ring*)))
|
---|
[830] | 294 | . ,body))
|
---|
| 295 |
|
---|
[219] | 296 | (defmacro with-elimination-orders ((primary secondary elimination-order)
|
---|
| 297 | &body body)
|
---|
| 298 | "Evaluate BODY with primary and secondary elimination orders set to PRIMARY and SECONDARY."
|
---|
| 299 | `(let ((*primary-elimination-order* (or (find-order ,primary) *primary-elimination-order*))
|
---|
| 300 | (*secondary-elimination-order* (or (find-order ,secondary) *secondary-elimination-order*))
|
---|
| 301 | (*elimination-order* (or (find-order ,elimination-order) *elimination-order*)))
|
---|
| 302 | . ,body))
|
---|
| 303 |
|
---|
| 304 |
|
---|
[98] | 305 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 306 | ;;
|
---|
| 307 | ;; Maxima-level interface functions
|
---|
| 308 | ;;
|
---|
| 309 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 310 |
|
---|
| 311 | ;; Auxillary function for removing zero polynomial
|
---|
| 312 | (defun remzero (plist) (remove #'poly-zerop plist))
|
---|
| 313 |
|
---|
| 314 | ;;Simple operators
|
---|
| 315 |
|
---|
| 316 | (define-binop $poly_add poly-add
|
---|
| 317 | "Adds two polynomials P and Q")
|
---|
| 318 |
|
---|
| 319 | (define-binop $poly_subtract poly-sub
|
---|
| 320 | "Subtracts a polynomial Q from P.")
|
---|
| 321 |
|
---|
| 322 | (define-binop $poly_multiply poly-mul
|
---|
| 323 | "Returns the product of polynomials P and Q.")
|
---|
| 324 |
|
---|
| 325 | (define-binop $poly_s_polynomial spoly
|
---|
| 326 | "Returns the syzygy polynomial (S-polynomial) of two polynomials P and Q.")
|
---|
| 327 |
|
---|
| 328 | (define-unop $poly_primitive_part poly-primitive-part
|
---|
| 329 | "Returns the polynomial P divided by GCD of its coefficients.")
|
---|
| 330 |
|
---|
| 331 | (define-unop $poly_normalize poly-normalize
|
---|
| 332 | "Returns the polynomial P divided by the leading coefficient.")
|
---|
| 333 |
|
---|
[222] | 334 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 335 | ;;
|
---|
| 336 | ;; Macro facility for writing Maxima-level wrappers for
|
---|
| 337 | ;; functions operating on internal representation
|
---|
| 338 | ;;
|
---|
| 339 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 340 |
|
---|
| 341 | (defmacro with-parsed-polynomials (((maxima-vars &optional (maxima-new-vars nil new-vars-supplied-p))
|
---|
| 342 | &key (polynomials nil)
|
---|
[1288] | 343 | (poly-lists nil)
|
---|
| 344 | (poly-list-lists nil)
|
---|
| 345 | (value-type nil))
|
---|
[222] | 346 | &body body
|
---|
| 347 | &aux (vars (gensym))
|
---|
[1288] | 348 | (new-vars (gensym)))
|
---|
[222] | 349 | `(let ((,vars (coerce-maxima-list ,maxima-vars))
|
---|
| 350 | ,@(when new-vars-supplied-p
|
---|
[1288] | 351 | (list `(,new-vars (coerce-maxima-list ,maxima-new-vars)))))
|
---|
[222] | 352 | (coerce-to-maxima
|
---|
| 353 | ,value-type
|
---|
| 354 | (with-coefficient-ring ($poly_coefficient_ring)
|
---|
| 355 | (with-monomial-order ($poly_monomial_order)
|
---|
| 356 | (with-elimination-orders ($poly_primary_elimination_order
|
---|
| 357 | $poly_secondary_elimination_order
|
---|
| 358 | $poly_elimination_order)
|
---|
| 359 | (let ,(let ((args nil))
|
---|
[1288] | 360 | (dolist (p polynomials args)
|
---|
| 361 | (setf args (cons `(,p (parse-poly ,p ,vars)) args)))
|
---|
| 362 | (dolist (p poly-lists args)
|
---|
| 363 | (setf args (cons `(,p (parse-poly-list ,p ,vars)) args)))
|
---|
| 364 | (dolist (p poly-list-lists args)
|
---|
| 365 | (setf args (cons `(,p (parse-poly-list-list ,p ,vars)) args))))
|
---|
[222] | 366 | . ,body))))
|
---|
| 367 | ,(if new-vars-supplied-p
|
---|
| 368 | `(append ,vars ,new-vars)
|
---|
[1288] | 369 | vars))))
|
---|
[222] | 370 |
|
---|
| 371 |
|
---|
[98] | 372 | ;;Functions
|
---|
| 373 |
|
---|
| 374 | (defmfun $poly_expand (p vars)
|
---|
| 375 | "This function is equivalent to EXPAND(P) if P parses correctly to a polynomial.
|
---|
| 376 | If the representation is not compatible with a polynomial in variables VARS,
|
---|
| 377 | the result is an error."
|
---|
| 378 | (with-parsed-polynomials ((vars) :polynomials (p)
|
---|
| 379 | :value-type :polynomial)
|
---|
| 380 | p))
|
---|
| 381 |
|
---|
| 382 | (defmfun $poly_expt (p n vars)
|
---|
| 383 | (with-parsed-polynomials ((vars) :polynomials (p) :value-type :polynomial)
|
---|
[1002] | 384 | (poly-expt *maxima-ring* p n)))
|
---|
[98] | 385 |
|
---|
| 386 | (defmfun $poly_content (p vars)
|
---|
| 387 | (with-parsed-polynomials ((vars) :polynomials (p))
|
---|
[1002] | 388 | (poly-content *maxima-ring* p)))
|
---|
[98] | 389 |
|
---|
| 390 | (defmfun $poly_pseudo_divide (f fl vars
|
---|
| 391 | &aux (vars (coerce-maxima-list vars))
|
---|
| 392 | (f (parse-poly f vars))
|
---|
| 393 | (fl (parse-poly-list fl vars)))
|
---|
| 394 | (multiple-value-bind (quot rem c division-count)
|
---|
[1002] | 395 | (poly-pseudo-divide *maxima-ring* f fl)
|
---|
[98] | 396 | `((mlist)
|
---|
| 397 | ,(coerce-to-maxima :poly-list quot vars)
|
---|
| 398 | ,(coerce-to-maxima :polynomial rem vars)
|
---|
| 399 | ,c
|
---|
| 400 | ,division-count)))
|
---|
| 401 |
|
---|
| 402 | (defmfun $poly_exact_divide (f g vars)
|
---|
| 403 | (with-parsed-polynomials ((vars) :polynomials (f g) :value-type :polynomial)
|
---|
[1002] | 404 | (poly-exact-divide *maxima-ring* f g)))
|
---|
[98] | 405 |
|
---|
| 406 | (defmfun $poly_normal_form (f fl vars)
|
---|
| 407 | (with-parsed-polynomials ((vars) :polynomials (f)
|
---|
| 408 | :poly-lists (fl)
|
---|
| 409 | :value-type :polynomial)
|
---|
[1002] | 410 | (normal-form *maxima-ring* f (remzero fl) nil)))
|
---|
[98] | 411 |
|
---|
| 412 | (defmfun $poly_buchberger_criterion (g vars)
|
---|
| 413 | (with-parsed-polynomials ((vars) :poly-lists (g) :value-type :logical)
|
---|
[1002] | 414 | (buchberger-criterion *maxima-ring* g)))
|
---|
[98] | 415 |
|
---|
| 416 | (defmfun $poly_buchberger (fl vars)
|
---|
| 417 | (with-parsed-polynomials ((vars) :poly-lists (fl) :value-type :poly-list)
|
---|
[1002] | 418 | (buchberger *maxima-ring* (remzero fl) 0 nil)))
|
---|
[98] | 419 |
|
---|
| 420 | (defmfun $poly_reduction (plist vars)
|
---|
| 421 | (with-parsed-polynomials ((vars) :poly-lists (plist)
|
---|
| 422 | :value-type :poly-list)
|
---|
[1002] | 423 | (reduction *maxima-ring* plist)))
|
---|
[98] | 424 |
|
---|
| 425 | (defmfun $poly_minimization (plist vars)
|
---|
| 426 | (with-parsed-polynomials ((vars) :poly-lists (plist)
|
---|
| 427 | :value-type :poly-list)
|
---|
| 428 | (minimization plist)))
|
---|
| 429 |
|
---|
| 430 | (defmfun $poly_normalize_list (plist vars)
|
---|
| 431 | (with-parsed-polynomials ((vars) :poly-lists (plist)
|
---|
| 432 | :value-type :poly-list)
|
---|
[1002] | 433 | (poly-normalize-list *maxima-ring* plist)))
|
---|
[98] | 434 |
|
---|
| 435 | (defmfun $poly_grobner (f vars)
|
---|
| 436 | (with-parsed-polynomials ((vars) :poly-lists (f)
|
---|
| 437 | :value-type :poly-list)
|
---|
[1002] | 438 | (grobner *maxima-ring* (remzero f))))
|
---|
[98] | 439 |
|
---|
| 440 | (defmfun $poly_reduced_grobner (f vars)
|
---|
| 441 | (with-parsed-polynomials ((vars) :poly-lists (f)
|
---|
| 442 | :value-type :poly-list)
|
---|
[1002] | 443 | (reduced-grobner *maxima-ring* (remzero f))))
|
---|
[98] | 444 |
|
---|
| 445 | (defmfun $poly_depends_p (p var mvars
|
---|
| 446 | &aux (vars (coerce-maxima-list mvars))
|
---|
| 447 | (pos (position var vars)))
|
---|
| 448 | (if (null pos)
|
---|
| 449 | (merror "~%Variable ~M not in the list of variables ~M." var mvars)
|
---|
| 450 | (poly-depends-p (parse-poly p vars) pos)))
|
---|
| 451 |
|
---|
| 452 | (defmfun $poly_elimination_ideal (flist k vars)
|
---|
| 453 | (with-parsed-polynomials ((vars) :poly-lists (flist)
|
---|
| 454 | :value-type :poly-list)
|
---|
[1002] | 455 | (elimination-ideal *maxima-ring* flist k nil 0)))
|
---|
[98] | 456 |
|
---|
| 457 | (defmfun $poly_colon_ideal (f g vars)
|
---|
| 458 | (with-parsed-polynomials ((vars) :poly-lists (f g) :value-type :poly-list)
|
---|
[1002] | 459 | (colon-ideal *maxima-ring* f g nil)))
|
---|
[98] | 460 |
|
---|
| 461 | (defmfun $poly_ideal_intersection (f g vars)
|
---|
| 462 | (with-parsed-polynomials ((vars) :poly-lists (f g) :value-type :poly-list)
|
---|
[1002] | 463 | (ideal-intersection *maxima-ring* f g nil)))
|
---|
[98] | 464 |
|
---|
| 465 | (defmfun $poly_lcm (f g vars)
|
---|
| 466 | (with-parsed-polynomials ((vars) :polynomials (f g) :value-type :polynomial)
|
---|
[1002] | 467 | (poly-lcm *maxima-ring* f g)))
|
---|
[98] | 468 |
|
---|
| 469 | (defmfun $poly_gcd (f g vars)
|
---|
| 470 | ($first ($divide (m* f g) ($poly_lcm f g vars))))
|
---|
| 471 |
|
---|
| 472 | (defmfun $poly_grobner_equal (g1 g2 vars)
|
---|
| 473 | (with-parsed-polynomials ((vars) :poly-lists (g1 g2))
|
---|
[1002] | 474 | (grobner-equal *maxima-ring* g1 g2)))
|
---|
[98] | 475 |
|
---|
| 476 | (defmfun $poly_grobner_subsetp (g1 g2 vars)
|
---|
| 477 | (with-parsed-polynomials ((vars) :poly-lists (g1 g2))
|
---|
[1002] | 478 | (grobner-subsetp *maxima-ring* g1 g2)))
|
---|
[98] | 479 |
|
---|
| 480 | (defmfun $poly_grobner_member (p g vars)
|
---|
| 481 | (with-parsed-polynomials ((vars) :polynomials (p) :poly-lists (g))
|
---|
[1002] | 482 | (grobner-member *maxima-ring* p g)))
|
---|
[98] | 483 |
|
---|
| 484 | (defmfun $poly_ideal_saturation1 (f p vars)
|
---|
| 485 | (with-parsed-polynomials ((vars) :poly-lists (f) :polynomials (p)
|
---|
| 486 | :value-type :poly-list)
|
---|
[1002] | 487 | (ideal-saturation-1 *maxima-ring* f p 0)))
|
---|
[98] | 488 |
|
---|
| 489 | (defmfun $poly_saturation_extension (f plist vars new-vars)
|
---|
| 490 | (with-parsed-polynomials ((vars new-vars)
|
---|
| 491 | :poly-lists (f plist)
|
---|
| 492 | :value-type :poly-list)
|
---|
[1002] | 493 | (saturation-extension *maxima-ring* f plist)))
|
---|
[98] | 494 |
|
---|
| 495 | (defmfun $poly_polysaturation_extension (f plist vars new-vars)
|
---|
| 496 | (with-parsed-polynomials ((vars new-vars)
|
---|
| 497 | :poly-lists (f plist)
|
---|
| 498 | :value-type :poly-list)
|
---|
[1002] | 499 | (polysaturation-extension *maxima-ring* f plist)))
|
---|
[98] | 500 |
|
---|
| 501 | (defmfun $poly_ideal_polysaturation1 (f plist vars)
|
---|
| 502 | (with-parsed-polynomials ((vars) :poly-lists (f plist)
|
---|
| 503 | :value-type :poly-list)
|
---|
[1002] | 504 | (ideal-polysaturation-1 *maxima-ring* f plist 0 nil)))
|
---|
[98] | 505 |
|
---|
| 506 | (defmfun $poly_ideal_saturation (f g vars)
|
---|
| 507 | (with-parsed-polynomials ((vars) :poly-lists (f g)
|
---|
| 508 | :value-type :poly-list)
|
---|
[1002] | 509 | (ideal-saturation *maxima-ring* f g 0 nil)))
|
---|
[98] | 510 |
|
---|
| 511 | (defmfun $poly_ideal_polysaturation (f ideal-list vars)
|
---|
| 512 | (with-parsed-polynomials ((vars) :poly-lists (f)
|
---|
| 513 | :poly-list-lists (ideal-list)
|
---|
| 514 | :value-type :poly-list)
|
---|
[1002] | 515 | (ideal-polysaturation *maxima-ring* f ideal-list 0 nil)))
|
---|
[98] | 516 |
|
---|
| 517 | (defmfun $poly_lt (f vars)
|
---|
| 518 | (with-parsed-polynomials ((vars) :polynomials (f) :value-type :polynomial)
|
---|
| 519 | (make-poly-from-termlist (list (poly-lt f)))))
|
---|
| 520 |
|
---|
| 521 | (defmfun $poly_lm (f vars)
|
---|
| 522 | (with-parsed-polynomials ((vars) :polynomials (f) :value-type :polynomial)
|
---|
[1002] | 523 | (make-poly-from-termlist (list (make-term (poly-lm f) (funcall (ring-unit *maxima-ring*)))))))
|
---|
[98] | 524 |
|
---|
[1640] | 525 | |#
|
---|