Chat (Lingr.com)
Informaiton
Daily
Column
- MySQL日本語の旅(5/1)
- アクセス向上秘伝(5/9)
- 一風変ったHaskellλ門(6/13)
- SICP Answer Book (5/31) 問題3.26追加
Zope Solution
Extra
アーカイブ
OSS案内所
Site Info
関連リンク
##(link2sicp "book-Z-H-12.html#%_thm_1.31" "Exercise 1.31")
解答例
a. 再帰プロセス版 product
(define (product term a next b)
(if (> a b)
1
(* (term a) (product term (next a) next b))))
b. 反復プロセス版 product
(define (product term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (* (term a) result))))
(iter a 1))
factorial
(define (factorial n) (define (term i) i) (define (next i) (+ i 1)) (product term 1 next n))
Wallis PI
(define (wallis-pi n)
(define (term i)
(/ (* (* 2 i) (* 2 (+ i 1)))
(square (+ (* 2 i) 1))))
(define (next i) (+ i 1))
(* 4 (product term 1 next n)))
コード
##(sicp-answer-code "ex-1.31.scm")