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@ 1936

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

* empty log message *

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