While I don't have a specific explanation (I have not looked closely
enough), I was somewhat bemused by the consequences of executing:

   NXT1=: 4 : 'x nxt1 y [ echo x;y'
   PS1=: 0 +/@:((NXT1 ,^:(0 ~: [) ])^:_)~ ]
   (PS1 - ^.@>:)"0 % 2^>:i.5

Sums of alternating signed floating point numbers of similar magnitude
have a tendency to lose precision. (And, values in the range of 1e_323
also tend to run into issues, if that matters.)

Take care,

-- 
Raul

On Sat, Sep 11, 2021 at 6:37 AM Hauke Rehr <hauke.r...@uni-jena.de> wrote:
>
> Hello,
>
> I just wanted to look at some power series,
> here is code for ^.@>:
> (quite literal translation from the maths)
>
> nxt1 =: [ (^ % (* _1 ^ >:)@]) #@]
> ps1 =: 0 +/@:((nxt1 ,^:(0~:[) ])^:_)~ ]
>
> now executing
> (ps1 - ^.@>:)"0 % 2^>:i.5
> gives
> _1.11022e_16 _5.55112e_17 _1.38778e_17 6.93889e_18 0
> or
> _1.11022e_16 0 2.77556e_17 6.93889e_18 0
> depending on J version
> not bad
>
> I thought I made an improvement when I rewrote it thus:
> nxt2 =: [ (^ % ]) #@]
> ps2 =: 0 -/@:((nxt2 ,^:(0~:[) ])^:_)~ ]
>
> but now I get
> (ps2 - ^.@>:)"0 % 2^>:i.5
> _0.81093 _0.446287 2.77556e_17 _0.121249 0
> ouch!
>
> … and now I’d have expected
> +/@:(* 1 _1 $~ #)@:
> instead of -/@:
> not to help with that bad result but it did
> _0.81093 _0.446287 _1.38778e_17 _0.121249 0
>
> Okay, this will be representation/fp issues;
> still the difference in accuracy puzzles me
> when comparing ps1 and ps2 …
>
> Does anyone have an explanation?
>
> --
> ----------------------
> mail written using NEO
> neo-layout.org
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to