Function: math-poly-gcd-coefs
math-poly-gcd-coefs is a byte-compiled function defined in
calc-poly.el.gz.
Signature
(math-poly-gcd-coefs U V)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-poly.el.gz
;;; Compute the GCD of two univariate polynomial lists.
;;; Knuth section 4.6.1, algorithm C.
(defun math-poly-gcd-coefs (u v)
(let ((d (math-poly-gcd (math-poly-gcd-list u)
(math-poly-gcd-list v)))
(g 1) (h 1) (z 0) r delta)
(while (and u v (Math-zerop (car u)) (Math-zerop (car v)))
(setq u (cdr u) v (cdr v) z (1+ z)))
(or (eq d 1)
(setq u (math-poly-div-list u d)
v (math-poly-div-list v d)))
(while (progn
(setq delta (- (length u) (length v)))
(if (< delta 0)
(setq r u u v v r delta (- delta)))
(setq r (math-poly-pseudo-div u v))
(cdr r))
(setq u v
v (math-poly-div-list r (math-mul g (math-pow h delta)))
g (nth (1- (length u)) u)
h (if (<= delta 1)
(math-mul (math-pow g delta) (math-pow h (- 1 delta)))
(math-poly-div-exact (math-pow g delta)
(math-pow h (1- delta))))))
(setq v (if r
(list d)
(math-mul-list (math-poly-div-list v (math-poly-gcd-list v)) d)))
(if (math-guess-if-neg (nth (1- (length v)) v))
(setq v (math-mul-list v -1)))
(while (>= (setq z (1- z)) 0)
(setq v (cons 0 v)))
v))