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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
23 | ;;
|
---|
24 | ;; Implementations of various admissible monomial orders
|
---|
25 | ;;
|
---|
26 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
27 |
|
---|
28 | (defpackage "ORDER"
|
---|
29 | (:use :cl :monomial)
|
---|
30 | (:export "LEX>"
|
---|
31 | "GRLEX>"
|
---|
32 | "REVLEX>"
|
---|
33 | "GREVLEX>"
|
---|
34 | "INVLEX>"
|
---|
35 | "MONOMIAL-ORDER"
|
---|
36 | "*MONOMIAL-ORDER*"
|
---|
37 | "REVERSE-MONOMIAL-ORDER"
|
---|
38 | "*PRIMARY-ELIMINATION-ORDER*"
|
---|
39 | "*SECONDARY-ELIMINATION-ORDER*"
|
---|
40 | "*ELIMINATION-ORDER*"
|
---|
41 | "ELIMINATION-ORDER"
|
---|
42 | "ELIMINATION-ORDER-1"))
|
---|
43 |
|
---|
44 | (in-package :order)
|
---|
45 |
|
---|
46 | ;; pure lexicographic
|
---|
47 | (defun lex> (p q &optional (start 0) (end (monom-dimension p)))
|
---|
48 | "Return T if P>Q with respect to lexicographic order, otherwise NIL.
|
---|
49 | The second returned value is T if P=Q, otherwise it is NIL."
|
---|
50 | (do ((i start (1+ i)))
|
---|
51 | ((>= i end) (values nil t))
|
---|
52 | (cond
|
---|
53 | ((> (monom-elt p i) (monom-elt q i))
|
---|
54 | (return-from lex> (values t nil)))
|
---|
55 | ((< (monom-elt p i) (monom-elt q i))
|
---|
56 | (return-from lex> (values nil nil))))))
|
---|
57 |
|
---|
58 | ;; total degree order , ties broken by lexicographic
|
---|
59 | (defun grlex> (p q &optional (start 0) (end (monom-dimension p)))
|
---|
60 | "Return T if P>Q with respect to graded lexicographic order, otherwise NIL.
|
---|
61 | The second returned value is T if P=Q, otherwise it is NIL."
|
---|
62 | (let ((d1 (monom-total-degree p start end))
|
---|
63 | (d2 (monom-total-degree q start end)))
|
---|
64 | (cond
|
---|
65 | ((> d1 d2) (values t nil))
|
---|
66 | ((< d1 d2) (values nil nil))
|
---|
67 | (t
|
---|
68 | (lex> p q start end)))))
|
---|
69 |
|
---|
70 |
|
---|
71 | ;; reverse lexicographic
|
---|
72 | (defun revlex> (p q &optional (start 0) (end (monom-dimension p)))
|
---|
73 | "Return T if P>Q with respect to reverse lexicographic order, NIL
|
---|
74 | otherwise. The second returned value is T if P=Q, otherwise it is
|
---|
75 | NIL. This is not and admissible monomial order because some sets do
|
---|
76 | not have a minimal element. This order is useful in constructing other
|
---|
77 | orders."
|
---|
78 | (do ((i (1- end) (1- i)))
|
---|
79 | ((< i start) (values nil t))
|
---|
80 | (cond
|
---|
81 | ((< (monom-elt p i) (monom-elt q i))
|
---|
82 | (return-from revlex> (values t nil)))
|
---|
83 | ((> (monom-elt p i) (monom-elt q i))
|
---|
84 | (return-from revlex> (values nil nil))))))
|
---|
85 |
|
---|
86 |
|
---|
87 | ;; total degree, ties broken by reverse lexicographic
|
---|
88 | (defun grevlex> (p q &optional (start 0) (end (monom-dimension p)))
|
---|
89 | "Return T if P>Q with respect to graded reverse lexicographic order,
|
---|
90 | NIL otherwise. The second returned value is T if P=Q, otherwise it is NIL."
|
---|
91 | (let ((d1 (monom-total-degree p start end))
|
---|
92 | (d2 (monom-total-degree q start end)))
|
---|
93 | (cond
|
---|
94 | ((> d1 d2) (values t nil))
|
---|
95 | ((< d1 d2) (values nil nil))
|
---|
96 | (t
|
---|
97 | (revlex> p q start end)))))
|
---|
98 |
|
---|
99 | (defun invlex> (p q &optional (start 0) (end (monom-dimension p)))
|
---|
100 | "Return T if P>Q with respect to inverse lexicographic order, NIL otherwise
|
---|
101 | The second returned value is T if P=Q, otherwise it is NIL."
|
---|
102 | (do ((i (1- end) (1- i)))
|
---|
103 | ((< i start) (values nil t))
|
---|
104 | (cond
|
---|
105 | ((> (monom-elt p i) (monom-elt q i))
|
---|
106 | (return-from invlex> (values t nil)))
|
---|
107 | ((< (monom-elt p i) (monom-elt q i))
|
---|
108 | (return-from invlex> (values nil nil))))))
|
---|
109 |
|
---|
110 |
|
---|
111 | (defun reverse-monomial-order (order)
|
---|
112 | "Create the inverse monomial order to the given monomial order ORDER."
|
---|
113 | #'(lambda (x y) (funcall order y x)))
|
---|
114 |
|
---|
115 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
116 | ;;
|
---|
117 | ;; Order making functions
|
---|
118 | ;;
|
---|
119 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
120 |
|
---|
121 | (defun make-elimination-order-maker (primary-elimination-order secondary-elimination-order)
|
---|
122 | "Return a function with a single integer argument K. This should be
|
---|
123 | the number of initial K variables X[0],X[1],...,X[K-1], which precede
|
---|
124 | remaining variables. The call to the closure creates a predicate
|
---|
125 | which compares monomials according to the K-th elimination order. The
|
---|
126 | monomial orders PRIMARY-ELIMINATION-ORDER and
|
---|
127 | SECONDARY-ELIMINATION-ORDER are used to compare the first K and the
|
---|
128 | remaining variables, respectively, with ties broken by lexicographical
|
---|
129 | order. That is, if PRIMARY-ELIMINATION-ORDER yields (VALUES NIL T),
|
---|
130 | which indicates that the first K variables appear with identical
|
---|
131 | powers, then the result is that of a call to
|
---|
132 | SECONDARY-ELIMINATION-ORDER applied to the remaining variables
|
---|
133 | X[K],X[K+1],..."
|
---|
134 | #'(lambda (k)
|
---|
135 | #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
|
---|
136 | (multiple-value-bind (primary equal)
|
---|
137 | (funcall primary-elimination-order p q start k)
|
---|
138 | (if equal
|
---|
139 | (funcall secondary-elimination-order p q k end)
|
---|
140 | (values primary nil))))))
|
---|
141 |
|
---|
142 | (defun make-elimination-order-1 (secondary-elimination-order q &optional (start 0) (end (monom-dimension p)))
|
---|
143 | "Equivalent to the function returned by the call to (ELIMINATION-ORDER PRIMARY-ELIMINATION-ORDER SECONDARY-ELIMINATION-ORDER 1).
|
---|
144 | It is an optimization used for the 1-st elimination ideal. We note that PRIMARY-ELIMINATION-ORDER could be LEX> or any
|
---|
145 | other order, as all orders coincide in 1 variabl."
|
---|
146 | #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
|
---|
147 | (cond
|
---|
148 | ((> (monom-elt p start) (monom-elt q start)) (values t nil))
|
---|
149 | ((< (monom-elt p start) (monom-elt q start)) (values nil nil))
|
---|
150 | (t (funcall secondary-elimination-order p q (1+ start) end)))))
|
---|