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/polynomial-sugar.lisp@ 4505

Last change on this file since 4505 was 4505, checked in by Marek Rychlik, 8 years ago

* empty log message *

File size: 1.5 KB
Line 
1(in-package "POLYNOMIAL")
2
3(defgeneric static-sugar (object)
4 (:documentation "Return statically calculated sugar of object OBJECT. That is,
5the sugar value which does not assume that the object is a result of any prior calculations.")
6 (:method ((object monom))
7 "Static sugar of a monom OBJECT is simply the total degree."
8 (total-degree object))
9 (:method ((object poly))
10 "Static sugar of a poly OBJECT is the maximum sugar of its terms."
11 (with-slots (termlist)
12 object
13 (loop for trm in termlist maximize (sugar trm)))))
14
15(defclass sugar ()
16 ((value :initarg :value :initform -1 :accessor sugar-value :type fixnum)))
17
18(defclass monom-with-sugar (monom sugar) ())
19
20(defmethod print-object ((self monom-with-sugar) stream)
21 (print-unreadable-object (self stream :type t :identity t)
22 (with-accessors ((exponents monom-exponents) (value sugar-value))
23 self
24 (format stream "EXPONENTS=~A SUGAR=~A"
25 exponents value))))
26
27
28(defmethod shared-initialize :after ((self monom-with-sugar) slot-names &rest initargs &key)
29 "Initialize sugar value based on the exponents."
30 (declare (ignore slot-names initargs))
31 (setf (slot-value self 'value) (static-sugar self)))
32
33(defclass term-with-sugar (term sugar) ())
34
35(defmethod print-object ((self term-with-sugar) stream)
36 (print-unreadable-object (self stream :type t :identity t)
37 (with-accessors ((exponents monom-exponents) (value sugar-value) (coeff term-coeff))
38 self
39 (format stream "EXPONENTS=~A COEFF=~A SUGAR=~A"
40 exponents coeff value))))
Note: See TracBrowser for help on using the repository browser.