Exercise 1.31:
The sum procedure is only the simplest of a vast number of similar
abstractions that can be captured as higher-order procedures. Write an analogous
procedure called product that returns the product of the values of a
function at points over a given range. Show how to define factorial in
terms of product. Also use product to compute approximations to
π using the formula
π
4
=
2
⋅
4
⋅
4
⋅
6
⋅
6
⋅
8
⋅
⋯
3
⋅
3
⋅
5
⋅
5
⋅
7
⋅
7
⋅
⋯
.
If your product procedure generates a recursive process, write one that
generates an iterative process. If it generates an iterative process, write
one that generates a recursive process.
练习 1.31:
sum 过程只是大量类似抽象中最简单的一个,这些抽象都可以用高阶过程来捕捉。写出一个类似的称为 product 的过程,它返回给定范围内各点处某函数值的乘积。说明如何用 product 来定义 factorial。同时用 product 按如下公式计算 π 的近似值:
π/4 = (2·4·4·6·6·8·⋯) / (3·3·5·5·7·7·⋯)
若你的 product 过程产生递归型计算过程,请再写一个产生迭代型计算过程的版本;若它产生迭代型计算过程,则写一个产生递归型计算过程的版本。