Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; a is a polynomial and b is a polynomial (list of terms)
- ;; poly+term* can add poly+terms
- (define (poly+poly* a b temp) (if (null? b) temp (poly+poly* (poly+term* a (car b)) (cdr
- b) (poly+term* a (carb))))))
- ;;returns a+b
- ;;multiplies a polynomial by a term
- (define (poly-term* t a temp) (if (null? a) temp (poly-term* t (cdr a) (map (lambda (x)
- ((make-term (x) (+ (pow-of x) (pow-of (car a))) (* (coef-of x) (coef-of (car a)))))
- a))))
- ;; foil out a and b using poly-term*
- ;; returns a list of lists
- (define (foil* a b temp) (if (null? a) temp (foil* (poly-term* (cdr a) b) cons(
- (poly-term* (car a) b) temp))))
- ;;simplify foil
- (define (foil** a b) (foil* a b '()))
- ;;now to simplify polynomial using poly+poly*
- (define (simplify lst temp) (if (null? (car (car lst))) temp (simplify (cdr lst) cons(
- (poly+poly* (car lst) (car (cdr lst)) '()) '())))
- ;; now multiply will return a*b simplified
- (define (multiply a b) (simplify (foil** a b) '()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement