close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

source: branches/f4grobner/mx-grobner.lisp@ 112

Last change on this file since 112 was 112, checked in by Marek Rychlik, 9 years ago

* empty log message *

File size: 10.2 KB
Line 
1;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*-
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
22(in-package :maxima)
23
24(macsyma-module cgb-maxima)
25
26(eval-when
27 #+gcl (load eval)
28 #-gcl (:load-toplevel :execute)
29 (format t "~&Loading maxima-grobner ~a ~a~%"
30 "$Revision: 2.0 $" "$Date: 2015/06/02 0:34:17 $"))
31
32;;FUNCTS is loaded because it contains the definition of LCM
33($load "functs")
34
35
36;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37;;
38;; Maxima expression ring
39;;
40;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41
42(defparameter *expression-ring*
43 (make-ring
44 ;;(defun coeff-zerop (expr) (meval1 `(($is) (($equal) ,expr 0))))
45 :parse #'(lambda (expr)
46 (when modulus (setf expr ($rat expr)))
47 expr)
48 :unit #'(lambda () (if modulus ($rat 1) 1))
49 :zerop #'(lambda (expr)
50 ;;When is exactly a maxima expression equal to 0?
51 (cond ((numberp expr)
52 (= expr 0))
53 ((atom expr) nil)
54 (t
55 (case (caar expr)
56 (mrat (eql ($ratdisrep expr) 0))
57 (otherwise (eql ($totaldisrep expr) 0))))))
58 :add #'(lambda (x y) (m+ x y))
59 :sub #'(lambda (x y) (m- x y))
60 :uminus #'(lambda (x) (m- x))
61 :mul #'(lambda (x y) (m* x y))
62 ;;(defun coeff-div (x y) (cadr ($divide x y)))
63 :div #'(lambda (x y) (m// x y))
64 :lcm #'(lambda (x y) (meval1 `((|$LCM|) ,x ,y)))
65 :ezgcd #'(lambda (x y) (apply #'values (cdr ($ezgcd ($totaldisrep x) ($totaldisrep y)))))
66 ;; :gcd #'(lambda (x y) (second ($ezgcd x y)))))
67 :gcd #'(lambda (x y) ($gcd x y))))
68
69(defvar *maxima-ring* *expression-ring*
70 "The ring of coefficients, over which all polynomials
71are assumed to be defined.")
72
73;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74;;
75;; Unary and binary operation definition facility
76;;
77;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78
79(defmacro define-unop (maxima-name fun-name
80 &optional (documentation nil documentation-supplied-p))
81 "Define a MAXIMA-level unary operator MAXIMA-NAME corresponding to unary function FUN-NAME."
82 `(defun ,maxima-name (p vars
83 &aux
84 (vars (coerce-maxima-list vars))
85 (p (parse-poly p vars)))
86 ,@(when documentation-supplied-p (list documentation))
87 (coerce-to-maxima :polynomial (,fun-name *maxima-ring* p) vars)))
88
89(defmacro define-binop (maxima-name fun-name
90 &optional (documentation nil documentation-supplied-p))
91 "Define a MAXIMA-level binary operator MAXIMA-NAME corresponding to binary function FUN-NAME."
92 `(defmfun ,maxima-name (p q vars
93 &aux
94 (vars (coerce-maxima-list vars))
95 (p (parse-poly p vars))
96 (q (parse-poly q vars)))
97 ,@(when documentation-supplied-p (list documentation))
98 (coerce-to-maxima :polynomial (,fun-name *maxima-ring* p q) vars)))
99
100
101;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
102;;
103;; Maxima-level interface functions
104;;
105;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106
107;; Auxillary function for removing zero polynomial
108(defun remzero (plist) (remove #'poly-zerop plist))
109
110;;Simple operators
111
112(define-binop $poly_add poly-add
113 "Adds two polynomials P and Q")
114
115(define-binop $poly_subtract poly-sub
116 "Subtracts a polynomial Q from P.")
117
118(define-binop $poly_multiply poly-mul
119 "Returns the product of polynomials P and Q.")
120
121(define-binop $poly_s_polynomial spoly
122 "Returns the syzygy polynomial (S-polynomial) of two polynomials P and Q.")
123
124(define-unop $poly_primitive_part poly-primitive-part
125 "Returns the polynomial P divided by GCD of its coefficients.")
126
127(define-unop $poly_normalize poly-normalize
128 "Returns the polynomial P divided by the leading coefficient.")
129
130;;Functions
131
132(defmfun $poly_expand (p vars)
133 "This function is equivalent to EXPAND(P) if P parses correctly to a polynomial.
134If the representation is not compatible with a polynomial in variables VARS,
135the result is an error."
136 (with-parsed-polynomials ((vars) :polynomials (p)
137 :value-type :polynomial)
138 p))
139
140(defmfun $poly_expt (p n vars)
141 (with-parsed-polynomials ((vars) :polynomials (p) :value-type :polynomial)
142 (poly-expt *maxima-ring* p n)))
143
144(defmfun $poly_content (p vars)
145 (with-parsed-polynomials ((vars) :polynomials (p))
146 (poly-content *maxima-ring* p)))
147
148(defmfun $poly_pseudo_divide (f fl vars
149 &aux (vars (coerce-maxima-list vars))
150 (f (parse-poly f vars))
151 (fl (parse-poly-list fl vars)))
152 (multiple-value-bind (quot rem c division-count)
153 (poly-pseudo-divide *maxima-ring* f fl)
154 `((mlist)
155 ,(coerce-to-maxima :poly-list quot vars)
156 ,(coerce-to-maxima :polynomial rem vars)
157 ,c
158 ,division-count)))
159
160(defmfun $poly_exact_divide (f g vars)
161 (with-parsed-polynomials ((vars) :polynomials (f g) :value-type :polynomial)
162 (poly-exact-divide *maxima-ring* f g)))
163
164(defmfun $poly_normal_form (f fl vars)
165 (with-parsed-polynomials ((vars) :polynomials (f)
166 :poly-lists (fl)
167 :value-type :polynomial)
168 (normal-form *maxima-ring* f (remzero fl) nil)))
169
170(defmfun $poly_buchberger_criterion (g vars)
171 (with-parsed-polynomials ((vars) :poly-lists (g) :value-type :logical)
172 (buchberger-criterion *maxima-ring* g)))
173
174(defmfun $poly_buchberger (fl vars)
175 (with-parsed-polynomials ((vars) :poly-lists (fl) :value-type :poly-list)
176 (buchberger *maxima-ring* (remzero fl) 0 nil)))
177
178(defmfun $poly_reduction (plist vars)
179 (with-parsed-polynomials ((vars) :poly-lists (plist)
180 :value-type :poly-list)
181 (reduction *maxima-ring* plist)))
182
183(defmfun $poly_minimization (plist vars)
184 (with-parsed-polynomials ((vars) :poly-lists (plist)
185 :value-type :poly-list)
186 (minimization plist)))
187
188(defmfun $poly_normalize_list (plist vars)
189 (with-parsed-polynomials ((vars) :poly-lists (plist)
190 :value-type :poly-list)
191 (poly-normalize-list *maxima-ring* plist)))
192
193(defmfun $poly_grobner (f vars)
194 (with-parsed-polynomials ((vars) :poly-lists (f)
195 :value-type :poly-list)
196 (grobner *maxima-ring* (remzero f))))
197
198(defmfun $poly_reduced_grobner (f vars)
199 (with-parsed-polynomials ((vars) :poly-lists (f)
200 :value-type :poly-list)
201 (reduced-grobner *maxima-ring* (remzero f))))
202
203(defmfun $poly_depends_p (p var mvars
204 &aux (vars (coerce-maxima-list mvars))
205 (pos (position var vars)))
206 (if (null pos)
207 (merror "~%Variable ~M not in the list of variables ~M." var mvars)
208 (poly-depends-p (parse-poly p vars) pos)))
209
210(defmfun $poly_elimination_ideal (flist k vars)
211 (with-parsed-polynomials ((vars) :poly-lists (flist)
212 :value-type :poly-list)
213 (elimination-ideal *maxima-ring* flist k nil 0)))
214
215(defmfun $poly_colon_ideal (f g vars)
216 (with-parsed-polynomials ((vars) :poly-lists (f g) :value-type :poly-list)
217 (colon-ideal *maxima-ring* f g nil)))
218
219(defmfun $poly_ideal_intersection (f g vars)
220 (with-parsed-polynomials ((vars) :poly-lists (f g) :value-type :poly-list)
221 (ideal-intersection *maxima-ring* f g nil)))
222
223(defmfun $poly_lcm (f g vars)
224 (with-parsed-polynomials ((vars) :polynomials (f g) :value-type :polynomial)
225 (poly-lcm *maxima-ring* f g)))
226
227(defmfun $poly_gcd (f g vars)
228 ($first ($divide (m* f g) ($poly_lcm f g vars))))
229
230(defmfun $poly_grobner_equal (g1 g2 vars)
231 (with-parsed-polynomials ((vars) :poly-lists (g1 g2))
232 (grobner-equal *maxima-ring* g1 g2)))
233
234(defmfun $poly_grobner_subsetp (g1 g2 vars)
235 (with-parsed-polynomials ((vars) :poly-lists (g1 g2))
236 (grobner-subsetp *maxima-ring* g1 g2)))
237
238(defmfun $poly_grobner_member (p g vars)
239 (with-parsed-polynomials ((vars) :polynomials (p) :poly-lists (g))
240 (grobner-member *maxima-ring* p g)))
241
242(defmfun $poly_ideal_saturation1 (f p vars)
243 (with-parsed-polynomials ((vars) :poly-lists (f) :polynomials (p)
244 :value-type :poly-list)
245 (ideal-saturation-1 *maxima-ring* f p 0)))
246
247(defmfun $poly_saturation_extension (f plist vars new-vars)
248 (with-parsed-polynomials ((vars new-vars)
249 :poly-lists (f plist)
250 :value-type :poly-list)
251 (saturation-extension *maxima-ring* f plist)))
252
253(defmfun $poly_polysaturation_extension (f plist vars new-vars)
254 (with-parsed-polynomials ((vars new-vars)
255 :poly-lists (f plist)
256 :value-type :poly-list)
257 (polysaturation-extension *maxima-ring* f plist)))
258
259(defmfun $poly_ideal_polysaturation1 (f plist vars)
260 (with-parsed-polynomials ((vars) :poly-lists (f plist)
261 :value-type :poly-list)
262 (ideal-polysaturation-1 *maxima-ring* f plist 0 nil)))
263
264(defmfun $poly_ideal_saturation (f g vars)
265 (with-parsed-polynomials ((vars) :poly-lists (f g)
266 :value-type :poly-list)
267 (ideal-saturation *maxima-ring* f g 0 nil)))
268
269(defmfun $poly_ideal_polysaturation (f ideal-list vars)
270 (with-parsed-polynomials ((vars) :poly-lists (f)
271 :poly-list-lists (ideal-list)
272 :value-type :poly-list)
273 (ideal-polysaturation *maxima-ring* f ideal-list 0 nil)))
274
275(defmfun $poly_lt (f vars)
276 (with-parsed-polynomials ((vars) :polynomials (f) :value-type :polynomial)
277 (make-poly-from-termlist (list (poly-lt f)))))
278
279(defmfun $poly_lm (f vars)
280 (with-parsed-polynomials ((vars) :polynomials (f) :value-type :polynomial)
281 (make-poly-from-termlist (list (make-term (poly-lm f) (funcall (ring-unit *maxima-ring*)))))))
282
Note: See TracBrowser for help on using the repository browser.