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