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@ 92

Last change on this file since 92 was 75, checked in by Marek Rychlik, 10 years ago

* empty log message *

File size: 6.2 KB
RevLine 
[75]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
[61]23;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24;;
25;; Buchberger Algorithm Implementation
26;;
27;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28
29(defun buchberger (ring f start &optional (top-reduction-only $poly_top_reduction_only))
30 "An implementation of the Buchberger algorithm. Return Grobner basis
31of the ideal generated by the polynomial list F. Polynomials 0 to
32START-1 are assumed to be a Grobner basis already, so that certain
33critical pairs will not be examined. If TOP-REDUCTION-ONLY set, top
34reduction will be preformed. This function assumes that all polynomials
35in F are non-zero."
36 (declare (type fixnum start))
37 (when (endp f) (return-from buchberger f)) ;cut startup costs
38 (debug-cgb "~&GROBNER BASIS - BUCHBERGER ALGORITHM")
39 (when (plusp start) (debug-cgb "~&INCREMENTAL:~d done" start))
40 #+grobner-check (when (plusp start)
41 (grobner-test ring (subseq f 0 start) (subseq f 0 start)))
42 ;;Initialize critical pairs
43 (let ((b (pair-queue-initialize (make-pair-queue)
44 f start))
45 (b-done (make-hash-table :test #'equal)))
46 (declare (type priority-queue b) (type hash-table b-done))
47 (dotimes (i (1- start))
48 (do ((j (1+ i) (1+ j))) ((>= j start))
49 (setf (gethash (list (elt f i) (elt f j)) b-done) t)))
50 (do ()
51 ((pair-queue-empty-p b)
52 #+grobner-check(grobner-test ring f f)
53 (debug-cgb "~&GROBNER END")
54 f)
55 (let ((pair (pair-queue-remove b)))
56 (declare (type pair pair))
57 (cond
58 ((criterion-1 pair) nil)
59 ((criterion-2 pair b-done f) nil)
60 (t
61 (let ((sp (normal-form ring (spoly ring (pair-first pair)
62 (pair-second pair))
63 f top-reduction-only)))
64 (declare (type poly sp))
65 (cond
66 ((poly-zerop sp)
67 nil)
68 (t
69 (setf sp (poly-primitive-part ring sp)
70 f (nconc f (list sp)))
71 ;; Add new critical pairs
72 (dolist (h f)
73 (pair-queue-insert b (make-pair h sp)))
74 (debug-cgb "~&Sugar: ~d Polynomials: ~d; Pairs left: ~d; Pairs done: ~d;"
75 (pair-sugar pair) (length f) (pair-queue-size b)
76 (hash-table-count b-done)))))))
77 (setf (gethash (list (pair-first pair) (pair-second pair)) b-done)
78 t)))))
79
80(defun parallel-buchberger (ring f start &optional (top-reduction-only $poly_top_reduction_only))
81 "An implementation of the Buchberger algorithm. Return Grobner basis
82of the ideal generated by the polynomial list F. Polynomials 0 to
83START-1 are assumed to be a Grobner basis already, so that certain
84critical pairs will not be examined. If TOP-REDUCTION-ONLY set, top
85reduction will be preformed."
86 (declare (ignore top-reduction-only)
87 (type fixnum start))
88 (when (endp f) (return-from parallel-buchberger f)) ;cut startup costs
89 (debug-cgb "~&GROBNER BASIS - PARALLEL-BUCHBERGER ALGORITHM")
90 (when (plusp start) (debug-cgb "~&INCREMENTAL:~d done" start))
91 #+grobner-check (when (plusp start)
92 (grobner-test ring (subseq f 0 start) (subseq f 0 start)))
93 ;;Initialize critical pairs
94 (let ((b (pair-queue-initialize (make-pair-queue) f start))
95 (b-done (make-hash-table :test #'equal)))
96 (declare (type priority-queue b)
97 (type hash-table b-done))
98 (dotimes (i (1- start))
99 (do ((j (1+ i) (1+ j))) ((>= j start))
100 (declare (type fixnum j))
101 (setf (gethash (list (elt f i) (elt f j)) b-done) t)))
102 (do ()
103 ((pair-queue-empty-p b)
104 #+grobner-check(grobner-test ring f f)
105 (debug-cgb "~&GROBNER END")
106 f)
107 (let ((pair (pair-queue-remove b)))
108 (when (null (pair-division-data pair))
109 (setf (pair-division-data pair) (list (spoly ring
110 (pair-first pair)
111 (pair-second pair))
112 (make-poly-zero)
113 (funcall (ring-unit ring))
114 0)))
115 (cond
116 ((criterion-1 pair) nil)
117 ((criterion-2 pair b-done f) nil)
118 (t
119 (let* ((dd (pair-division-data pair))
120 (p (first dd))
121 (sp (second dd))
122 (c (third dd))
123 (division-count (fourth dd)))
124 (cond
125 ((poly-zerop p) ;normal form completed
126 (debug-cgb "~&~3T~d reduction~:p" division-count)
127 (cond
128 ((poly-zerop sp)
129 (debug-cgb " ---> 0")
130 nil)
131 (t
132 (setf sp (poly-nreverse sp)
133 sp (poly-primitive-part ring sp)
134 f (nconc f (list sp)))
135 ;; Add new critical pairs
136 (dolist (h f)
137 (pair-queue-insert b (make-pair h sp)))
138 (debug-cgb "~&Sugar: ~d Polynomials: ~d; Pairs left: ~d; Pairs done: ~d;"
139 (pair-sugar pair) (length f) (pair-queue-size b)
140 (hash-table-count b-done))))
141 (setf (gethash (list (pair-first pair) (pair-second pair))
142 b-done) t))
143 (t ;normal form not complete
144 (do ()
145 ((cond
146 ((> (poly-sugar sp) (pair-sugar pair))
147 (debug-cgb "(~a)?" (poly-sugar sp))
148 t)
149 ((poly-zerop p)
150 (debug-cgb ".")
151 t)
152 (t nil))
153 (setf (first dd) p
154 (second dd) sp
155 (third dd) c
156 (fourth dd) division-count
157 (pair-sugar pair) (poly-sugar sp))
158 (pair-queue-insert b pair))
159 (multiple-value-setq (p sp c division-count)
160 (normal-form-step ring f p sp c division-count))))))))))))
Note: See TracBrowser for help on using the repository browser.