Created
          October 28, 2012 14:40 
        
      - 
      
- 
        Save sunilnandihalli/3968777 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (defprotocol polynomial | |
| (eval-poly [this t]) | |
| (derivative [this]) | |
| (derivative [this n]) | |
| (coeffs [this])) | |
| (deftype poly [coeffs] | |
| polynomial | |
| (eval-poly [this t] | |
| (reduce #(+ (* %1 t) %2) 0.0 coeffs)) | |
| (derivative [this] | |
| (->poly (map #(* %1 %2) coeffs (range (count coeffs) 0 -1)))) | |
| (derivative [this n] | |
| (loop [c-poly this n-left n] | |
| (if-not (> n 0) c-poly | |
| (recur (derivative c-poly) (dec n))))) | |
| (coeffs [this] coeffs)) | 
        
      
            kumarshantanu
  
      
      
      commented 
        Oct 28, 2012 
      
    
  
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment