[1201] | 1 | ;;; -*- Mode: Lisp -*-
|
---|
[75] | 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 |
|
---|
[485] | 22 | (defpackage "BUCHBERGER"
|
---|
[580] | 23 | (:use :cl :grobner-debug
|
---|
[4132] | 24 | :polynomial :division
|
---|
[580] | 25 | :criterion :pair-queue :priority-queue
|
---|
[4390] | 26 | :ring
|
---|
[580] | 27 | )
|
---|
[4131] | 28 | (:export "BUCHBERGER" "PARALLEL-BUCHBERGER")
|
---|
| 29 | (:documentation "Buchberger Algorithm Implementation."))
|
---|
[75] | 30 |
|
---|
[486] | 31 | (in-package :buchberger)
|
---|
| 32 |
|
---|
[61] | 33 |
|
---|
[4131] | 34 | (defun buchberger (f
|
---|
[1289] | 35 | &optional
|
---|
[1309] | 36 | (start 0)
|
---|
[4132] | 37 | (top-reduction-only $poly_top_reduction_only))
|
---|
[61] | 38 | "An implementation of the Buchberger algorithm. Return Grobner basis
|
---|
| 39 | of the ideal generated by the polynomial list F. Polynomials 0 to
|
---|
| 40 | START-1 are assumed to be a Grobner basis already, so that certain
|
---|
| 41 | critical pairs will not be examined. If TOP-REDUCTION-ONLY set, top
|
---|
| 42 | reduction will be preformed. This function assumes that all polynomials
|
---|
| 43 | in F are non-zero."
|
---|
[4131] | 44 | (declare (type fixnum start))
|
---|
[61] | 45 | (when (endp f) (return-from buchberger f)) ;cut startup costs
|
---|
| 46 | (debug-cgb "~&GROBNER BASIS - BUCHBERGER ALGORITHM")
|
---|
| 47 | (when (plusp start) (debug-cgb "~&INCREMENTAL:~d done" start))
|
---|
[4131] | 48 | #+grobner-check (when (plusp start)
|
---|
| 49 | (grobner-test (subseq f 0 start) (subseq f 0 start)))
|
---|
[61] | 50 | ;;Initialize critical pairs
|
---|
[4194] | 51 | (let ((b (make-critical-pair-queue *normal-strategy* f start))
|
---|
[61] | 52 | (b-done (make-hash-table :test #'equal)))
|
---|
[4192] | 53 | (declare (type critical-pair-queue b) (type hash-table b-done))
|
---|
[61] | 54 | (dotimes (i (1- start))
|
---|
| 55 | (do ((j (1+ i) (1+ j))) ((>= j start))
|
---|
| 56 | (setf (gethash (list (elt f i) (elt f j)) b-done) t)))
|
---|
| 57 | (do ()
|
---|
[4192] | 58 | ((queue-empty-p b)
|
---|
| 59 | #+grobner-check(grobner-test f f)
|
---|
[61] | 60 | (debug-cgb "~&GROBNER END")
|
---|
| 61 | f)
|
---|
[4192] | 62 | (let ((pair (dequeue b)))
|
---|
| 63 | (declare (type critical-pair pair))
|
---|
[61] | 64 | (cond
|
---|
| 65 | ((criterion-1 pair) nil)
|
---|
| 66 | ((criterion-2 pair b-done f) nil)
|
---|
| 67 | (t
|
---|
[4192] | 68 | (let ((sp (normal-form (s-polynomial
|
---|
| 69 | (critical-pair-first pair)
|
---|
| 70 | (critical-pair-second pair))
|
---|
[61] | 71 | f top-reduction-only)))
|
---|
| 72 | (declare (type poly sp))
|
---|
| 73 | (cond
|
---|
[4192] | 74 | ((universal-zerop sp)
|
---|
[61] | 75 | nil)
|
---|
| 76 | (t
|
---|
[4170] | 77 | (setf sp (poly-primitive-part sp)
|
---|
[61] | 78 | f (nconc f (list sp)))
|
---|
| 79 | ;; Add new critical pairs
|
---|
| 80 | (dolist (h f)
|
---|
[4194] | 81 | (enqueue b (make-instance 'critical-pair :first h :second sp)))
|
---|
[4192] | 82 | (debug-cgb "~&Polynomials: ~d; Pairs left: ~d; Pairs done: ~d;"
|
---|
| 83 | (length f) (queue-size b)
|
---|
[61] | 84 | (hash-table-count b-done)))))))
|
---|
[4192] | 85 | (setf (gethash (list (critical-pair-first pair) (critical-pair-second pair)) b-done)
|
---|
[61] | 86 | t)))))
|
---|