fib=: 3 : 0 M.
if. 1>:y do. y else. (fib y-1)+fib y-2 end.
)
fibx=: 3 : 0
if. 1>:y do. y else. (fibx y-1)+fibx y-2 end.
)
f7=: 3 : 0
mp=. +/ .*
{.{: mp/ mp~^:(I.|.#:y) 2 2$0 1 1 1x
)
f7a=: 3 : 0
mp=. +/ .*
{.{: mp/ mp~^:(I.|.#:y) 2 2$0 1 1 1
)
6!:2 'j=: fib 32' NB. memo version
0.000424922
6!:2 'k=: fibx 32' NB. non-memo version
43.4159
6!:2 'f7 32'
0.000136794
6!:2 'f7a 32'
6.5888e_5
The fair comparison would be between fib and f7a,
since f7 uses extended precision numbers but fib
does not.
The point of fib is not that it is better than f7a,
but that M. removes the exponential time penalty
associated with a straightforward recursive
algorithm.
----- Original Message -----
From: Brian Schott <[EMAIL PROTECTED]>
Date: Friday, September 8, 2006 5:19 am
Subject: Re: [Jbeta] u M. (Memo)
> Would you mind posting the timing comparison for the
> matrix power version on the jwiki? I have thought of the
> matrix power version as the most J like.
>
> f7=: 3 : 0
> mp=. +/ .*
> {.{: mp/ mp~^:(I.|.#:y) 2 2$0 1 1 1x
> )
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm