[60] | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 2 | ;;
|
---|
| 3 | ;; Pair queue implementation
|
---|
| 4 | ;;
|
---|
| 5 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 6 |
|
---|
| 7 | (defun sugar-pair-key (p q &aux (lcm (monom-lcm (poly-lm p) (poly-lm q)))
|
---|
| 8 | (d (monom-sugar lcm)))
|
---|
| 9 | "Returns list (S LCM-TOTAL-DEGREE) where S is the sugar of the S-polynomial of
|
---|
| 10 | polynomials P and Q, and LCM-TOTAL-DEGREE is the degree of is LCM(LM(P),LM(Q))."
|
---|
| 11 | (declare (type poly p q) (type monom lcm) (type fixnum d))
|
---|
| 12 | (cons (max
|
---|
| 13 | (+ (- d (monom-sugar (poly-lm p))) (poly-sugar p))
|
---|
| 14 | (+ (- d (monom-sugar (poly-lm q))) (poly-sugar q)))
|
---|
| 15 | lcm))
|
---|
| 16 |
|
---|
| 17 | (defstruct (pair
|
---|
| 18 | (:constructor make-pair (first second
|
---|
| 19 | &aux
|
---|
| 20 | (sugar (car (sugar-pair-key first second)))
|
---|
| 21 | (division-data nil))))
|
---|
| 22 | (first nil :type poly)
|
---|
| 23 | (second nil :type poly)
|
---|
| 24 | (sugar 0 :type fixnum)
|
---|
| 25 | (division-data nil :type list))
|
---|
| 26 |
|
---|
| 27 | ;;(defun pair-sugar (pair &aux (p (pair-first pair)) (q (pair-second pair)))
|
---|
| 28 | ;; (car (sugar-pair-key p q)))
|
---|
| 29 |
|
---|
| 30 | (defun sugar-order (x y)
|
---|
| 31 | "Pair order based on sugar, ties broken by normal strategy."
|
---|
| 32 | (declare (type cons x y))
|
---|
| 33 | (or (< (car x) (car y))
|
---|
| 34 | (and (= (car x) (car y))
|
---|
| 35 | (< (monom-total-degree (cdr x))
|
---|
| 36 | (monom-total-degree (cdr y))))))
|
---|
| 37 |
|
---|
| 38 | (defvar *pair-key-function* #'sugar-pair-key
|
---|
| 39 | "Function that, given two polynomials as argument, computed the key
|
---|
| 40 | in the pair queue.")
|
---|
| 41 |
|
---|
| 42 | (defvar *pair-order* #'sugar-order
|
---|
| 43 | "Function that orders the keys of pairs.")
|
---|
| 44 |
|
---|
| 45 | (defun make-pair-queue ()
|
---|
| 46 | "Constructs a priority queue for critical pairs."
|
---|
| 47 | (make-priority-queue
|
---|
| 48 | :element-type 'pair
|
---|
| 49 | :element-key #'(lambda (pair) (funcall *pair-key-function* (pair-first pair) (pair-second pair)))
|
---|
| 50 | :test *pair-order*))
|
---|
| 51 |
|
---|
| 52 | (defun pair-queue-initialize (pq f start
|
---|
| 53 | &aux
|
---|
| 54 | (s (1- (length f)))
|
---|
| 55 | (b (nconc (makelist (make-pair (elt f i) (elt f j))
|
---|
| 56 | (i 0 (1- start)) (j start s))
|
---|
| 57 | (makelist (make-pair (elt f i) (elt f j))
|
---|
| 58 | (i start (1- s)) (j (1+ i) s)))))
|
---|
| 59 | "Initializes the priority for critical pairs. F is the initial list of polynomials.
|
---|
| 60 | START is the first position beyond the elements which form a partial
|
---|
| 61 | grobner basis, i.e. satisfy the Buchberger criterion."
|
---|
| 62 | (declare (type priority-queue pq) (type fixnum start))
|
---|
| 63 | (dolist (pair b pq)
|
---|
| 64 | (priority-queue-insert pq pair)))
|
---|
| 65 |
|
---|
| 66 | (defun pair-queue-insert (b pair)
|
---|
| 67 | (priority-queue-insert b pair))
|
---|
| 68 |
|
---|
| 69 | (defun pair-queue-remove (b)
|
---|
| 70 | (priority-queue-remove b))
|
---|
| 71 |
|
---|
| 72 | (defun pair-queue-size (b)
|
---|
| 73 | (priority-queue-size b))
|
---|
| 74 |
|
---|
| 75 | (defun pair-queue-empty-p (b)
|
---|
| 76 | (priority-queue-empty-p b))
|
---|