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

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

* empty log message *

File size: 6.0 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 (do ((i start (1+ i)))
51 ((>= i end) (values nil t))
52 (cond
53 ((> (monom-elt p i) (monom-elt q i))
54 (return-from lex> (values t nil)))
55 ((< (monom-elt p i) (monom-elt q i))
56 (return-from lex> (values nil nil))))))
57
58;; total degree order , ties broken by lexicographic
59(defun grlex> (p q &optional (start 0) (end (monom-dimension p)))
60 "Return T if P>Q with respect to graded lexicographic order, otherwise NIL.
61The second returned value is T if P=Q, otherwise it is NIL."
62 (let ((d1 (monom-total-degree p start end))
63 (d2 (monom-total-degree q start end)))
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 (do ((i (1- end) (1- i)))
79 ((< i start) (values nil t))
80 (cond
81 ((< (monom-elt p i) (monom-elt q i))
82 (return-from revlex> (values t nil)))
83 ((> (monom-elt p i) (monom-elt q i))
84 (return-from revlex> (values nil nil))))))
85
86
87;; total degree, ties broken by reverse lexicographic
88(defun grevlex> (p q &optional (start 0) (end (monom-dimension p)))
89 "Return T if P>Q with respect to graded reverse lexicographic order,
90NIL otherwise. The second returned value is T if P=Q, otherwise it is NIL."
91 (let ((d1 (monom-total-degree p start end))
92 (d2 (monom-total-degree q start end)))
93 (cond
94 ((> d1 d2) (values t nil))
95 ((< d1 d2) (values nil nil))
96 (t
97 (revlex> p q start end)))))
98
99(defun invlex> (p q &optional (start 0) (end (monom-dimension p)))
100 "Return T if P>Q with respect to inverse lexicographic order, NIL otherwise
101The second returned value is T if P=Q, otherwise it is NIL."
102 (do ((i (1- end) (1- i)))
103 ((< i start) (values nil t))
104 (cond
105 ((> (monom-elt p i) (monom-elt q i))
106 (return-from invlex> (values t nil)))
107 ((< (monom-elt p i) (monom-elt q i))
108 (return-from invlex> (values nil nil))))))
109
110
111(defun reverse-monomial-order (order)
112 "Create the inverse monomial order to the given monomial order ORDER."
113 #'(lambda (x y) (funcall order y x)))
114
115;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
116;;
117;; Order making functions
118;;
119;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120
121(defun make-elimination-order-maker (primary-elimination-order secondary-elimination-order)
122 "Return a function with a single integer argument K. This should be
123the number of initial K variables X[0],X[1],...,X[K-1], which precede
124remaining variables. The call to the closure creates a predicate
125which compares monomials according to the K-th elimination order. The
126monomial orders PRIMARY-ELIMINATION-ORDER and
127SECONDARY-ELIMINATION-ORDER are used to compare the first K and the
128remaining variables, respectively, with ties broken by lexicographical
129order. That is, if PRIMARY-ELIMINATION-ORDER yields (VALUES NIL T),
130which indicates that the first K variables appear with identical
131powers, then the result is that of a call to
132SECONDARY-ELIMINATION-ORDER applied to the remaining variables
133X[K],X[K+1],..."
134 #'(lambda (k)
135 #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
136 (multiple-value-bind (primary equal)
137 (funcall primary-elimination-order p q start k)
138 (if equal
139 (funcall secondary-elimination-order p q k end)
140 (values primary nil))))))
141
142(defun elimination-order-1 (secondary-elimination-order q &optional (start 0) (end (monom-dimension p)))
143 "Equivalent to the function returned by the call to (ELIMINATION-ORDER NIL SECONDARY-ELIMINATION-ORDER 1)."
144 (cond
145 ((> (monom-elt p start) (monom-elt q start)) (values t nil))
146 ((< (monom-elt p start) (monom-elt q start)) (values nil nil))
147 (t (funcall secondary-elimination-order p q (1+ start) end))))
Note: See TracBrowser for help on using the repository browser.