<< Previous exercise (2.95) | Index | Next exercise (2.97) >>
(define (pseudo-remainder-terms L1 L2) (let ((f1 (first-term L1)) (f2 (first-term L2))) (let ((o1 (order f1)) (o2 (order f2)) (c (coeff f2))) (let ((k (expt c (add 1 (sub o1 o2))))) (let ((k-terms (adjoin-term (make-term 0 k) (the-empty-termlist)))) (cadr (div-terms (mul-terms k-terms L1) L2))))))) (define (gcd-coeff terms) (define (coeff-list terms) (if (empty-termlist? terms) '() (cons (coeff (first-term terms)) (coeff-list (rest-terms terms))))) (apply gcd (coeff-list terms))) (define (gcd-terms L1 L2) (if (empty-termlist? L2) (let ((coeff-terms (adjoin-term (make-term 0 (gcd-coeff L1)) (the-empty-termlist)))) (car (div-terms L1 coeff-terms))) (gcd-terms L2 (pseudo-remainder-terms L1 L2))))
LisScheSic
The book mul-terms,div-terms all assume arguments to be list, so we should use (list (make-term 0 gcd-coeff)), etc. (also see Sphinxsky's implementation which I only checked that it uses adjoin-term to do the same thing as (list (make-term 0 gcd-coeff)).)