sicp-ex-2.95



<< Previous exercise (2.94) | Index | Next exercise (2.96) >>


 (define P1 (make-polynomial 'x '((2 1) (1 -2) (0 1)))) 
 (define P2 (make-polynomial 'x '((2 11) (0 7)))) 
 (define P3 (make-polynomial 'x '((1 13) (0 5)))) 
  
 (define Q1 (mul P1 P2)) 
 (define Q2 (mul P1 P3)) 
  
 (greatest-common-divisor Q1 Q2) 
 ;; Value: (polynomial x (2 1458/169) (1 -2916/169) (0 1458/169)) 
  
 ;; So what happened? Why do we get such a strange result? 
  
 ;; When gcd-terms is applied to the terms of Q1 and Q2, it returnes another call 
 ;; of gcd-terms taking the terms of Q2 and the remainder terms of Q1 
 ;; divided by Q2 as its arguments. Unfortunately the remainder terms have 
 ;; nonintegers as coefficients. That’s why the final result has noninteger 
 ;; coefficients. 

https://wqzhang.wordpress.com/2009/07/09/sicp-exercise-2-95/ (link broken)