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

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