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/ideal.lisp@ 1597

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

* empty log message *

File size: 10.3 KB
Line 
1;;; -*- Mode: Lisp -*-
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;; Operations in ideal theory
25;;
26;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27
28(defpackage "IDEAL"
29 (:use :cl :ring :monomial :order :term :polynomial :division :grobner-wrap :ring-and-order)
30 (:export "POLY-DEPENDS-P"
31 "RING-INTERSECTION"
32 "ELIMINATION-IDEAL"
33 "COLON-IDEAL"
34 "COLON-IDEAL-1"
35 "IDEAL-INTERSECTION"
36 "POLY-LCM"
37 "GROBNER-EQUAL"
38 "GROBNER-SUBSETP"
39 "GROBNER-MEMBER"
40 "IDEAL-SATURATION-1"
41 "IDEAL-SATURATION"
42 "IDEAL-POLYSATURATION-1"
43 "IDEAL-POLYSATURATION"
44 ))
45
46(in-package :ideal)
47
48;; Does the term depend on variable K?
49(defun term-depends-p (term k)
50 "Return T if the term TERM depends on variable number K."
51 (monom-depends-p (term-monom term) k))
52
53;; Does the polynomial P depend on variable K?
54(defun poly-depends-p (p k)
55 "Return T if the term polynomial P depends on variable number K."
56 (some #'(lambda (term) (term-depends-p term k)) (poly-termlist p)))
57
58(defun ring-intersection (plist k)
59 "This function assumes that polynomial list
60PLIST=(P[0],P[1],...,P[J-1]) is a Grobner basis and it calculates the
61intersection of Id({P[0],P[1],...,P[J-1]}) with the ring
62R[X[K],...,X[N-1]], i.e. it discards polynomials which depend on
63variables X[0], X[1], ..., X[K-1]."
64 (dotimes (i k plist)
65 (setf plist
66 (remove-if #'(lambda (p)
67 (poly-depends-p p i))
68 plist))))
69
70(defun elimination-ideal (ring-and-order flist k
71 &optional
72 (top-reduction-only $poly_top_reduction_only)
73 (start 0))
74 "Given a list of polynomials FLIST, and an integer K, tt finds and
75returns the Groebner basis the elimination ideal of Id({FLIST})
76obtained by eliminating the first K variables. Optional argument
77TOP-REDUCTION-ONLY indicates whether to fully reduce or only
78top-reduce. Optional argument START, defaulting to 0, is used to
79indicate that the first START elements of F form a Groebner basis."
80
81 (ring-intersection (reduced-grobner ring-and-order flist start top-reduction-only) k))
82
83(defun colon-ideal (ring-and-order f g
84 &optional
85 (top-reduction-only $poly_top_reduction_only)
86 &aux
87 (ring (ro-ring ring-and-order)))
88 "Returns the reduced Grobner basis of the colon ideal Id(F):Id(G),
89where F and G are two lists of polynomials. The colon ideal I:J is
90defined as the set of polynomials H such that for all polynomials W in
91J the polynomial W*H belongs to I."
92 (declare (type ring-and-order ring-and-order))
93 (cond
94 ((endp g)
95 ;;Id(G) consists of 0 only so W*0=0 belongs to Id(F)
96 (if (every #'poly-zerop f)
97 (error "First ideal must be non-zero.")
98 (list (make-poly-from-termlist
99 (list (make-term
100 (make-monom :dimension (monom-dimension (poly-lm (find-if-not #'poly-zerop f))))
101 (funcall (ring-unit ring))))))))
102 ((endp (cdr g))
103 (colon-ideal-1 ring-and-order f (car g) top-reduction-only))
104 (t
105 (ideal-intersection ring-and-order
106 (colon-ideal-1 ring-and-order f (car g) top-reduction-only)
107 (colon-ideal ring-and-order f (rest g) top-reduction-only)
108 top-reduction-only))))
109
110(defun colon-ideal-1 (ring-and-order f g
111 &optional
112 (top-reduction-only $poly_top_reduction_only))
113 "Returns the reduced Grobner basis of the colon ideal Id(F):Id({G}), where
114F is a list of polynomials and G is a polynomial."
115 (declare (type ring-and-order ring-and-order))
116 (mapcar #'(lambda (x)
117 (poly-exact-divide ring-and-order x g))
118 (ideal-intersection ring-and-order f (list g) top-reduction-only)))
119
120(defun ideal-intersection (ring-and-order f g
121 &optional
122 (top-reduction-only $poly_top_reduction_only)
123 (ring (ro-ring ring-and-order)))
124 (declare (type ring-and-order ring-and-order))
125 (mapcar #'poly-contract
126 (ring-intersection
127 (reduced-grobner
128 ring-and-order
129 (append (mapcar #'(lambda (p) (poly-extend p (make-monom :dimension 1 :initial-exponent 1))) f)
130 (mapcar #'(lambda (p)
131 (poly-append (poly-extend (poly-uminus ring p)
132 (make-monom :dimension 1 :initial-exponent 1))
133 (poly-extend p)))
134 g))
135 0
136 top-reduction-only)
137 1)))
138
139(defun poly-lcm (ring-and-order f g &aux (ring (ro-ring ring-and-order)))
140 "Return LCM (least common multiple) of two polynomials F and G.
141The polynomials must be ordered according to monomial order PRED
142and their coefficients must be compatible with the RING structure
143defined in the COEFFICIENT-RING package."
144 (cond
145 ((poly-zerop f) f)
146 ((poly-zerop g) g)
147 ((and (endp (cdr (poly-termlist f))) (endp (cdr (poly-termlist g))))
148 (let ((m (monom-lcm (poly-lm f) (poly-lm g))))
149 (make-poly-from-termlist (list (make-term m (funcall (ring-lcm ring) (poly-lc f) (poly-lc g)))))))
150 (t
151 (multiple-value-bind (f f-cont)
152 (poly-primitive-part ring f)
153 (multiple-value-bind (g g-cont)
154 (poly-primitive-part ring g)
155 (scalar-times-poly
156 ring
157 (funcall (ring-lcm ring) f-cont g-cont)
158 (poly-primitive-part ring (car (ideal-intersection ring-and-order (list f) (list g) nil)))))))))
159
160;; Do two Grobner bases yield the same ideal?
161(defun grobner-equal (ring-and-order g1 g2)
162 "Returns T if two lists of polynomials G1 and G2, assumed to be Grobner bases,
163generate the same ideal, and NIL otherwise."
164 (declare (type ring-and-order ring-and-order))
165 (and (grobner-subsetp ring-and-order g1 g2) (grobner-subsetp ring-and-order g2 g1)))
166
167(defun grobner-subsetp (ring-and-order g1 g2)
168 "Returns T if a list of polynomials G1 generates
169an ideal contained in the ideal generated by a polynomial list G2,
170both G1 and G2 assumed to be Grobner bases. Returns NIL otherwise."
171 (declare (type ring-and-order ring-and-order))
172 (every #'(lambda (p) (grobner-member ring-and-order p g2)) g1))
173
174(defun grobner-member (ring-and-order p g)
175 "Returns T if a polynomial P belongs to the ideal generated by the
176polynomial list G, which is assumed to be a Grobner basis. Returns NIL otherwise."
177 (declare (type ring-and-order ring-and-order))
178 (poly-zerop (normal-form ring-and-order p g nil)))
179
180;; Calculate F : p^inf
181(defun ideal-saturation-1 (ring-and-order f p
182 &optional
183 (start 0)
184 (top-reduction-only $poly_top_reduction_only)
185 &aux
186 (ring (ro-ring ring-and-order)))
187 "Returns the reduced Grobner basis of the saturation of the ideal
188generated by a polynomial list F in the ideal generated by a single
189polynomial P. The saturation ideal is defined as the set of
190polynomials H such for some natural number n (* (EXPT P N) H) is in
191the ideal spanned by F. Geometrically, over an algebraically closed
192field, this is the set of polynomials in the ideal generated by F
193which do not identically vanish on the variety of P."
194 (declare (type ring-and-order ring-and-order))
195 (mapcar
196 #'poly-contract
197 (ring-intersection
198 (reduced-grobner
199 ring-and-order
200 (saturation-extension-1 ring f p)
201 start top-reduction-only)
202 1)))
203
204
205;; Calculate F : p1^inf : p2^inf : ... : ps^inf
206(defun ideal-polysaturation-1 (ring-and-order f plist
207 &optional
208 (start 0)
209 (top-reduction-only $poly_top_reduction_only))
210 "Returns the reduced Grobner basis of the ideal obtained by a
211sequence of successive saturations in the polynomials
212of the polynomial list PLIST of the ideal generated by the
213polynomial list F."
214 (cond
215 ((endp plist)
216 (reduced-grobner ring-and-order f start top-reduction-only))
217 (t (let ((g (ideal-saturation-1 ring-and-order f (car plist) start top-reduction-only)))
218 (ideal-polysaturation-1 ring-and-order g (rest plist) (length g) top-reduction-only)))))
219
220(defun ideal-saturation (ring-and-order f g
221 &optional
222 (start 0)
223 (top-reduction-only $poly_top_reduction_only)
224 &aux
225 (k (length g))
226 (ring (ro-ring ring-and-order)))
227 "Returns the reduced Grobner basis of the saturation of the ideal
228generated by a polynomial list F in the ideal generated a polynomial
229list G. The saturation ideal is defined as the set of polynomials H
230such for some natural number n and some P in the ideal generated by G
231the polynomial P**N * H is in the ideal spanned by F. Geometrically,
232over an algebraically closed field, this is the set of polynomials in
233the ideal generated by F which do not identically vanish on the
234variety of G."
235 (declare (type ring-and-order ring-and-order))
236 (mapcar
237 #'(lambda (q) (poly-contract q k))
238 (ring-intersection
239 (reduced-grobner ring-and-order
240 (polysaturation-extension ring f g)
241 start
242 top-reduction-only)
243 k)))
244
245(defun ideal-polysaturation (ring-and-order f ideal-list
246 &optional
247 (start 0)
248 (top-reduction-only $poly_top_reduction_only))
249 "Returns the reduced Grobner basis of the ideal obtained by a
250successive applications of IDEAL-SATURATION to F and lists of
251polynomials in the list IDEAL-LIST."
252 (declare (type ring-and-order ring-and-order))
253 (cond
254 ((endp ideal-list) f)
255 (t (let ((h (ideal-saturation ring-and-order f (car ideal-list) start top-reduction-only)))
256 (ideal-polysaturation ring-and-order h (rest ideal-list) (length h) top-reduction-only)))))
Note: See TracBrowser for help on using the repository browser.