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/monom.lisp@ 3554

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

* empty log message *

File size: 19.9 KB
RevLine 
[1201]1;;; -*- Mode: Lisp -*-
[81]2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3;;;
4;;; Copyright (C) 1999, 2002, 2009, 2015 Marek Rychlik <rychlik@u.arizona.edu>
5;;;
6;;; This program is free software; you can redistribute it and/or modify
7;;; it under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 2 of the License, or
9;;; (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19;;;
20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21
[1610]22(defpackage "MONOM"
[3446]23 (:use :cl :copy)
[422]24 (:export "MONOM"
[423]25 "EXPONENT"
[2781]26 "MONOM-DIMENSION"
27 "MONOM-EXPONENTS"
[3442]28 "MONOM-EQUALP"
29 "MONOM-ELT"
30 "MONOM-TOTAL-DEGREE"
[3466]31 "MONOM-SUGAR"
[3442]32 "MONOM-MULTIPLY-BY"
33 "MONOM-DIVIDE-BY"
34 "MONOM-COPY-INSTANCE"
35 "MONOM-MULTIPLY-2"
36 "MONOM-MULTIPLY"
37 "MONOM-DIVIDES-P"
38 "MONOM-DIVIDES-LCM-P"
39 "MONOM-LCM-DIVIDES-LCM-P"
40 "MONOM-LCM-EQUAL-LCM-P"
41 "MONOM-DIVISIBLE-BY-P"
42 "MONOM-REL-PRIME-P"
43 "MONOM-LCM"
44 "MONOM-GCD"
45 "MONOM-DEPENDS-P"
46 "MONOM-LEFT-TENSOR-PRODUCT-BY"
47 "MONOM-RIGHT-TENSOR-PRODUCT-BY"
48 "MONOM-LEFT-CONTRACT"
49 "MAKE-MONOM-VARIABLE"
[3472]50 "MONOM->LIST"
51 "LEX>"
52 "GRLEX>"
53 "REVLEX>"
54 "GREVLEX>"
55 "INVLEX>"
56 "REVERSE-MONOMIAL-ORDER"
[3482]57 "MAKE-ELIMINATION-ORDER-FACTORY")
[2524]58 (:documentation
[3477]59 "This package implements basic operations on monomials, including
60various monomial orders.
61
[2524]62DATA STRUCTURES: Conceptually, monomials can be represented as lists:
[81]63
[2524]64 monom: (n1 n2 ... nk) where ni are non-negative integers
65
66However, lists may be implemented as other sequence types, so the
67flexibility to change the representation should be maintained in the
68code to use general operations on sequences whenever possible. The
69optimization for the actual representation should be left to
70declarations and the compiler.
71
72EXAMPLES: Suppose that variables are x and y. Then
73
74 Monom x*y^2 ---> (1 2) "))
75
[1610]76(in-package :monom)
[48]77
[1925]78(proclaim '(optimize (speed 3) (space 0) (safety 0) (debug 0)))
[1923]79
[48]80(deftype exponent ()
81 "Type of exponent in a monomial."
82 'fixnum)
83
[2022]84(defclass monom ()
[3312]85 ((exponents :initarg :exponents :accessor monom-exponents
[3054]86 :documentation "The powers of the variables."))
[3289]87 ;; default-initargs are not needed, they are handled by SHARED-INITIALIZE
88 ;;(:default-initargs :dimension 'foo :exponents 'bar :exponent 'baz)
[2779]89 (:documentation
90 "Implements a monomial, i.e. a product of powers
91of variables, like X*Y^2."))
[880]92
[2245]93(defmethod print-object ((self monom) stream)
[3196]94 (print-unreadable-object (self stream :type t :identity t)
[3313]95 (with-accessors ((exponents monom-exponents))
[3216]96 self
[3313]97 (format stream "EXPONENTS=~A"
98 exponents))))
[2027]99
[3299]100(defmethod initialize-instance :after ((self monom)
[3297]101 &key
102 (dimension 0 dimension-supplied-p)
103 (exponents nil exponents-supplied-p)
[3318]104 (exponent 0)
[3297]105 &allow-other-keys
[2390]106 )
[3329]107 "The following INITIALIZE-INSTANCE method allows instance initialization
108of a MONOM in a style similar to MAKE-ARRAY, e.g.:
[3328]109
110 (MAKE-INSTANCE :EXPONENTS '(1 2 3)) --> #<MONOM EXPONENTS=#(1 2 3)>
111 (MAKE-INSTANCE :DIMENSION 3) --> #<MONOM EXPONENTS=#(0 0 0)>
112 (MAKE-INSTANCE :DIMENSION 3 :EXPONENT 7) --> #<MONOM EXPONENTS=#(7 7 7)>
[3329]113
114If both DIMENSION and EXPONENTS are supplied, they must be compatible,
115i.e. the length of EXPONENTS must be equal DIMENSION. If EXPONENTS
116is not supplied, a monom with repeated value EXPONENT is created.
117By default EXPONENT is 0, which results in a constant monomial.
[3328]118"
[3315]119 (cond
120 (exponents-supplied-p
[3327]121 (when (and dimension-supplied-p
122 (/= dimension (length exponents)))
123 (error "EXPONENTS (~A) must have supplied length DIMENSION (~A)"
124 exponents dimension))
[3315]125 (let ((dim (length exponents)))
126 (setf (slot-value self 'exponents) (make-array dim :initial-contents exponents))))
[3321]127 (dimension-supplied-p
[3315]128 ;; when all exponents are to be identical
[3321]129 (setf (slot-value self 'exponents) (make-array (list dimension)
130 :initial-element exponent
131 :element-type 'exponent)))
132 (t
133 (error "Initarg DIMENSION or EXPONENTS must be supplied."))))
[3293]134
[3443]135(defgeneric monom-dimension (m)
136 (:method ((m monom))
137 (length (monom-exponents m))))
[3317]138
[3541]139(defgeneric universal-equalp (object1 object2)
140 (:documentation "Returns T iff OBJECT1 and OBJECT2 are equal.")
[3443]141 (:method ((m1 monom) (m2 monom))
[3541]142 "Returns T iff monomials M1 and M2 have identical EXPONENTS."
[3535]143 (equalp (monom-exponents m1) (monom-exponents m2))))
[2547]144
[3443]145(defgeneric monom-elt (m index)
[3550]146 (:documentation "Return the power in the monomial M of variable number INDEX."
[3443]147 (:method ((m monom) index)
[3550]148 "Return the power in the monomial M of variable number INDEX."
[3443]149 (with-slots (exponents)
150 m
151 (elt exponents index))))
[48]152
[3443]153(defgeneric (setf monom-elt) (new-value m index)
[3550]154 (:documentation "Set the power in the monomial M of variable number INDEX.")
[3443]155 (:method (new-value (m monom) index)
156 (with-slots (exponents)
157 m
[3453]158 (setf (elt exponents index) new-value))))
[2023]159
[3551]160(defgeneric total-degree (m &optional start end)
161 (:documentation "Return the total degree of a monomoal M. Optinally, a range
[3449]162of variables may be specified with arguments START and END.")
163 (:method ((m monom) &optional (start 0) (end (monom-dimension m)))
164 (declare (type fixnum start end))
165 (with-slots (exponents)
166 m
167 (reduce #'+ exponents :start start :end end))))
[48]168
[3552]169(defgeneric sugar (m &optional start end)
[3446]170 (:documentation "Return the sugar of a monomial M. Optinally, a range
171of variables may be specified with arguments START and END.")
172 (:method ((m monom) &optional (start 0) (end (monom-dimension m)))
173 (declare (type fixnum start end))
[3552]174 (total-degree m start end)))
[48]175
[3553]176(defgeneric multiply-by (self other)
[3549]177 (:documentation "Multiply SELF by OTHER, return SELF.")
[3446]178 (:method ((self monom) (other monom))
179 (with-slots ((exponents1 exponents))
180 self
181 (with-slots ((exponents2 exponents))
182 other
183 (unless (= (length exponents1) (length exponents2))
184 (error "Incompatible dimensions"))
185 (map-into exponents1 #'+ exponents1 exponents2)))
186 self))
[2069]187
[3553]188(defgeneric divide-by (self other)
[3544]189 (:documentation "Divide SELF by OTHER, return SELF.")
[3446]190 (:method ((self monom) (other monom))
191 (with-slots ((exponents1 exponents))
192 self
193 (with-slots ((exponents2 exponents))
194 other
195 (unless (= (length exponents1) (length exponents2))
196 (error "divide-by: Incompatible dimensions."))
197 (unless (every #'>= exponents1 exponents2)
198 (error "divide-by: Negative power would result."))
199 (map-into exponents1 #'- exponents1 exponents2)))
200 self))
[2818]201
[3448]202(defmethod copy-instance :around ((object monom) &rest initargs &key &allow-other-keys)
203 "An :AROUND method of COPY-INSTANCE. It replaces
204exponents with a fresh copy of the sequence."
[3446]205 (declare (ignore object initargs))
206 (let ((copy (call-next-method)))
207 (setf (monom-exponents copy) (copy-seq (monom-exponents copy)))
[3453]208 copy))
[2950]209
[3553]210(defgeneric multiply-2 (object1 object2)
[3543]211 (:documentation "Multiply OBJECT1 by OBJECT2")
212 (:method (object1 object2)
[3547]213 (universal-multiply-by (copy-instance object1) (copy-instance object2))))
[2816]214
[3554]215(defgeneric multiply (&rest factors)
216 (:documentation "Non-destructively divide object NUMERATOR by product of DENOMINATORS.")
217 (:method ((numerator monom) &rest denominators)
218 (reduce #'multiply-2 factors)))
219
[3553]220(defgeneric divide (numerator &rest denominators)
[3543]221 (:documentation "Non-destructively divide object NUMERATOR by product of DENOMINATORS.")
222 (:method ((numerator monom) &rest denominators)
[3553]223 (divide-by (copy-instance numerator) (reduce #'multiply-2 denominators))))
[48]224
[3441]225(defmethod monom-divides-p ((m1 monom) (m2 monom))
[48]226 "Returns T if monomial M1 divides monomial M2, NIL otherwise."
[2039]227 (with-slots ((exponents1 exponents))
228 m1
229 (with-slots ((exponents2 exponents))
230 m2
231 (every #'<= exponents1 exponents2))))
[48]232
[2075]233
[3441]234(defmethod monom-divides-lcm-p ((m1 monom) (m2 monom) (m3 monom))
[2055]235 "Returns T if monomial M1 divides LCM(M2,M3), NIL otherwise."
[875]236 (every #'(lambda (x y z) (<= x (max y z)))
[869]237 m1 m2 m3))
[48]238
[3441]239(defmethod monom-lcm-divides-lcm-p ((m1 monom) (m2 monom) (m3 monom) (m4 monom))
[48]240 "Returns T if monomial MONOM-LCM(M1,M2) divides MONOM-LCM(M3,M4), NIL otherwise."
[1890]241 (declare (type monom m1 m2 m3 m4))
[869]242 (every #'(lambda (x y z w) (<= (max x y) (max z w)))
243 m1 m2 m3 m4))
244
[3441]245(defmethod monom-lcm-equal-lcm-p (m1 m2 m3 m4)
[2075]246 "Returns T if monomial LCM(M1,M2) equals LCM(M3,M4), NIL otherwise."
[2171]247 (with-slots ((exponents1 exponents))
[2076]248 m1
[2171]249 (with-slots ((exponents2 exponents))
[2076]250 m2
[2171]251 (with-slots ((exponents3 exponents))
[2076]252 m3
[2171]253 (with-slots ((exponents4 exponents))
[2076]254 m4
[2077]255 (every
256 #'(lambda (x y z w) (= (max x y) (max z w)))
257 exponents1 exponents2 exponents3 exponents4))))))
[48]258
[3441]259(defmethod monom-divisible-by-p ((m1 monom) (m2 monom))
[48]260 "Returns T if monomial M1 is divisible by monomial M2, NIL otherwise."
[2171]261 (with-slots ((exponents1 exponents))
[2144]262 m1
[2171]263 (with-slots ((exponents2 exponents))
[2144]264 m2
265 (every #'>= exponents1 exponents2))))
[2078]266
[3441]267(defmethod monom-rel-prime-p ((m1 monom) (m2 monom))
[48]268 "Returns T if two monomials M1 and M2 are relatively prime (disjoint)."
[2171]269 (with-slots ((exponents1 exponents))
[2078]270 m1
[2171]271 (with-slots ((exponents2 exponents))
[2078]272 m2
[2154]273 (every #'(lambda (x y) (zerop (min x y))) exponents1 exponents2))))
[48]274
[2076]275
[3441]276(defmethod monom-lcm ((m1 monom) (m2 monom))
[48]277 "Returns least common multiple of monomials M1 and M2."
[3322]278 (with-slots ((exponents1 exponents))
[2082]279 m1
[2171]280 (with-slots ((exponents2 exponents))
[2082]281 m2
[3324]282 (let* ((exponents (copy-seq exponents1)))
[2082]283 (map-into exponents #'max exponents1 exponents2)
[3322]284 (make-instance 'monom :exponents exponents)))))
[48]285
[2080]286
[3441]287(defmethod monom-gcd ((m1 monom) (m2 monom))
[48]288 "Returns greatest common divisor of monomials M1 and M2."
[3322]289 (with-slots ((exponents1 exponents))
[2082]290 m1
[2171]291 (with-slots ((exponents2 exponents))
[2082]292 m2
[3322]293 (let* ((exponents (copy-seq exponents1)))
[2082]294 (map-into exponents #'min exponents1 exponents2)
[3322]295 (make-instance 'monom :exponents exponents)))))
[48]296
[3441]297(defmethod monom-depends-p ((m monom) k)
[48]298 "Return T if the monomial M depends on variable number K."
[2083]299 (declare (type fixnum k))
300 (with-slots (exponents)
301 m
[2154]302 (plusp (elt exponents k))))
[48]303
[3441]304(defmethod monom-left-tensor-product-by ((self monom) (other monom))
[3323]305 (with-slots ((exponents1 exponents))
[3020]306 self
[3323]307 (with-slots ((exponents2 exponents))
[3020]308 other
[3323]309 (setf exponents1 (concatenate 'vector exponents2 exponents1))))
[3036]310 self)
[48]311
[3441]312(defmethod monom-right-tensor-product-by ((self monom) (other monom))
[3323]313 (with-slots ((exponents1 exponents))
[3026]314 self
[3323]315 (with-slots ((exponents2 exponents))
[3026]316 other
[3323]317 (setf exponents1 (concatenate 'vector exponents1 exponents2))))
[3036]318 self)
[3026]319
[3441]320(defmethod monom-left-contract ((self monom) k)
[1638]321 "Drop the first K variables in monomial M."
[2085]322 (declare (fixnum k))
[3323]323 (with-slots (exponents)
[3040]324 self
[3323]325 (setf exponents (subseq exponents k)))
[3039]326 self)
[886]327
328(defun make-monom-variable (nvars pos &optional (power 1)
[2218]329 &aux (m (make-instance 'monom :dimension nvars)))
[886]330 "Construct a monomial in the polynomial ring
331RING[X[0],X[1],X[2],...X[NVARS-1]] over the (unspecified) ring RING
332which represents a single variable. It assumes number of variables
333NVARS and the variable is at position POS. Optionally, the variable
334may appear raised to power POWER. "
[1924]335 (declare (type fixnum nvars pos power) (type monom m))
[2089]336 (with-slots (exponents)
337 m
[2154]338 (setf (elt exponents pos) power)
[2089]339 m))
[1151]340
[3441]341(defmethod monom->list ((m monom))
[1152]342 "A human-readable representation of a monomial M as a list of exponents."
[2779]343 (coerce (monom-exponents m) 'list))
[3472]344
345
[3474]346;; pure lexicographic
[3472]347(defgeneric lex> (p q &optional start end)
348 (:documentation "Return T if P>Q with respect to lexicographic
349order, otherwise NIL. The second returned value is T if P=Q,
350otherwise it is NIL.")
[3483]351 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
[3472]352 (declare (type fixnum start end))
353 (do ((i start (1+ i)))
354 ((>= i end) (values nil t))
355 (cond
[3483]356 ((> (monom-elt p i) (monom-elt q i))
[3472]357 (return-from lex> (values t nil)))
[3483]358 ((< (monom-elt p i) (monom-elt q i))
[3472]359 (return-from lex> (values nil nil)))))))
360
[3475]361;; total degree order, ties broken by lexicographic
[3472]362(defgeneric grlex> (p q &optional start end)
363 (:documentation "Return T if P>Q with respect to graded
364lexicographic order, otherwise NIL. The second returned value is T if
365P=Q, otherwise it is NIL.")
[3483]366 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
[3472]367 (declare (type monom p q) (type fixnum start end))
[3483]368 (let ((d1 (monom-total-degree p start end))
369 (d2 (monom-total-degree q start end)))
[3472]370 (declare (type fixnum d1 d2))
371 (cond
372 ((> d1 d2) (values t nil))
373 ((< d1 d2) (values nil nil))
374 (t
375 (lex> p q start end))))))
376
377;; reverse lexicographic
378(defgeneric revlex> (p q &optional start end)
379 (:documentation "Return T if P>Q with respect to reverse
380lexicographic order, NIL otherwise. The second returned value is T if
381P=Q, otherwise it is NIL. This is not and admissible monomial order
382because some sets do not have a minimal element. This order is useful
383in constructing other orders.")
[3483]384 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
[3472]385 (declare (type fixnum start end))
386 (do ((i (1- end) (1- i)))
387 ((< i start) (values nil t))
388 (declare (type fixnum i))
389 (cond
[3483]390 ((< (monom-elt p i) (monom-elt q i))
[3472]391 (return-from revlex> (values t nil)))
[3483]392 ((> (monom-elt p i) (monom-elt q i))
[3472]393 (return-from revlex> (values nil nil)))))))
394
395
396;; total degree, ties broken by reverse lexicographic
397(defgeneric grevlex> (p q &optional start end)
398 (:documentation "Return T if P>Q with respect to graded reverse
399lexicographic order, NIL otherwise. The second returned value is T if
400P=Q, otherwise it is NIL.")
[3483]401 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
[3472]402 (declare (type fixnum start end))
[3483]403 (let ((d1 (monom-total-degree p start end))
404 (d2 (monom-total-degree q start end)))
[3472]405 (declare (type fixnum d1 d2))
406 (cond
407 ((> d1 d2) (values t nil))
408 ((< d1 d2) (values nil nil))
409 (t
410 (revlex> p q start end))))))
411
412(defgeneric invlex> (p q &optional start end)
413 (:documentation "Return T if P>Q with respect to inverse
414lexicographic order, NIL otherwise The second returned value is T if
415P=Q, otherwise it is NIL.")
[3483]416 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
[3472]417 (declare (type fixnum start end))
418 (do ((i (1- end) (1- i)))
419 ((< i start) (values nil t))
420 (declare (type fixnum i))
421 (cond
[3483]422 ((> (monom-elt p i) (monom-elt q i))
[3472]423 (return-from invlex> (values t nil)))
[3483]424 ((< (monom-elt p i) (monom-elt q i))
[3472]425 (return-from invlex> (values nil nil)))))))
426
427(defun reverse-monomial-order (order)
428 "Create the inverse monomial order to the given monomial order ORDER."
[3483]429 #'(lambda (p q &optional (start 0) (end (monom-dimension q)))
[3472]430 (declare (type monom p q) (type fixnum start end))
431 (funcall order q p start end)))
432
433;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
434;;
435;; Order making functions
436;;
437;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
438
439;; This returns a closure with the same signature
440;; as all orders such as #'LEX>.
[3487]441(defun make-elimination-order-factory-1 (&optional (secondary-elimination-order #'lex>))
[3472]442 "It constructs an elimination order used for the 1-st elimination ideal,
443i.e. for eliminating the first variable. Thus, the order compares the degrees of the
444first variable in P and Q first, with ties broken by SECONDARY-ELIMINATION-ORDER."
[3483]445 #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
[3472]446 (declare (type monom p q) (type fixnum start end))
447 (cond
[3483]448 ((> (monom-elt p start) (monom-elt q start))
[3472]449 (values t nil))
[3483]450 ((< (monom-elt p start) (monom-elt q start))
[3472]451 (values nil nil))
452 (t
453 (funcall secondary-elimination-order p q (1+ start) end)))))
454
455;; This returns a closure which is called with an integer argument.
456;; The result is *another closure* with the same signature as all
457;; orders such as #'LEX>.
[3486]458(defun make-elimination-order-factory (&optional
[3472]459 (primary-elimination-order #'lex>)
460 (secondary-elimination-order #'lex>))
461 "Return a function with a single integer argument K. This should be
462the number of initial K variables X[0],X[1],...,X[K-1], which precede
463remaining variables. The call to the closure creates a predicate
464which compares monomials according to the K-th elimination order. The
465monomial orders PRIMARY-ELIMINATION-ORDER and
466SECONDARY-ELIMINATION-ORDER are used to compare the first K and the
467remaining variables, respectively, with ties broken by lexicographical
468order. That is, if PRIMARY-ELIMINATION-ORDER yields (VALUES NIL T),
469which indicates that the first K variables appear with identical
470powers, then the result is that of a call to
471SECONDARY-ELIMINATION-ORDER applied to the remaining variables
472X[K],X[K+1],..."
473 #'(lambda (k)
474 (cond
475 ((<= k 0)
476 (error "K must be at least 1"))
477 ((= k 1)
[3485]478 (make-elimination-order-factory-1 secondary-elimination-order))
[3472]479 (t
[3483]480 #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
[3472]481 (declare (type monom p q) (type fixnum start end))
482 (multiple-value-bind (primary equal)
483 (funcall primary-elimination-order p q start k)
484 (if equal
485 (funcall secondary-elimination-order p q k end)
486 (values primary nil))))))))
487
[3531]488(defclass term (monom)
489 ((coeff :initarg :coeff :accessor term-coeff))
490 (:default-initargs :coeff nil)
491 (:documentation "Implements a term, i.e. a product of a scalar
492and powers of some variables, such as 5*X^2*Y^3."))
493
494(defmethod print-object ((self term) stream)
495 (print-unreadable-object (self stream :type t :identity t)
496 (with-accessors ((exponents monom-exponents)
[3532]497 (coeff term-coeff))
[3531]498 self
499 (format stream "EXPONENTS=~A COEFF=~A"
500 exponents coeff))))
501
[3542]502(defmethod universal-equalp ((term1 term) (term2 term))
503 "Returns T if TERM1 and TERM2 are equal as MONOM, and coefficients
504are UNIVERSAL-EQUALP."
[3540]505 (and (call-next-method)
506 (universal-equalp (term-coeff term1) (term-coeff term2))))
[3531]507
[3533]508(defmethod update-instance-for-different-class :after ((old monom) (new term) &key)
509 (setf (term-coeff new) 1))
[3531]510
[3538]511(defmethod term-multiply-by ((self term) (other term))
[3531]512 "Destructively multiply terms SELF and OTHER and store the result into SELF.
513It returns SELF."
[3538]514 (setf (term-coeff self) (universal-multiply-by (term-coeff self) (scalar-coeff other))))
[3531]515
[3539]516(defmethod term-left-tensor-product-by ((self term) (other term))
517 (setf (term-coeff self) (universal-multiply-by (term-coeff self) (term-coeff other)))
[3531]518 (call-next-method))
519
[3540]520(defmethod term-right-tensor-product-by ((self term) (other term))
[3533]521 (setf (term-coeff self) (multiply-by (term-coeff self) (term-coeff other)))
[3531]522 (call-next-method))
523
[3533]524(defmethod monom-divide-by ((self term) (other term))
[3531]525 "Destructively divide term SELF by OTHER and store the result into SELF.
526It returns SELF."
[3533]527 (setf (term-coeff self) (divide-by (term-coeff self) (term-coeff other)))
[3531]528 (call-next-method))
529
[3533]530(defmethod monom-unary-minus ((self term))
531 (setf (term-coeff self) (monom-unary-minus (term-coeff self)))
[3531]532 self)
533
[3533]534(defmethod monom-multiply ((term1 term) (term2 term))
[3531]535 "Non-destructively multiply TERM1 by TERM2."
[3533]536 (monom-multiply-by (copy-instance term1) (copy-instance term2)))
[3531]537
[3533]538(defmethod monom-multiply ((term1 number) (term2 monom))
[3531]539 "Non-destructively multiply TERM1 by TERM2."
[3533]540 (monom-multiply term1 (change-class (copy-instance term2) 'term)))
[3531]541
[3533]542(defmethod monom-zerop ((self term))
543 (zerop (term-coeff self)))
Note: See TracBrowser for help on using the repository browser.