Changeset 3731
- Timestamp:
- 2015-09-10T16:51:18-07:00 (9 years ago)
- Location:
- branches/f4grobner/.junk
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/.junk/monomial.lisp
r2441 r3731 204 204 "A human-readable representation of a monomial M as a list of exponents." 205 205 (coerce m 'list)) 206 207 (defclass term (monom) 208 () 209 (:documentation "Implements a term, i.e. a product of a scalar 210 and powers of some variables, such as 5*X^2*Y^3.")) 211 212 (defmethod print-object ((self term) stream) 213 (print-unreadable-object (self stream :type t :identity t) 214 (with-accessors ((exponents monom-exponents) 215 (coeff scalar-coeff)) 216 self 217 (format stream "EXPONENTS=~A COEFF=~A" 218 exponents coeff)))) 219 220 221 (defmethod r-equalp ((term1 term) (term2 term)) 222 (when (r-equalp (scalar-coeff term1) (scalar-coeff term2)) 223 (call-next-method))) 224 225 (defmethod update-instance-for-different-class :after ((old monom) (new scalar) &key) 226 (setf (scalar-coeff new) 1)) 227 228 (defmethod multiply-by :before ((self term) (other term)) 229 "Destructively multiply terms SELF and OTHER and store the result into SELF. 230 It returns SELF." 231 (setf (scalar-coeff self) (multiply-by (scalar-coeff self) (scalar-coeff other)))) 232 233 (defmethod left-tensor-product-by ((self term) (other term)) 234 (setf (scalar-coeff self) (multiply-by (scalar-coeff self) (scalar-coeff other))) 235 (call-next-method)) 236 237 (defmethod right-tensor-product-by ((self term) (other term)) 238 (setf (scalar-coeff self) (multiply-by (scalar-coeff self) (scalar-coeff other))) 239 (call-next-method)) 240 241 (defmethod left-tensor-product-by ((self term) (other monom)) 242 (call-next-method)) 243 244 (defmethod right-tensor-product-by ((self term) (other monom)) 245 (call-next-method)) 246 247 (defmethod divide-by ((self term) (other term)) 248 "Destructively divide term SELF by OTHER and store the result into SELF. 249 It returns SELF." 250 (setf (scalar-coeff self) (divide-by (scalar-coeff self) (scalar-coeff other))) 251 (call-next-method)) 252 253 (defmethod unary-minus ((self term)) 254 (setf (scalar-coeff self) (unary-minus (scalar-coeff self))) 255 self) 256 257 (defmethod r* ((term1 term) (term2 term)) 258 "Non-destructively multiply TERM1 by TERM2." 259 (multiply-by (copy-instance term1) (copy-instance term2))) 260 261 (defmethod r* ((term1 number) (term2 monom)) 262 "Non-destructively multiply TERM1 by TERM2." 263 (r* term1 (change-class (copy-instance term2) 'term))) 264 265 (defmethod r* ((term1 number) (term2 term)) 266 "Non-destructively multiply TERM1 by TERM2." 267 (setf (scalar-coeff term2) 268 (r* term1 (scalar-coeff term2))) 269 term2) 270 271 (defmethod r-zerop ((self term)) 272 (r-zerop (scalar-coeff self)))
Note:
See TracChangeset
for help on using the changeset viewer.