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@ 4511

Last change on this file since 4511 was 4511, checked in by Marek Rychlik, 9 years ago

* empty log message *

File size: 2.1 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 (static-sugar trm)))))
14
15(defclass sugar ()
16 ((value :initarg :value :initform -1 :accessor sugar-value :type fixnum))
17 (:documentation "Sugar is a quantity added to various objects, such as monomials, terms and polynomials."))
18
19(defclass monom-with-sugar (monom sugar) ())
20
21(defmethod print-object ((self monom-with-sugar) stream)
22 (print-unreadable-object (self stream :type t :identity t)
23 (with-accessors ((exponents monom-exponents) (value sugar-value))
24 self
25 (format stream "EXPONENTS=~A SUGAR=~A"
26 exponents value))))
27
28
29(defmethod shared-initialize :after ((self monom-with-sugar) slot-names &rest initargs &key)
30 "Initialize sugar value based on the exponents."
31 (declare (ignore slot-names initargs))
32 (setf (slot-value self 'value) (static-sugar self)))
33
34(defmethod multiply-by :after ((self sugar) (other sugar))
35 (with-slots (value)
36 self
37 (with-slots ((other-value value))
38 other
39 (incf value other-value)))
40 self)
41
42(defclass term-with-sugar (term sugar) ())
43
44(defmethod print-object ((self term-with-sugar) stream)
45 (print-unreadable-object (self stream :type t :identity t)
46 (with-accessors ((exponents monom-exponents) (value sugar-value) (coeff term-coeff))
47 self
48 (format stream "EXPONENTS=~A COEFF=~A SUGAR=~A"
49 exponents coeff value))))
50
51(defclass poly-with-sugar (poly sugar) ())
52
53(defmethod shared-initialize :after ((self poly-with-sugar) slot-names &rest initargs &key)
54 "Initialize sugar to its static value, which is the maximum of sugar values of the terms."
55 (declare (ignore slot-names initargs))
56 (setf (slot-value self 'value) (static-sugar self)))
Note: See TracBrowser for help on using the repository browser.