<div dir="ltr">On Tue, Apr 9, 2013 at 3:30 PM, Pierpaolo Bernardi <span dir="ltr"><<a href="mailto:olopierpa@gmail.com" target="_blank">olopierpa@gmail.com</a>></span> wrote:<div><br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div><div>while the for version should be almost all big x big.</div></div></div></div></div></blockquote><div><br></div><div style>oops, no. The for version should be almost all fix x big.</div><div style><br></div><div style>
Here's a count considering also the type of the result of the multiplication:</div><div style><br></div><div style><div>> (fact 1000000)</div><div>#hash(((fix fix -> fix) . 437071)</div><div> ((big big -> big) . 209717)</div>
<div> ((fix big -> big) . 46338)</div><div> ((fix fix fix -> fix) . 48577)</div><div> ((fix fix -> big) . 209718))</div><div><br></div><div>====</div><div><br></div><div><div><br></div><div>(define x*-counter 'not-initialized)</div>
<div><br></div><div>(define (x* . args)</div><div> (define (classify x)</div><div> (if (fixnum? x)</div><div> 'fix</div><div> 'big))</div><div> (define res (apply * args))</div><div> (hash-update! x*-counter </div>
<div> (append (map classify args)</div><div> '(->)</div><div> (list (classify res)))</div><div> add1</div><div> 0)</div><div>
(apply * args))</div><div><br></div><div>;; from included; to excluded.</div><div>(define (mult from to)</div><div> (case (- to from)</div><div> ((0) 1)</div><div> ((1) from)</div><div> ((2) (x* from (+ from 1)))</div>
<div> ((3) (x* from (+ from 1) (+ from 2)))</div><div> ;; ...</div><div> (else</div><div> (let ((middle (quotient (+ from to) 2)))</div><div> (x* (mult from middle) (mult middle to))))))</div><div><br></div>
<div>(define (fact n)</div><div> (set! x*-counter (make-hash))</div><div> (define f (if (zero? n)</div><div> 1</div><div> (mult 2 (add1 n))))</div><div> (values ;f</div><div> x*-counter))</div>
</div><div><br></div></div></div></div></div></div>