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


Ignore:
Timestamp:
2016-06-13T20:28:56-07:00 (9 years ago)
Author:
Marek Rychlik
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/polynomial.lisp

    r4456 r4457  
    7676
    7777(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
    8379             :documentation "List of terms.")
    8480   (order :initform #'lex> :initarg :order :accessor poly-term-order
    8581          :documentation "Monomial/term order."))
    86   (:default-initargs :dimension nil :termlist nil :order #'lex>)
     82  (:default-initargs :termlist nil :order #'lex>)
    8783  (:documentation "A polynomial with a list of terms TERMLIST, ordered
    8884according to term order ORDER, which defaults to LEX>."))
     
    9086(defmethod print-object ((self poly) stream)
    9187  (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)
    9489                     (order poly-term-order))
    9590        self
    96       (format stream "DIMENSION=~A TERMLIST=~A ORDER=~A"
    97               dimension termlist order))))
     91      (format stream "TERMLIST=~A ORDER=~A"
     92              termlist order))))
    9893
    9994(defmethod copy-instance :around ((object poly)  &rest initargs &key &allow-other-keys)
     
    115110    self))
    116111
     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
    117117(defgeneric poly-insert-term (self term)
    118118  (:documentation "Insert a term TERM into SELF before all other
    119119terms. Order is not enforced.")
    120120  (: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)))))
    124125    (push term (poly-termlist self))
    125126    self))
     
    133134  (:documentation "Append a term TERM to SELF after all other terms. Order is not enforced.")
    134135  (: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)))
    139141    self))
    140142
     
    182184(defmethod update-instance-for-different-class :after ((old term) (new poly) &key)
    183185  "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)))
    187187
    188188(defmethod update-instance-for-different-class :after ((old monom) (new poly) &key)
    189189  "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))))
    193191 
    194192(defmethod universal-equalp ((self poly) (other poly))
    195193  "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))))
    199198
    200199(defgeneric leading-term (object)
     
    597596                        (t (list prod)))))
    598597                (poly-termlist self)))
    599   (incf (poly-dimension self) (monom-dimension other))
    600598  self)
    601599
     
    608606                        (t (list prod)))))
    609607                (poly-termlist self)))
    610   (incf (poly-dimension self) (monom-dimension other))
    611608  self)
    612609
     
    741738  "Ensures that the number of variables in VARS maches the polynomial dimension of the
    742739polynomial SELF."
    743   (with-slots (dimension)
    744       self
     740  (let ((dimension (poly-dimension self)))
    745741    (assert (= (length vars) dimension)
    746742            nil
     
    764760
    765761(defmethod make-zero-for ((self poly))
    766   (make-instance 'poly :dimension (poly-dimension self)))
     762  (make-instance 'poly))
    767763
    768764(defmethod make-unit-for ((self poly))
Note: See TracChangeset for help on using the changeset viewer.