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