[1] | 1 | ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*-
|
---|
| 2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 3 | ;;;
|
---|
[72] | 4 | ;;; Copyright (C) 1999, 2002, 2009, 2015 Marek Rychlik <rychlik@u.arizona.edu>
|
---|
[1] | 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 |
|
---|
[182] | 22 | (in-package :ngrobner)
|
---|
[135] | 23 |
|
---|
[1] | 24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 25 | ;;
|
---|
| 26 | ;; Global switches
|
---|
| 27 | ;;
|
---|
[94] | 28 | ;; Can be used in Maxima just fine, as they observe the
|
---|
[95] | 29 | ;; Maxima naming convention, i.e. all names visible at the
|
---|
[96] | 30 | ;; Maxima toplevel begin with a '$'.
|
---|
[94] | 31 | ;;
|
---|
[1] | 32 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 33 |
|
---|
[97] | 34 | (defvar $poly_monomial_order '$lex
|
---|
[1] | 35 | "This switch controls which monomial order is used in polynomial
|
---|
| 36 | and Grobner basis calculations. If not set, LEX will be used")
|
---|
| 37 |
|
---|
[97] | 38 | (defvar $poly_coefficient_ring '$expression_ring
|
---|
[1] | 39 | "This switch indicates the coefficient ring of the polynomials
|
---|
| 40 | that will be used in grobner calculations. If not set, Maxima's
|
---|
| 41 | general expression ring will be used. This variable may be set
|
---|
| 42 | to RING_OF_INTEGERS if desired.")
|
---|
| 43 |
|
---|
[97] | 44 | (defvar $poly_primary_elimination_order nil
|
---|
[1] | 45 | "Name of the default order for eliminated variables in elimination-based functions.
|
---|
| 46 | If not set, LEX will be used.")
|
---|
| 47 |
|
---|
[97] | 48 | (defvar $poly_secondary_elimination_order nil
|
---|
[1] | 49 | "Name of the default order for kept variables in elimination-based functions.
|
---|
| 50 | If not set, LEX will be used.")
|
---|
| 51 |
|
---|
[97] | 52 | (defvar $poly_elimination_order nil
|
---|
[1] | 53 | "Name of the default elimination order used in elimination calculations.
|
---|
| 54 | If set, it overrides the settings in variables POLY_PRIMARY_ELIMINATION_ORDER
|
---|
| 55 | and SECONDARY_ELIMINATION_ORDER. The user must ensure that this is a true
|
---|
| 56 | elimination order valid for the number of eliminated variables.")
|
---|
| 57 |
|
---|
[97] | 58 | (defvar $poly_return_term_list nil
|
---|
[1] | 59 | "If set to T, all functions in this package will return each polynomial as a
|
---|
| 60 | list of terms in the current monomial order rather than a Maxima general expression.")
|
---|
| 61 |
|
---|
[128] | 62 | (defvar *ratdisrep-fun* #'identity
|
---|
[129] | 63 | "A function applied to polynomials after conversion to Maxima representation.")
|
---|
[124] | 64 |
|
---|
[1] | 65 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 66 | ;;
|
---|
| 67 | ;; These are provided mostly for debugging purposes To enable
|
---|
| 68 | ;; verification of grobner bases with BUCHBERGER-CRITERION, do
|
---|
| 69 | ;; (pushnew :grobner-check *features*) and compile/load this file.
|
---|
| 70 | ;; With this feature, the calculations will slow down CONSIDERABLY.
|
---|
| 71 | ;;
|
---|
| 72 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 73 |
|
---|
| 74 | (defun grobner-test (ring g f)
|
---|
| 75 | "Test whether G is a Grobner basis and F is contained in G. Return T
|
---|
| 76 | upon success and NIL otherwise."
|
---|
| 77 | (debug-cgb "~&GROBNER CHECK: ")
|
---|
| 78 | (let (($poly_grobner_debug nil)
|
---|
| 79 | (stat1 (buchberger-criterion ring g))
|
---|
| 80 | (stat2
|
---|
| 81 | (every #'poly-zerop
|
---|
| 82 | (makelist (normal-form ring (copy-tree (elt f i)) g nil)
|
---|
| 83 | (i 0 (1- (length f)))))))
|
---|
| 84 | (unless stat1 (error "~&Buchberger criterion failed."))
|
---|
| 85 | (unless stat2
|
---|
| 86 | (error "~&Original polys not in ideal spanned by Grobner.")))
|
---|
| 87 | (debug-cgb "~&GROBNER CHECK END")
|
---|
| 88 | t)
|
---|
| 89 |
|
---|
| 90 |
|
---|
[66] | 91 |
|
---|
[1] | 92 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 93 | ;;
|
---|
| 94 | ;; Conversion from internal to infix form
|
---|
| 95 | ;;
|
---|
| 96 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 97 |
|
---|
| 98 | (defun coerce-to-infix (poly-type object vars)
|
---|
| 99 | (case poly-type
|
---|
| 100 | (:termlist
|
---|
| 101 | `(+ ,@(mapcar #'(lambda (term) (coerce-to-infix :term term vars)) object)))
|
---|
| 102 | (:polynomial
|
---|
| 103 | (coerce-to-infix :termlist (poly-termlist object) vars))
|
---|
| 104 | (:poly-list
|
---|
| 105 | `([ ,@(mapcar #'(lambda (p) (coerce-to-infix :polynomial p vars)) object)))
|
---|
| 106 | (:term
|
---|
| 107 | `(* ,(term-coeff object)
|
---|
| 108 | ,@(mapcar #'(lambda (var power) `(expt ,var ,power))
|
---|
| 109 | vars (monom-exponents (term-monom object)))))
|
---|
| 110 | (otherwise
|
---|
| 111 | object)))
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 115 | ;;
|
---|
| 116 | ;; Order utilities
|
---|
| 117 | ;;
|
---|
| 118 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
[373] | 119 |
|
---|
[1] | 120 | (defun find-order (order)
|
---|
| 121 | "This function returns the order function bases on its name."
|
---|
| 122 | (cond
|
---|
| 123 | ((null order) nil)
|
---|
| 124 | ((symbolp order)
|
---|
| 125 | (case order
|
---|
| 126 | ((lex :lex $lex) #'lex>)
|
---|
| 127 | ((grlex :grlex $grlex) #'grlex>)
|
---|
| 128 | ((grevlex :grevlex $grevlex) #'grevlex>)
|
---|
| 129 | ((invlex :invlex $invlex) #'invlex>)
|
---|
| 130 | ((elimination-order-1 :elimination-order-1 elimination_order_1) #'elimination-order-1)
|
---|
| 131 | (otherwise
|
---|
[120] | 132 | (warn "~%Warning: Order ~A not found. Using default.~%" order))))
|
---|
[1] | 133 | (t
|
---|
[120] | 134 | (warn "~%Order specification ~A is not recognized. Using default.~%" order)
|
---|
[1] | 135 | nil)))
|
---|
| 136 |
|
---|
[373] | 137 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 138 | ;;
|
---|
| 139 | ;; Ring utilities
|
---|
| 140 | ;;
|
---|
| 141 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 142 |
|
---|
[1] | 143 | (defun find-ring (ring)
|
---|
| 144 | "This function returns the ring structure bases on input symbol."
|
---|
| 145 | (cond
|
---|
| 146 | ((null ring) nil)
|
---|
| 147 | ((symbolp ring)
|
---|
| 148 | (case ring
|
---|
| 149 | ((expression-ring :expression-ring $expression_ring) *expression-ring*)
|
---|
| 150 | ((ring-of-integers :ring-of-integers $ring_of_integers) *ring-of-integers*)
|
---|
| 151 | (otherwise
|
---|
[121] | 152 | (warn "~%Warning: Ring ~A not found. Using default.~%" ring))))
|
---|
[1] | 153 | (t
|
---|
[121] | 154 | (warn "~%Ring specification ~A is not recognized. Using default.~%" ring)
|
---|
[1] | 155 | nil)))
|
---|