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/order.lisp@ 2630

Last change on this file since 2630 was 2439, checked in by Marek Rychlik, 10 years ago

* empty log message *

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