The "recur" solution uses +/\ and */\ which are supported by special code; f/\. for general f is not.
http://www.jsoftware.com/help/dictionary/special.htm ----- Original Message ----- From: Xu Zuoqian <[EMAIL PROTECTED]> Date: Sunday, March 9, 2008 17:28 Subject: Re: [Jprogramming] Is there a tacit version EMA? To: Programming forum <[email protected]> > I am confused of the relative speed. > The two reverses in the explict algorithm is insignificant,and > we also > ignore additions.Then the explict algorithm has 2*n > multiplications,and Mike's algorithm has 3*n multiplication + n > divisions.But it's speed is about 10x the speed of the explict > algorithm.What's wrong? > > 2008/3/10, Roger Hui <[EMAIL PROTECTED]>: > > > Where it came from before that, I know not. > > > > > > I first saw the algorithm in the APL Quote-Quad magazine > > in the 1970's. I'll see if I can find it in my > (incomplete)> collection of Quote-Quads. > > > > > > > > > > ----- Original Message ----- > > From: Mike Powell <[EMAIL PROTECTED]> > > Date: Saturday, March 8, 2008 19:09 > > Subject: Re: [Jprogramming] Is there a tacit version EMA? > > To: Programming forum <[email protected]> > > > > > Xu, > > > > > > Your EMA question is related to algorithms for linear > > > recurrence > > > relations. There is a much loved algorithm (probably because > > > it's > > > usually found to be lean and mean) that I first > encountered at > > > IP > > > Sharp in a newsletter quiz. We used it all over the place, > > > particularly wherever a present value or discounted > cash flow > > > was in > > > play. Where it came from before that, I know not. It > goes like this. > > > > > > If you have a linear recurrence relation of the form: > > > > > > r[0] is m[0] times a[0] > > > r[i] is a[i] + m[i] times r[i- > > > > 1] (i >0) > > > > > > then this can be calculated in vector languages in the > following way: > > > > > > a recur m;t > > > t is timesscan m > > > r is t times plusscan a div t > > > > > > I'd be most interested to see a J algorithm for this, > > > particularly a > > > tacit one. I note that we have a reflexive piece (t) > and that > > > there > > > may be an opportunity for an inverse (* and %). > > > > > > As far as the EMA is concerned, I suggest Xu's original > > > requirement is > > > solved with: > > > > > > (y[0] , k times 1 drop y) recur (length y) replicate 1 > - k ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
