;; A Polynomial is a (listof Number) ;; Interpretation: ;; - each list is a list of coefficients ;; - the exponent for each index, i, (starting from 0) of a list of length N ;; is N-i-1 ;; Data examples "4" (list 4) "x + 3" (list 1 3) "x^3 + 2x^2 + 3x + 4" (list 1 2 3 4) ;; der: Polynomial -> Polynomail ;; retuns the derivative of p (define (der p) ;; handles the case were there's a polynomial of at least 1 (local ((define (der2 p acc) (cond [(empty? (rest p)) empty] [else (cons (* acc (first p)) (der2 (rest p) (- acc 1)))]))) (cond [(= (length p) 1) (list 0)] [else (der2 p (- (length p) 1))]))) ;; Examples ;; d/dx 4 = 0 (equal? (der (list 4)) (list 0)) ;; d/dx x + 3 (equal? (der (list 1 3)) (list 1)) ;; d/x x^3 + 2x^2 + 3x + 4 = 3x^2 + 4x + 3 (equal? (der (list 1 2 3 4)) (list 3 4 3))