By considering 10 12 o. x (magnitude and phase angle)
in x^y, you may be able to get a more general solution,
dispensing with the need for the constant 0.5p1+o.i.32 .



----- Original Message -----
From: Kip Murray <[email protected]>
Date: Monday, May 25, 2009 21:01
Subject: Re: [Jchat] Clean elementary functions?
To: Chat forum <[email protected]>

> Here is what I settled on, taking Roger's suggestions and adding mine:
> 
>     rsin =: 1&o. 
> *         (1p1 * i. 32) -
> .@(e.!.0)~ |   NB. real sine
>     rcos =: 2&o. * (0.5p1 + 1p1 * i. 32) -
> .@(e.!.0)~ |
>     re   =: 9&o.
>     im   =: 11&o.
> 
>     mexp=: ^...@re * (rcos j. rsin)@im
> 
>     exp =: mexp : (mexp@(^...@[ * ]))
> 
>     sin =: 0j_0.5 * exp@(0j1*]) - 
> exp@(0j_1*])   NB. complex sine
> 
>     cos =:    0.5 * exp@(0j1*]) + 
> exp@(0j_1*])
> Then
> 
>     0j1 exp i. 5 4
> 1 0j1 _1 0j_1
> 1 0j1 _1 0j_1
> 1 0j1 _1 0j_1
> 1 0j1 _1 0j_1
> 1 0j1 _1 0j_1
> 
>     sin ,. 0j1 + 2p1 * i. 4
> 0j1.1752
> 0j1.1752
> 0j1.1752
> 0j1.1752
> 
>     exp ,. 1 + 0j2p1 * i. 4
> 2.71828
> 2.71828
> 2.71828
> 2.71828
> 
>     1p1*31 32
> 97.3894 100.531
> 
>     0.5p1 + 1p1*31 32
> 98.9602 102.102
> 
> 
> Kip Murray wrote:
> > And
> > 
> >    0j1 exp i. 4
> > 1 0j1 _1 0j_1
> > 
> > but you still can't duplicate with exp your J 6.03 feat with 
> 0j1 ^ i. 5 4 .
> > 
> > Thank you for working on this.
> > 
> > I am uneasy about replacing zero crossings \ and / with - in 
> the graphs 
> > of real cos and sin, but I want to have apparent periodicities 
> 0 = (exp 
> > z) - exp z + 0j2p1 and
> > 0 = (cos z) - cos z + 2p1 and 0 = (sin z) - sin z + 2p1 as in 
> (now using 
> > my sin and exp)
> > 
> >    sin 0j1 + 2p1 * i. 4 1
> > 0j1.1752
> > 0j1.1752
> > 0j1.1752
> > 0j1.1752
> > 
> >    exp 1 + 0j2p1 * i. 4 1
> > 2.71828
> > 2.71828
> > 2.71828
> > 2.71828
> > 
> >    NB. compare
> > 
> >    1 o. 0j1 + 2p1 * i. 4 1
> >            0j1.1752
> > _3.77946e_16j1.1752
> > _7.55892e_16j1.1752
> > _1.13384e_15j1.1752
> > 
> >    ^ 1 + 0j2p1 * i. 4 1
> >              2.71828
> > 2.71828j_6.65787e_16
> > 2.71828j_1.33157e_15
> > 2.71828j_1.99736e_15
> > 
> > Below if you replace 0.5p1 1.5p1 by (0.5p1 + 2p1 * i.10) and 
> do 
> > something similar for
> > sin, that might do for practical purposes.  Later an 
> extended sin and 
> > cos could
> > be defined in terms of exp.
> > 
> > 
> > Roger Hui wrote:
> >> cos should check for 1.5p1 as well as 0.5p1 :
> >>
> >>    cos=: 2&o. * 0.5p1 1.5p1 -.@(e.!.0)~ |
> >>
> >> With this change, we get:
> >>
> >>    mexp (i.4) * ^.0j1
> >> 1 0j1 _1 0j_1
> >>
> >>
> >>
> >> ----- Original Message -----
> >> From: Roger Hui <[email protected]>
> >> Date: Monday, May 25, 2009 10:10
> >> Subject: Re: [Jchat] Clean elementary functions?
> >> To: Chat forum <[email protected]>
> >>
> >>> I believe that if you want a "clean" result at all,
> >>> it's better to give it for sin and cos only if the argument 
> is the 
> >>> best possible 64-bit representation for pi (or pi%2).  Thus:
> >>>
> >>> sin =: 1&o. *   1p1 ~:!.0 |
> >>> cos =: 2&o. * 0.5p1 ~:!.0 |
> >>> re  =: 9&o.
> >>> im  =: 11&o.
> >>> mexp=: ^...@re * (cos j. sin)@im
> >>>
> >>> exp =: mexp : (mexp@(^...@[ * ]))
> >>>
> >>>    2 exp 3
> >>> 8
> >>>      1j1 exp 2
> >>> 0j2
> >>>    0j1 exp 2
> >>> _1
> >>>    0 = 1 + exp 0j1 * 1p1
> >>> 1
> >>>    exp _24
> >>> 3.77513e_11
> >>>
> >>> hex  =: {:@(2&(3!:3))"0
> >>> unhex=: 3!:2@((}:2(3!:3) 1p1)&,)"1
> >>>
> >>>    sin 1p1 _1p1
> >>> 0 0
> >>>    hex 1p1
> >>> 400921fb54442d18
> >>>    sin unhex (}:hex 1p1),"1 0 '79'
> >>> 5.6655e_16 _3.21629e_16
> >>>
> >>>    cos 0.5p1 _0.5p1
> >>> 0 0
> >>>    hex 0.5p1
> >>> 3ff921fb54442d18
> >>>    cos unhex (}:hex 0.5p1),"1 0 '79'
> >>> 2.83275e_16 _1.60814e_16
> >>>
> >>>
> >>>
> >>> ----- Original Message -----
> >>> From: Kip Murray <[email protected]>
> >>> Date: Friday, May 22, 2009 18:54
> >>> Subject: Re: [Jchat] Clean elementary functions?
> >>> To: Chat forum <[email protected]>
> >>>
> >>>>     NB. Here is a model for ^ that has 
> 0 = 1 + ^ 0j1*1p1
> >>>>     load 'numeric'
> >>>>
> >>>>     cos =: clean@(2&o.)
> >>>>
> >>>>     sin =: clean@(1&o.)
> >>>>
> >>>>     mexp =:  3 : 0
> >>>> 'u v' =. +. y
> >>>> (^u)*(cos v)+0j1*sin v
> >>>> )
> >>>>
> >>>>     exp =: 3 : 0
> >>>> mexp y
> >>>> :
> >>>> mexp y * ^. x
> >>>> )
> >>>>
> >>>>     i =: 0j1
> >>>>
> >>>>     pi =: 1p1
> >>>>
> >>>>     2 exp 3
> >>>> 8
> >>>>     i exp 2
> >>>> _1
> >>>>     0 = 1 + exp i*pi
> >>>> 1
> >>>>     exp _24
> >>>> 3.77513e_11
> >>>>
> >>>>     NB. That is, exp x remains positive 
> for real x
> >>>>
> >>>> Kip Murray
> >>>>
> >>>>
> >>>> Kip Murray wrote:
> >>>>> This is great!  /Kip
> >>>>>
> >>>>>
> >>>>> Roger Hui wrote:
> >>>>>> In J6.03:
> >>>>>>
> >>>>>>     0j1 ^ i.5 4
> >>>>>> 1 0j1 _1 0j_1
> >>>>>> 1 0j1 _1 0j_1
> >>>>>> 1 0j1 _1 0j_1
> >>>>>> 1 0j1 _1 0j_1
> >>>>>> 1 0j1 _1 0j_1
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> ----- Original Message -----
> >>>>>> From: Roger Hui <[email protected]>
> >>>>>> Date: Thursday, May 21, 2009 17:46
> >>>>>> Subject: Re: [Jchat] Clean elementary functions?
> >>>>>> To: Chat forum <[email protected]>
> >>>>>>
> >>>>>>> I am in sympathy with your concern.
> >>>>>>> A solution in the particular case of z^n is to do
> >>>>>>> repeated squaring instead of ^n*^.z .
> >>>>>>> The interpreter already does that for real z .
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> ----- Original Message -----
> >>>>>>> From: Kip Murray <[email protected]>
> >>>>>>> Date: Thursday, May 21, 2009 15:48
> >>>>>>> Subject: [Jchat] Clean elementary functions?
> >>>>>>> To: Chat forum <[email protected]>
> >>>>>>>
> >>>>>>>> Caution, rant follows.  /Kip Murray
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>      NB. It is too bad that whereas
> >>>>>>>>
> >>>>>>>>      0j1*0j1
> >>>>>>>> _1
> >>>>>>>>
> >>>>>>>>      NB. and
> >>>>>>>>
> >>>>>>>>      *:0j1
> >>>>>>>> _1
> >>>>>>>>
> >>>>>>>>      NB. we get
> >>>>>>>>
> >>>>>>>>      0j1^2
> >>>>>>>> _1j1.22465e_16
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>      NB. The culprit appears 
> to be
> >>>>>>>>
> >>>>>>>>      1 o. o. 1
> >>>>>>>> 1.22465e_16
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>      NB. because 0j1^2 is 
> calculated as
> >>>>>>>>
> >>>>>>>>      ^ 2 * ^. 0j1
> >>>>>>>> _1j1.22465e_16
> >>>>>>>>
> >>>>>>>>      NB. which has real part
> >>>>>>>>
> >>>>>>>>      2 o. o. 1
> >>>>>>>> _1
> >>>>>>>>
> >>>>>>>>      NB. and imaginary part
> >>>>>>>>
> >>>>>>>>      1 o. o. 1
> >>>>>>>> 1.22465e_16
> >>>>>>>>
> >>>>>>>>      NB. Sometimes I think 
> verb "clean" 
> >>>> should be incorporated    NB.
> >>>>>>>> in the elementary functions!  Maybe just in 1&o. 
> and 2&o.
> >>>>>>>>      NB. The TI-83 calculator 
> gives 
> >>>> "clean" results for i^2 and e^(i
> >>>>>>>> pi).
> >>>>>>>>
> >>>>>>>>      load 'numeric'
> >>>>>>>>
> >>>>>>>>      clean 0j1^2
> >>>>>>>> _1
> >>>>>>>>
> >>>>>>>>      clean ^ 0j1 * 1p1
> >>>>>>>> _1
> >>>>>>>>
> >>>>>>>>      0j1^2
> >>>>>>>> _1j1.22465e_16
> >>>>>>>>
> >>>>>>>>      ^ 0j1 * 1p1
> >>>>>>>> _1j1.22465e_16
> >>>>>>>>
> >>>>>>>>      clean
> >>>>>>>> 1e_10&$: :(4 : 0)
> >>>>>>>> if. L. y do.
> >>>>>>>>     x clean each y
> >>>>>>>> else.
> >>>>>>>>     if. (3!:0 y) e. 16 16384 do.
> >>>>>>>>       j./"1 y * x <: | 
> y=. +.y
> >>>>>>>>     else.
> >>>>>>>>       y * x <: |y
> >>>>>>>>     end.
> >>>>>>>> end.
> >>>>>>>> )
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to