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

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

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)))))
  • How many times is the procedure p applied when (sine 12.15) is evaluated?

    5 times (12.153 \lceil \frac{12.15}{3} \rceil )
                sine 12.15
                    |
                P(sine 4.05)
                    |
                P(sine 1.35)
                    |
                P(sine 0.45)
                    |
                P(sine 0.15)
                    |
                P(sine 0.05)
    
  • 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?

    ResourceOfSpace(n)=θ(n3) ResourceOfSpace(n) = \theta(\lceil \frac{n}{3} \rceil)

ResourceOfTime(n)=θ(n3) ResourceOfTime(n) = \theta(\lceil \frac{n}{3} \rceil)

results matching ""

    No results matching ""