|
Here are some interesting timings of tristream multiplication. I am just multiplying a tristream xreal by itself 1 through 6 times, and asking for a mere 3 digits of output, including the integer part. The cpu time goes up in the sequence 10, 10, 30, 110, 420. Then multiplication 6 times fails for lack of memory. What's going on here? You could figure out the first few trits of this result by hand in a minute with an index card for notes. Why is Scheme running out of memory? Is it a bug in my multiplication code? Does anyone have code that works much better? Is it inherent in the trinary representation? Would another base improve things?
I'm being disingenuous here, because I know the essence of the answer. But it's real interesting, and not what anybody thought of at first when proposing infinite expansions as streams.
(load "ratintvl-3_ratpair-1,mod1.scm");Loading "ratintvl-3_ratpair-1,mod1.scm" -- done
;Value: std_ratintvl->string
(load "xreal-2_tristream-1,mod2.scm");Loading "xreal-2_tristream-1,mod2.scm" -- done
;Value: mult_xreal
(load "progutils-3.scm");Loading "progutils-3.scm" -- done
;Value: testerrcase
(define (repeat_mult xr1 xr2 n)
(cond ((<= n 0) xr1)
(else (repeat_mult (mult_xreal xr1 xr2) xr2 (- n 1)))))
;Value: repeat_mult
(comp_time
(stream-head
(repeat_mult (rational->xreal 111112/111111)
(rational->xreal 1)
1)
3)
#t)
Run time: 10
GC time: 0
Real time: 1
;Value 5: (1 0 0)
(comp_time
(stream-head
(repeat_mult (rational->xreal 111112/111111)
(rational->xreal 1)
2)
3)
#t)
Run time: 10
GC time: 0
Real time: 6
;Value 6: (1 0 0)
; I repeated the 2-step multiplication to make sure that I wasn't
; using old cached values of stream elements.
(comp_time
(stream-head
(repeat_mult (rational->xreal 111112/111111)
(rational->xreal 1)
2)
3)
#t)
Run time: 10
GC time: 0
Real time: 6
;Value 7: (1 0 0)
(comp_time
(stream-head
(repeat_mult (rational->xreal 111112/111111)
(rational->xreal 1)
3)
3)
#t)
Run time: 30
GC time: 10
Real time: 44
;Value 8: (1 0 0)
(comp_time
(stream-head
(repeat_mult (rational->xreal 111112/111111)
(rational->xreal 1)
4)
3)
#t)
Run time: 110
GC time: 10
Real time: 254
;Value 9: (1 0 0)
(comp_time
(stream-head
(repeat_mult (rational->xreal 111112/111111)
(rational->xreal 1)
5)
3)
#t)
Run time: 420
GC time: 100
Real time: 1449
;Value 10: (1 0 0)
(comp_time
(stream-head
(repeat_mult (rational->xreal 111112/111111)
(rational->xreal 1)
6)
3)
#t);Aborting!: out of memory
;GC #305: took: 0.20 (50%) CPU time, 0.20 (10%) real time; free: 241416
;GC #306: took: 0.10 (100%) CPU time, 0.10 (40%) real time; free: 241547
;GC #307: took: 0.10 (100%) CPU time, 0.10 (11%) real time; free: 241548
(comp_time
(stream-head
(repeat_mult (rational->xreal 111112/111111)
(rational->xreal 1)
5)
3)
#t)
Run time: 400
GC time: 100
Real time: 1407
;Value 11: (1 0 0)
|