John,

Being curious as to whether amend in place applies
to "F=: F y}~ t" I performed the following experiment.
Perhaps there is an error in my experiment, but the
timing difference is surprising.

   F=: 0 1x
   f0c=: 3 : 0
 if. y >: #F do. F=: F,(1+y-#F)$_1 end.
 if. 0 <: y{F do. y{F return. end.
 F=: F y}~ t=. 1e6 | (y-2) +&f0c (y-1)
 t
)
   F1=: 0 1x
   f0c1=: 3 : 0
 if. y >: #F1 do. F1=: F1,(1+y-#F1)$_1 end.
 if. 0 <: y{F1 do. y{F1 return. end.
 F1=:  (t=. 1e6 | (y-2) +&f0c (y-1)) y}  F1
 t
)
   (f0c1 -: f0c)"0] 1000
1
   6!:2 'f0c 1000'
1.76264
   6!:2 'f0c1 1000'
0.0034108


On Fri, Oct 17, 2008 at 10:07 PM, John Randall
<[EMAIL PROTECTED]> wrote:
> Does append in place really work, or am I missing something?
>
> Here is the do-it-yourself memoization for the Fibonacci function from
>
> http://www.jsoftware.com/jwiki/Essays/Fibonacci_Sequence
>
> F=: 0 1x
> f0c=: 3 : 0
>  if. y >: #F do. F=: F,(1+y-#F)$_1 end.
>  if. 0 <: y{F do. y{F return. end.
>  F=: F y}~ t=. 1e6 | (y-2) +&f0c (y-1)
>  t
> )
>
> I have modified only with the mod 1e6: this is to keep numbers a
> sensible size.  I now test it with various arguments:
>
> test=:3 : 0
> t=.0$0
> for_p. 1e3*>:i.10 do.
> F=:0 1x
> t=.t, 6!:2 'f0c"0  i. p'
> end.
> )
>
> diff=:2 -~/\ ]
>
>
> ]t=:test''
> 0.21368 0.72439 1.53614 2.65898 4.06148 5.77984 7.81953 10.1861 12.8458
> 15.9044
>   diff t
> 0.51071 0.811749 1.12284 1.4025 1.71836 2.03969 2.36657 2.65966 3.0586
>   diff^:2 t
> 0.301039 0.31109 0.27966 0.315863 0.321328 0.326884 0.293085 0.39894
>
>
> The times look quadratic to me.  Anyone have any thoughts?
>
> Best wishes,
>
> John
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
(B=) <-----my sig
Brian Schott
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to