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 4240 for branches/f4grobner


Ignore:
Timestamp:
2016-06-04T19:41:09-07:00 (9 years ago)
Author:
Marek Rychlik
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/monom.lisp

    r4239 r4240  
    179179    (total-degree m start end)))
    180180
    181 (defgeneric multiply-by (self other)
    182   (:documentation "Multiply SELF by OTHER, return SELF. The object SELF
    183 may be destructively modified in the process, while OTHER should remain
    184 unmodified.")
    185   (:method ((self number) (other number)) (* self other))
    186   (:method ((self monom) (other monom))
    187     (with-slots ((exponents1 exponents))
    188         self
    189       (with-slots ((exponents2 exponents))
    190           other
    191         (unless (= (length exponents1) (length exponents2))
    192           (error "Incompatible dimensions"))
    193         (map-into exponents1 #'+ exponents1 exponents2)))
    194     self))
     181(defmethod multiply-by ((self monom) (other monom))
     182  (with-slots ((exponents1 exponents))
     183      self
     184    (with-slots ((exponents2 exponents))
     185        other
     186      (unless (= (length exponents1) (length exponents2))
     187        (error "Incompatible dimensions"))
     188      (map-into exponents1 #'+ exponents1 exponents2)))
     189  self)
    195190
    196191(defun multiply (factor &rest more-factors)
     
    200195  (reduce #'multiply-by more-factors :initial-value (copy-instance factor)))
    201196
    202 (defgeneric divide-by (self other)
    203   (:documentation "Divide SELF by OTHER, return SELF.")
    204   (:method ((self number) (other number)) (/ self other))
    205   (:method ((self monom) (other monom))
    206     (with-slots ((exponents1 exponents))
    207         self
    208       (with-slots ((exponents2 exponents))
    209           other
    210         (unless (= (length exponents1) (length exponents2))
    211           (error "divide-by: Incompatible dimensions."))
    212         (unless (every #'>= exponents1 exponents2)
    213           (error "divide-by: Negative power would result."))
    214         (map-into exponents1 #'- exponents1 exponents2)))
    215   self))
     197(defmethod divide-by ((self monom) (other monom))
     198  (with-slots ((exponents1 exponents))
     199      self
     200    (with-slots ((exponents2 exponents))
     201        other
     202      (unless (= (length exponents1) (length exponents2))
     203        (error "divide-by: Incompatible dimensions."))
     204      (unless (every #'>= exponents1 exponents2)
     205        (error "divide-by: Negative power would result."))
     206      (map-into exponents1 #'- exponents1 exponents2)))
     207  self)
    216208
    217209(defmethod copy-instance :around ((object monom)  &rest initargs &key &allow-other-keys)
     
    222214    copy))
    223215
    224 (defgeneric unary-inverse (self)
    225   (:documentation "Returns the unary inverse of SELF.")
    226   (:method ((self number)) (/ self))
    227   (:method :before ((self monom))
    228            (assert (zerop (total-degree self))
    229                    nil
    230                    "Monom ~A must have total degree 0 to be invertible." self))
    231   (:method ((self monom)) self))
     216(defmethod unary-inverse :before ((self monom))
     217  (assert (zerop (total-degree self))
     218          nil
     219          "Monom ~A must have total degree 0 to be invertible.")
     220  self)
     221
     222(defmethod unary-inverse ((self monom)) self)
    232223
    233224(defun divide (numerator &rest denominators)
     
    540531and powers of some variables, such as 5*X^2*Y^3."))
    541532
    542 (defmethod initialize-instance :around ((self term) &rest initargs &key coeff)
     533(defmethod initialize-instance :around ((self term) &rest initargs &key (coeff 1))
    543534  "A convenience method. If a coefficient is an integer, wrap it in the INTEGER-RING object"
    544535  ;; Dispatch on supplied type of coefficient
     
    549540  (apply #'call-next-method (cons self initargs)))
    550541 
    551 (defmethod update-instance-for-different-class :after ((old monom) (new term) &key (coeff 1))
     542(defmethod update-instance-for-different-class :after ((old monom) (new term) &key coeff)
    552543  "Converts OLD of class MONOM to a NEW of class TERM, initializing coefficient to COEFF."
    553544  (reinitialize-instance new :coeff coeff))
     
    608599  (setf (term-coeff self) (divide-by (term-coeff self) (term-coeff other))))
    609600
    610 (defgeneric unary-minus (self)
    611   (:documentation "Negate object SELF and return it.")
    612   (:method ((self number)) (- self))
    613   (:method ((self term))
    614     (setf (term-coeff self) (unary-minus (term-coeff self)))
    615     self))
     601(defmethod unary-minus ((self term))
     602  (setf (term-coeff self) (unary-minus (term-coeff self)))
     603  self)
    616604
    617605(defgeneric universal-zerop (self)
Note: See TracChangeset for help on using the changeset viewer.