close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

source: branches/f4grobner/buchberger.lisp@ 4495

Last change on this file since 4495 was 4475, checked in by Marek Rychlik, 9 years ago

* empty log message *

File size: 4.1 KB
Line 
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(defpackage "BUCHBERGER"
23 (:use :cl :grobner-debug
24 :polynomial :division
25 :criterion :pair-queue :priority-queue
26 :ring
27 )
28 (:export "BUCHBERGER"
29 "GROBNER-MEMBER"
30 "GROBNER-SUBSETP"
31 "GROBNER-EQUAL"
32 )
33 (:documentation "Buchberger Algorithm Implementation."))
34
35(in-package :buchberger)
36
37
38(defun buchberger (f
39 &optional
40 (start 0)
41 (top-reduction-only $poly_top_reduction_only))
42 "An implementation of the Buchberger algorithm. Return Grobner basis
43of the ideal generated by the polynomial list F. Polynomials 0 to
44START-1 are assumed to be a Grobner basis already, so that certain
45critical pairs will not be examined. If TOP-REDUCTION-ONLY set, top
46reduction will be preformed. This function assumes that all polynomials
47in F are non-zero."
48 (declare (type fixnum start))
49 (when (endp f) (return-from buchberger f)) ;cut startup costs
50 (debug-cgb "~&GROBNER BASIS - BUCHBERGER ALGORITHM")
51 (when (plusp start) (debug-cgb "~&INCREMENTAL:~d done" start))
52 #+grobner-check (when (plusp start)
53 (grobner-test (subseq f 0 start) (subseq f 0 start)))
54 ;;Initialize critical pairs
55 (let ((b (make-critical-pair-queue *normal-strategy* f start))
56 (b-done (make-hash-table :test #'equal)))
57 (declare (type critical-pair-queue b) (type hash-table b-done))
58 (dotimes (i (1- start))
59 (do ((j (1+ i) (1+ j))) ((>= j start))
60 (setf (gethash (list (elt f i) (elt f j)) b-done) t)))
61 (do ()
62 ((queue-empty-p b)
63 #+grobner-check(grobner-test f f)
64 (debug-cgb "~&GROBNER END")
65 f)
66 (let ((pair (dequeue b)))
67 (declare (type critical-pair pair))
68 (cond
69 ((criterion-1 pair) nil)
70 ((criterion-2 pair b-done f) nil)
71 (t
72 (let ((sp (normal-form (s-polynomial
73 (critical-pair-first pair)
74 (critical-pair-second pair))
75 f top-reduction-only)))
76 (declare (type poly sp))
77 (cond
78 ((universal-zerop sp)
79 nil)
80 (t
81 (setf sp (poly-primitive-part sp)
82 f (nconc f (list sp)))
83 ;; Add new critical pairs
84 (dolist (h f)
85 (enqueue b (make-instance 'critical-pair :first h :second sp)))
86 (debug-cgb "~&Polynomials: ~d; Pairs left: ~d; Pairs done: ~d;"
87 (length f) (queue-size b)
88 (hash-table-count b-done)))))))
89 (setf (gethash (list (critical-pair-first pair) (critical-pair-second pair)) b-done)
90 t)))))
91
92
93(defun grobner-member (p g)
94 "Returns T if a polynomial P belongs to the ideal generated by the
95polynomial list G, which is assumed to be a Grobner basis. Returns NIL otherwise."
96 (universal-zerop (normal-form p g nil)))
97
98
99(defun grobner-subsetp (g1 g2)
100 "Returns T if a list of polynomials G1 generates
101an ideal contained in the ideal generated by a polynomial list G2,
102both G1 and G2 assumed to be Grobner bases. Returns NIL otherwise."
103 (every #'(lambda (p) (grobner-member p g2)) g1))
104
105
106(defun grobner-equal (g1 g2)
107 "Returns T if two lists of polynomials G1 and G2, assumed to be Grobner bases,
108generate the same ideal, and NIL otherwise."
109 (and (grobner-subsetp g1 g2) (grobner-subsetp g2 g1)))
Note: See TracBrowser for help on using the repository browser.