The first sin definition is psuedo code: (sin y) = -/ (y ^ i) % ! i=. 1 + 2 * i. n
You need to use the full definition from the paper... My suggestion is to create a new script from the collected definitions section ... DP=: 40 round=: DP&$: : (4 : 0) b %~ <.1r2+y*b=. 10x^x ) pi=: DP&$: : (4 : 0) b %~ (x:!.0 y) * <.@o. b=. 10x^x+8+0>.>.10^.>./|y ) cnt=: 4 : 0 NB. range index; # terms; standardized argument t=. ((x+0>.>.(10^.|y)-10^.2p1) pi 2)|x:!.0 y c=. (1,0.25p1*2+i.6) I. x:^:_1 t t=. (1+x) round +/(_1x^c+0 1)*t,(1r2*>.c%2)*(1+x) pi 1 e=. 0.1^x n=. e (>i.1:) d (^%!@]) 2*i.x>.<.0.5*d^.e [ d=. x:^:_1 t c;n;t ) sin=: DP&$: : (4 : 0) " 0 'c n t'=. x cnt y (_1^c e. 4 5 6 7) * -/ t (^%!@]) (2x*i.n) + c e. 0 3 4 7 ) On Thu, Aug 7, 2014 at 8:31 AM, Raul Miller <[email protected]> wrote: > You might try replacing > =:=: > with > =: > > Thanks, > > -- > Raul > > > > On Thu, Aug 7, 2014 at 5:58 AM, Linda Alvord <[email protected]> > wrote: > >> Roger, I havejust begun to read this thread and I went to your article and >> I >> can't seem to implement the definition of sin2 using the Taylor's series. >> >> >> f=: 13 :'(*: 2 o. y)+*:1 o. y' >> 0j50 ": 50 f 1 >> 1.00000000000000000000000000000000000000000000000000 >> sin=:1 o. ] >> cos=:2 o. ] >> g=: 13 :'(*:cos y)+*:sin y' >> 0j50 ": 50 g 1 >> 1.00000000000000000000000000000000000000000000000000 >> 0j50 ": 50 (h=:sin +&*: cos) 1 >> 1.00000000000000000000000000000000000000000000000000 >> 50 (g-:h) 1 >> 1 >> >> -:1p1 >> 1.5708 >> (-:1p1)^4 >> 6.08807 >> >> NB.(sin y) = -/ (y ^ i) % ! i=. 1 + 2 * i. n >> NB.(cos y) = -/ (y ^ i) % ! i=. 2 * i. n >> >> sin2=:=: 13 :'-/(y^i)% ! i=. 1+2 *i. x' >> |syntax error: scriptd >> | sin2=:=:13 :'-/(y^i)% ! i=. 1+2 *i. x' >> |[-15] c:\users\owner\j802-user\temp\11.ijs >> >> Linda >> >> >> -----Original Message----- >> From: [email protected] >> [mailto:[email protected]] On Behalf Of Dan Bron >> Sent: Tuesday, August 05, 2014 4:03 PM >> To: [email protected] >> Subject: Re: [Jprogramming] Power for the powerless >> >> Your series look promising, the problem I'm having is turning them into >> action. >> >> Can you post a collected set of definitions which calculate a^b for all >> real a and b without using ^ or ^. (explicitly or implicitly)? If it >> makes it easier, it's ok to use x^y where it may be trivially and >> transparently replaced by */ y$x . >> >> >> ----- Original Message --------------- >> >> Subject: Re: [Jprogramming] Power for the powerless >> From: Roger Hui <[email protected]> >> Date: Tue, 5 Aug 2014 12:46:22 -0700 >> To: Programming forum <[email protected]> >> >> The power series I gave work for all real a and b in a^b (which is the >> original problem). >> >> >> >> >> On Tue, Aug 5, 2014 at 11:28 AM, Dan Bron <[email protected]> wrote: >> >> > What shall we do for negative exponents and/or negative bases? >> > >> > ----- Original Message --------------- >> > >> > Subject: Re: [Jprogramming] Power for the powerless >> > From: Marshall Lochbaum <[email protected]> >> > Date: Tue, 5 Aug 2014 12:54:22 -0400 >> > To: [email protected] >> > >> > The correct trick is to invert x and negate y if x is greater than 2, >> > since >> > >> > ((%x)^(-y)) = x^y >> > >> > . Unfortunately this eats up quite a few characters due to the reliance >> > on both x and y. Here are two ways to implement it: >> > >> > e=:1+[:+/[:*/\<:@[*(i.50)(-~%>:@[)] >> > exp=:e`(%@[e-@])@.(2<[) >> > >> > or (all on one line) >> > >> > exp=:(1+[:+/[:*/\<:@[*(i.50)(-~%>:@[)])/@((%@{.,-@{:)^:(2<{.))@, >> > >> > Either is a complete solution to the given problem aside from the "no >> > array operations" restriction, although the parameter of 50 is too small >> > for some arguments. >> > >> > Marshall >> > >> > On Tue, Aug 05, 2014 at 12:12:29PM -0400, Marshall Lochbaum wrote: >> > > 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: [email protected] >> > > > > To: [email protected] >> > > > > Subject: Re: [Jprogramming] Power for the powerless >> > > > > >> > > > > "A really simple approach would be " >> > > > > >> > > > > for integer powers, >> > > > > >> > > > > pow =: [: */ #~ >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > ----- Original Message ----- >> > > > > From: Raul Miller <[email protected]> >> > > > > To: Programming forum <[email protected]> >> > > > > 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 <[email protected]> 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 <[email protected]> >> > > > > > Date: Mon, 4 Aug 2014 21:51:08 -0700 >> > > > > > To: Programming forum <[email protected]> >> > > > > > >> > > > > > ?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 <[email protected]> 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 >> > ---------------------------------------------------------------------- >> > 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 >> >> ---------------------------------------------------------------------- >> 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
