In both versions of the code, if you give a single "exponent" n, the code would produce a single answer for S(n). Internally, it would keep a single intermediate result. If what it's doing is what you suspect (accuse! :-) it of doing, you can verify it by using space=:7!:2 space '10 next 1 0' space '20 next 1 0' and look at the grow of the space consumption.
BTW, since the function is extremely fast growing, 5^.2^1023 440.582 441 next 1 0 1.76105e308 1.32079e308 442 next 1 0 _ _ If you are not interested in rational numbers, the function has only a few possible answers. If you are worried about time/space, one approach may be to recompute a vector S of length 442 of all possible results, and then define next=: {&S . On Thu, Dec 20, 2012 at 5:28 AM, alessandro codenotti <cod...@live.it>wrote: > > I think I badly explained myself, or maybe i completely misunderstood the > code: > > > next=.5&(0 3 + *) > > the verb next simply applies the "multiply by five and add 3" to is right > argument a number of times given by is left argument, right? > > > (i. 20) next 1 0 > > this instruction, first applies 0 times "next" to 1 0, then applies once > "next" to 1 0, then applies twice "next" to 1 0, ... , then applies 20 > times "next" to 1 0, right? > > this mean that S(0) has been calculated 20 times, S(1) has been calculated > 19 times, S(n) has been calculated 20-n times since every time the function > next restarts from > the first term (which is 1 0), right? > > What i mean is that with something like the following pseudo-code S(n) is > calculated once avoiding a huge waste of time and memory: > > S(1)=1 0 > for i=2 to 20 do > S(i)=.3+5*S(i-1) > end > > My question then was if the code: > > > next=.0 3+*&5 > > 20 next@]^:(i.@[) 1 0 > > has the same problem or not and, in case of a positive answer, how can i > translate my pseudo-code in J avoiding an explicit loop. > > It may be that I completely misunderstood your code and the problem that > is worring me doesn't exist at all but I'm really a beginner in J... > > Alessandro > > > > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm