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