Exercise 1.15

Read Exercise 1.15


(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) The sine procedure ends when angle is < 0.1 – for every call to sine, p is called and angle is divided by 3. So p is called n times calculating (sine 12.15) where:
12.15/3n < 0.1
3n < 121.5
n = 5;

b) When calculating (sine a) – a is divided by 3 each time, so the number of steps is O(log3a)

4 thoughts on “Exercise 1.15

  1. This doesn’t mention space requirements but that should be the same as for time: log3(n).
    For every recursive call, we need to first get the save the result of sin(x/3) and then use it to compute the value of sin(x) via `p` procedure.

  2. How do you calculate log3(a) in the calculator? Because when I press log12.15/log3 it gives me 2.27… which is not the same answer as part a.

    1. (log3 a) isn’t how many calls to sine (or p) are made, but rather the rate those values change as a gets very large.

Leave a comment