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