我正在学习这本书SICP,以及练习1.15:
Exercise 1.15. The sine of an angle (specified in radians) can be computed by making use of the approximation sin x x if x is sufficiently small, and the trigonometric identity
to reduce the size of the argument of sin. (For purposes of this exercise an angle is considered ``sufficiently small'' if its magnitude is not greater than 0.1 radians.) These ideas are incorporated in the following procedures:
(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)))))
a. How many times is the procedure p applied when (sine 12.15) is evaluated?
b. What is the order of growth in space and number of steps (as a function of a) used by the process generated by the sine procedure when (sine a) is evaluated?
我自己得到“步数增长顺序”的答案是 log 3 a 。但我发现有些东西说,表达式中的常量可以忽略,所以它与 log a 相同,看起来更简单。
我理解 2n 可以简化为 n , 2n 2 + 1 可以简化为 n 2 ,但不确定这是否也适用于 log 3 a 。
答案 0 :(得分:0)
是的,你可以(因为我们只是对步数的顺序感兴趣,而不是确切的步数)
考虑changing the base of a logarithm的公式:
log b (x)= log a (x)/ log a (b)
换句话说,您可以将log 3 (a)重写为:
log 3 (a)= log 10 (a)/ log 10 (3)
由于log 10 (3)只是一个常数,那么对于增长的顺序,我们只对log 10 (a)term感兴趣。