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

Reply via email to