1 | ;;; -*- Mode: Lisp -*-
|
---|
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 | (defpackage "PAIR-QUEUE"
|
---|
23 | (:use :cl :priority-queue :monom :polynomial :utils)
|
---|
24 | (:export "PAIR"
|
---|
25 | "MAKE-PAIR"
|
---|
26 | "PAIR-FIRST"
|
---|
27 | "PAIR-SECOND"
|
---|
28 | "PAIR-SUGAR"
|
---|
29 | "PAIR-DIVISION-DATA"
|
---|
30 | "*PAIR-KEY-FUNCTION*"
|
---|
31 | "*PAIR-ORDER*"
|
---|
32 | "MAKE-PAIR-QUEUE"
|
---|
33 | "PAIR-QUEUE-INITIALIZE"
|
---|
34 | "PAIR-QUEUE-INSERT"
|
---|
35 | "PAIR-QUEUE-REMOVE"
|
---|
36 | "PAIR-QUEUE-SIZE"
|
---|
37 | "PAIR-QUEUE-EMPTY-P"
|
---|
38 | "SET-PAIR-HEURISTIC"
|
---|
39 | )
|
---|
40 | (:documentation "Critical pair queue implementation. The pair queue is a list of critical
|
---|
41 | pairs, ordered by some partial order. Pair queue is a kind of priority queue.")
|
---|
42 | )
|
---|
43 |
|
---|
44 |
|
---|
45 | (in-package :pair-queue)
|
---|
46 |
|
---|
47 | (defstruct (pair
|
---|
48 | (:constructor make-pair (first second
|
---|
49 | &aux
|
---|
50 | (division-data nil))))
|
---|
51 | (first nil :type poly)
|
---|
52 | (second nil :type poly)
|
---|
53 | (division-data nil :type list))
|
---|
54 |
|
---|
55 | (defvar *pair-key-function* nil
|
---|
56 | "Function that, given two polynomials as argument, computed the key
|
---|
57 | in the pair queue.")
|
---|
58 |
|
---|
59 | (defvar *pair-order* nil
|
---|
60 | "Function that orders the keys of pairs.")
|
---|
61 |
|
---|
62 | (defun make-pair-queue ()
|
---|
63 | "Constructs a priority queue for critical pairs."
|
---|
64 | (make-priority-queue
|
---|
65 | :element-type 'pair
|
---|
66 | :element-key #'(lambda (pair) (funcall *pair-key-function* (pair-first pair) (pair-second pair)))
|
---|
67 | :test *pair-order*))
|
---|
68 |
|
---|
69 | (defun pair-queue-initialize (pq f start
|
---|
70 | &aux
|
---|
71 | (s (1- (length f)))
|
---|
72 | (b (nconc (makelist (make-pair (elt f i) (elt f j))
|
---|
73 | (i 0 (1- start)) (j start s))
|
---|
74 | (makelist (make-pair (elt f i) (elt f j))
|
---|
75 | (i start (1- s)) (j (1+ i) s)))))
|
---|
76 | "Initializes the priority for critical pairs. F is the initial list of polynomials.
|
---|
77 | START is the first position beyond the elements which form a partial
|
---|
78 | grobner basis, i.e. satisfy the Buchberger criterion."
|
---|
79 | (declare (type priority-queue pq) (type fixnum start))
|
---|
80 | (dolist (pair b pq)
|
---|
81 | (priority-queue-insert pq pair)))
|
---|
82 |
|
---|
83 | (defun pair-queue-insert (b pair)
|
---|
84 | (priority-queue-insert b pair))
|
---|
85 |
|
---|
86 | (defun pair-queue-remove (b)
|
---|
87 | (priority-queue-remove b))
|
---|
88 |
|
---|
89 | (defun pair-queue-size (b)
|
---|
90 | (priority-queue-size b))
|
---|
91 |
|
---|
92 | (defun pair-queue-empty-p (b)
|
---|
93 | (priority-queue-empty-p b))
|
---|
94 |
|
---|
95 | (defun set-pair-heuristic (method)
|
---|
96 | "Sets up variables *PAIR-KEY-FUNCTION* and *PAIR-ORDER* used
|
---|
97 | to determine the priority of critical pairs in the priority queue."
|
---|
98 | (ecase method
|
---|
99 | ((minimal-lcm :minimal-lcm $minimal_lcm)
|
---|
100 | (setf *pair-key-function* #'(lambda (p q)
|
---|
101 | (universal-lcm (leading-monomial p) (leading-monomial q)))
|
---|
102 | *pair-order* #'reverse-monomial-order))
|
---|
103 | ((minimal-total-degree :minimal-total-degree $minimal_total_degree)
|
---|
104 | (setf *pair-key-function* #'(lambda (p q)
|
---|
105 | (total-degree
|
---|
106 | (universal-lcm (leading-monomial p) (leading-monomial q))))
|
---|
107 | *pair-order* #'<))
|
---|
108 | ((minimal-length :minimal-length $minimal_length)
|
---|
109 | (setf *pair-key-function* #'(lambda (p q)
|
---|
110 | (+ (poly-length p) (poly-length q)))
|
---|
111 | *pair-order* #'<))))
|
---|
112 |
|
---|