I think Raul missed a term: exp=: 1 + (* 1+ (* 0.5 + (*1r6+(*1r24+(*1r120+(*1r720+(*1r5040+ (*1r40320+(*1r362880"_)))))))))
In any case, the list of constants is easy to generate. This generates a hundred numbers in the series, in rational fractions:: c =. x: 1 % !i.100x c 1 1 1r2 1r6 1r24 1r120 1r720 1r5040 1r40320 1r362880 1r3628800 1r39916800 1r479001600 1r6227020800 1r87178291200 1r1307674368000 1r20922789888000 1r355687428096000 1r6402373705728000 1r121645100408832000 1r2432902008176640000 1r51090942171709440000 1r11240... Unfortunately my J skills aren't good enough to insert all 100 of these values in to Raul's equation. Skip Skip Cave Cave Consulting LLC On Tue, Aug 5, 2014 at 10:16 AM, Raul Miller <[email protected]> wrote: > This is getting silly, but: > > ^T.10 > > 1 1 0.5 0.16666666666666666 0.041666666666666664 0.0083333333333333332 > 0.0013888888888888889 0.00019841269841269841 2.4801587301587302e_5 > 2.7557319223985893e_6&p. > > > exp=: 1 + (* 1+ (* 0.5 + > (*1r6+(*1r24+(*1r720+(*1r5040+(*1r40320+(*1r362880"_)))))))) > > > That's not accurate enough, except for exponents near zero, but it's enough > to illustrate the principle. > > > Thanks, > > > -- > > Raul > > > > > On Tue, Aug 5, 2014 at 9:49 AM, Dan Bron <[email protected]> wrote: > > > Raul wrote: > > > A really simple approach would be to use T. > > > pow=: ^ T. 99 > > > > First: probably a better name for your function is "exp" instead of "pow" > > ("exp" is a monad related to the dyad "pow" by fixing its left argument > to > > 1x1). > > > > But certainly exp is a welcome improvement over my formulation, with a > > couple caveats. Specifically, even if we write off the presence of the > > primitive ^ in ^T.99 as permissible due to the use-mention distinction, > > the result of T., as you point out: > > > > > gives you a polynomial expression > > > > i.e., is an expression involving p., which is not one of the specifically > > enumerated operations. More problematic, it has an implicit use of ^ (the > > DoJ explicitly defines x p. y as +/x*y^i.#x). This is why I explicitly > > excluded T.'s cousin t. in the message you replied to: > > > > > can you calculate the power series without using ^ > > > explicitly or implicitly (e.g. via t. or #: etc)? > > > > With that said, you made me realize that the Taylor coefficients for ^y > are > > fairly straightforward, and I can calculate them without t. or T. or even > > ! : > > > > exp =: 250 & ( # +/ . % &(_1 |.!.1 */\) >:@:i.@:[ ) > > > > [I have no idea how many terms I should include, but 250 seemed > sufficient > > for the spot checks I did.] > > > > Which is a lot more precise than my previous *: > > > > > exp =: 1e5 spow~ 1 + %&1e5 > > > spow =: */@:#~ > > > > Unfortunately, since most of the complexity of my original function is in > > the estimatation of ^.y (that is, log), it mutes the impact of this > > improvement to ^y (unless someone can show me how to generalize it to > x^y > > i.e., truly pow, not exp?). > > > > However, 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 > > > > Let me play with that a bit. > > > > -Dan > > > > * Speaking of spow, Pascal wrote: > > > > > "A really simple approach would be" > > > for integer powers, > > > pow =: [: */ #~ > > > > Yes, spow is a core function of the more general pow; but note it's not > for > > all "integer powers", it's for non-negative integer powers. See also the > > RosettaCode "exponentiation" task [1], which shows how to generalize this > > to negative powers simply: > > > > > exp =: *@:] %: */@:(#~|) > > > > But unfortunately, this uses %: which is not in our toolbox either. > > > > [1] RC: Exponentiation in J > > http://rosettacode.org/wiki/Exponentiation_operator#J > > > > > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
