1 665c255d 2023-08-04 jrmu ;; Exercise 1.30. The sum procedure above generates a linear recursion. The procedure can be rewritten so that the sum is performed iteratively. Show how to do this by filling in the missing expressions in the following definition:
3 665c255d 2023-08-04 jrmu (define (sum term a next b)
4 665c255d 2023-08-04 jrmu (define (iter a result)
7 665c255d 2023-08-04 jrmu (iter (next a) (+ (term a) result))))
10 665c255d 2023-08-04 jrmu (define (integral f a b dx)
11 665c255d 2023-08-04 jrmu (define (add-dx x) (+ x dx))
12 665c255d 2023-08-04 jrmu (* (sum f (+ a (/ dx 2.0)) add-dx b)
15 665c255d 2023-08-04 jrmu (define (cube x) (* x x x))
17 665c255d 2023-08-04 jrmu (define (test-case actual expected)
18 665c255d 2023-08-04 jrmu (load-option 'format)
20 665c255d 2023-08-04 jrmu (format #t "Actual: ~A Expected: ~A" actual expected))
24 665c255d 2023-08-04 jrmu (test-case (integral cube 0.0 1.0 0.001) 0.25)