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/gebauer-moeller.lisp@ 568

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

* empty log message *

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