# SICP 2.5 exercises cont. 2

**Posted:**February 10, 2013

**Filed under:**Improving, SICP Leave a comment

**2.87**

(define (zero-terms? term-list) (cond ((empty-termlist? term-list) #t) ((not (= 0 (coeff (first-term term-list)))) #f) (else (zero-terms? (rest-terms term-list))))) (put '=zero? '(polynomial) (lambda (p) (zero-terms? (term-list p))))

Decently straightforward.

**2.88**

Define subtraction in terms of generic add and generic negate. Then implement the negation for polynomials.

(define (sub x y) (add x (negate y))) (define (negate-terms term-list) (if (empty-termlist? term-list) (the-empty-termlist) (cons (make-term (order (first-term term-list)) (- (coeff (first-term term-list)))) (negate-terms (rest-terms term-list))))) (define (negate-poly p) (make-polynomial (variable p) (negate-terms (term-list p))))

It’s Chinese New Year so I had some stuff to do, like eating lots.

Advertisements