There's a slight conflict between your description (right argument is
number of recursive iterations) and your example results (which show
one less doubling than is indicated in your right argument). I am also
not sure how using S: would be useful, so I left out d3. There are
actually several possibilities for d1, though. Anyways, this might be
close to what you are looking for:

## Advertising

d1=:4 :0
if. 0<y do.
(x,2*{:x) d1 y-1
else.
x
end.
)
d2=: +:@]^:(i.@>:@[)~
Thanks,
--
Raul
On Tue, Jun 12, 2018 at 2:08 AM Skip Cave <s...@caveconsulting.com> wrote:
>
> I want to try to understand recursive functions in J. To start this
> learning process, I want to investigate J verbs that will generate a
> doubling sequence. For example, the verb 'd' where x = the starting
> integer, and y = the number of iterations:
>
> 2 d 6
> 2 4 8 16 32 64
>
> 5 d 4
> 5 10 20 40
>
> 7 d 10
> 7 14 28 56 112 224 448 896 1792 3584
>
> Define three different simple recursive verbs in J, to implement this
> recursive doubling function:
> 1. d1 - Just calling the function recursively
> 2. d2 - Using the Power operator ^:
> 3. d3 - Using Spread S: and Memo M.
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm