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

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

* empty log message *

File size: 6.1 KB
RevLine 
[80]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
[444]22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23;;
24;; Implementations of various admissible monomial orders
25;;
26;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27
[412]28(defpackage "ORDER"
29 (:use :cl :monomial)
30 (:export "LEX>"
31 "GRLEX>"
32 "REVLEX>"
33 "GREVLEX>"
[440]34 "INVLEX>"
35 "MONOMIAL-ORDER"
[506]36 "*MONOMIAL-ORDER*"
[440]37 "REVERSE-MONOMIAL-ORDER"
38 "*PRIMARY-ELIMINATION-ORDER*"
39 "*SECONDARY-ELIMINATION-ORDER*"
40 "*ELIMINATION-ORDER*"
41 "ELIMINATION-ORDER"
42 "ELIMINATION-ORDER-1"))
[80]43
[417]44(in-package :order)
45
[49]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
[426]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
[49]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))))))
[439]109
110;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111;;
112;; Some globally-defined variables holding monomial orders
113;; and related macros/functions.
114;;
115;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
116
117(defvar *monomial-order* #'lex>
118 "Default order for monomial comparisons. This global variable holds
119the order which is in effect when performing polynomial
120arithmetic. The global order is called by the macro MONOMIAL-ORDER,
121which is somewhat more elegant than FUNCALL.")
122
[457]123(defun monomial-order (x y)
[439]124 "Calls the global monomial order function, held by *MONOMIAL-ORDER*."
[457]125 (funcall *monomial-order* x y))
[439]126
[457]127(defun reverse-monomial-order (x y)
[439]128 "Calls the inverse monomial order to the global monomial order function,
129held by *MONOMIAL-ORDER*."
[457]130 (monomial-order y x))
[439]131
132;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
133;;
134;; Order making functions
135;;
136;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
137
[899]138(defun elimination-order (primary-elimination-order secondary-elimination-order k)
[439]139 "Return a predicate which compares monomials according to the
[899]140K-th elimination order. The monomial orders PRIMARY-ELIMINATION-ORDER
141and SECONDARY-ELIMINATION-ORDER control the behavior on the first K
[439]142and the remaining variables, respectively."
143 #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
144 (multiple-value-bind (primary equal)
[901]145 (funcall primary-elimination-order p q start k)
[439]146 (if equal
[901]147 (funcall secondary-elimination-order p q k end)
[439]148 (values primary nil)))))
149
[900]150(defun elimination-order-1 (secondary-elimination-order q &optional (start 0) (end (monom-dimension p)))
151 "Equivalent to the function returned by the call to (ELIMINATION-ORDER NIL SECONDARY-ELIMINATION-ORDER 1)."
[439]152 (cond
153 ((> (monom-elt p start) (monom-elt q start)) (values t nil))
154 ((< (monom-elt p start) (monom-elt q start)) (values nil nil))
[900]155 (t (funcall secondary-elimination-order p q (1+ start) end))))
Note: See TracBrowser for help on using the repository browser.