Mercurial > hg > jgplsrc
view test/g602.ijs @ 0:e0bbaa717f41 draft default tip
lol J
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Mon, 25 Nov 2013 11:56:30 -0500 |
parents | |
children |
line wrap: on
line source
NB. ":y on non-empty numeric array y ------------------------------------ sprintf =: ": real =: {.@+. imag =: {:@+. minus =: $&'_'@('-'&=@{.) ubar =: >@({&(<;._1 ' _ _ _. _.'))@('iInN'&i.@{.) afte =: minus , (i.&0@(e.&'-+0') }. ]) efmt =: >:@(i.&'e') ({. , afte@}.) ] finite =: ]`efmt@.('e'&e.) massage =: finite`ubar@.(e.&'iInN'@{.) fmtD =: (minus,massage@(e.&'-+'@{.}.])) @ sprintf cleanZ =: (* ] >&| (2^_44)"_ * |.)&.+. fmtZ1 =: fmtD@real , 'j'&,@fmtD@imag`(''"_)@.(0&=@imag) fmtZ =: fmtZ1 NB. @ cleanZ fmtB =: {&'01' fmtI =: sprintf fmt =: (fmtB&.>)`(fmtI&.>)`(fmtD&.>)`(fmtZ&.>) @. (1 4 8&i.@(3!:0)) sh =: (*/@}:,{:@(1&,))@$ ($,) ] width =: (<:@{. 0} ])@:>:@(>./)@sh@:(#&>) th =: (-@width ;@:({.&.>)"1 ]) @ fmt f =: ": -: th f x=:1=?2 3 4$2 f x=:_50+?2 3 4$100 f x=:o._50+?2 3 4$100 f x=:r.?4 3 2$100 f x=:1=?2 f x=:_50+?100 f x=:o._50+?100 f x=:r.?100 f x=:r.0 f x=:_3.1415e_76 _3.1415e76 f x=:_3.1415e_76j_3.1415e76 f _ f __ f _. f 3 7$ _ 3 __ 4 _. 6 (":_3.1415e_76) -: fmtD '-3.1415e-76' (":_3.1415e76 ) -: fmtD '-3.1415e+076' (": _) -: fmtD 'INF' (": _) -: fmtD 'inf' (":__) -: fmtD '-INF' (":__) -: fmtD '-inf' (":_.) -: fmtD 'NAN' (":_.) -: fmtD 'nan' (":_.) -: fmtD '+NAN01' (":_.) -: fmtD '+nan01' (,'_' ) -: ": _ '__' -: ": __ '_.' -: ": _. (":x) -: }. ; ' ',&.>":&.>x=: 4 5,imax,1 _2 3 (":x) -: }. ; ' ',&.>":&.>x=: 4 5,imin,1 _2 3 (":imax) -: ": <:2x^IF64{31 63 (":imin) -: ": - 2x^IF64{31 63 sqz=: #"1~ -.@(1 1&E.)@(*./)@(' '&=) (":x) -: sqz _3 }.@,\' ',.":,., x=: 2 3$imax,1 2 _3 (":x) -: sqz _3 }.@,\' ',.":,., x=: 2 3$imin,1 2 _3 NB. ":y print precision ------------------------------------------------- pi=:o.1 '3.14159' -: ":pi '3.14159' -: ":!.6 pi '3.141592653589793' -: ":!.16 pi ppq =: 9!:10 pp =: 9!:11 6 -: ppq '' x=:7^_4+i.14 (": -: ":!. 6) x (": -: ":!. 4) x [ pp 4 (": -: ":!. 8) x [ pp 8 (": -: ":!.12) x [ pp 12 (": -: ":!. 6) x [ pp 6 'domain error' -: pp etx 'a' 'domain error' -: pp etx <7 'domain error' -: pp etx 7.5 'domain error' -: pp etx 7j5 'domain error' -: pp etx _6 'rank error' -: pp etx 5 6 'limit error' -: pp etx 25 NB. ":y on boxed array y ------------------------------------------------ boxed =: 32 = 3!:0 mt =: 0 e. $ boxc =: 9!:6 '' tcorn =: 2 0{boxc tint =: 1 10{boxc bcorn =: 8 6{boxc bint =: 7 10{boxc sh =: (*/@}: , {:)@(1&,)@$ $ , rows =: */\.@}:@$ bl =: }.@(,&0)@(+/)@(0&=)@(|/ i.@{.@(,&1)) mask =: 1&,. #&, ,.&0@>:@i.@# mat =: mask@bl@rows { ' ' , sh edge =: ,@(1&,.)@[ }.@# +:@#@[ $ ] left =: edge&(3 9{boxc)@>@(0&{)@[ , "0 1"2 ] right =: edge&(5 9{boxc)@>@(0&{)@[ ,~"0 1"2 ] top =: 1&|.@(tcorn&,)@(edge&tint)@>@(1&{)@[ ,"2 ] bot =: 1&|.@(bcorn&,)@(edge&bint)@>@(1&{)@[ ,"2~ ] perim =: [ top [ bot [ left right topleft =: (4{boxc)&((<0 0)}) @ ((_2{boxc)&,.) @ ((_1{boxc)&,) inside =: 1 1&}. @: ; @: (,.&.>/"1) @: (topleft&.>) take =: {. ' '"_^:mt frame =: [ perim {@[ inside@:(take&.>)"2 ,:^:(1 = #@$)@] rc =: (>./@sh&.>) @: (,.@|:"2@:(0&{"1);1&{"1) @: ($&>) thorn1 =: ":`thbox @. boxed thbox =: (rc frame ]) @: (mat@thorn1&.>) f =: ": -: thorn1 y =: 2 3$(i.2 3);'abc';(i.4 1);(2 2$'ussr');12;<+&.>i.2 2 3 f y f <'abc' f <'' f <2 0 3$'abc' f <2 3 4 2$'abc' f ;:'Cogito, ergo sum.' f (?3$20)?&.>30 f <i.2 3 f 3;<o.i.2 3 f <<3;<r.?1 1 2 3$100 f <<'';i.2 0 3 4 2 f +&.>i.2 3 4 f (<i.3 4) (<0 0 0)} +.&.>i.2 3 4 NB. x":y ---------------------------------------------------------------- sp =: +./@(0&>)@+.@[ >:@*. 0&<:@] f0 =: (-.&' ') @ (((* * 20&+@|)@{. j. {:)@+.@[ ": ]) f =: 4 : 0 ((*./0<:+.x)*x sp {.y)}. ; ((x sp y)$&.>' ') ,&.> x <@f0"0 y ) f =: 4 : 0 }.;' ' ,&.> x <@f0"0 y ) NB. Boolean t=:(,. 15 j.i.10) <@": 0 t -: (1+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '0.',9$'0' t=:(,.- 15 j.i.10) <@": 0 t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 ' 0.',9$'0' (0j4 f t) -: 0j4 ": t=:1=?9$2 (0j_4 f t) -: 0j_4 ": t=:1=?9$2 (0 ": t) -: 0 ": (2-2)+t=:?10 10$2 '*****' -: 5j6":0 NB. integer t=:(,.15 j. i.10) <@": 3 t -: (1+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '3.',9$'0' t=:(,.15 j. i.10) <@": _3 t -: (2+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '_3.',9$'0' t=:(,.-15 j. i.10) <@": 3 t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 ' 3.',9$'0' t=:(,.-15 j. i.10) <@": _3 t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 '_3.',9$'0' (0j4 f t) -: 0j4 ": t=:_50+?9$100 (0j_4 f t) -: 0j_4 ": t=:_50+?9$100 '*****' -: 5j3":12 NB. floating point t=:(,. 15 j. i.10) <@": 3.2 t -: (1+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '3.2',8$'0' t=:(,. 15 j. i.10) <@": _3.2 t -: (2+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '_3.2',8$'0' t=:(,.-15 j. i.10) <@": 3.2 t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 ' 3.2',8$'0' t=:(,.-15 j. i.10) <@": _3.2 t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 '_3.2',8$'0' (0j4 f t) -: 0j4 ": t=:o._50+?9$100 (0j_4 f t) -: 0j_4 ": t=:o._50+?9$100 '*****' -: 5j3":_1.2 NB. complex t=:(,. 15 j. i.10) <@": 3.2j4 t -: (1+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '3.2',8$'0' t=:(,. 15 j. i.10) <@": _3.2j4 t -: (2+(*k)+k=:i.10) <&(_15&{.)@{."0 1 '_3.2',8$'0' t=:(,.-15 j. i.10) <@": 3.2j4 t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 ' 3.2',8$'0' t=:(,.-15 j. i.10) <@": _3.2j4 t -: (2+(*k)+k=:i.10) <&(15&{.)&(,&'e0')@{."0 1 '_3.2',8$'0' '*****' -: 5j3":_1.2j4 (;_1 _2 _3<@{."0 t{'01') -: 1 2 3": t=:1=?3$2 (;_1 _2 _3<@{."0 t{'0123456789') -: 1 2 3": t=:?3$10 (9 {."1 ' _',:' __') -: 0 _1 { _9j2 ": ,. _ , (i: 5) , __ (9 {."1 ' _',:' __') -: 0 _1 { 9j_2 ": ,. _ , (i: 5) , __ test =: 4 : '((}:$z)-:}:$y),(#$z)-:1>.#$y [ z=: x ": y' 9j4 test 50 9j4 test ,12 9j4 test 1 2 3 9j4 test i.1 3 9j4 test i.3 1 9j4 test i.3 4 9j4 test i.2 3 4 9j4 test i.2 3 4 5 0j4 test 50 0j4 test ,12 0j4 test 1 2 3 0j4 test i.1 3 0j4 test i.3 1 0j4 test i.3 4 0j4 test i.2 3 4 0j4 test i.2 3 4 5 9j4 test i.0 9j4 test i.5 0 9j4 test i.0 5 9j4 test i.2 0 4 0j4 test i.0 0j4 test i.5 0 0j4 test i.0 5 0j4 test i.2 0 4 (_12{.'1234.57') -: 12j2 ": 1234.567 -:/ 10 ": ,. 3.33e_16 _3.33e_16 -:/ 10j4 ": ,. 3.33e_16 _3.33e_16 ' 0' -: 3 ": _3.33e_12j_4.44e_14 'domain error' -: 9.2 ": etx 12 'domain error' -: 9j2 ": etx '3 4' 'domain error' -: 9j2 ": etx <123 'domain error' -: 'ab' ": etx 4 5 'domain error' -: (<21) ": etx 4 5 'length error' -: 1 2 ": etx 4 'length error' -: 1 2 ": etx 4 5 6 'length error' -: 1 2 ": etx i.2 3 'length error' -: 1 2 ": etx i.2 3 4 NB. x":y on boxed arrays ------------------------------------------------ (0 0 ": x) -: ": x=: ,. ;: 'Cogito, ergo sum.' (' *'{~0=i.3 3) -: 3 3{.1 1}.0 0":x=:x,:|.x=:(1 1$'*');3 3$'*' (' *'{~1=i.3 3) -: 3 3{.1 1}.0 1":x (' *'{~2=i.3 3) -: 3 3{.1 1}.0 2":x (' *'{~3=i.3 3) -: 3 3{.1 1}.1 0":x (' *'{~4=i.3 3) -: 3 3{.1 1}.1 1":x (' *'{~5=i.3 3) -: 3 3{.1 1}.1 2":x (' *'{~6=i.3 3) -: 3 3{.1 1}.2 0":x (' *'{~7=i.3 3) -: 3 3{.1 1}.2 1":x (' *'{~8=i.3 3) -: 3 3{.1 1}.2 2":x f =: 4 : 0 old=.9!:16 '' 9!:17 x z=.":y 9!:17 old z ) 0 0 (f -: ":) x=:i.&.>i.2 3 4 0 1 (f -: ":) x 0 2 (f -: ":) x 1 0 (f -: ":) x 1 1 (f -: ":) x 1 2 (f -: ":) x 2 0 (f -: ":) x 2 1 (f -: ":) x 2 2 (f -: ":) x 0 0 (f -: ":) x=:i.&.><"1 >:7 7#:?4 3$49 0 1 (f -: ":) x 0 2 (f -: ":) x 1 0 (f -: ":) x 1 1 (f -: ":) x 1 2 (f -: ":) x 2 0 (f -: ":) x 2 1 (f -: ":) x 2 2 (f -: ":) x 'domain error' -: 'ab' ": etx 1;2;3 'domain error' -: 1.2 0 ": etx 1;2;3 'domain error' -: 1 2j3 ": etx 1;2;3 'domain error' -: (1;2) ": etx 1;2;3 'length error' -: 0 1 2 3 ": etx 1;2;3 'length error' -: (i.0) ": etx 1;2;3 NB. x":y on extended integers ------------------------------------------- 20j4 (": -: (": x:)) x=: _5e8+?20$1e9 20j4 (": -: (": x:)) ,.x 20j4 (": -: (": x:)) 5 4$x 20j0 (": -: (": x:)) x 20j0 (": -: (": x:)) ,.x 20j0 (": -: (": x:)) 5 4$x 0j4 (": -: (": x:)) x 0j4 (": -: (": x:)) ,.x 0j4 (": -: (": x:)) 5 4$x 0 (": -: (": x:)) x 0 (": -: (": x:)) ,.x 0 (": -: (": x:)) 5 4$x 0j_4 (": -: (": x:)) 123454 0j_4 (": -: (": x:)) 123455 0j_4 (": -: (": x:)) 123456 0j_4 (": -: (": x:)) 123496 0j_4 (": -: (": x:)) 123996 0j_4 (": -: (": x:)) 129996 0j_4 (": -: (": x:)) 199996 0j_4 (": -: (": x:)) 999996 _14 (": -: (": x:)) 123454 _14 (": -: (": x:)) 123455 _14 (": -: (": x:)) 123456 _14 (": -: (": x:)) 123496 _14 (": -: (": x:)) 123996 _14 (": -: (": x:)) 129996 _14 (": -: (": x:)) 199996 _14 (": -: (": x:)) 999996 0j_6 (": -: (": x:)) 1234 0j_6 (": -: (": x:)) 1235 0j_6 (": -: (": x:)) 1236 0j_6 (": -: (": x:)) 1239 0j_6 (": -: (": x:)) 1299 0j_6 (": -: (": x:)) 1999 0j_6 (": -: (": x:)) 9999 0j3 (": -: (": x:^:_1)) 12344x 12346 12347 % 10000x 0j3 (": -: (": x:^:_1)) 12349x 12399 12999 19999 99999 % 10000x 0j3 (": -: (": x:^:_1)) x=: %/x: (+ 0&=) _4e8+?2 20 5$1e9 12j3 (": -: (": x:^:_1)) 12344x 12346 12347 % 10000x 12j3 (": -: (": x:^:_1)) 12349x 12399 12999 19999 99999 % 10000x 12j3 (": -: (": x:^:_1)) x=: %/x: (+ 0&=) _4e8+?2 20 5$1e9 '0.0000e0' -: 0j_4 ": 0r1 '0.0000' -: 0j4 ": 0r1 2 50027 -: $ 0j25 ": ,. 10 ^ 0 50000x 4!:55 ;:'afte bcorn bint bl bot boxc boxed cleanZ edge efmt ' 4!:55 ;:'f f0 finite fmt fmtB fmtD fmtI fmtZ fmtZ1 frame ' 4!:55 ;:'imag inside k left mask massage mat minus mt perim ' 4!:55 ;:'pi pp ppq rc real right rows sh sp sprintf ' 4!:55 ;:'sqz t take tcorn test th thbox thorn1 tint top ' 4!:55 ;:'topleft ubar width x y z '