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

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

* empty log message *

File size: 8.6 KB
RevLine 
[73]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
[67]22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23;;
24;; Operations in ideal theory
25;;
26;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27
28;; Does the term depend on variable K?
29(defun term-depends-p (term k)
30 "Return T if the term TERM depends on variable number K."
31 (monom-depends-p (term-monom term) k))
32
33;; Does the polynomial P depend on variable K?
34(defun poly-depends-p (p k)
35 "Return T if the term polynomial P depends on variable number K."
36 (some #'(lambda (term) (term-depends-p term k)) (poly-termlist p)))
37
38(defun ring-intersection (plist k)
39 "This function assumes that polynomial list PLIST is a Grobner basis
40and it calculates the intersection with the ring R[x[k+1],...,x[n]], i.e.
41it discards polynomials which depend on variables x[0], x[1], ..., x[k]."
42 (dotimes (i k plist)
43 (setf plist
44 (remove-if #'(lambda (p)
45 (poly-depends-p p i))
46 plist))))
47
48(defun elimination-ideal (ring flist k
49 &optional (top-reduction-only $poly_top_reduction_only) (start 0)
50 &aux (*monomial-order*
51 (or *elimination-order*
52 (elimination-order k))))
53 (ring-intersection (reduced-grobner ring flist start top-reduction-only) k))
54
55(defun colon-ideal (ring f g &optional (top-reduction-only $poly_top_reduction_only))
56 "Returns the reduced Grobner basis of the colon ideal Id(F):Id(G),
57where F and G are two lists of polynomials. The colon ideal I:J is
58defined as the set of polynomials H such that for all polynomials W in
59J the polynomial W*H belongs to I."
60 (cond
61 ((endp g)
62 ;;Id(G) consists of 0 only so W*0=0 belongs to Id(F)
63 (if (every #'poly-zerop f)
64 (error "First ideal must be non-zero.")
65 (list (make-poly
66 (list (make-term
67 (make-monom (monom-dimension (poly-lm (find-if-not #'poly-zerop f)))
68 :initial-element 0)
69 (funcall (ring-unit ring))))))))
70 ((endp (cdr g))
71 (colon-ideal-1 ring f (car g) top-reduction-only))
72 (t
73 (ideal-intersection ring
74 (colon-ideal-1 ring f (car g) top-reduction-only)
75 (colon-ideal ring f (rest g) top-reduction-only)
76 top-reduction-only))))
77
78(defun colon-ideal-1 (ring f g &optional (top-reduction-only $poly_top_reduction_only))
79 "Returns the reduced Grobner basis of the colon ideal Id(F):Id({G}), where
80F is a list of polynomials and G is a polynomial."
81 (mapcar #'(lambda (x) (poly-exact-divide ring x g)) (ideal-intersection ring f (list g) top-reduction-only)))
82
83
84(defun ideal-intersection (ring f g &optional (top-reduction-only $poly_top_reduction_only)
85 &aux (*monomial-order* (or *elimination-order*
86 #'elimination-order-1)))
87 (mapcar #'poly-contract
88 (ring-intersection
89 (reduced-grobner
90 ring
91 (append (mapcar #'(lambda (p) (poly-extend p (make-monom 1 :initial-element 1))) f)
92 (mapcar #'(lambda (p)
93 (poly-append (poly-extend (poly-uminus ring p)
94 (make-monom 1 :initial-element 1))
95 (poly-extend p)))
96 g))
97 0
98 top-reduction-only)
99 1)))
100
101(defun poly-lcm (ring f g)
102 "Return LCM (least common multiple) of two polynomials F and G.
103The polynomials must be ordered according to monomial order PRED
104and their coefficients must be compatible with the RING structure
105defined in the COEFFICIENT-RING package."
106 (cond
107 ((poly-zerop f) f)
108 ((poly-zerop g) g)
109 ((and (endp (cdr (poly-termlist f))) (endp (cdr (poly-termlist g))))
110 (let ((m (monom-lcm (poly-lm f) (poly-lm g))))
111 (make-poly-from-termlist (list (make-term m (funcall (ring-lcm ring) (poly-lc f) (poly-lc g)))))))
112 (t
113 (multiple-value-bind (f f-cont)
114 (poly-primitive-part ring f)
115 (multiple-value-bind (g g-cont)
116 (poly-primitive-part ring g)
117 (scalar-times-poly
118 ring
119 (funcall (ring-lcm ring) f-cont g-cont)
120 (poly-primitive-part ring (car (ideal-intersection ring (list f) (list g) nil)))))))))
121
122;; Do two Grobner bases yield the same ideal?
123(defun grobner-equal (ring g1 g2)
124 "Returns T if two lists of polynomials G1 and G2, assumed to be Grobner bases,
125generate the same ideal, and NIL otherwise."
126 (and (grobner-subsetp ring g1 g2) (grobner-subsetp ring g2 g1)))
127
128(defun grobner-subsetp (ring g1 g2)
129 "Returns T if a list of polynomials G1 generates
130an ideal contained in the ideal generated by a polynomial list G2,
131both G1 and G2 assumed to be Grobner bases. Returns NIL otherwise."
132 (every #'(lambda (p) (grobner-member ring p g2)) g1))
133
134(defun grobner-member (ring p g)
135 "Returns T if a polynomial P belongs to the ideal generated by the
136polynomial list G, which is assumed to be a Grobner basis. Returns NIL otherwise."
137 (poly-zerop (normal-form ring p g nil)))
138
139;; Calculate F : p^inf
140(defun ideal-saturation-1 (ring f p start &optional (top-reduction-only $poly_top_reduction_only)
141 &aux (*monomial-order* (or *elimination-order*
142 #'elimination-order-1)))
143 "Returns the reduced Grobner basis of the saturation of the ideal
144generated by a polynomial list F in the ideal generated by a single
145polynomial P. The saturation ideal is defined as the set of
146polynomials H such for some natural number n (* (EXPT P N) H) is in the ideal
147F. Geometrically, over an algebraically closed field, this is the set
148of polynomials in the ideal generated by F which do not identically
149vanish on the variety of P."
150 (mapcar
151 #'poly-contract
152 (ring-intersection
153 (reduced-grobner
154 ring
155 (saturation-extension-1 ring f p)
156 start top-reduction-only)
157 1)))
158
159
160
161;; Calculate F : p1^inf : p2^inf : ... : ps^inf
162(defun ideal-polysaturation-1 (ring f plist start &optional (top-reduction-only $poly_top_reduction_only))
163 "Returns the reduced Grobner basis of the ideal obtained by a
164sequence of successive saturations in the polynomials
165of the polynomial list PLIST of the ideal generated by the
166polynomial list F."
167 (cond
168 ((endp plist) (reduced-grobner ring f start top-reduction-only))
169 (t (let ((g (ideal-saturation-1 ring f (car plist) start top-reduction-only)))
170 (ideal-polysaturation-1 ring g (rest plist) (length g) top-reduction-only)))))
171
172(defun ideal-saturation (ring f g start &optional (top-reduction-only $poly_top_reduction_only)
173 &aux
174 (k (length g))
175 (*monomial-order* (or *elimination-order*
176 (elimination-order k))))
177 "Returns the reduced Grobner basis of the saturation of the ideal
178generated by a polynomial list F in the ideal generated a polynomial
179list G. The saturation ideal is defined as the set of polynomials H
180such for some natural number n and some P in the ideal generated by G
181the polynomial P**N * H is in the ideal spanned by F. Geometrically,
182over an algebraically closed field, this is the set of polynomials in
183the ideal generated by F which do not identically vanish on the
184variety of G."
185 (mapcar
186 #'(lambda (q) (poly-contract q k))
187 (ring-intersection
188 (reduced-grobner ring
189 (polysaturation-extension ring f g)
190 start
191 top-reduction-only)
192 k)))
193
194(defun ideal-polysaturation (ring f ideal-list start &optional (top-reduction-only $poly_top_reduction_only))
195 "Returns the reduced Grobner basis of the ideal obtained by a
196successive applications of IDEAL-SATURATION to F and lists of
197polynomials in the list IDEAL-LIST."
198 (cond
199 ((endp ideal-list) f)
200 (t (let ((h (ideal-saturation ring f (car ideal-list) start top-reduction-only)))
201 (ideal-polysaturation ring h (rest ideal-list) (length h) top-reduction-only)))))
Note: See TracBrowser for help on using the repository browser.