SICP 1.29-1.33体会
来源:互联网 发布:云计算平台有哪些 编辑:程序博客网 时间:2024/05/16 15:06
1.29 到1.33这5道题特别好。好在什么地方? 作者深入浅出的设计了一学习过程,特别适合学习和上手。
强烈建议大家都做做,特别精彩, 全部做完大概1-2小时,也不是很费时间。
下面是自己的作业:
1.29
(define (sympson-integral f a b n)
(define (sum term start next end)
(if (> start end)
0
(+ (term start)
(sum term (next start) next end))))
(define h (/ (- b a) n))
(define (funcY index)
(f (+ a (* index h))))
(define (termY index)
(cond ((= index 0) (funcY index))
((= index n) (funcY index))
((= (remainder index 2) 1) (* 4 (funcY index)))
(else (* 2 (funcY index)))))
(define (next-index index)
(+ index 1))
(/ (* h (sum termY 0 next-index n))
3))
1.30
(define (sum term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (+ (term a) result))))
(iter a 0))
1.31
(define (product term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (* result (term a)))))
(iter a 1.0))
(define (product-recursive term a next b)
(if (> a b)
1.0
(* (term a)
(product-recursive term (next a) next b))))
(define (product-pi-term index)
(/ (* (+ 2.0 (* index 2))
(+ 4.0 (* index 2)))
(square (+ 3.0 (* index 2)))))
(define (next a)
(+ a 1))
(define (product-pi n)
(product product-pi-term 0 next n))
(define (product-pi-recur n)
(product-recursive product-pi-term 0 next n))
1.32
(define (accumulate-i combiner null-value term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (combiner result (term a)))))
(iter a null-value))
(define (accumulate-r combiner null-value term a next b)
(if (> a b)
null-value
(combiner (term a)
(accumulate-r combiner null-value term (next a) next b))))
(define (product-combiner x y)
(* x y))
(define (product-i term a next b)
(accumulate-i product-combiner 1.0 term a next b))
(define (product-r term a next b)
(accumulate-r product-combiner 1.0 term a next b))
(define (sum-combiner x y)
(+ x y))
(define (sum-i term a next b)
(accumulate-i sum-combiner 0 term a next b))
(define (sum-r term a next b)
(accumulate-r sum-combiner 0 term a next b))
(define (product-pi-term index)
(/ (* (+ 2.0 (* index 2))
(+ 4.0 (* index 2)))
(square (+ 3.0 (* index 2)))))
(define (next a)
(+ a 1))
(define (product-pi-i n)
(product-i product-pi-term 0 next n))
1.33
(define (filter-accumulate-i combiner null-value term a next b filter)
(define (iter a result)
(if (> a b)
result
(if (filter a)
(iter (next a) (combiner result (term a)))
(iter (next a) result))))
(iter a null-value))
(define (filter-accumulate-r combiner null-value term a next b filter)
(define (recur a)
(if (> a b)
null-value
(if (filter a)
(combiner (term a)
(recur (next a)))
(recur (next a)))))
(recur a))
(define (prime? n)
(= n (smallest-divisor n)))
(define (smallest-divisor n)
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(else (find-divisor n (+ test-divisor 1)))))
(define (divides? a b)
(= (remainder b a) 0))
(find-divisor n 2))
(define (sum-prime-i a b)
(define (next a)
(+ a 1))
(define (combine x y)
(+ x y))
(define (term x)
x)
(filter-accumulate-i combine 0 term a next b prime?))
(define (sum-prime-r a b)
(define (next a)
(+ a 1))
(define (combine x y)
(+ x y))
(define (term x)
x)
(filter-accumulate-r combine 0 term a next b prime?))
(define (gcd a b)
(if (= b 0)
a
(gcd b (remainder a b))))
(define (sum-gcd-n-i n)
(define (next x)
(+ 1 x))
(define (combine x y)
(* x y))
(define null-value 1.0)
(define (term x)
x)
(define (gcd-filter x)
(= (gcd x n) 1))
(filter-accumulate-i combine null-value term 2 next n gcd-filter))
(define (sum-gcd-n-r n)
(define (next x)
(+ 1 x))
(define (combine x y)
(* x y))
(define null-value 1.0)
(define (term x)
x)
(define (gcd-filter x)
(= (gcd x n) 1))
(filter-accumulate-r combine null-value term 2 next n gcd-filter))
- SICP 1.29-1.33体会
- SICP 1.20体会
- SICP 1.21 1.22 体会
- SICP 1.23-1.26体会
- SICP 1.27 1.28体会
- SICP 1.29-1.33
- SICP 习题1.1 -1.15体会
- SICP 习题1.16-1.19体会
- SICP 1.34-1.39习题体会
- SICP 习题1.33
- sicp
- SICP
- SICP习题解答1.29-1.39
- 【SICP练习】23 练习1.29
- 【SICP练习】27 练习1.33
- SICP 习题 (1.29)解题总结
- SICP 习题 (1.33)解题总结
- 体会!
- Unity3D模型制作规范
- VS2010,原来还有这些快捷键,果断记下来!
- VPS主机上MySQL数据库的优化
- 酵照重遗贪涎蜒杖履刳兰钠故掠姥
- 分莱鸥徘门纠栈的栈仁裁伤肛涎谱
- SICP 1.29-1.33体会
- 好稼忻鞠鞠杭峦饭衬未杭谱统啃且
- 隙谷巧郧纠陡必纠惶下杖忻倨辛训
- 绿对颈掠胖撩统套够诶故门兆逊谓
- 信链秦稚涛姥毁蒲踪伤捣侍纪安荣
- 垦链氛撩桥韶灯够杭炊拖唤灾涡哨
- 删涯鸥统磁倨泊院恼桨杭恼磁苛鼐
- 谜呛娇然轿门亮负缆杖撩妓纤旨拖
- //结构体成员 内存分布情况,及计算结构体大小;