Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.98 KB | None | 0 0
  1. ;; a is a polynomial and b is a polynomial (list of terms)
  2. ;; poly+term* can add poly+terms
  3.  
  4. (define (poly+poly* a b temp) (if (null? b) temp (poly+poly* (poly+term* a (car b)) (cdr
  5.  
  6. b) (poly+term* a (carb))))))
  7.  
  8. ;;returns a+b
  9.  
  10. ;;multiplies a polynomial by a term
  11.  
  12. (define (poly-term* t a temp) (if (null? a) temp (poly-term* t (cdr a) (map (lambda (x)
  13.  
  14. ((make-term (x) (+ (pow-of x) (pow-of (car a))) (* (coef-of x) (coef-of (car a)))))
  15.  
  16. a))))
  17.  
  18. ;; foil out a and b using poly-term*
  19. ;; returns a list of lists
  20.  
  21. (define (foil* a b temp) (if (null? a) temp (foil* (poly-term* (cdr a) b) cons(
  22.  
  23. (poly-term* (car a) b) temp))))
  24.  
  25.  
  26. ;;simplify foil
  27.  
  28. (define (foil** a b) (foil* a b '()))
  29.  
  30. ;;now to simplify polynomial using poly+poly*
  31.  
  32. (define (simplify lst temp) (if (null? (car (car lst))) temp (simplify (cdr lst) cons(
  33.  
  34. (poly+poly* (car lst) (car (cdr lst)) '()) '())))
  35.  
  36. ;; now multiply will return a*b simplified
  37.  
  38. (define (multiply a b) (simplify (foil** a b) '()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement