随笔分类 - SICP
摘要:(define (compose f g) (lambda (x) (f (g x)))) ((compose square inc) 6) ((compose inc inc) 6)
阅读全文
摘要:(define (double f) (lambda (x) (f (f x)))) (define (inc x) (+ x 1)) (((double (double double)) inc) 5) ;amazing (((double (double (double double))) inc) 0)
阅读全文
摘要:;2.2 (define (make-point x y) (cons x y)) (define (x-point p) (car p)) (define (y-point p) (cdr p)) (define (print-point p) (newline) (display "{") (display (x-point p)) (display ","...
阅读全文
摘要:(define (make-rat n d) (let ((g (gcd n d))) (cons (/ n g) (/ d g)))) (define (numer x) (car x)) (define (denom x) (cdr x)) (define (print-rat x) (newline) (cond ((= (denom x) 1) (display ...
阅读全文
摘要:(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 midpoint))) ...
阅读全文
摘要:(define (filtered-accumulate filter? combiner null-value term a next b) (define (iter a result) (cond ((> a b) result) ((filter? a) (iter (next a) (combiner (...
阅读全文
摘要:(define (filtered-accumulate filter? combiner null-value term a next b) (define (iter a result) (cond ((> a b) result) ((filter? a) (iter (next a) (combiner (...
阅读全文
摘要:(define (accumulate combiner null-value term a next b) (define (iter a result) (if (> a b) result (iter (next a) (combiner (term a) result)))) (iter a null-value)) (def...
阅读全文
摘要:(define (product term a next b) (if (> a b) 1 (* (term a) (product term (next a) next b)))) (product (lambda (x) x) 1 (lambda (i) (+ i 1)) 5) ...
阅读全文
摘要:为什么要把iter塞到sum里面去: 嗯,为了减少通信开销. 回头看递归写法: "我们要以困难的方式搞定它!"
阅读全文
摘要:(define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) next b)))) (define (integral f a b dx) ;积分 (define (add-dx x) (+ x dx)) (* (sum f (+ a (/ dx 2.0)...
阅读全文
摘要:(define (next n) (if (= n 2) 3 (+ n 2))) (define (find-divisor n test-divisor) (cond ((> (square test-divisor) n) n) ((divides? n test-divisor) test-divisor) (else (f...
阅读全文
摘要:(define (next-odd n) (if (odd? n) (+ 2 n) (+ 1 n))) (define (smallest-divisor n) (find-divisor n 2)) (define (find-divisor n test-divisor) (cond ((> (square test-divisor) n) n) ...
阅读全文
摘要:如果N是合数,则必有一个小于或者等于根号N的素因子. 因为任何合数都可表示为两个或者更多个素数之积. 假如N是合数且其素因子都大于根号N,那么将产生矛盾:根号N*根号N>N.所以合数必有(至少)一个不大于根号N的素因子
阅读全文
摘要:用java来跑一跑: 经过我拙劣的比较,对数级比线性还是要好很多的.
阅读全文
摘要:(define (double a) (+ a a)) (define (halve a) (/ a 2)) (define (mult a b) (mult-iter a b 0)) (define (mult-iter a b product) (cond ((= b 0) product) ((even? b) (mult-iter (double a...
阅读全文
浙公网安备 33010602011771号