这次回顾第一章剩余全部习题。
学习资料:
https://github.com/DeathKing/Learning-SICP
https://mitpress.mit.edu/sites/default/files/sicp/index.html
https://www.bilibili.com/video/BV1Xx41117tr?from=search&seid=14983483066585274454
参考资料:
https://sicp.readthedocs.io/en/latest
参考资料:
https://sicp.readthedocs.io/en/latest
1.29(p39)
记
那么
从而得到代码:
1 | (define (sum term a next b) |
1 | 0.25000000000000044 |
1.30(p40)
1 | (define (sum term a next b) |
1.31(p40)
定义
那么
定义
代码如下:
1 | (define (product1 term a next b) |
结果如下:
1 | Factorial: |
1.32(p40)
1 | ; 递归 |
结果:
1 | Test for accumulate1 and sum: |
1.33(p40)
对之前的代码稍微修改即可,这里(a)的函数包含上下界$a,b$:
1 | ;; prime? |
结果如下:
1 | Test for a: 17 |
1.34(p44)
1 | (define (square x) |
结果如下:
1 | 4 |
1.35(p47)
求解方程可得:
所以结论成立。
对应代码:
1 | (define tolerance 0.00001) |
结果如下:
1 | 1.6180327868852458 |
1.36(p47)
1 | (define tolerance 0.00001) |
结果如下:
1 | 平均阻尼情形: |
1.37(p47)
1 | (define (cont-frac1 n d k) |
结果如下:
1 | 0.6179775280898876 |
1.38(p47)
$D_i$的计算公式如下:
代码如下:
1 | (define (cont-frac n d k) |
结果如下:
1 | 2.7182817182817183 |
1.39(p48)
注意到有如下试试
所以取
然后利用之前的过程即可,代码如下:
1 | (define (cont-frac n d k) |
结果如下:
1 | 0.6483608274590866 |
1.40(p51)
1 | ; fixed-point |
结果如下:
1 | -0.9999999999999872 |
1.41(p51)
1 | (define (double f) |
结果如下:
1 | 7 |
结果说明:
定义
下面用数学归纳法证明:
其中
当$n=0$时,
所以结论成立。
假设$n=k$时结论成立,那么$n=k+1$时,
所以$n=k+1$时结论也成立。
1.42(p51)
1 | (define (compose f g) |
结果如下:
1 | 49 |
1.43(p51)
利用递归即可:
1 | (define (compose f g) |
结果如下:
1 | 625 |
1.44(p51)
1 | (define (compose f g) |
结果如下:
1 | 1.2100000000666669 |
1.45(p52)
1 | ; fixed-point |
结果如下:
1 | 1.4953487812212205 |
1.46(p52)
1 | (define (iterative-improve good-enough? improve) |
结果如下:
1 | 1.4142156862745097 |