Exactly.  If u has side effects or depends on side effects you should not 
use u M. .  That is, if there is some y for which (u y) -: u y is 0, 
you should not use u M. .  (Likewise for the dyad.)

Moreover, the dictionary page says that M. is commonly used 
for multiply recursive verbs.  The classic example is the 
Fibonacci number calculation (shown on the dictionary page), 
where the use of M. reduces the complexity from exponential to linear.  
If u is not multiply recursive and even more so if u is not even recursive,
you should think twice before using u M. .  There is a trade-off between 
the time and space needed to store and look-up the arguments and results, 
and the time and space for just recomputing u from scratch.  If the latter 
is relatively small you should not bother with u M. and instead just use u .

See also http://en.wikipedia.org/wiki/Memoization



----- Original Message -----
From: Raul Miller <[EMAIL PROTECTED]>
Date: Saturday, October 27, 2007 8:08
Subject: Re: [Jbeta] M. working as designed?
To: Beta forum <[email protected]>

> On 10/27/07, david alis <[EMAIL PROTECTED]> wrote:
> > What is happening is that repeated invocations of foo_with_M produce
> > identical results when successive arguments are the same.
> >
> > In this example the value of n doesn't change between invocations.
> > Is this correct?
> 
> That is what it is supposed to do.
> 
> Here's another simpler example:
>    ? bind 1000 M. "0 ] 4#i.1 3
> 740 105 669
> 740 105 669
> 740 105 669
> 740 105 669
> 
> Here's what the vocabulary page on M. says:
> 
>    u M. is the same as u but may keep a record of the 
> arguments   and results for reuse.
> 
> It looks to me like M. is doing what it is supposed to be doing:
> reusing results when some arguments are reused.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to