(wat-aro)

生きてます

2015-10-08から1日間の記事一覧

SICP 問題1.39

(define (tan-cf x k) (cont-frac (lambda (i) (if (= i 1) x (- (square x)))) (lambda (i) (- (* 2.0 i) 1.0)) k))

SICP 問題1.38

(define (e-2 k) (cont-frac (lambda (i) 1.0) (lambda (i) (if (= (modulo i 3) 2) (* 2 (+ 1 (quotient i 3))) 1.0)) k))

SICP 問題1.37

無限連分数の近似値 ;; 再帰的プロセス (define (cont-frac n d k) (define (recur i) (if (= i k) (/ (n i) (d i)) (/ (n i) (+ (d i) (recur (+ i 1)))))) (recur 1)) ;; 反復的プロセス (define (cont-frac n d k) (define (iter i res) (if (= i 0) res …

SICP 問題1.36

(define (fixed-point2 f first-guess) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (try guess) (let ((next (f guess))) (display guess) (newline) (if (close-enough? guess next) next (try next)))) (try first-guess)) (d…

SICP 問題1.35

x → 1 + 1/xを使い,fixed-point手続きにより黄金比を計算する (define (fixed-point f first-guess) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (try guess) (let ((next (f guess))) (if (close-enough? guess next) next (tr…

SICP 問題1.34

(define (f g) (g 2)) インタプリタに(f f)を評価させるとどうなるか. (f f) (f 2) (2 2) (f f)のfに引数を適用し,(f 2)となる. このfに引数を適用すると(2 2)となる. (2 2)を評価しようとするが2は手続きでないためエラーとなり終了する.

SICP 問題1.33

;; 再帰的プロセスで (define (filtered-accumulate filter combiner null-value term a next b) (cond ((> a b) null-value) ((filter a) (combiner (term a) (filtered-accumulate filter combiner null-value term (next a) next b))) (else (filterd-acc…

SICP 問題1.32

;; 再帰的プロセスで (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)))) ;; 反復的プロセスで (define (accumulate combiner null-value term …

SICP 問題1.31

;; 再帰的プロセスでproduct (define (product term a next b) (if (> a b) 0 (* (term a) (product term (next a) next b)))) ;; 反復的プロセスでproduct (define (product term a next b) (define (iter a result) (if (> a b) result (iter (next a) (* …