0.  I think this would be better as the conjunction
u M. v      mu lu ru
where v analyzes the operands and produces a result that is
used as the memoization key.  v of ] (or ; for dyads) would
produce a result similar to the adverb result.  v should have
a way to say 'don't memoize', possibly by returning an
empty result or possibly by failing.

An application I would use this for is in alpha-beta
minimzation, where you repeatedly have to evaluate game
positions.  The argument to u would be a position, not
a small integer, but it sure would be great to use
the M. feature: v would convert the game position
to a canonical form, decide whether it's worth saving
(positions too far into the future probably aren't),
and let M. do its thing.  If need be, v could keep
its own lookaside of memoizable positions that it
would look into to provide its integer result.

I can see some possible virtue in a gerund form
  u1`u2 M. v
where v analyzes [x and] y, and u1 is called if
the function is to be evaluated, while u2 is called if the
saved value is being returned.  I'm not sure when I would
use this but it seems like a useful stub to have.

1.  Does u M. have to be assigned to a name?  If so,
is the memoization saved as part of the name?  When
is the table reinitialized?  In
  u M. v u M. y
is memoization effective, and is the same table shared
by the two identical verbs?  Would it make a difference
if
  foo =: u M.
and we wrote
  foo v foo y
?

2.  It appears from the announcement that the table
is persistent.  Can it be erased, and can some upper
limit be put on the amount of storage it uses?

Henry Rich

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Roger Hui
> Sent: Thursday, September 07, 2006 1:24 AM
> To: [email protected]
> Subject: [Jbeta] u M. (Memo)
> 
> Something in J6.02 to look forward to.
> 
> Memo     u M.      mu lu ru  
> 
> u M. is the same as u but may keep a record of the
> argument(s) and results for later look-up and reuse.
> It is commonly used for multiply-recursive verbs.             
>           
> 
> The current implementation retains results only for 
> arguments that are small non-negative integer atoms.
> 
> For example:
> 
> 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.
> )
> 
>    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
> 
> Another example is finding the number of partition
> of n.  The following verbs implement a recurrence relation by 
> Euler, equation 11 in 
> http://mathworld.wolfram.com/PartitionFunctionP.html
> 
> rec=: 3 : 0
>  _1>.y--:k*"1 ] _1 1+/3*k=. 1+i.1+<.%:y*0.6666666
> )
> 
> pn=: 3 : 0 M.
>  if. 0>:y do. 0=y else. -/+/pn"0 rec y end.
> )
> 
> pnx=: 3 : 0
>  if. 0>:y do. 0=y else. -/+/pnx"0 rec y end.
> )
> 
>    6!:2 'j=: pn 27'   NB. memo version
> 0.00147935
>    6!:2 'k=: pnx 27'  NB. non-memo version
> 73.649
>    j
> 3010
>    k
> 3010
> 
> Subsequent applications of a memoized verb to the 
> same argument produces the result quickly:
> 
>    6!:2 'fib 32'
> 2.5049e_5
>    6!:2 'pn 27'
> 2.46019e_5
> 
> 
> ----------------------------------------------------------------------
> For information about J forums see 
> http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to