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

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

* empty log message *

File size: 21.4 KB
Line 
1;;; -*- Mode: Lisp -*-
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
22(defpackage "MONOM"
23 (:use :cl :copy)
24 (:export "MONOM"
25 "TERM"
26 "EXPONENT"
27 "MONOM-DIMENSION"
28 "MONOM-EXPONENTS"
29 "UNIVERSAL-EQUALP"
30 "MONOM-ELT"
31 "TOTAL-DEGREE"
32 "SUGAR"
33 "MULTIPLY-BY"
34 "DIVIDE-BY"
35 "DIVIDE"
36 "MULTIPLY-2"
37 "MULTIPLY"
38 "DIVIDES-P"
39 "DIVIDES-LCM-P"
40 "LCM-DIVIDES-LCM-P"
41 "LCM-EQUAL-LCM-P"
42 "DIVISIBLE-BY-P"
43 "REL-PRIME-P"
44 "UNIVERSAL-LCM"
45 "UNIVERSAL-GCD"
46 "DEPENDS-P"
47 "LEFT-TENSOR-PRODUCT-BY"
48 "RIGHT-TENSOR-PRODUCT-BY"
49 "LEFT-CONTRACT"
50 "MAKE-MONOM-VARIABLE"
51 "->LIST"
52 "LEX>"
53 "GRLEX>"
54 "REVLEX>"
55 "GREVLEX>"
56 "INVLEX>"
57 "REVERSE-MONOMIAL-ORDER"
58 "MAKE-ELIMINATION-ORDER-FACTORY"
59 "TERM-COEFF"
60 "UNARY-MINUS"
61 "UNIVERSAL-ZEROP")
62 (:documentation
63 "This package implements basic operations on monomials, including
64various monomial orders.
65
66DATA STRUCTURES: Conceptually, monomials can be represented as lists:
67
68 monom: (n1 n2 ... nk) where ni are non-negative integers
69
70However, lists may be implemented as other sequence types, so the
71flexibility to change the representation should be maintained in the
72code to use general operations on sequences whenever possible. The
73optimization for the actual representation should be left to
74declarations and the compiler.
75
76EXAMPLES: Suppose that variables are x and y. Then
77
78 Monom x*y^2 ---> (1 2) "))
79
80(in-package :monom)
81
82(proclaim '(optimize (speed 0) (space 0) (safety 3) (debug 0)))
83
84(deftype exponent ()
85 "Type of exponent in a monomial."
86 'fixnum)
87
88(defclass monom ()
89 ((exponents :initarg :exponents :accessor monom-exponents
90 :documentation "The powers of the variables."))
91 ;; default-initargs are not needed, they are handled by SHARED-INITIALIZE
92 ;;(:default-initargs :dimension 'foo :exponents 'bar :exponent 'baz)
93 (:documentation
94 "Implements a monomial, i.e. a product of powers
95of variables, like X*Y^2."))
96
97(defmethod print-object ((self monom) stream)
98 (print-unreadable-object (self stream :type t :identity t)
99 (with-accessors ((exponents monom-exponents))
100 self
101 (format stream "EXPONENTS=~A"
102 exponents))))
103
104(defmethod initialize-instance :after ((self monom)
105 &key
106 (dimension 0 dimension-supplied-p)
107 (exponents nil exponents-supplied-p)
108 (exponent 0)
109 &allow-other-keys
110 )
111 "The following INITIALIZE-INSTANCE method allows instance initialization
112of a MONOM in a style similar to MAKE-ARRAY, e.g.:
113
114 (MAKE-INSTANCE 'MONOM :EXPONENTS '(1 2 3)) --> #<MONOM EXPONENTS=#(1 2 3)>
115 (MAKE-INSTANCE 'MONOM :DIMENSION 3) --> #<MONOM EXPONENTS=#(0 0 0)>
116 (MAKE-INSTANCE 'MONOM :DIMENSION 3 :EXPONENT 7) --> #<MONOM EXPONENTS=#(7 7 7)>
117
118If both DIMENSION and EXPONENTS are supplied, they must be compatible,
119i.e. the length of EXPONENTS must be equal DIMENSION. If EXPONENTS
120is not supplied, a monom with repeated value EXPONENT is created.
121By default EXPONENT is 0, which results in a constant monomial.
122"
123 (cond
124 (exponents-supplied-p
125 (when (and dimension-supplied-p
126 (/= dimension (length exponents)))
127 (error "EXPONENTS (~A) must have supplied length DIMENSION (~A)"
128 exponents dimension))
129 (let ((dim (length exponents)))
130 (setf (slot-value self 'exponents) (make-array dim :initial-contents exponents))))
131 (dimension-supplied-p
132 ;; when all exponents are to be identical
133 (setf (slot-value self 'exponents) (make-array (list dimension)
134 :initial-element exponent
135 :element-type 'exponent)))
136 (t
137 (error "Initarg DIMENSION or EXPONENTS must be supplied."))))
138
139(defgeneric monom-dimension (m)
140 (:method ((m monom))
141 (length (monom-exponents m))))
142
143(defgeneric universal-equalp (object1 object2)
144 (:documentation "Returns T iff OBJECT1 and OBJECT2 are equal.")
145 (:method ((object1 cons) (object2 cons)) (every #'universal-equalp object1 object2))
146 (:method ((object1 number) (object2 number)) (= object1 object2))
147 (:method ((m1 monom) (m2 monom))
148 "Returns T iff monomials M1 and M2 have identical EXPONENTS."
149 (equalp (monom-exponents m1) (monom-exponents m2))))
150
151(defgeneric monom-elt (m index)
152 (:documentation "Return the power in the monomial M of variable number INDEX.")
153 (:method ((m monom) index)
154 "Return the power in the monomial M of variable number INDEX."
155 (with-slots (exponents)
156 m
157 (elt exponents index))))
158
159(defgeneric (setf monom-elt) (new-value m index)
160 (:documentation "Set the power in the monomial M of variable number INDEX.")
161 (:method (new-value (m monom) index)
162 (with-slots (exponents)
163 m
164 (setf (elt exponents index) new-value))))
165
166(defgeneric total-degree (m &optional start end)
167 (:documentation "Return the total degree of a monomoal M. Optinally, a range
168of variables may be specified with arguments START and END.")
169 (:method ((m monom) &optional (start 0) (end (monom-dimension m)))
170 (declare (type fixnum start end))
171 (with-slots (exponents)
172 m
173 (reduce #'+ exponents :start start :end end))))
174
175(defgeneric sugar (m &optional start end)
176 (:documentation "Return the sugar of a monomial M. Optinally, a range
177of variables may be specified with arguments START and END.")
178 (:method ((m monom) &optional (start 0) (end (monom-dimension m)))
179 (declare (type fixnum start end))
180 (total-degree m start end)))
181
182(defgeneric multiply-by (self other)
183 (:documentation "Multiply SELF by OTHER, return SELF.")
184 (:method ((self number) (other number)) (* self other))
185 (:method ((self monom) (other monom))
186 (with-slots ((exponents1 exponents))
187 self
188 (with-slots ((exponents2 exponents))
189 other
190 (unless (= (length exponents1) (length exponents2))
191 (error "Incompatible dimensions"))
192 (map-into exponents1 #'+ exponents1 exponents2)))
193 self))
194
195
196(defgeneric divide-by (self other)
197 (:documentation "Divide SELF by OTHER, return SELF.")
198 (:method ((self number) (other number)) (/ self other))
199 (:method ((self monom) (other monom))
200 (with-slots ((exponents1 exponents))
201 self
202 (with-slots ((exponents2 exponents))
203 other
204 (unless (= (length exponents1) (length exponents2))
205 (error "divide-by: Incompatible dimensions."))
206 (unless (every #'>= exponents1 exponents2)
207 (error "divide-by: Negative power would result."))
208 (map-into exponents1 #'- exponents1 exponents2)))
209 self))
210
211(defmethod copy-instance :around ((object monom) &rest initargs &key &allow-other-keys)
212 "An :AROUND method of COPY-INSTANCE. It replaces
213exponents with a fresh copy of the sequence."
214 (declare (ignore object initargs))
215 (let ((copy (call-next-method)))
216 (setf (monom-exponents copy) (copy-seq (monom-exponents copy)))
217 copy))
218
219(defun multiply-2 (object1 object2)
220 "Multiply OBJECT1 by OBJECT2"
221 (multiply-by (copy-instance object1) (copy-instance object2)))
222
223(defun multiply (&rest factors)
224 "Non-destructively multiply list FACTORS."
225 (cond ((endp factors) 1)
226 ((endp (rest factors)) (first factors))
227 (t (reduce #'multiply-2 factors :initial-value 1))))
228
229(defun divide (numerator &rest denominators)
230 "Non-destructively divide object NUMERATOR by product of DENOMINATORS."
231 (divide-by (copy-instance numerator) (apply #'multiply denominators)))
232
233(defgeneric divides-p (object1 object2)
234 (:documentation "Returns T if OBJECT1 divides OBJECT2.")
235 (:method ((m1 monom) (m2 monom))
236 "Returns T if monomial M1 divides monomial M2, NIL otherwise."
237 (with-slots ((exponents1 exponents))
238 m1
239 (with-slots ((exponents2 exponents))
240 m2
241 (every #'<= exponents1 exponents2)))))
242
243(defgeneric divides-lcm-p (object1 object2 object3)
244 (:documentation "Returns T if OBJECT1 divides LCM(OBJECT2,OBJECT3), NIL otherwise.")
245 (:method ((m1 monom) (m2 monom) (m3 monom))
246 "Returns T if monomial M1 divides LCM(M2,M3), NIL otherwise."
247 (with-slots ((exponents1 exponents))
248 m1
249 (with-slots ((exponents2 exponents))
250 m2
251 (with-slots ((exponents3 exponents))
252 m3
253 (every #'(lambda (x y z) (<= x (max y z)))
254 exponents1 exponents2 exponents3))))))
255
256(defgeneric lcm-divides-lcm-p (object1 object2 object3 object4)
257 (:method ((m1 monom) (m2 monom) (m3 monom) (m4 monom))
258 "Returns T if monomial LCM(M1,M2) divides LCM(M3,M4), NIL otherwise."
259 (with-slots ((exponents1 exponents))
260 m1
261 (with-slots ((exponents2 exponents))
262 m2
263 (with-slots ((exponents3 exponents))
264 m3
265 (with-slots ((exponents4 exponents))
266 m4
267 (every #'(lambda (x y z w) (<= (max x y) (max z w)))
268 exponents1 exponents2 exponents3 exponents4)))))))
269
270(defgeneric monom-lcm-equal-lcm-p (object1 object2 object3 object4)
271 (:method ((m1 monom) (m2 monom) (m3 monom) (m4 monom))
272 "Returns T if monomial LCM(M1,M2) equals LCM(M3,M4), NIL otherwise."
273 (with-slots ((exponents1 exponents))
274 m1
275 (with-slots ((exponents2 exponents))
276 m2
277 (with-slots ((exponents3 exponents))
278 m3
279 (with-slots ((exponents4 exponents))
280 m4
281 (every
282 #'(lambda (x y z w) (= (max x y) (max z w)))
283 exponents1 exponents2 exponents3 exponents4)))))))
284
285(defgeneric divisible-by-p (object1 object2)
286 (:documentation "Return T if OBJECT1 is divisible by OBJECT2.")
287 (:method ((m1 monom) (m2 monom))
288 "Returns T if monomial M1 is divisible by monomial M2, NIL otherwise."
289 (with-slots ((exponents1 exponents))
290 m1
291 (with-slots ((exponents2 exponents))
292 m2
293 (every #'>= exponents1 exponents2)))))
294
295(defgeneric rel-prime-p (object1 object2)
296 (:documentation "Returns T if objects OBJECT1 and OBJECT2 are relatively prime.")
297 (:method ((m1 monom) (m2 monom))
298 "Returns T if two monomials M1 and M2 are relatively prime (disjoint)."
299 (with-slots ((exponents1 exponents))
300 m1
301 (with-slots ((exponents2 exponents))
302 m2
303 (every #'(lambda (x y) (zerop (min x y))) exponents1 exponents2)))))
304
305(defgeneric universal-lcm (object1 object2)
306 (:documentation "Returns the multiple of objects OBJECT1 and OBJECT2.")
307 (:method ((m1 monom) (m2 monom))
308 "Returns least common multiple of monomials M1 and M2."
309 (with-slots ((exponents1 exponents))
310 m1
311 (with-slots ((exponents2 exponents))
312 m2
313 (let* ((exponents (copy-seq exponents1)))
314 (map-into exponents #'max exponents1 exponents2)
315 (make-instance 'monom :exponents exponents))))))
316
317
318(defgeneric universal-gcd (object1 object2)
319 (:documentation "Returns GCD of objects OBJECT1 and OBJECT2")
320 (:method ((object1 number) (object2 number)) (gcd object1 object2))
321 (:method ((m1 monom) (m2 monom))
322 "Returns greatest common divisor of monomials M1 and M2."
323 (with-slots ((exponents1 exponents))
324 m1
325 (with-slots ((exponents2 exponents))
326 m2
327 (let* ((exponents (copy-seq exponents1)))
328 (map-into exponents #'min exponents1 exponents2)
329 (make-instance 'monom :exponents exponents))))))
330
331(defgeneric depends-p (object k)
332 (:documentation "Returns T iff object OBJECT depends on variable K.")
333 (:method ((m monom) k)
334 "Return T if the monomial M depends on variable number K."
335 (declare (type fixnum k))
336 (with-slots (exponents)
337 m
338 (plusp (elt exponents k)))))
339
340(defgeneric left-tensor-product-by (self other)
341 (:documentation "Returns a tensor product SELF by OTHER, stored into
342 SELF. Return SELF.")
343 (:method ((self monom) (other monom))
344 (with-slots ((exponents1 exponents))
345 self
346 (with-slots ((exponents2 exponents))
347 other
348 (setf exponents1 (concatenate 'vector exponents2 exponents1))))
349 self))
350
351(defgeneric right-tensor-product-by (self other)
352 (:documentation "Returns a tensor product of OTHER by SELF, stored
353 into SELF. Returns SELF.")
354 (:method ((self monom) (other monom))
355 (with-slots ((exponents1 exponents))
356 self
357 (with-slots ((exponents2 exponents))
358 other
359 (setf exponents1 (concatenate 'vector exponents1 exponents2))))
360 self))
361
362(defgeneric left-contract (self k)
363 (:documentation "Drop the first K variables in object SELF.")
364 (:method ((self monom) k)
365 "Drop the first K variables in monomial M."
366 (declare (fixnum k))
367 (with-slots (exponents)
368 self
369 (setf exponents (subseq exponents k)))
370 self))
371
372(defun make-monom-variable (nvars pos &optional (power 1)
373 &aux (m (make-instance 'monom :dimension nvars)))
374 "Construct a monomial in the polynomial ring
375RING[X[0],X[1],X[2],...X[NVARS-1]] over the (unspecified) ring RING
376which represents a single variable. It assumes number of variables
377NVARS and the variable is at position POS. Optionally, the variable
378may appear raised to power POWER. "
379 (declare (type fixnum nvars pos power) (type monom m))
380 (with-slots (exponents)
381 m
382 (setf (elt exponents pos) power)
383 m))
384
385(defgeneric ->list (object)
386 (:method ((m monom))
387 "A human-readable representation of a monomial M as a list of exponents."
388 (coerce (monom-exponents m) 'list)))
389
390;; pure lexicographic
391(defgeneric lex> (p q &optional start end)
392 (:documentation "Return T if P>Q with respect to lexicographic
393order, otherwise NIL. The second returned value is T if P=Q,
394otherwise it is NIL.")
395 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
396 (declare (type fixnum start end))
397 (do ((i start (1+ i)))
398 ((>= i end) (values nil t))
399 (cond
400 ((> (monom-elt p i) (monom-elt q i))
401 (return-from lex> (values t nil)))
402 ((< (monom-elt p i) (monom-elt q i))
403 (return-from lex> (values nil nil)))))))
404
405;; total degree order, ties broken by lexicographic
406(defgeneric grlex> (p q &optional start end)
407 (:documentation "Return T if P>Q with respect to graded
408lexicographic order, otherwise NIL. The second returned value is T if
409P=Q, otherwise it is NIL.")
410 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
411 (declare (type monom p q) (type fixnum start end))
412 (let ((d1 (total-degree p start end))
413 (d2 (total-degree q start end)))
414 (declare (type fixnum d1 d2))
415 (cond
416 ((> d1 d2) (values t nil))
417 ((< d1 d2) (values nil nil))
418 (t
419 (lex> p q start end))))))
420
421;; reverse lexicographic
422(defgeneric revlex> (p q &optional start end)
423 (:documentation "Return T if P>Q with respect to reverse
424lexicographic order, NIL otherwise. The second returned value is T if
425P=Q, otherwise it is NIL. This is not and admissible monomial order
426because some sets do not have a minimal element. This order is useful
427in constructing other orders.")
428 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
429 (declare (type fixnum start end))
430 (do ((i (1- end) (1- i)))
431 ((< i start) (values nil t))
432 (declare (type fixnum i))
433 (cond
434 ((< (monom-elt p i) (monom-elt q i))
435 (return-from revlex> (values t nil)))
436 ((> (monom-elt p i) (monom-elt q i))
437 (return-from revlex> (values nil nil)))))))
438
439
440;; total degree, ties broken by reverse lexicographic
441(defgeneric grevlex> (p q &optional start end)
442 (:documentation "Return T if P>Q with respect to graded reverse
443lexicographic order, NIL otherwise. The second returned value is T if
444P=Q, otherwise it is NIL.")
445 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
446 (declare (type fixnum start end))
447 (let ((d1 (total-degree p start end))
448 (d2 (total-degree q start end)))
449 (declare (type fixnum d1 d2))
450 (cond
451 ((> d1 d2) (values t nil))
452 ((< d1 d2) (values nil nil))
453 (t
454 (revlex> p q start end))))))
455
456(defgeneric invlex> (p q &optional start end)
457 (:documentation "Return T if P>Q with respect to inverse
458lexicographic order, NIL otherwise The second returned value is T if
459P=Q, otherwise it is NIL.")
460 (:method ((p monom) (q monom) &optional (start 0) (end (monom-dimension p)))
461 (declare (type fixnum start end))
462 (do ((i (1- end) (1- i)))
463 ((< i start) (values nil t))
464 (declare (type fixnum i))
465 (cond
466 ((> (monom-elt p i) (monom-elt q i))
467 (return-from invlex> (values t nil)))
468 ((< (monom-elt p i) (monom-elt q i))
469 (return-from invlex> (values nil nil)))))))
470
471(defun reverse-monomial-order (order)
472 "Create the inverse monomial order to the given monomial order ORDER."
473 #'(lambda (p q &optional (start 0) (end (monom-dimension q)))
474 (declare (type monom p q) (type fixnum start end))
475 (funcall order q p start end)))
476
477;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
478;;
479;; Order making functions
480;;
481;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
482
483;; This returns a closure with the same signature
484;; as all orders such as #'LEX>.
485(defun make-elimination-order-factory-1 (&optional (secondary-elimination-order #'lex>))
486 "It constructs an elimination order used for the 1-st elimination ideal,
487i.e. for eliminating the first variable. Thus, the order compares the degrees of the
488first variable in P and Q first, with ties broken by SECONDARY-ELIMINATION-ORDER."
489 #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
490 (declare (type monom p q) (type fixnum start end))
491 (cond
492 ((> (monom-elt p start) (monom-elt q start))
493 (values t nil))
494 ((< (monom-elt p start) (monom-elt q start))
495 (values nil nil))
496 (t
497 (funcall secondary-elimination-order p q (1+ start) end)))))
498
499;; This returns a closure which is called with an integer argument.
500;; The result is *another closure* with the same signature as all
501;; orders such as #'LEX>.
502(defun make-elimination-order-factory (&optional
503 (primary-elimination-order #'lex>)
504 (secondary-elimination-order #'lex>))
505 "Return a function with a single integer argument K. This should be
506the number of initial K variables X[0],X[1],...,X[K-1], which precede
507remaining variables. The call to the closure creates a predicate
508which compares monomials according to the K-th elimination order. The
509monomial orders PRIMARY-ELIMINATION-ORDER and
510SECONDARY-ELIMINATION-ORDER are used to compare the first K and the
511remaining variables, respectively, with ties broken by lexicographical
512order. That is, if PRIMARY-ELIMINATION-ORDER yields (VALUES NIL T),
513which indicates that the first K variables appear with identical
514powers, then the result is that of a call to
515SECONDARY-ELIMINATION-ORDER applied to the remaining variables
516X[K],X[K+1],..."
517 #'(lambda (k)
518 (cond
519 ((<= k 0)
520 (error "K must be at least 1"))
521 ((= k 1)
522 (make-elimination-order-factory-1 secondary-elimination-order))
523 (t
524 #'(lambda (p q &optional (start 0) (end (monom-dimension p)))
525 (declare (type monom p q) (type fixnum start end))
526 (multiple-value-bind (primary equal)
527 (funcall primary-elimination-order p q start k)
528 (if equal
529 (funcall secondary-elimination-order p q k end)
530 (values primary nil))))))))
531
532(defclass term (monom)
533 ((coeff :initarg :coeff :accessor term-coeff))
534 (:default-initargs :coeff nil)
535 (:documentation "Implements a term, i.e. a product of a scalar
536and powers of some variables, such as 5*X^2*Y^3."))
537
538(defmethod update-instance-for-different-class :before ((old monom) (new term) &key (coeff 1))
539 "Converts OLD of class MONOM to a NEW of class TERM, initializing coefficient to COEFF."
540 (reinitialize-instance new :coeff coeff))
541
542(defmethod print-object ((self term) stream)
543 (print-unreadable-object (self stream :type t :identity t)
544 (with-accessors ((exponents monom-exponents)
545 (coeff term-coeff))
546 self
547 (format stream "EXPONENTS=~A COEFF=~A"
548 exponents coeff))))
549
550(defmethod universal-equalp ((term1 term) (term2 term))
551 "Returns T if TERM1 and TERM2 are equal as MONOM, and coefficients
552are UNIVERSAL-EQUALP."
553 (and (call-next-method)
554 (universal-equalp (term-coeff term1) (term-coeff term2))))
555
556(defmethod update-instance-for-different-class :after ((old monom) (new term) &key)
557 (setf (term-coeff new) 1))
558
559(defmethod multiply-by :before ((self term) (other term))
560 "Destructively multiply terms SELF and OTHER and store the result into SELF.
561It returns SELF."
562 (setf (term-coeff self) (multiply-by (term-coeff self) (term-coeff other))))
563
564(defmethod left-tensor-product-by :before ((self term) (other term))
565 (setf (term-coeff self) (multiply-by (term-coeff self) (term-coeff other))))
566
567(defmethod right-tensor-product-by :before ((self term) (other term))
568 (setf (term-coeff self) (multiply-by (term-coeff self) (term-coeff other))))
569
570(defmethod divide-by :before ((self term) (other term))
571 (setf (term-coeff self) (divide-by (term-coeff self) (term-coeff other))))
572
573(defgeneric unary-minus (self)
574 (:documentation "Negate object SELF and return it.")
575 (:method ((self number)) (- self))
576 (:method ((self term))
577 (setf (term-coeff self) (unary-minus (term-coeff self)))
578 self))
579
580(defgeneric universal-zerop (self)
581 (:documentation "Return T iff SELF is zero.")
582 (:method ((self number)) (zerop self))
583 (:method ((self term))
584 (universal-zerop (term-coeff self))))
Note: See TracBrowser for help on using the repository browser.