0. Making M. a conjunction complicates matters too much. You could use M. as [EMAIL PROTECTED] M. (where u and v are as you described), or you could write your own version of M. using global names in a locale.
1. M. can be effective on anonymous verbs: 6!:2 '+/@:($:"0)@(-&1 2)[EMAIL PROTECTED](1>:]) M. 32' 0.000132038 6!:2 '+/@:($:"0)@(-&1 2)[EMAIL PROTECTED](1>:]) 32' 8.54617 Each instance of u M. has its own look-up table. u M. v u M. y can be effective, but note that there would be two look-up tables. If foo=: u M. then foo v foo y would have one look-up table. This is exactly the construct used in the fib example in my original msg ((fib y-1)+fib y-2). 2. The look-up table is erased when the verb is erased or redefined. Other than calling u M. with arguments, the user has little or no control over what is in this table. ----- Original Message ----- From: Henry Rich <[EMAIL PROTECTED]> Date: Thursday, September 7, 2006 2:50 pm Subject: RE: [Jbeta] u M. (Memo) > 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] > > [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
