Section 1.3 - Formulating Abstractions With Higer-Order Procedures

Section 1.3.1 - Procedures as Arguments

Exercise 1.29

Here is the implementation of Simpson’s Rule. Note that we defined h as a
procedure with no arguments since we haven’t learned about let yet.

And running it we can see that it converges faster than the previous solution:

Exercise 1.30

Exercise 1.31

product is very similar to sum:

And we can write the iterative version:

Exercise 1.32

This is a recursive version of accumulate:

We can use it to build sum and product:

And we can write the iterative version:

Exercise 1.33

We just skip the combiner if the predicate is not satisfied:

Then we can define the procedure that generates the sum of squares of primes
between a and b, and the procedure that generates the product of relative
primes less than n: