0

I'm learning the book SICP, and for the exercise 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?

I get the answer of the "order of growth in number of steps" by myself is log3 a. But I found something say, the constants in the expression can be ignored, so it's the same as log a, which looks simpler.

I understand the 2n can be simplified to n, and 2n2 + 1 can be simplified to n2, but not sure if this is applied to log3 a too.

Freewind
  • 193,756
  • 157
  • 432
  • 708
  • "Constants that can be ignored" are the C in `C * O(..)`, eg. `C * O(lg3(n))` -> `O(lg3(n))` - the subscript/superscript in the examples pertains to the function involving n, not a constant value. – user2864740 Mar 14 '16 at 07:21

1 Answers1

0

Yes, you can (since we're just interested in the order of the number of steps, not the exact number of steps)

Consider the formula for changing the base of a logarithm:

logb(x) = loga(x) / loga(b)

In other words you can rewrite log3(a) as:

log3(a) = log10(a) / log10(3)

Since log10(3) is just a constant, then for the order of growth we are only interested in the log10(a) term.

emmagordon
  • 1,222
  • 8
  • 17