Serendip
Web Studio

1.3.3一般的方法としての手続き(区間二分法による方程式の零点の探索) – SICP(計算機プログラムの構造と解釈)その18

2008年11月21日
blog
sicp

1.3.3 一般的方法としての手続き 区間二分法による方程式の零点の探索 (define (search f neg-point pos-point) (let ((midpoint (average neg-point pos-point))) (if (close-enough? neg-point pos-point) midpoint (let ((test-value (f midpoi…続きを読む

局所変数letの使い方、問題1.34 – SICP(計算機プログラムの構造と解釈)その17

2008年11月20日
blog
sicp

局所変数 let の使い方 let は変数を特定の範囲内に束縛する。 変数の値は let の外側で計算される。 問題1.34 (define (f g) (g 2)) (f square) (square 2) (* 2 2) 4 (f (lambda (z) (* z (+ z 1)))) ((lambda (z) (* z (+ z 1))) 2) (* 2 (+ 2 1)) (* 2 3) …続きを読む

問題1.33 – SICP(計算機プログラムの構造と解釈)その16

2008年11月19日
blog
sicp

問題1.33 まず再帰的プロセスのものを書く。 (define (filtered-accumulate combiner null-value filter-pre term a next b) (cond ((> a b) null-value) ((filter-pre a) (combiner (term a) (filtered-accumulate combiner null-v…続きを読む

問題1.32a、問題1.32b – SICP(計算機プログラムの構造と解釈)その15

2008年11月19日
blog
sicp

問題1.32 a 再帰的プロセスの accumulate (define (accumulate combiner null-value term a next b) (if (> a b) null-value (combiner (term a) (accumulate combiner null-value term (next a) next b)))) ;; sum (define…続きを読む

問題1.31a、問題1.31b – SICP(計算機プログラムの構造と解釈)その14

2008年11月19日
blog
sicp

問題1.31 a sum 手続きとほぼ同じ形で表せる(+ が * になる)。 ただし、a > b の際の戻り値が1となる。 (define (product term a next b) (if (> a b) 1 (* (term a) (product term (next a) next b)))) product を使って factorial を書く。 (define (fac…続きを読む

問題1.30 – SICP(計算機プログラムの構造と解釈)その13

2008年11月19日
blog
sicp

問題1.30 線形再帰の sum 手続き (define (sum1 term a next b) (if (> a b) 0 (+ (term a) (sum1 term (next a) next b)))) a から b までの整数の和(線形再帰手続き) (define (sum-integers1 a b) (define (identify x) x) (define (inc x…続きを読む

問題1.29 – SICP(計算機プログラムの構造と解釈)その12

2008年11月18日
blog
sicp

問題1.27 パス 問題1.28 パス 問題1.29 うーん、Simpsonの公式を使った方が精度が落ちているような気がする… (define (cube x) (* x x x)) (define (inc x) (+ x 1)) (define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) n…続きを読む

問題1.24、問題1.26 – SICP(計算機プログラムの構造と解釈)その11

2008年11月17日
blog
sicp

問題1.24 計算量は Θ(log n) の増加なので 1,000:1,000,000 は 1:2 程度と予想される。 結果を見ると 1:4 ぐらいになっている。 (define (square n) (* n n)) (define (smallest-divisor n) (find-divisor n 2)) (define (find-divisor n test-divisor…続きを読む

問題1.21、問題1.22、問題1.23 – SICP(計算機プログラムの構造と解釈)その10

2008年11月16日
blog
sicp

問題1.21 (define (square n) (* n n)) (define (smallest-divisor n) (find-divisor n 2)) (define (find-divisor n test-divisor) (cond ((> (square test-divisor) n) n) ((divides? test-divisor n) test-divis…続きを読む

問題1.19、問題1.20 – SICP(計算機プログラムの構造と解釈)その9

2008年11月15日
blog
sicp

問題1.19 p’ : (+ (* p p) (* q q)) q’ : (+ (* 2 p q) (* q q)) 問題1.20 (define (gcd a b) (if (= b 0) a (gcd b (remainder a b)))) 正規順序の置き換えの場合。赤字部分が実行される remainder。 remainder を rem と省略表記している。 18回。 (gcd 206 …続きを読む

PREV 1 2 3 … 60 61 62 63 64 65 66 67 68 69 70 NEXT
serendipity [sèrəndípəti]
ものをうまく発見する能力、幸運な発見
actionscript android angularjs arduino clojure cms css design eclipse emacs firefox flash git golang graphic hardware heroku html java javascript language-c linux mac manual mysql ooo perl photo php postgresql rails ruby scheme server sicp sqlite ubuntu unix vim webservice windows wordpress youtube
  • Blog (ブログ)
  • Information (お知らせ)
  • Software(ソフトウェア)
  • 2024年12月 (1)
  • 2023年12月 (1)
  • 2022年12月 (1)
  • 2021年12月 (1)
  • 2020年12月 (1)
  • 2019年2月 (1)
  •    過去のアーカイブ
Copyright © Serendip. All rights reserved.
Since 30/Jan/2000.
  • ホーム
  • Blog (ブログ)
  • Information (お知らせ)
  • Software(ソフトウェア)