I wrote:
> Jon Hough's suggestion looks very promising:
>
>   x^y =  (1 +(x-1))^y
>   e^pi = (1+(e-1))^pi   =  1+ pi*e + pi*(pi - 1)*e*e/2! +...
>   http://en.wikipedia.org/wiki/Binomial_series

Ok, here's a whack at that:

           binser =: (( ( (#@:] # {.@:[) ; (-~{:)~ ; >:@:]) )&> <\@:i.)~ <@,
        
           ('x^k';('y-i.k');'k!') , 5 binser 7 4
        +---------+---------+---------+
        |x^k      |y-i.k    |k!       |
        +---------+---------+---------+
        |7        |4        |1        |
        +---------+---------+---------+
        |7 7      |4 3      |1 2      |
        +---------+---------+---------+
        |7 7 7    |4 3 2    |1 2 3    |
        +---------+---------+---------+
        |7 7 7 7  |4 3 2 1  |1 2 3 4  |
        +---------+---------+---------+
        |7 7 7 7 7|4 3 2 1 0|1 2 3 4 5|
        +---------+---------+---------+
        
           1 + +/ *`%/"1 */&> 5 binser 7 4
        4096

Note the 1 + ... part would not be required if  <\  included the empty
prefix (which is really neat if you think about it). Unfortunately, while
this seems to work ok for 7^4, it breaks on 4^7, 7^4.5, and basically
everything else.  But I think I've played with this enough for the moment.

-Dan

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

Reply via email to