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

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