Hello, I am not sure if I understand the concept of memoization and its realization in J through M. as indicated in the essay at http://www.jsoftware.com/jwiki/Essays/Memoization
When I looked at http://en.wikipedia.org/wiki/Memoization, I understood that memoization is most effective when the function is invoked later, the values in the associated array are scanned before actual computation is done.
From the essay I have:
6!:2 'j=: fib 32' NB. memo version 0.000424922 6!:2 'k=: fibx 32' NB. non-memo version 43.4159 j 2178309 k 2178309 Given that, I have the following questions: 1) How is it that the first call to fib is faster? Would not the creation and storage of values in the associated array actually slow the computation down? Or did I misunderstand something here? 2) What happens to the associated array post computation? 3) How would match dyad (-:) work when comparing a Memoized and non Memoized versions? I ask this since the essay shows the values instead of using the match dyad. Regards, Yuva On 11/14/06, Roger Hui <[EMAIL PROTECTED]> wrote:
See also http://www.jsoftware.com/jwiki/Essays/Memoization ----- Original Message ----- From: June Kim <[EMAIL PROTECTED]> Date: Monday, November 13, 2006 9:01 pm Subject: [Jprogramming] The Priest Mathematician > http://www.programming- > challenges.com/pg.php?page=downloadproblem&probid=110606&format=html > This one is not difficult. One can use dynamic programming. (If I were > solving this problem in other languages, I'd use memoization.) > > As Roger has masterfully shown in > http://www.jsoftware.com/jwiki/Essays/Collatz_Conjecture , J's > approach to dynamic programming is updating(amending }) an array > repetitively. > > How would you solve this problem in J, efficiently and elegantly? ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
