Exercise 2.94: Using div-terms, implement
the procedure remainder-terms and use this to define gcd-terms as
above. Now write a procedure gcd-poly that computes the polynomial
GCD of two polys. (The procedure should signal an error if the two
polys are not in the same variable.) Install in the system a generic operation
greatest-common-divisor that reduces to gcd-poly for polynomials
and to ordinary gcd for ordinary numbers. As a test, try
(define p1
(make-polynomial
'x '((4 1) (3 -1) (2 -2) (1 2))))
(define p2
(make-polynomial
'x '((3 1) (1 -1))))
(greatest-common-divisor p1 p2)
and check your result by hand.
练习 2.94:利用 div-terms 实现 remainder-terms 过程,并用它按上面的方式定义 gcd-terms。然后编写过程 gcd-poly,用于计算两个多项式的多项式 GCD。(若两个多项式的变量不同,该过程应报错。)在系统中安装一个通用操作 greatest-common-divisor,对多项式归结为 gcd-poly,对普通数归结为普通的 gcd。作为测试,尝试
(define p1
(make-polynomial
'x '((4 1) (3 -1) (2 -2) (1 2))))
(define p2
(make-polynomial
'x '((3 1) (1 -1))))
(greatest-common-divisor p1 p2)
并手动验证结果。
(define p1
(make-polynomial
'x '((4 1) (3 -1) (2 -2) (1 2))))
(define p2
(make-polynomial
'x '((3 1) (1 -1))))
(greatest-common-divisor p1 p2)