8 ;; 2 * a * (b/2) if b is even,
9 ;; a + a * (b-1) if b is odd
12 (define (fast-mult a b)
14 ((even? b) (double (* a (halve b))))
15 (else (+ a (* a (- b 1))))))
21 (define (test-case actual expected)
24 (format #t "Actual: ~A Expected: ~A" actual expected))
25 (test-case (fast-mult 0 0) 0)
26 (test-case (fast-mult 0 1) 0)
27 (test-case (fast-mult 0 8) 0)
28 (test-case (fast-mult 5 0) 0)
29 (test-case (fast-mult 2 1) 2)
30 (test-case (fast-mult 3 3) 9)
31 (test-case (fast-mult 5 4) 20)
32 (test-case (fast-mult 12 13) 156)
33 (test-case (fast-mult 12 24) 288)