[Jprogramming] Power for the powerless
Marshall Lochbaum
mwlochbaum at gmail.com
Tue Aug 5 16:12:29 UTC 2014
The binomial series can be implemented efficiently by grouping the terms
like this:
((1+x)^y) = 1 + (x*y) * 1 + (x*2%~y-1) * 1 + (x*3%~y-2) ...
that is,
1 + +/ */\ x * (y-i._)%(>:i._)
Putting it together (and remembering to decrement x), we have
exp =: 1 + [: +/ [: */\ <:@[ * (i.50) (-~%>:@[) ]
1.3 exp 9.6
12.4124
1.3^9.6
12.4124
1.3 (exp - ^) 9.6
5.32907e_15
Unfortunately, this only converges for x where 1 >: |x-1 , that is, a
disc in the complex plane around 1 of radius 1. To extend it to a
complete solution, we need to rescale x to fit in that circle. For
positive numbers, we can take the square root of x and double y until x
is between zero and two. But that's already quite unwieldy. It's
probably better to use the exp-multiply-log solution.
Marshall
On Tue, Aug 05, 2014 at 02:14:39PM +0100, Jon Hough wrote:
> The J is a little out of my league, but for non-integers, youcould use Binomial Theorem, as I said.(http://en.wikipedia.org/wiki/Binomial_series)
> e.g.
> e^pi = (1+(e-1))^pi = 1+ pi*e + pi*(pi - 1)*e*e/2! +...
> There's no exponentiation and you can calculate to arbitrary precision.
>
> > Date: Tue, 5 Aug 2014 05:33:42 -0700
> > From: programming at jsoftware.com
> > To: programming at jsoftware.com
> > Subject: Re: [Jprogramming] Power for the powerless
> >
> > "A really simple approach would be "
> >
> > for integer powers,
> >
> > pow =: [: */ #~
> >
> >
> >
> >
> > ----- Original Message -----
> > From: Raul Miller <rauldmiller at gmail.com>
> > To: Programming forum <programming at jsoftware.com>
> > Cc:
> > Sent: Tuesday, August 5, 2014 2:36:53 AM
> > Subject: Re: [Jprogramming] Power for the powerless
> >
> > A really simple approach would be to use T.
> >
> > pow=: ^ T. 99
> > That gives you a polynomial expression
> >
> >
> > Here's a shorter version:
> >
> > ^ T. 4
> >
> > 1 1 0.5 0.16666666666666666&p.
> >
> > Here's the more accurate version:
> >
> > (^ -: pow) 10 11 12
> >
> > 1
> >
> >
> > It's not necessarily efficient, but it's really simple.
> >
> >
> > Thanks,
> >
> >
> > --
> >
> > Raul
> >
> >
> >
> > On Tue, Aug 5, 2014 at 1:01 AM, Dan Bron <j at bron.us> wrote:
> >
> > > That's a long page, but in brief: can you calculate the power series
> > > without using ^ explicitly or implicitly (e.g. via t. or #: etc)? Are all
> > > the ^s I see in those power series easily replaced by instances of
> > > */@:#"0 ?
> > >
> > > In other words, does that page teach me how to do the trick when literally
> > > the only mathematical functions in my toolbox are (dyads) + - * % and
> > > (monad) | ?
> > >
> > > -Dan
> > >
> > > ----- Original Message ---------------
> > >
> > > Subject: Re: [Jprogramming] Power for the powerless
> > > From: Roger Hui <rogerhui.canada at gmail.com>
> > > Date: Mon, 4 Aug 2014 21:51:08 -0700
> > > To: Programming forum <programming at jsoftware.com>
> > >
> > > ?Can you not just use power series (for both exp and ln)? See
> > > http://www.jsoftware.com/jwiki/Essays/Extended%20Precision%20Functions .?
> > >
> > >
> > > On Mon, Aug 4, 2014 at 9:39 PM, Dan Bron <j at bron.us> wrote:
> > >
> > > > There's a StackExchange puzzle which challeges us to implement power
> > > (i.e.
> > > > dyad ^) using only the simple arithmetic dyads + - * % and monad | [1].
> > > In
> > > > other words, we may not use ^ or ^. or variants. There are still several
> > > > open questions on the puzzle, not least of which involves the domain of
> > > > the inputs (can the base be negative?) and range of the outputs (how much
> > > > precision is required?), but neverthless we can make some assumptions and
> > > > start to sketch an approach.
> > >
> > >
> > > ----------------------------------------------------------------------
> > > 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
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list