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

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

* empty log message *

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