| 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 |
|
---|
| 22 | (in-package :ngrobner)
|
---|
| 23 |
|
---|
| 24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 25 | ;;
|
---|
| 26 | ;; An implementation of the algorithm of Gebauer and Moeller, as
|
---|
| 27 | ;; described in the book of Becker-Weispfenning, p. 232
|
---|
| 28 | ;;
|
---|
| 29 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 30 |
|
---|
| 31 | (defun gebauer-moeller (ring f start &optional (top-reduction-only $poly_top_reduction_only))
|
---|
| 32 | "Compute Grobner basis by using the algorithm of Gebauer and
|
---|
| 33 | Moeller. This algorithm is described as BUCHBERGERNEW2 in the book by
|
---|
| 34 | Becker-Weispfenning entitled ``Grobner Bases''. This function assumes
|
---|
| 35 | that all polynomials in F are non-zero."
|
---|
| 36 | (declare (ignore top-reduction-only)
|
---|
| 37 | (type fixnum start))
|
---|
| 38 | (cond
|
---|
| 39 | ((endp f) (return-from gebauer-moeller nil))
|
---|
| 40 | ((endp (cdr f))
|
---|
| 41 | (return-from gebauer-moeller (list (poly-primitive-part ring (car f))))))
|
---|
| 42 | (debug-cgb "~&GROBNER BASIS - GEBAUER MOELLER ALGORITHM")
|
---|
| 43 | (when (plusp start) (debug-cgb "~&INCREMENTAL:~d done" start))
|
---|
| 44 | #+grobner-check (when (plusp start)
|
---|
| 45 | (grobner-test ring (subseq f 0 start) (subseq f 0 start)))
|
---|
| 46 | (let ((b (make-pair-queue))
|
---|
| 47 | (g (subseq f 0 start))
|
---|
| 48 | (f1 (subseq f start)))
|
---|
| 49 | (do () ((endp f1))
|
---|
| 50 | (multiple-value-setq (g b)
|
---|
| 51 | (gebauer-moeller-update g b (poly-primitive-part ring (pop f1)))))
|
---|
| 52 | (do () ((pair-queue-empty-p b))
|
---|
| 53 | (let* ((pair (pair-queue-remove b))
|
---|
| 54 | (g1 (pair-first pair))
|
---|
| 55 | (g2 (pair-second pair))
|
---|
| 56 | (h (normal-form ring (spoly ring g1 g2)
|
---|
| 57 | g
|
---|
| 58 | nil #| Always fully reduce! |#
|
---|
| 59 | )))
|
---|
| 60 | (unless (poly-zerop h)
|
---|
| 61 | (setf h (poly-primitive-part ring h))
|
---|
| 62 | (multiple-value-setq (g b)
|
---|
| 63 | (gebauer-moeller-update g b h))
|
---|
| 64 | (debug-cgb "~&Sugar: ~d Polynomials: ~d; Pairs left: ~d~%"
|
---|
| 65 | (pair-sugar pair) (length g) (pair-queue-size b))
|
---|
| 66 | )))
|
---|
| 67 | #+grobner-check(grobner-test ring g f)
|
---|
| 68 | (debug-cgb "~&GROBNER END")
|
---|
| 69 | g))
|
---|
| 70 |
|
---|
| 71 | (defun gebauer-moeller-update (g b h
|
---|
| 72 | &aux
|
---|
| 73 | c d e
|
---|
| 74 | (b-new (make-pair-queue))
|
---|
| 75 | g-new)
|
---|
| 76 | "An implementation of the auxillary UPDATE algorithm used by the
|
---|
| 77 | Gebauer-Moeller algorithm. G is a list of polynomials, B is a list of
|
---|
| 78 | critical pairs and H is a new polynomial which possibly will be added
|
---|
| 79 | to G. The naming conventions used are very close to the one used in
|
---|
| 80 | the book of Becker-Weispfenning."
|
---|
| 81 | (declare
|
---|
| 82 | #+allegro (dynamic-extent b)
|
---|
| 83 | (type poly h)
|
---|
| 84 | (type priority-queue b))
|
---|
| 85 | (setf c g d nil)
|
---|
| 86 | (do () ((endp c))
|
---|
| 87 | (let ((g1 (pop c)))
|
---|
| 88 | (declare (type poly g1))
|
---|
| 89 | (when (or (monom-rel-prime-p (poly-lm h) (poly-lm g1))
|
---|
| 90 | (and
|
---|
| 91 | (notany #'(lambda (g2) (monom-lcm-divides-monom-lcm-p
|
---|
| 92 | (poly-lm h) (poly-lm g2)
|
---|
| 93 | (poly-lm h) (poly-lm g1)))
|
---|
| 94 | c)
|
---|
| 95 | (notany #'(lambda (g2) (monom-lcm-divides-monom-lcm-p
|
---|
| 96 | (poly-lm h) (poly-lm g2)
|
---|
| 97 | (poly-lm h) (poly-lm g1)))
|
---|
| 98 | d)))
|
---|
| 99 | (push g1 d))))
|
---|
| 100 | (setf e nil)
|
---|
| 101 | (do () ((endp d))
|
---|
| 102 | (let ((g1 (pop d)))
|
---|
| 103 | (declare (type poly g1))
|
---|
| 104 | (unless (monom-rel-prime-p (poly-lm h) (poly-lm g1))
|
---|
| 105 | (push g1 e))))
|
---|
| 106 | (do () ((pair-queue-empty-p b))
|
---|
| 107 | (let* ((pair (pair-queue-remove b))
|
---|
| 108 | (g1 (pair-first pair))
|
---|
| 109 | (g2 (pair-second pair)))
|
---|
| 110 | (declare (type pair pair)
|
---|
| 111 | (type poly g1 g2))
|
---|
| 112 | (when (or (not (monom-divides-monom-lcm-p
|
---|
| 113 | (poly-lm h)
|
---|
| 114 | (poly-lm g1) (poly-lm g2)))
|
---|
| 115 | (monom-lcm-equal-monom-lcm-p
|
---|
| 116 | (poly-lm g1) (poly-lm h)
|
---|
| 117 | (poly-lm g1) (poly-lm g2))
|
---|
| 118 | (monom-lcm-equal-monom-lcm-p
|
---|
| 119 | (poly-lm h) (poly-lm g2)
|
---|
| 120 | (poly-lm g1) (poly-lm g2)))
|
---|
| 121 | (pair-queue-insert b-new (make-pair g1 g2)))))
|
---|
| 122 | (dolist (g3 e)
|
---|
| 123 | (pair-queue-insert b-new (make-pair h g3)))
|
---|
| 124 | (setf g-new nil)
|
---|
| 125 | (do () ((endp g))
|
---|
| 126 | (let ((g1 (pop g)))
|
---|
| 127 | (declare (type poly g1))
|
---|
| 128 | (unless (monom-divides-p (poly-lm h) (poly-lm g1))
|
---|
| 129 | (push g1 g-new))))
|
---|
| 130 | (push h g-new)
|
---|
| 131 | (values g-new b-new))
|
---|