Daniel-Nikpayuk_SICP-Solutions/Chapter 1/1.3/exercise-1.29 (Simpson's Rule)/exercise.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Copyright 2015 Daniel Nikpayuk
;;
;; This file is part of SICP Solutions.
;;
;; SICP Solutions is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
;;
;; SICP Solutions is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License along with SICP Solutions. If not, see
;; <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (cube x) (* x x x))

(define (integral f a b n)
 (define (simpson h)
  (define (scalar k) (if (= (remainder k 2) 0) 2 4))
  (define (sum acc k)
   (cond
    ((> k n) acc)
    (else (sum (+ acc (* (scalar k) (f (+ a (* k h))) )) (+ k 1)))
   )
  )
  (/ (* h (sum 0 0)) 3.0)
 )
 (display (simpson (/ (- b a) n)))
 (newline)
)

(integral cube 0 1 100)
(integral cube 0 1 100)
(integral cube 0 1 1000)


