Fix bug in poly-div and work on 2.95

main
Felix Martin 2020-12-08 19:16:44 -05:00
parent 7fbc842873
commit 6282f0aaab
1 changed files with 22 additions and 4 deletions

View File

@ -97,7 +97,7 @@
(let ((g (gcd n d)))
(if (eq? g 'nogcd)
(cons n d)
(cons (/ n g) (/ d g)))))
(cons (div n g) (div d g)))))
(define (add-rat x y)
(let ((new-n (add (mul (numer x) (denom y))
(mul (numer y) (denom x))))
@ -959,7 +959,7 @@
(term-list (contents terms)))
(cons term-type (map negate-term term-list))))
(if (empty-termlist? L1)
(list L1 L2)
(list L1 L1)
(let ((t1 (first-term L1)) ; dividend
(t2 (first-term L2))) ; divisor
(if (> (order t2) (order t1))
@ -987,14 +987,16 @@
(=zero?-terms (term-list p)))
(define (remainder-terms a b)
(cdr (div-terms a b)))
(cadr (div-terms a b)))
(define (gcd-terms a b)
; (display "GCD-TERMS") (display a) (display b) (newline)
(if (empty-termlist? b)
a
(gcd-terms b (remainder-terms a b))))
(define (gcd-poly p1 p2)
(display "GCD-POLY") (display p1) (display p2) (newline)
(if (same-variable? (variable p1) (variable p2))
(make-poly (variable p1)
(gcd-terms (term-list p1)
@ -1092,6 +1094,22 @@
(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)
(assert (greatest-common-divisor p1 p2)
(make-poly-sparse 'x '((2 -1) (1 1))))
(display "\nex-2.95\n")
(define p1 (make-poly-sparse 'x '((2 1) (1 -2) (0 1))))
(define p2 (make-poly-sparse 'x '((2 11) (0 7))))
(define p3 (make-poly-sparse 'x '((1 13) (0 5))))
(define q1 (mul p1 p2))
(define q2 (mul p1 p3))
(display q1) (newline)
(display q2) (newline)
(display (greatest-common-divisor q1 q2)) (newline)