Sorry, slightly careless in drafting - I'll correct the errors inline.
Please discard my earlier post.
On 15/02/2021 13:16, 'Michael Day' via Programming wrote:
Yes, it does seem to misbehave.
I looked at what happens with @ rather than @:
t0=: <.@ -:@ (* >:)
t1 =: <.@:-:@:(* >:)
(t0,:t1) 5928745 5928745 NB. compare @ with @:
17575011601885 17575011601885
17575011601886 17575011601886
I thought [: might fix it - but no:
tbr0=: [: <. [: -: (* >:)"0
tbr1 =: [: <. [: -: (* >:)
(tbr0,: tbr1) 5928745 5928745
17575011601886 17575011601886
17575011601886 17575011601886
They are all ok with scalar input:
~. (t0, t1, tbr0, tbr1) 5928745
17575011601885
Luckily, they're all ok with lists of small input values:
(t0, t1, tbr0,: tbr1) 5 5
15 15
15 15
15 15
15 15
So where does the problem arise? A crude binary search reveals:
#@:~.@:,@:(t0, t1, tbr0,: tbr1)@(2&#) 5928744 NB. OK
1
#@:~.@:,@:(t0, t1, tbr0,: tbr1)@(2&#) 5928745 NB. fails here!
2
#@:~.@:,@:(t0, t1, tbr0,: tbr1)@(2&#)"0 ] 5928745 + i:3 NB. not
exhaustive...
1 1 1 2 2 2 2
JVERSION
Engine: j903/j64avx2/windows
Beta-d: commercial/2021-02-04T10:15:00
Library: 9.03.01
Qt IDE: 1.9.2/5.12.10(5.12.10)
Platform: Win 64
Installer: J903 install
InstallPath: c:/d/j903-beta
Contact: www.jsoftware.com
BUT - there's similar behaviour in J902.
A bit worrying - Thanks!
Mike
On 15/02/2021 09:59, Stefan Baumann wrote:
Dear all,
I had an issue when calculating the triangular number with the formula
<.@:-:@:(*
:) in list context. Starting from 5928745 the outcome in list
context is
larger than the correct value (additionally calculated with the binomial
coefficient in the first box):
t=: <.@:-:@:(* >:)
((2&!)@:>:; t ;{.@:t@:,~) 5928744
+--------------+--------------+--------------+
|17575005673140|17575005673140|17575005673140|
+--------------+--------------+--------------+
((2&!)@:>:; t ;{.@:t@:,~) 5928745
+--------------+--------------+--------------+
|17575011601885|17575011601885|17575011601886|
+--------------+--------------+--------------+
JVERSION
Engine: j902/j64avx2/windows
Release-a: commercial/2020-12-05T13:36:01
Library: 9.02.08
Platform: Win 64
Installer: J902 install
InstallPath: c:/users/wzhbsn/_/opt/j
Contact: www.jsoftware.com
Thanks. Stefan.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm