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 | (defpackage "ORDER-MK"
|
---|
23 | (:use :cl :order :monomial)
|
---|
24 | (:export "MONOMIAL-ORDER"
|
---|
25 | "REVERSE-MONOMIAL-ORDER"
|
---|
26 | "*PRIMARY-ELIMINATION-ORDER*"
|
---|
27 | "*SECONDARY-ELIMINATION-ORDER*"
|
---|
28 | "*ELIMINATION-ORDER*"
|
---|
29 | "ELIMINATION-ORDER"
|
---|
30 | "ELIMINATION-ORDER-1"))
|
---|
31 |
|
---|
32 | (in-package :order-mk)
|
---|
33 |
|
---|
34 | (defvar *monomial-order* #'lex>
|
---|
35 | "Default order for monomial comparisons. This global variable holds
|
---|
36 | the order which is in effect when performing polynomial
|
---|
37 | arithmetic. The global order is called by the macro MONOMIAL-ORDER,
|
---|
38 | which is somewhat more elegant than FUNCALL.")
|
---|
39 |
|
---|
40 | (defmacro monomial-order (x y)
|
---|
41 | "Calls the global monomial order function, held by *MONOMIAL-ORDER*."
|
---|
42 | `(funcall *monomial-order* ,x ,y))
|
---|
43 |
|
---|
44 | (defmacro reverse-monomial-order (x y)
|
---|
45 | "Calls the inverse monomial order to the global monomial order function,
|
---|
46 | held by *MONOMIAL-ORDER*."
|
---|
47 | `(monomial-order ,y ,x))
|
---|
48 |
|
---|
49 | (defvar *primary-elimination-order* #'lex>)
|
---|
50 |
|
---|
51 | (defvar *secondary-elimination-order* #'lex>)
|
---|
52 |
|
---|
53 | (defvar *elimination-order* nil
|
---|
54 | "Default elimination order used in elimination-based functions.
|
---|
55 | If not NIL, it is assumed to be a proper elimination order. If NIL,
|
---|
56 | we will construct an elimination order using the values of
|
---|
57 | *PRIMARY-ELIMINATION-ORDER* and *SECONDARY-ELIMINATION-ORDER*.")
|
---|
58 |
|
---|
59 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
60 | ;;
|
---|
61 | ;; Order making functions
|
---|
62 | ;;
|
---|
63 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
64 |
|
---|
65 | (defun elimination-order (k)
|
---|
66 | "Return a predicate which compares monomials according to the
|
---|
67 | K-th elimination order. Two variables *PRIMARY-ELIMINATION-ORDER*
|
---|
68 | and *SECONDARY-ELIMINATION-ORDER* control the behavior on the first K
|
---|
69 | and the remaining variables, respectively."
|
---|
70 | (declare (type fixnum k))
|
---|
71 | #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
|
---|
72 | (declare (type monom p q) (type fixnum start end))
|
---|
73 | (multiple-value-bind (primary equal)
|
---|
74 | (funcall *primary-elimination-order* p q start k)
|
---|
75 | (if equal
|
---|
76 | (funcall *secondary-elimination-order* p q k end)
|
---|
77 | (values primary nil)))))
|
---|
78 |
|
---|
79 | (defun elimination-order-1 (p q &optional (start 0) (end (monom-dimension p)))
|
---|
80 | "Equivalent to the function returned by the call to (ELIMINATION-ORDER 1)."
|
---|
81 | (declare (type monom p q) (type fixnum start end))
|
---|
82 | (cond
|
---|
83 | ((> (monom-elt p start) (monom-elt q start)) (values t nil))
|
---|
84 | ((< (monom-elt p start) (monom-elt q start)) (values nil nil))
|
---|
85 | (t (funcall *secondary-elimination-order* p q (1+ start) end))))
|
---|