Chapter 1, Building Abstractions with Procedures

Section - Procedures and the Processes They Generate

Exercise 1.18


It assumes $a,b \ge 0$.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(define (ml-itr a b)
  (define (mitr r aa bb)
     (cond ((= bb 0) r)
         ((even? bb) (mitr r (double aa) (half bb)))
         (else (mitr (+ r aa) aa (- bb 1))))
  )
  (mitr 0 a b)
)  


(define (half a)
  (/ a 2)
)

(define (double a)
  (* a 2)
)