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

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

* empty log message *

File size: 6.2 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(defun make-elimination-order-1 (secondary-elimination-order q &optional (start 0) (end (monom-dimension p)))
116 "It constructs an elimination order used for the 1-st elimination ideal,
117i.e. for eliminating the first variable. Thus, the order compares the degrees of the
118first variable in P and Q first, with ties broken by SECONDARY-ELIMINATION-ORDER."
119 #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
120 (cond
121 ((> (monom-elt p start) (monom-elt q start))
122 (values t nil))
123 ((< (monom-elt p start) (monom-elt q start))
124 (values nil nil))
125 (t
126 (funcall secondary-elimination-order p q (1+ start) end)))))
127
128(defun make-elimination-order-maker (primary-elimination-order secondary-elimination-order)
129 "Return a function with a single integer argument K. This should be
130the number of initial K variables X[0],X[1],...,X[K-1], which precede
131remaining variables. The call to the closure creates a predicate
132which compares monomials according to the K-th elimination order. The
133monomial orders PRIMARY-ELIMINATION-ORDER and
134SECONDARY-ELIMINATION-ORDER are used to compare the first K and the
135remaining variables, respectively, with ties broken by lexicographical
136order. That is, if PRIMARY-ELIMINATION-ORDER yields (VALUES NIL T),
137which indicates that the first K variables appear with identical
138powers, then the result is that of a call to
139SECONDARY-ELIMINATION-ORDER applied to the remaining variables
140X[K],X[K+1],..."
141 #'(lambda (k)
142 (cond
143 ((<= k 0)
144 (error "K must be at least 1"))
145 ((= k 1)
146 (make-elimination-order-1 secondary-elimination-order))
147 (t
148 #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
149 (multiple-value-bind (primary equal)
150 (funcall primary-elimination-order p q start k)
151 (if equal
152 (funcall secondary-elimination-order p q k end)
153 (values primary nil))))))))
154
Note: See TracBrowser for help on using the repository browser.