jsoftware / j-playground

J playground
https://jsoftware.github.io/j-playground/bin/html2/
Other
10 stars 5 forks source link

gpoly failure #48

Open joebo opened 2 years ago

joebo commented 2 years ago

Playground link

1:@:(dbr bind Debug)@:(9!:19)2^_44[(prolog [ echo^:ECHOFILENAME) './gpoly.ijs'
1
   NB. p. y ----------------------------------------------------------------

   NB. test failed on small ct
   ct   =: 9!:18''
   9!:19[2^_40

   test =: 3 : 0
 c=: y
 x=:    1024 %~ _500+?  40$10000
 z=: j./1024 %~ _500+?2 40$10000
 r=: p. c
 d=: p. r
 assert. *./ 1e_6  > c (+/@:|@[ %~ |@]) c p. >{:r
 assert. *./ 1e_13 > c %&(+/@:|)~ -/c,:d
 assert. (c p. z) -:!.1e_12 r p. z
 assert. (c p. z) -:!.1e_11 d p. z
 assert. (c p. x) -:!.1e_12 r p. x
 assert. (c p. x) -:!.1e_11 d p. x
 assert. (p. c) -: p. c,0 0 0 0 0
 1
)

   test _48 1 0 0 0 1  NB. Caused trouble
1

   test _10+?11$25
1
   test _10+?10$25
1
   test _10+? 9$25
1

   test j./_10+?2 11$25
1
   test j./_10+?2 10$25
1
   test j./_10+?2  9$25
1

   4!:55 ;:'c d r x z' 
1 1 1 1 1

   (1;n$_1)   -: p. n!~i.>:n=:>:?15
1
   (n!~i.>:n) -: p. <n$_1
1
   ((|.(1+n)$1 _1)*n!~i.>:n) -: p. <n$1
1

   1e_14 > | (p.&< p. ]) r=:1 0 1 
1 1 1
   1e_14 > | (p.&< p. ]) r=:1 0 1 1
1 1 1 1
   1e_14 > | (p.&< p. ]) r=:2 3 4
1 1 1
   1e_14 > | (p.&< p. ]) r=:2 3 4 5
1 1 1 1
   1e_14 > | (p.&< p. ]) r=:2 3 4.5 
1 1 1
   1e_14 > | (p.&< p. ]) r=:2 3 4.5 6
1 1 1 1
   1e_14 > | (p.&< p. ]) r=:1j2 3j4 5
1 1 1
   1e_14 > | (p.&< p. ]) r=:1j2 3j4 5 6
1 1 1 1
   1e_14 > | (p.&< p. ]) r=:5j7 5j_7 1j2
1 1 1

   (p.<r) -: p. ({.1 1  );}.2,  r=:_7+?3$20
1
   (p.<r) -: p. ({.1 1  );}.2.5,r
1
   (p.<r) -: p. ({.1 1  );}.2j5,r
1
   (p.<r) -: p. ({.1 2  );}.2,  r
1
   (p.<r) -: p. ({.1 2  );}.2.5,r
1
   (p.<r) -: p. ({.1 2  );}.2j5,r
1
   (p.<r) -: p. ({.1 2  );}.2,  r
1
   (p.<r) -: p. ({.1 2  );}.2.5,r
1
   (p.<r) -: p. ({.1 2  );}.2j5,r
1
   (p.<r) -: p. ({.1 2.5);}.2,  r
1
   (p.<r) -: p. ({.1 2.5);}.2.5,r
1
   (p.<r) -: p. ({.1 2.5);}.2j5,r
1
   (p.<r) -: p. ({.1 2j5);}.2,  r
1
   (p.<r) -: p. ({.1 2j5);}.2.5,r
1
   (p.<r) -: p. ({.1 2j5);}.2j5,r
1

   (0;'') -: p. ''
1
   (0;'') -: p. i.0
1
   (0;'') -: p. 0$<''
1
   (0;'') -: p. 0
1
   (0;'') -: p. ,0
1
   (0;'') -: p. 0 0 0 0 0
1

   (1;,r) -: p. 1,~-r=:o._400+?1000
1
   (1;,r) -: p. 1,~-r=:r._400+?1000
1

   f =: 3 : ('''a b c''=.|.y'; '(+:a)%~-b(+,-)%:(*:b)-4*a*c')
   (f -:&(/:~) >@{:@p.) c=:(0.1*_500+?2$2000),>:?500
1
   (f -:&(/:~) >@{:@p.) c=:r.(0.1*_500+?2$2000),>:?500
1

   (-: p.^:2) 0j1 0j1
1
   (-: p.^:2) 3j4;i._4
1

   (,1) -: p. <''
1
   (,1) -: p. <i.0
1
   (,1) -: p. a:
1

   'domain error' -: p. etx 'abcd'
1
   'domain error' -: p. etx <'abcd'
1
   'domain error' -: p. etx <<3 4 5
1
   'domain error' -: p. etx 4;'abcd'
1
   'domain error' -: p. etx 4;<<2 3 4
1
   'domain error' -: p. etx 'a' ;3 4 5 6
1
   'domain error' -: p. etx (<3);3 4 5 6
1
   'domain error' -: p. etx 4
1
   'domain error' -: p. etx 4 0 0 0 0 
1

   'length error' -: p. etx 3;4 5 6;7 8 9 10
1

   'rank error'   -: p. etx 3;i.3 4
1
   'rank error'   -: p. etx 3;i.0 0
1
   'rank error'   -: p. etx (,3);3 4 5 6
1
   'rank error'   -: p. etx '';3 4 5 6
1
   'rank error'   -: p. etx 2 3;3 4 5 6
1

   NB. "difficult" roots ---------------------------------------------------

   NB. examples from Nakano, Yamashita, and Nishikawa, Vector 21.2, Spring 2005

   c=: ''
   c=: c,< _4 6 _3 1
   c=: c,< _9 9 _3 1
   c=: c,< _2 6 _6 1
   c=: c,< _18 18 _6 1
   c=: c,< _3 9 _9 1
   c=: c,< _12 18 _9 1
   c=: c,< _1 6 _12 1
   c=: c,< _4 12 _12 1
   c=: c,< _9 18 _12 1
   c=: c,< _5 15 _15 1
   c=: c,< _20 30 _15 1
   c=: c,< 12 _30 27 _10 1
   c=: c,< 2 _3 _3 6 0 _3 1
   c=: c,< 175 210 99 _40 _33 _10 1 0 1
   r=: >@{:@p.&.> c
   1e_12 > c >./@:|@:p.&> r
1 1 1 1 1 1 1 1 1 1 1 1 1 1

   c=: 1 50000 1  NB. Andrew Nikitin
   r=: >{:p. c
   1e_6 > >./ | c p. r
1

   test=: 3 : 0  NB. finding roots exactly
 assert. r1 -:!.0&(/:~) r=: >{:p. c=: p. <r1=: y
 1
)

   test 2,10$1
1
   test 1r2,10$1r3
1
   test 1024,10$1r2
1
   test 4 5#1r2 1r3
1
   test 4 5#1r3 1r2
1
   test 1+i.20  NB. Wilkinson monster
1

   ptimes=: +//.@(*/)  NB. polynomial multiplication
   c=: (p.<3j4 3j_4) ptimes p. <1r2,8$1r3
   r=: >{:p. c
   NB. r -:&(/:~) 3j4 3j_4,1r2,8$1r3

   NB. p. roots of unity ---------------------------------------------------

   rou =: ^@:j.@:o.@:+:@(%~i.)
   rov =: >@{:@p.@(_1&,)@({.&1)@-
   rs  =: \: +.

   1e_12 > (rou (>./)@(<./)@:|@(-/) rov)"0 >:i.10
1 1 1 1 1 1 1 1 1 1

   err =: - %&(+/)&:| ]
   f   =: p.@<@rou
   g   =: _1&,@({.&1)@-

   1e_11 >| (f err g)"0 >:i.10
1 1 1 1 1 1 1 1 1 1

   NB. x p. y --------------------------------------------------------------

   pc =: ([ +/@:* i.@#@[ ^~ ])"1 0
   pr =: (>@{.@[ * >@{:@[ */@:-~ ])"1 0
   fc =: *./@,@:(p. -: pc)
   fr =: *./@,@:(p. -: pr)

   NB. Boolean

   (x=:?5$2) fc y=:?7$2
1
   (x=:?5$2) fc y=:_7+?2 3 4$13
1
   (x=:?2$2) fc y=:o._7+?3 4$13
1
   (x=:?6$2) fc y=:r._7+?2 1 4$13
1

   NB. integer

   (x=:_5+?5$11) fc y=:?7$2
1
   (x=:_5+?5$11) fc y=:_7+?2 3 4$13
1
   (x=:_5+?2$11) fc y=:o._7+?3 4$13
1
   (x=:_5+?6$11) fc y=:r._7+?2 1 4$13
1

   NB. real

   (x=:_2.5+?5$11) fc y=:?7$2
1
   (x=:_2.5+?5$11) fc y=:_7+?2 3 4$13
1
   (x=:_2.5+?2$11) fc y=:o._7+?3 4$13
1
   (x=:o._4+?6$11) fc y=:r._7+?2 1 4$13
1

   NB. complex

   (x=:j./_5+?2 5$11) fc y=:?7$2
1
   (x=:r.?5$110)      fc y=:_7+?2 3 4$13
1
   (x=:r.?2$110)      fc y=:o._7+?3 4$13
1
   (x=:r._4+?6$11)    fc y=:r._7+?2 1 4$13
1

   ($0) -: (1 1&p. 0#0) % (1 1&p. 0#0)  NB. crashed when loop ran with 0 elements
1
   ($0) -: (1 1&p. 0#4) % (1 1&p. 0#4)  NB. crashed when loop ran with 0 elements
1
   ($0) -: (1 1&p. 0#1.) % (1 1&p. 0#1.)  NB. crashed when loop ran with 0 elements
1
   ($0) -: (1 1&p. 0#1j1) % (1 1&p. 0#1j1)  NB. crashed when loop ran with 0 elements
1

   'domain error' -: ($0) p. etx y=:?3 4$2
1
   'domain error' -: ($0) p. etx y=:?3 4 1$100
1
   'domain error' -: ($0) p. etx y=:o.?3 4$100
1
   'domain error' -: ($0) p. etx y=:r.?3 4$100
1

   'domain error' -: ($0) p. etx y=:?3 4$2
1
   'domain error' -: ($0) p. etx y=:?3 4 1$100
1
   'domain error' -: ($0) p. etx y=:o.?3 4$100
1
   'domain error' -: ($0) p. etx y=:r.?3 4$100
1

   (( <1 2 3) p. x) -: (1;1 2 3) p. x=:?2 3 4$100
1
   ((,<1 2 3) p. x) -: (1;1 2 3) p. x=:?2 3 4$100
1

   ((2  ;1r7) p. x) -: 2   * x-1r7 [ x=: ?2 3 4$100
1
   ((2.5;1r7) p. x) -: 2.5 * x-1r7 [ x=: ?2 3 4$100
1
   ((2j5;1r7) p. x) -: 2j5 * x-1r7 [ x=: ?2 3 4$100
1

   ((2  ;1r7) p. x) -: 2   * x-1r7 [ x=: o.?2 3 4$100
1
   ((2.5;1r7) p. x) -: 2.5 * x-1r7 [ x=: o.?2 3 4$100
1
   ((2j5;1r7) p. x) -: 2j5 * x-1r7 [ x=: o.?2 3 4$100
1

   ((2  ;1r7) p. x) -: 2   * x-1r7 [ x=: j./?2 3 4$100
1
   ((2.5;1r7) p. x) -: 2.5 * x-1r7 [ x=: j./?2 3 4$100
1
   ((2j5;1r7) p. x) -: 2j5 * x-1r7 [ x=: j./?2 3 4$100
1

   (i.2 3) fc"1 i.5
1 1

   x=: 2 5 ?@$ 10
   y=: 2   ?@$ 12
   x (p."2 1 -: p."1 0"2 1) y
1
   3 2 3 -: $ 0 1 2 p."0 _ i. 2 3
1
   2 3 4 -: $ 0 1 2 p."1 _ i. 2 3 4
1
   2 3 4 -: $ 0 1 2 p."1 1 i. 2 3 4
1
   2 3 4 -: $ 0 1 2 p."1 2 i. 2 3 4
1
   2 3 4 -: $ 0 1 2 p."1 3 i. 2 3 4
1
   2 3 4 -: $ 0 1 2 p."1 4 i. 2 3 4
1
   0 12 52 -: (i. 3 3) p."1 0 i. 3
1

   'domain error' -: 'abc'       p. etx 3    
1
   'domain error' -: 4 5 6       p. etx 'ab' 
1
   'domain error' -: 1 2 3       p. etx <4 5 6 
1
   'domain error' -: 1 2 3       p. etx <3;4 5 6 
1
   'domain error' -: (3;4 5)     p. etx 'ab' 
1
   'domain error' -: ('a';_3 7)  p. etx 4 5  
1
   'domain error' -: (3;'abc')   p. etx 4 5  
1
   'domain error' -: (3;<<1 2 3) p. etx 4 5  
1
   'domain error' -: ((<3);2 3)  p. etx 4 5  
1

   'length error' -: (i.2 4)     p. etx 3 4 5   
1
   'length error' -: (3;4 5;6 7) p. etx 1 2 3 4 
1

   'rank error'   -: (3 4;1 2 3) p. etx 4 5     
1
   'rank error'   -: (3;i.2 3)   p. etx 4 5     
1

   NB. x ^@:p. y -----------------------------------------------------------
   'domain error' -: ($0) ^@:p. etx y=:?3 4$2
1
   'domain error' -: ($0) ^@:p. etx y=:?3 4 1$100
1
   'domain error' -: ($0) ^@:p. etx y=:o.?3 4$100
1
   'domain error' -: ($0) ^@:p. etx y=:r.?3 4$100
1

   'domain error' -: ($0) ^@:p. etx y=:?3 4$2
1
   'domain error' -: ($0) ^@:p. etx y=:?3 4 1$100
1
   'domain error' -: ($0) ^@:p. etx y=:o.?3 4$100
1
   'domain error' -: ($0) ^@:p. etx y=:r.?3 4$100
1

   f =: 4 : 0
res =. (x ^@p. etx y) (-: +. -:&(0 ([`([: I. 1e_50 > |@])`])} ])`1:@.(2 e. ,&(3!:0)) ) x ^@:p. etx y  NB. either tolerant = or both less than a tiny value
if. -. res do. xx =: x [ yy =: y end.
res
)

   y =: (10 ?@$ 2);(_500 + 10 ?@$ 1000);(_5 10 p. 10 ?@$ 0);(j./ _5 10 p. 2 10 ?@$ 0);(x: _500 + 10 ?@$ 1000);(_2 x: x: (+ 0&=) _500 + 10 2 ?@$ 1000);_ __ 0 0 __ _ _ _ __ __
   (0;1;2.5;2j1;3x;4r3) f&>/ y
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
   (0 1;1 3;2.5 3.2;2j1 3j1;3x 2x;4r3 8r5) f&>/ y
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
   (0 1 1;1 3 2;2.5 3.2 _1.4;2j1 3j1 0.5j_1;3x 2x 4x;4r3 8r5 6) f&>/ y
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
   (<2.5 3.2 _1.4 _) f&>/ y
0 1 1 1 1 1 0
|assertion failure
|[-279] //test/gpoly.ijs
rdm commented 2 years ago

This playground link does not work for me. I get: |value error: ECHOFILENAME

This suggests that this was run in a pre-conditioned environment, presumably one representing the contents of https://github.com/jsoftware/jsource/blob/master/test/tsu.ijs

That said, when I insert those lines at the top of the edit window and run all lines, this is not failing for me in Microsoft Edge, nor in Vivaldi.

joebo commented 2 years ago

Ya, I realize that is suboptimal the way I linked the files, but I figured it was better than nothing and less work than creating a new gist for each... Just igmore the ECHO FILENAME error and look for where there is 0 on a test case or assertion failure an/or find the line from the report above. Thanks for the feedback and trying it out

rdm commented 2 years ago

I was getting other value errors when I did it that way.

I've also updated my previous comment -- this looks like a consequence of browser specific failures.

joebo commented 2 years ago

Hmm, I'm seeing failures in edge on windows.. The direct playground link fails on other cases too due to missing 'etx' definition. I haven't been able to track that down on cursory search

This is from edge, which is the same result i get on chrome

image

joebo commented 2 years ago

I found the definition for etx in tsu.ijs like you mentioned

etx      =: 1 : 'u :: (<:@(13!:11)@i.@0: >@{ 9!:8@i.@0:)'  NB. error message from error number

Adding that to the top of the playground link still shows errors / failing tests (highlighted below)

I haven't dug into the cause yet image

rdm commented 2 years ago

Ah.. I was searching for assertion failure -- though thinking back on this, I don't know why I would have been doing that.

My apologies.

joebo commented 2 years ago

Retested and still failing after the gemm changes in 517e00a2f9c77a2cbe65bd89d624331fb90fe563

1:@:(dbr bind Debug)@:(9!:19)2^_44[(prolog [ echo^:ECHOFILENAME) './gpoly.ijs'
etx      =: 1 : 'u :: (<:@(13!:11)@i.@0: >@{ 9!:8@i.@0:)'  NB. error message from error number

f =: 4 : 0
res =. (x ^@p. etx y) (-: +. -:&(0 ([`([: I. 1e_50 > |@])`])} ])`1:@.(2 e. ,&(3!:0)) ) x ^@:p. etx y  NB. either tolerant = or both less than a tiny value
if. -. res do. xx =: x [ yy =: y end.
res
)

y =: (10 ?@$ 2);(_500 + 10 ?@$ 1000);(_5 10 p. 10 ?@$ 0);(j./ _5 10 p. 2 10 ?@$ 0);(x: _500 + 10 ?@$ 1000);(_2 x: x: (+ 0&=) _500 + 10 2 ?@$ 1000);_ __ 0 0 __ _ _ _ __ __
(<2.5 3.2 _1.4 _) f&>/ y

Here is a small reproducible example

Playground Link