Implement 2.94
This commit is contained in:
@@ -986,6 +986,22 @@
|
|||||||
(else (=zero?-terms (rest-terms terms)))))
|
(else (=zero?-terms (rest-terms terms)))))
|
||||||
(=zero?-terms (term-list p)))
|
(=zero?-terms (term-list p)))
|
||||||
|
|
||||||
|
(define (remainder-terms a b)
|
||||||
|
(cdr (div-terms a b)))
|
||||||
|
|
||||||
|
(define (gcd-terms a b)
|
||||||
|
(if (empty-termlist? b)
|
||||||
|
a
|
||||||
|
(gcd-terms b (remainder-terms a b))))
|
||||||
|
|
||||||
|
(define (gcd-poly p1 p2)
|
||||||
|
(if (same-variable? (variable p1) (variable p2))
|
||||||
|
(make-poly (variable p1)
|
||||||
|
(gcd-terms (term-list p1)
|
||||||
|
(term-list p2)))
|
||||||
|
(error "Polys not in same var -- ADD-POLY"
|
||||||
|
(list p1 p2))))
|
||||||
|
|
||||||
;; interface to rest of the system
|
;; interface to rest of the system
|
||||||
(define (tag p) (attach-tag 'polynomial p))
|
(define (tag p) (attach-tag 'polynomial p))
|
||||||
(put 'add '(polynomial polynomial)
|
(put 'add '(polynomial polynomial)
|
||||||
@@ -996,6 +1012,8 @@
|
|||||||
(lambda (p1 p2) (tag (sub-poly p1 p2))))
|
(lambda (p1 p2) (tag (sub-poly p1 p2))))
|
||||||
(put 'div '(polynomial polynomial)
|
(put 'div '(polynomial polynomial)
|
||||||
(lambda (p1 p2) (div-poly p1 p2)))
|
(lambda (p1 p2) (div-poly p1 p2)))
|
||||||
|
(put 'greatest-comond-divisor '(polynomial polynomial)
|
||||||
|
(lambda (p1 p2) (tag (gcd-poly p1 p2))))
|
||||||
(put '=zero? '(polynomial) =zero?-poly)
|
(put '=zero? '(polynomial) =zero?-poly)
|
||||||
(put 'make 'poly-sparse
|
(put 'make 'poly-sparse
|
||||||
(lambda (var terms) (tag (make-poly-sparse var terms))))
|
(lambda (var terms) (tag (make-poly-sparse var terms))))
|
||||||
@@ -1071,3 +1089,9 @@
|
|||||||
|
|
||||||
(display "\nex-2.94 - polynomial gcd\n")
|
(display "\nex-2.94 - polynomial gcd\n")
|
||||||
|
|
||||||
|
(define (greatest-common-divisor x y) (apply-generic 'greatest-comond-divisor x y))
|
||||||
|
(define p1 (make-poly-sparse 'x '((4 1) (3 -1) (2 -2) (1 2))))
|
||||||
|
(define p2 (make-poly-sparse 'x '((3 1) (1 -1))))
|
||||||
|
(display (greatest-common-divisor p1 p2)) (newline)
|
||||||
|
|
||||||
|
(display "\nex-2.95\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user