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

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

* empty log message *

File size: 6.9 KB
Line 
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.
49The second returned value is T if P=Q, otherwise it is NIL."
50 (declare (type monom p q) (type fixnum start end))
51 (do ((i start (1+ i)))
52 ((>= i end) (values nil t))
53 (declare (type fixnum i))
54 (cond
55 ((> (monom-elt p i) (monom-elt q i))
56 (return-from lex> (values t nil)))
57 ((< (monom-elt p i) (monom-elt q i))
58 (return-from lex> (values nil nil))))))
59
60;; total degree order , ties broken by lexicographic
61(defun grlex> (p q &optional (start 0) (end (monom-dimension p)))
62 "Return T if P>Q with respect to graded lexicographic order, otherwise NIL.
63The second returned value is T if P=Q, otherwise it is NIL."
64 (declare (type monom p q) (type fixnum start end))
65 (let ((d1 (monom-total-degree p start end))
66 (d2 (monom-total-degree q start end)))
67 (cond
68 ((> d1 d2) (values t nil))
69 ((< d1 d2) (values nil nil))
70 (t
71 (lex> p q start end)))))
72
73
74;; reverse lexicographic
75(defun revlex> (p q &optional (start 0) (end (monom-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 monom p q) (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 ((< (monom-elt p i) (monom-elt q i))
87 (return-from revlex> (values t nil)))
88 ((> (monom-elt p i) (monom-elt q i))
89 (return-from revlex> (values nil nil))))))
90
91
92;; total degree, ties broken by reverse lexicographic
93(defun grevlex> (p q &optional (start 0) (end (monom-dimension p)))
94 "Return T if P>Q with respect to graded reverse lexicographic order,
95NIL otherwise. The second returned value is T if P=Q, otherwise it is NIL."
96 (declare (type monom p q) (type fixnum start end))
97 (let ((d1 (monom-total-degree p start end))
98 (d2 (monom-total-degree q start end)))
99 (cond
100 ((> d1 d2) (values t nil))
101 ((< d1 d2) (values nil nil))
102 (t
103 (revlex> p q start end)))))
104
105(defun invlex> (p q &optional (start 0) (end (monom-dimension p)))
106 "Return T if P>Q with respect to inverse lexicographic order, NIL otherwise
107The second returned value is T if P=Q, otherwise it is NIL."
108 (declare (type monom p q) (type fixnum start end))
109 (do ((i (1- end) (1- i)))
110 ((< i start) (values nil t))
111 (declare (type fixnum i))
112 (cond
113 ((> (monom-elt p i) (monom-elt q i))
114 (return-from invlex> (values t nil)))
115 ((< (monom-elt p i) (monom-elt q i))
116 (return-from invlex> (values nil nil))))))
117
118;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119;;
120;; Some globally-defined variables holding monomial orders
121;; and related macros/functions.
122;;
123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
124
125(defvar *monomial-order* #'lex>
126 "Default order for monomial comparisons. This global variable holds
127the order which is in effect when performing polynomial
128arithmetic. The global order is called by the macro MONOMIAL-ORDER,
129which is somewhat more elegant than FUNCALL.")
130
131(defun monomial-order (x y)
132 "Calls the global monomial order function, held by *MONOMIAL-ORDER*."
133 (funcall *monomial-order* x y))
134
135(defun reverse-monomial-order (x y)
136 "Calls the inverse monomial order to the global monomial order function,
137held by *MONOMIAL-ORDER*."
138 (monomial-order y x))
139
140(defvar *primary-elimination-order* #'lex>)
141
142(defvar *secondary-elimination-order* #'lex>)
143
144(defvar *elimination-order* nil
145 "Default elimination order used in elimination-based functions.
146If not NIL, it is assumed to be a proper elimination order. If NIL,
147we will construct an elimination order using the values of
148*PRIMARY-ELIMINATION-ORDER* and *SECONDARY-ELIMINATION-ORDER*.")
149
150;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151;;
152;; Order making functions
153;;
154;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
155
156(defun elimination-order (k)
157 "Return a predicate which compares monomials according to the
158K-th elimination order. Two variables *PRIMARY-ELIMINATION-ORDER*
159and *SECONDARY-ELIMINATION-ORDER* control the behavior on the first K
160and the remaining variables, respectively."
161 (declare (type fixnum k))
162 #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
163 (declare (type monom p q) (type fixnum start end))
164 (multiple-value-bind (primary equal)
165 (funcall *primary-elimination-order* p q start k)
166 (if equal
167 (funcall *secondary-elimination-order* p q k end)
168 (values primary nil)))))
169
170(defun elimination-order-1 (p q &optional (start 0) (end (monom-dimension p)))
171 "Equivalent to the function returned by the call to (ELIMINATION-ORDER 1)."
172 (declare (type monom p q) (type fixnum start end))
173 (cond
174 ((> (monom-elt p start) (monom-elt q start)) (values t nil))
175 ((< (monom-elt p start) (monom-elt q start)) (values nil nil))
176 (t (funcall *secondary-elimination-order* p q (1+ start) end))))
Note: See TracBrowser for help on using the repository browser.