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