标签:os ar sp on c ef python as bs
解:1.45
从理论上不好证,得做试验,初步的想法是通过做试验找出计算n次方根需要计算平均阻尼的次数,找出规律,暂时未写
1.46
(define (iterative-improve good-enough? improve) (define (try x) (let ((next (improve x))) (if (good-enough? x next) next (try next)))) try) (define tolerance 0.00001) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (fixed-point f first-guess) ((iterative-improve close-enough? f) first-guess)) (define (sqrt x) (define (good-enough? dummy guess) (< (abs (- (* guess guess) x)) tolerance)) (define (improve guess) (/ (+ ( / x guess) guess) 2.0)) ((iterative-improve good-enough? improve) 1.0))
总结下:lisp不愧是用来做高阶函数演算的,这些功能用C来实现的话还真不知道该怎么写,写出来估计也会很丑。
标签:os ar sp on c ef python as bs
原文地址:http://my.oschina.net/u/1445655/blog/308422