a. Implement this algorithm as a procedure
that takes two term lists
as arguments and returns a list
, which are
reduced to lowest terms via the algorithm given above. Also write a procedure
, analogous to
, that checks to see if the two
have the same variable. If so,
strips off the variable and passes the problem to
, then reattaches the variable to the two term lists supplied by
b. Define a procedure analogous to
that does what the original
did for integers:
(define (reduce-integers n d) (let ((g (gcd n d))) (list (/ n g) (/ d g))))
as a generic operation that calls
to dispatch to either
(for polynomial arguments) or
arguments). You can now easily make the rational-arithmetic package reduce fractions to lowest terms by having
before combining the given numerator and denominator to form a rational number. The system now handles rational expressions in either integers or polynomials. To test your program, try the example at the beginning of this extended exercise:
(define p1 (make-polynomial 'x '((1 1)(0 1)))) (define p2 (make-polynomial 'x '((3 1)(0 -1)))) (define p3 (make-polynomial 'x '((1 1)))) (define p4 (make-polynomial 'x '((2 1)(0 -1)))) (define rf1 (make-rational p1 p2)) (define rf2 (make-rational p3 p4)) (add rf1 rf2)
See if you get the correct answer, correctly reduced to lowest terms.
The GCD computation is at the heart of any system that does operations on rational functions. The algorithm used above, although mathematically straightforward, is extremely slow. The slowness is due partly to the large number of division operations and partly to the enormous size of the intermediate coefficients generated by the pseudodivisions. One of the active areas in the development of algebraic-manipulation systems is the design of better algorithms for computing polynomial GCDs.
There are no comments yet.
You must log in to post a comment.Login