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.

Changeset 3531 for branches


Ignore:
Timestamp:
2015-09-05T15:36:37-07:00 (9 years ago)
Author:
Marek Rychlik
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/monom.lisp

    r3487 r3531  
    477477                   (values primary nil))))))))
    478478
     479
     480(defclass term (monom)
     481  ((coeff :initarg :coeff :accessor term-coeff))
     482  (:default-initargs :coeff nil)
     483  (:documentation "Implements a term, i.e. a product of a scalar
     484and powers of some variables, such as 5*X^2*Y^3."))
     485
     486(defmethod print-object ((self term) stream)
     487  (print-unreadable-object (self stream :type t :identity t)
     488    (with-accessors ((exponents monom-exponents)
     489                     (coeff scalar-coeff))
     490        self
     491      (format stream "EXPONENTS=~A COEFF=~A"
     492              exponents coeff))))
     493
     494
     495(defmethod r-equalp ((term1 term) (term2 term))
     496  (when (r-equalp (scalar-coeff term1) (scalar-coeff term2))
     497    (call-next-method)))
     498
     499(defmethod update-instance-for-different-class :after ((old monom) (new  scalar) &key)
     500  (setf (scalar-coeff new) 1))
     501
     502(defmethod multiply-by :before ((self term) (other term))
     503  "Destructively multiply terms SELF and OTHER and store the result into SELF.
     504It returns SELF."
     505  (setf (scalar-coeff self) (multiply-by (scalar-coeff self) (scalar-coeff other))))
     506
     507(defmethod left-tensor-product-by ((self term) (other term))
     508  (setf (scalar-coeff self) (multiply-by (scalar-coeff self) (scalar-coeff other)))
     509  (call-next-method))
     510
     511(defmethod right-tensor-product-by ((self term) (other term))
     512  (setf (scalar-coeff self) (multiply-by (scalar-coeff self) (scalar-coeff other)))
     513  (call-next-method))
     514
     515(defmethod left-tensor-product-by ((self term) (other monom))
     516  (call-next-method))
     517
     518(defmethod right-tensor-product-by ((self term) (other monom))
     519  (call-next-method))
     520
     521(defmethod divide-by ((self term) (other term))
     522  "Destructively divide term SELF by OTHER and store the result into SELF.
     523It returns SELF."
     524  (setf (scalar-coeff self) (divide-by (scalar-coeff self) (scalar-coeff other)))
     525  (call-next-method))
     526
     527(defmethod unary-minus ((self term))
     528  (setf (scalar-coeff self) (unary-minus (scalar-coeff self)))
     529  self)
     530
     531(defmethod r* ((term1 term) (term2 term))
     532  "Non-destructively multiply TERM1 by TERM2."
     533  (multiply-by (copy-instance term1) (copy-instance term2)))
     534
     535(defmethod r* ((term1 number) (term2 monom))
     536  "Non-destructively multiply TERM1 by TERM2."
     537  (r* term1 (change-class (copy-instance term2) 'term)))
     538
     539(defmethod r* ((term1 number) (term2 term))
     540  "Non-destructively multiply TERM1 by TERM2."
     541  (setf (scalar-coeff term2)
     542        (r* term1 (scalar-coeff term2)))
     543  term2)
     544
     545(defmethod r-zerop ((self term))
     546  (r-zerop (scalar-coeff self)))
Note: See TracChangeset for help on using the changeset viewer.