[4502] | 1 | (in-package "POLYNOMIAL")
|
---|
| 2 |
|
---|
| 3 | (defgeneric static-sugar (object)
|
---|
| 4 | (:documentation "Return statically calculated sugar of object OBJECT. That is,
|
---|
| 5 | the sugar value which does not assume that the object is a result of any prior calculations.")
|
---|
| 6 | (:method ((object monom))
|
---|
[4505] | 7 | "Static sugar of a monom OBJECT is simply the total degree."
|
---|
[4502] | 8 | (total-degree object))
|
---|
| 9 | (:method ((object poly))
|
---|
[4505] | 10 | "Static sugar of a poly OBJECT is the maximum sugar of its terms."
|
---|
| 11 | (with-slots (termlist)
|
---|
[4502] | 12 | object
|
---|
| 13 | (loop for trm in termlist maximize (sugar trm)))))
|
---|
| 14 |
|
---|
| 15 | (defclass sugar ()
|
---|
[4507] | 16 | ((value :initarg :value :initform -1 :accessor sugar-value :type fixnum))
|
---|
[4508] | 17 | (:documentation "Sugar is a quantity added to various objects, such
|
---|
| 18 | as monomials, terms and polynomials."))
|
---|
[4502] | 19 |
|
---|
| 20 | (defclass monom-with-sugar (monom sugar) ())
|
---|
| 21 |
|
---|
[4505] | 22 | (defmethod print-object ((self monom-with-sugar) stream)
|
---|
| 23 | (print-unreadable-object (self stream :type t :identity t)
|
---|
| 24 | (with-accessors ((exponents monom-exponents) (value sugar-value))
|
---|
| 25 | self
|
---|
| 26 | (format stream "EXPONENTS=~A SUGAR=~A"
|
---|
| 27 | exponents value))))
|
---|
| 28 |
|
---|
| 29 |
|
---|
[4502] | 30 | (defmethod shared-initialize :after ((self monom-with-sugar) slot-names &rest initargs &key)
|
---|
[4504] | 31 | "Initialize sugar value based on the exponents."
|
---|
[4502] | 32 | (declare (ignore slot-names initargs))
|
---|
[4504] | 33 | (setf (slot-value self 'value) (static-sugar self)))
|
---|
[4502] | 34 |
|
---|
[4505] | 35 | (defclass term-with-sugar (term sugar) ())
|
---|
[4502] | 36 |
|
---|
[4505] | 37 | (defmethod print-object ((self term-with-sugar) stream)
|
---|
| 38 | (print-unreadable-object (self stream :type t :identity t)
|
---|
| 39 | (with-accessors ((exponents monom-exponents) (value sugar-value) (coeff term-coeff))
|
---|
| 40 | self
|
---|
| 41 | (format stream "EXPONENTS=~A COEFF=~A SUGAR=~A"
|
---|
| 42 | exponents coeff value))))
|
---|