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/pair-queue.lisp@ 92

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

* empty log message *

File size: 3.7 KB
RevLine 
[76]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
[60]23;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24;;
25;; Pair queue implementation
26;;
27;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28
29(defun sugar-pair-key (p q &aux (lcm (monom-lcm (poly-lm p) (poly-lm q)))
30 (d (monom-sugar lcm)))
31 "Returns list (S LCM-TOTAL-DEGREE) where S is the sugar of the S-polynomial of
32polynomials P and Q, and LCM-TOTAL-DEGREE is the degree of is LCM(LM(P),LM(Q))."
33 (declare (type poly p q) (type monom lcm) (type fixnum d))
34 (cons (max
35 (+ (- d (monom-sugar (poly-lm p))) (poly-sugar p))
36 (+ (- d (monom-sugar (poly-lm q))) (poly-sugar q)))
37 lcm))
38
39(defstruct (pair
40 (:constructor make-pair (first second
41 &aux
42 (sugar (car (sugar-pair-key first second)))
43 (division-data nil))))
44 (first nil :type poly)
45 (second nil :type poly)
46 (sugar 0 :type fixnum)
47 (division-data nil :type list))
48
49;;(defun pair-sugar (pair &aux (p (pair-first pair)) (q (pair-second pair)))
50;; (car (sugar-pair-key p q)))
51
52(defun sugar-order (x y)
53 "Pair order based on sugar, ties broken by normal strategy."
54 (declare (type cons x y))
55 (or (< (car x) (car y))
56 (and (= (car x) (car y))
57 (< (monom-total-degree (cdr x))
58 (monom-total-degree (cdr y))))))
59
60(defvar *pair-key-function* #'sugar-pair-key
61 "Function that, given two polynomials as argument, computed the key
62in the pair queue.")
63
64(defvar *pair-order* #'sugar-order
65 "Function that orders the keys of pairs.")
66
67(defun make-pair-queue ()
68 "Constructs a priority queue for critical pairs."
69 (make-priority-queue
70 :element-type 'pair
71 :element-key #'(lambda (pair) (funcall *pair-key-function* (pair-first pair) (pair-second pair)))
72 :test *pair-order*))
73
74(defun pair-queue-initialize (pq f start
75 &aux
76 (s (1- (length f)))
77 (b (nconc (makelist (make-pair (elt f i) (elt f j))
78 (i 0 (1- start)) (j start s))
79 (makelist (make-pair (elt f i) (elt f j))
80 (i start (1- s)) (j (1+ i) s)))))
81 "Initializes the priority for critical pairs. F is the initial list of polynomials.
82START is the first position beyond the elements which form a partial
83grobner basis, i.e. satisfy the Buchberger criterion."
84 (declare (type priority-queue pq) (type fixnum start))
85 (dolist (pair b pq)
86 (priority-queue-insert pq pair)))
87
88(defun pair-queue-insert (b pair)
89 (priority-queue-insert b pair))
90
91(defun pair-queue-remove (b)
92 (priority-queue-remove b))
93
94(defun pair-queue-size (b)
95 (priority-queue-size b))
96
97(defun pair-queue-empty-p (b)
98 (priority-queue-empty-p b))
Note: See TracBrowser for help on using the repository browser.