| [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"
|
|---|
| 29 | "MIN-TOTAL-DEGREE-STRATEGY"
|
|---|
| [3965] | 30 | "MIN-COMBINED-LENGTH-STRATEGY"
|
|---|
| [3918] | 31 | )
|
|---|
| 32 | (:documentation "Critical pair queue implementation. The pair queue is a list of critical
|
|---|
| 33 | pairs, ordered by some partial order. Pair queue is a kind of priority queue.")
|
|---|
| 34 | )
|
|---|
| [449] | 35 |
|
|---|
| [450] | 36 | (in-package :pair-queue)
|
|---|
| 37 |
|
|---|
| [3919] | 38 | (defclass critical-pair ()
|
|---|
| [3921] | 39 | ((first :initform nil :initarg :first :accessor critical-pair-first :type poly)
|
|---|
| 40 | (second :initform nil :initarg :second :accessor critical-pair-second :type poly))
|
|---|
| [3930] | 41 | (:documentation "Represents a critical pair, i.e. a pair of two polynomials. The derived
|
|---|
| 42 | classes may add extra data used in computing the order of critical pairs."))
|
|---|
| [3919] | 43 |
|
|---|
| [3921] | 44 | (defmethod print-object ((self critical-pair) stream)
|
|---|
| [3920] | 45 | (print-unreadable-object (self stream :type t :identity t)
|
|---|
| 46 | (with-accessors ((first critical-pair-first)
|
|---|
| 47 | (second critical-pair-second))
|
|---|
| 48 | self
|
|---|
| 49 | (format stream "FIRST=~A SECOND=~A"
|
|---|
| 50 | first second))))
|
|---|
| 51 |
|
|---|
| [3927] | 52 | (defclass selection-strategy ()
|
|---|
| [3959] | 53 | ((pair-key-fn :initform #'(lambda (p q) (universal-lcm (leading-monomial p) (leading-monomial q)))
|
|---|
| 54 | :initarg :pair-key-fn
|
|---|
| 55 | :accessor pair-key-fn)
|
|---|
| 56 | (pair-order-fn :initform #'lex>
|
|---|
| 57 | :initarg :pair-order-fn
|
|---|
| 58 | :accessor pair-order-fn))
|
|---|
| [3940] | 59 | (:documentation "Represents the normal critical pair selection
|
|---|
| 60 | strategy. The two ingredients of a strategy is a function
|
|---|
| 61 | PAIR-KEY-FUNCTION which computes a key from the critical pair, which
|
|---|
| 62 | can be any type of data, and a function PAIR-ORDER-FN used to compaire
|
|---|
| 63 | the calculated keys to determine which pair is more promising and
|
|---|
| [3941] | 64 | should be considered first. The normal selection strategy for a given
|
|---|
| 65 | monomial order PAIR-ORDER-FN consists in selecting the pair with the
|
|---|
| 66 | minimal LCM of leading monomials first."))
|
|---|
| [60] | 67 |
|
|---|
| [3932] | 68 | (defmethod print-object ((self selection-strategy) stream)
|
|---|
| 69 | (print-unreadable-object (self stream :type t :identity t)
|
|---|
| 70 | (with-accessors ((pair-key-fn pair-key-fn)
|
|---|
| 71 | (pair-order-fn pair-order-fn))
|
|---|
| 72 | self
|
|---|
| 73 | (format stream "PAIR-KEY-FN=~A PAIR-ORDER-FN=~A"
|
|---|
| 74 | pair-key-fn pair-order-fn))))
|
|---|
| 75 |
|
|---|
| [3933] | 76 | (defclass min-total-degree-strategy (selection-strategy)
|
|---|
| 77 | ((pair-key-fn :initform #'(lambda (p q) (total-degree (universal-lcm (leading-monomial p) (leading-monomial q)))))
|
|---|
| [3943] | 78 | (pair-order-fn :initform #'<))
|
|---|
| [3933] | 79 | (:documentation "Make a selection strategy where a pair with a
|
|---|
| 80 | minimum total degree of LCM of leading monomials is selected."))
|
|---|
| [3932] | 81 |
|
|---|
| [3964] | 82 | (defclass min-combined-length-strategy (selection-strategy)
|
|---|
| [3935] | 83 | ((pair-key-fn :initform #'(lambda (p q) (+ (poly-length p) (poly-length q))))
|
|---|
| [3942] | 84 | (pair-order-fn :initform #'<))
|
|---|
| [3933] | 85 | (:documentation "Make a selection strategy where a pair with the minimum combined length of both
|
|---|
| 86 | polynomials is selected."))
|
|---|
| 87 |
|
|---|
| [3974] | 88 | (defun make-critical-pair-queue (&key pair-key-fn pair-order-fn (poly-list nil) (start 1)
|
|---|
| 89 | &aux (pq (make-priority-queue
|
|---|
| 90 | :element-type 'critical-pair
|
|---|
| 91 | :element-key #'(lambda (pair) (funcall pair-key-fn
|
|---|
| 92 | (critical-pair-first pair)
|
|---|
| 93 | (critical-pair-second pair)))
|
|---|
| 94 | :test pair-order-fn)))
|
|---|
| 95 | "Makes a priority queue for critical pairs. The argument POLY-LIST should the initial list of polynomials.
|
|---|
| [3958] | 96 | and START is the first position beyond the elements which form a
|
|---|
| 97 | partial Grobner basis, i.e. satisfy the Buchberger criterion."
|
|---|
| [3955] | 98 | ;; Add critical pairs for polynomials in POLY-LIST
|
|---|
| [3974] | 99 | (let* ((s (1- (length poly-list)))
|
|---|
| 100 | (b (nconc (makelist (make-instance 'critical-pair :first (elt poly-list i) :second (elt poly-list j))
|
|---|
| 101 | (i 0 (1- start)) (j start s))
|
|---|
| 102 | (makelist (make-instance 'critical-pair :first (elt poly-list i) :second (elt poly-list j))
|
|---|
| 103 | (i start (1- s)) (j (1+ i) s)))))
|
|---|
| 104 | (dolist (pair b pq)
|
|---|
| [3976] | 105 | (priority-queue-insert pq pair))))
|
|---|
| [3938] | 106 |
|
|---|
| [3944] | 107 |
|
|---|