I fooled myself.
The factorial gets into other functions’ series.
The first implementation was okay.






I found the solution now: -/ worked on some
inputs but not all because their lengths’
parity didn’t match. I added a factor _1
by prepending 0 for odd lengths:

ps2 =: 0 -/@:(0&,^:(2|#))@:((nxt2 ,^:(0 ~: [) ])^:_)~ ]

This gives the exact same results as ps1 did.
(For some J version at least)
Lesson learned: -/ on A is not the same as +/ on
(* 1 _1 $~ #) A, and order matters
I thought -/ works right to left as usual,
but didn’t remember I pre- rather than appended
items to the list of terms.
That’s why my signs were wrong in some instances.

And for the second issue:
Sure summing from small to big is better than the other
way around – yet I still think it looks too good …


For those who still want to understand my code,
read the explanation below.






So here’s the explanation I started writing earlier:

Good, I’ll try giving an explanation.
ln(x+1) is ^.@>:
the power series of which is
Σ(-1)^(k+1) x^k/k for any x with |x| < 1
EDIT: in the above line I made the mistake
               /(k!)
      and thought it had been wrong all along
I translated the terms of this sum to nxt1
and summed them up until they would “equal 0”
using ^:_ in ps1 which worked quite well

but then I thought I could neglect the sign in nxt2
and compensate using -/ instead of +/ in ps2 –
but I got worse results. That was unexpected:
I effectively left out (* _1 ^ >:)
and switched from +/ to -/ afterwards.
Which should have been algebraically equivalent.

I then found that changing the order of subtraction (|.)
and changing signs (0,) works. But now it looks oddly well:
the results seem to match ^.@>: perfectly.



Am 11.09.21 um 21:44 schrieb Hauke Rehr:
Okay, before anyone else wastes time on this:
I forgot the factorial, you’ll need to add a
! or !@] or something. That doesn’t do it yet.
I’ll try to find a correct phrasing first.

What I still find puzzling is that changing
the alt sign (* _1 ^ >:) (applied to # of a
list growing with the iterations) to replacing
+/ by -/ gave different results.

But let’s see if that still holds once I get
the sequence right.


Am 11.09.21 um 21:33 schrieb Raul Miller:
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,



--
----------------------
mail written using NEO
neo-layout.org

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to