Changeset 4457 for branches/f4grobner
- Timestamp:
- 2016-06-13T20:28:56-07:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/f4grobner/polynomial.lisp
r4456 r4457 76 76 77 77 (defclass poly (ring) 78 ((dimension :initform nil 79 :initarg :dimension 80 :accessor poly-dimension 81 :documentation "Shared dimension of all terms, the number of variables") 82 (termlist :initform nil :initarg :termlist :accessor poly-termlist 78 ((termlist :initform nil :initarg :termlist :accessor poly-termlist 83 79 :documentation "List of terms.") 84 80 (order :initform #'lex> :initarg :order :accessor poly-term-order 85 81 :documentation "Monomial/term order.")) 86 (:default-initargs : dimension nil :termlist nil :order #'lex>)82 (:default-initargs :termlist nil :order #'lex>) 87 83 (:documentation "A polynomial with a list of terms TERMLIST, ordered 88 84 according to term order ORDER, which defaults to LEX>.")) … … 90 86 (defmethod print-object ((self poly) stream) 91 87 (print-unreadable-object (self stream :type t :identity t) 92 (with-accessors ((dimension poly-dimension) 93 (termlist poly-termlist) 88 (with-accessors ((termlist poly-termlist) 94 89 (order poly-term-order)) 95 90 self 96 (format stream " DIMENSION=~ATERMLIST=~A ORDER=~A"97 dimensiontermlist order))))91 (format stream "TERMLIST=~A ORDER=~A" 92 termlist order)))) 98 93 99 94 (defmethod copy-instance :around ((object poly) &rest initargs &key &allow-other-keys) … … 115 110 self)) 116 111 112 (defgeneric poly-dimension (object) 113 (:documentation "The number of variables in the polynomial OBJECT") 114 (:method ((object poly)) 115 (monom-dimension (leading-monomial object)))) 116 117 117 (defgeneric poly-insert-term (self term) 118 118 (:documentation "Insert a term TERM into SELF before all other 119 119 terms. Order is not enforced.") 120 120 (:method ((self poly) (term term)) 121 (cond ((null (poly-dimension self)) 122 (setf (poly-dimension self) (monom-dimension term))) 123 (t (assert (= (poly-dimension self) (monom-dimension term))))) 121 (with-slots (termlist) 122 self 123 (unless (endp termlist) 124 (assert (= (monom-dimension (car termlist)) (monom-dimension term))))) 124 125 (push term (poly-termlist self)) 125 126 self)) … … 133 134 (:documentation "Append a term TERM to SELF after all other terms. Order is not enforced.") 134 135 (:method ((self poly) (term term)) 135 (cond ((null (poly-dimension self)) 136 (setf (poly-dimension self) (monom-dimension term))) 137 (t (assert (= (poly-dimension self) (monom-dimension term))))) 138 (setf (cdr (last (poly-termlist self))) (list term)) 136 (with-slots (termlist) 137 self 138 (unless (endp termlist) 139 (assert (= (monom-dimension (car termlist)) (monom-dimension term)))) 140 (setf (cdr (last (poly-termlist self))) (list term))) 139 141 self)) 140 142 … … 182 184 (defmethod update-instance-for-different-class :after ((old term) (new poly) &key) 183 185 "Converts OLD of class TERM to a NEW of class POLY, by making it into a 1-element TERMLIST." 184 (reinitialize-instance new 185 :dimension (monom-dimension old) 186 :termlist (list old))) 186 (reinitialize-instance new :termlist (list old))) 187 187 188 188 (defmethod update-instance-for-different-class :after ((old monom) (new poly) &key) 189 189 "Converts OLD of class MONOM to a NEW of class POLY, by making it into a 1-element TERMLIST." 190 (reinitialize-instance new 191 :dimension (monom-dimension old) 192 :termlist (list (change-class old 'term)))) 190 (reinitialize-instance new :termlist (list (change-class old 'term)))) 193 191 194 192 (defmethod universal-equalp ((self poly) (other poly)) 195 193 "Implements equality of polynomials." 196 (and (eql (poly-dimension self) (poly-dimension other)) 197 (every #'universal-equalp (poly-termlist self) (poly-termlist other)) 198 (eq (poly-term-order self) (poly-term-order other)))) 194 (and 195 ;(eql (poly-dimension self) (poly-dimension other)) 196 (every #'universal-equalp (poly-termlist self) (poly-termlist other)) 197 (eq (poly-term-order self) (poly-term-order other)))) 199 198 200 199 (defgeneric leading-term (object) … … 597 596 (t (list prod))))) 598 597 (poly-termlist self))) 599 (incf (poly-dimension self) (monom-dimension other))600 598 self) 601 599 … … 608 606 (t (list prod))))) 609 607 (poly-termlist self))) 610 (incf (poly-dimension self) (monom-dimension other))611 608 self) 612 609 … … 741 738 "Ensures that the number of variables in VARS maches the polynomial dimension of the 742 739 polynomial SELF." 743 (with-slots (dimension) 744 self 740 (let ((dimension (poly-dimension self))) 745 741 (assert (= (length vars) dimension) 746 742 nil … … 764 760 765 761 (defmethod make-zero-for ((self poly)) 766 (make-instance 'poly :dimension (poly-dimension self)))762 (make-instance 'poly)) 767 763 768 764 (defmethod make-unit-for ((self poly))
Note:
See TracChangeset
for help on using the changeset viewer.