sicp-ex-2.87



<< Previous exercise (2.86) | Index | Next exercise (2.88) >>


meterogan

  
  
  
 ;; add into polynomial package 
 (define (zero-poly? poly) 
   (define (zero-terms? termlist) 
     (or (empty-termlist? termlist) 
         (and (=zero? (coeff (first-term termlist))) 
              (zero-terms? (rest-terms termlist))))) 
   (zero-terms? (term-list poly))) 

Siki

The coefficient of a term can be either a number or a polynomial (Actually a number is a special polynomial with zero order). If it's number, we use the predicate (= x 0); If it's represented as a polynomial, it cannot be zero. The polynomial representation we adopt does not contain zero terms.

  
 ;;to be installed in polynomial package 
 (define (=zero? x) 
   (define (poly? x) 
     (pair? x)) 
   (cond ((number? x) (= x 0)) 
         ((poly? x) false) 
         (else (error "Unknown type")))) 
  
 (put '=zero? 'polynomial =zero?)