anchor.diff:                    for q1 in (reverse qq)
                     collect (cons q1 p0))))))
   
  -(defun polydiv (dividend divisor)
  -  "build an expression tree representing the structure of two-polynomial division"
  -  (labels ((stp (coef xyz pn)
  -             (cons coef
  -                   (loop for p in pn
  -                      for x in (reverse xyz)
  -                      collect (cons x (cons 'times p))))))
  -    (loop for a in dividend
  -       for x in (cons nil divisor)
  -       as px = nil then stps
  -       collecting x into xyz
  -       collecting (stp a (cdr xyz) px) into stps
  -       finally (return stps))))
  -  
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ;; CLOS definitions
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
positive.code:          as r = (g* gf px base)
           finally (return r))))
  
  
  (defmethod gdiv ((gf gf) dividend divisor)
    (let* ((numsym (1- (length divisor)))
           (dividend (rightp dividend (cdr divisor)))
           (divisor (rightp (cdr divisor) dividend)))
      (labels ((reduce-expr (e)
                 (cond
                   ((not (consp e)) e)
                   ((equal 'times (cadr e))
                    (if (zerop (caddr e)) 0
                        (g* gf (car e) (reduce (lambda (x y) (g+ gf x y)) (loop for n in (cddr e) collect (reduce-expr n))))))
                   ((consp (cadr e))
                    (reduce (lambda (x y) (g+ gf x y)) (loop for n in e collect (reduce-expr n))))
                   (t (g+ gf (car e) (reduce-expr (cadr e)))))))
        (let ((res (mapcar #'reduce-expr (polydiv dividend divisor))))
          (values (subseq res 0 (- (length res) numsym))
                  (subseq res (- (length res) numsym)))))))
  
  
negative.code: (defun rs-encode (gf m n)
    (multiple-value-bind (p q) (gdiv gf m (rs-generator gf n))
      (append m q)))
  
  ;; test cases
  ;; [18,52,86,00,00],[1,3,2] -> [18, 2, 116, 152, 232]
  ;; [18,52,86,77,00,00,00],[1,3,2,4] -> [18, 2, 116, 157, 90, 234, 78]
  