练习1.15

sinx=3sinx34sin3x3 \sin x = 3\sin {x\over{3}} - 4\sin^{3}{x\over{3}}

(define (cube x) (* x x x))
(define (p x) (- (* 3 x) (* 4 (cube x))))
(define (sine angle)
   (if (not (> (abs angle) 0.1))
       angle
       (p (sine (/ angle 3.0)))))

代换过程:

(sine 12.15)
(p (sine 4.05))
(p (p (sine 1.35)))
(p (p (p (sine 0.45))))
(p (p (p (p (sine 0.15)))))
(p (p (p (p (p (sine 0.05))))))
(p (p (p (p (p 0.05)))))

由此 p总共使用了5次

很容易看出 sine的时间复杂度和空间复杂度都是 O(log3n)O(\log_{3}n)

results matching ""

    No results matching ""