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

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

* empty log message *

File size: 6.3 KB
RevLine 
[1201]1;;; -*- Mode: Lisp -*-
[76]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
[449]22(defpackage "PAIR-QUEUE"
[3949]23 (:use :cl :priority-queue :monom :polynomial :symbolic-polynomial :utils)
[3920]24 (:export "CRITICAL-PAIR"
25 "CRITICAL-PAIR-FIRST"
26 "CRITICAL-PAIR-SECOND"
[3948]27 "CRITICAL-PAIR-QUEUE"
[3964]28 "SELECTION-STRATEGY"
[4189]29 "*NORMAL-STRATEGY*"
30 "*MIN-TOTAL-DEGREE-STRATEGY*"
31 "*MIN-COMBINED-LENGTH-STRATEGY*"
[4145]32 "MAKE-CRITICAL-PAIR-QUEUE"
[4143]33 "MAKE-CRITICAL-PAIRS"
[3918]34 )
35 (:documentation "Critical pair queue implementation. The pair queue is a list of critical
36pairs, ordered by some partial order. Pair queue is a kind of priority queue.")
37 )
[449]38
[450]39(in-package :pair-queue)
40
[3919]41(defclass critical-pair ()
[3921]42 ((first :initform nil :initarg :first :accessor critical-pair-first :type poly)
[4190]43 (second :initform nil :initarg :second :accessor critical-pair-second :type poly)
44 (data :initform nil :accessor critical-pair-division-data))
45 (:documentation "Represents a critical pair, i.e. a pair of two
46polynomials. The derived classes may add extra data used in computing
47the order of critical pairs."))
[3919]48
[3921]49(defmethod print-object ((self critical-pair) stream)
[3920]50 (print-unreadable-object (self stream :type t :identity t)
51 (with-accessors ((first critical-pair-first)
52 (second critical-pair-second))
53 self
54 (format stream "FIRST=~A SECOND=~A"
55 first second))))
56
[3927]57(defclass selection-strategy ()
[4138]58 ((pair-key-fn :initform (error "Initarg :pair-key-fn must be specified.")
[3959]59 :initarg :pair-key-fn
60 :accessor pair-key-fn)
[4138]61 (pair-order-fn :initform (error "Initarg :pair-order-fn must be specified.")
[3959]62 :initarg :pair-order-fn
63 :accessor pair-order-fn))
[4135]64 (:documentation "The two ingredients of a strategy is a function
[3940]65PAIR-KEY-FUNCTION which computes a key from the critical pair, which
66can be any type of data, and a function PAIR-ORDER-FN used to compaire
67the calculated keys to determine which pair is more promising and
[3941]68should be considered first. The normal selection strategy for a given
69monomial order PAIR-ORDER-FN consists in selecting the pair with the
70minimal LCM of leading monomials first."))
[60]71
[3932]72(defmethod print-object ((self selection-strategy) stream)
73 (print-unreadable-object (self stream :type t :identity t)
74 (with-accessors ((pair-key-fn pair-key-fn)
75 (pair-order-fn pair-order-fn))
76 self
77 (format stream "PAIR-KEY-FN=~A PAIR-ORDER-FN=~A"
78 pair-key-fn pair-order-fn))))
79
[4187]80(defparameter *normal-strategy*
[4135]81 (make-instance
82 'selection-strategy
83 :pair-key-fn #'(lambda (p q) (universal-lcm (leading-monomial p) (leading-monomial q)))
84 :pair-order-fn #'lex>)
85 "The normal selection strategy where a pair with the largest LCM of
86leading monomials is selected.")
[3932]87
[4187]88(defparameter *min-total-degree-strategy*
[4186]89 (make-instance
[4135]90 'selection-strategy
91 :pair-key-fn #'(lambda (p q) (total-degree (universal-lcm (leading-monomial p) (leading-monomial q))))
92 :pair-order-fn #'<)
93 "A selection strategy where a pair with a minimum total degree of
94 LCM of leading monomials is selected.")
[3933]95
[4187]96(defparameter *min-combined-length-strategy*
[4186]97 (make-instance
[4135]98 'selection-strategy
99 :pair-key-fn #'(lambda (p q) (+ (poly-length p) (poly-length q)))
100 :pair-order-fn #'<)
101 "A selection strategy where a pair with the minimum combined length of both
102polynomials is selected.")
[3938]103
[4148]104(defclass critical-pair-queue (priority-queue)
105 ()
[4160]106 (:documentation "Specializes class PRIORITY-QUEUE to ELEMENT-TYPE set to CRITICAL-PAIR."))
[4148]107
[4159]108(defmethod initialize-instance :before ((self critical-pair-queue) &key)
[4152]109 "Initializes the slot ELEMENT-TYPE to symbol CRITICAL-PAIR-QUEUE.
110This overrides the default ELEMENT-TYPE in the superclass."
[4151]111 (with-slots ((element-type-x priority-queue::element-type))
112 self
113 (setf element-type-x 'critical-pair))
114 self)
[4148]115
[4146]116(defun make-critical-pairs (poly-list
117 &optional (start 0)
[4142]118 &aux
119 (s (1- (length poly-list))))
[4183]120 "Create a list of critical pairs. The argument POLY-LIST is the
121initial list of polynomials and START is the first position beyond the
122elements which form a partial Grobner basis, i.e. satisfy the
123Buchberger criterion."
[4142]124 (nconc (makelist (make-instance 'critical-pair :first (elt poly-list i) :second (elt poly-list j))
125 (i 0 (1- start)) (j start s))
[4146]126 (makelist (make-instance 'critical-pair :first (elt poly-list i) :second (elt poly-list j))
127 (i start (1- s)) (j (1+ i) s))))
[4142]128
[4170]129(defgeneric enqueue-critical-pairs (self pair-lst)
130 (:documentation "Place pairs in PAIR-LST on the queue SELF.")
[4143]131 (:method ((self critical-pair-queue) pair-lst)
[4170]132 "Enqueue into queue QUEUE the elements of the list PAIR-LST."
[4143]133 (dolist (pair pair-lst self)
134 (enqueue self pair))))
[4135]135
[4162]136(defgeneric make-critical-pair-queue (object &optional poly-lst start)
137 (:documentation "Creates a CRITICAL-PAIR-QUEUE from an object OBJECT.")
138 (:method ((object selection-strategy) &optional (poly-lst nil) (start 0))
[4182]139 "Creates a CRITICAL-PAIR-QUEUE from a selection strategy OBJECT."
[4162]140 (with-slots (pair-key-fn pair-order-fn)
141 object
[4170]142 (let ((queue (make-instance 'critical-pair-queue
143 :element-key #'(lambda (pair)
144 (funcall pair-key-fn
145 (critical-pair-first pair)
146 (critical-pair-second pair)))
147 :test pair-order-fn)))
148 (enqueue-critical-pairs queue (make-critical-pairs poly-lst start))))))
[4162]149
Note: See TracBrowser for help on using the repository browser.