iota (can we play with...)
Posted: Mon Nov 30, 2015 6:22 pm
Hi All,
in J, iota is design like this
i. 3
0 1 2
i: 3
_3 _2 _1 0 1 2 3
i. _3
2 1 0
(i am sorry, i. and i: are disgracious)
in APL, iota is design like this
⍳ 3
1 2 3
magic of apl, the way is never only one, never unique.
to start simple by 0
{ 0, ⍳ (⍵-1) } 3
0 1 2
{ ⍵↑ 0, ⍳⍵ } 3
0 1 2
{ ¯1 + ⍳⍵ } 3
0 1 2
how to compare each ?
with number of clock for processor, quantity of memory cells, number of move register, ...
the question is not neligible when ⍵ go up to a very big number.
between alien and bigfoot, a strange function
{ ⍳⍵ } 3
1 2 3
may be it is more quicker than the simple iota with biggest number
for the iota symetric around 0
it is a sorted suite of 3 list :
{ (⌽¯1×⍳⍵) , 0 , (⍳⍵) } 3
¯3 ¯2 ¯1 0 1 2 3
or a list with 7 items and a decalage
{ (¯1×(⍵+1)) + ⍳1+2×⍵ } 3
¯3 ¯2 ¯1 0 1 2 3
i have tried also with
{ ⎕io ← ¯1×⍵ ⋄ ⍳1+2×⍵ } 3
DOMAIN ERROR
i dislike to change ⎕io.
now, this way is more readable (for me)
{ 0 , (⍳⍵) , (¯1×⍳⍵) } 3
0 1 2 3 ¯1 ¯2 ¯3
sort ← { ⍵[ ⍋⍵ ] }
series ← { 0 , (⍳⍵) , (¯1×⍳⍵) }
{ sort series ⍵ } 4
¯4 ¯3 ¯2 ¯1 0 1 2 3 4
and a curiosity to finish
series ← { 0, (, (1 ¯1) ×[1] (2 ⍵ ⍴ ⍳ ⍵)) }
{ sort series ⍵ } 4
¯4 ¯3 ¯2 ¯1 0 1 2 3 4
it is just a starter to discover iota
Regards,
Yves
in J, iota is design like this
i. 3
0 1 2
i: 3
_3 _2 _1 0 1 2 3
i. _3
2 1 0
(i am sorry, i. and i: are disgracious)
in APL, iota is design like this
⍳ 3
1 2 3
magic of apl, the way is never only one, never unique.
to start simple by 0
{ 0, ⍳ (⍵-1) } 3
0 1 2
{ ⍵↑ 0, ⍳⍵ } 3
0 1 2
{ ¯1 + ⍳⍵ } 3
0 1 2
how to compare each ?
with number of clock for processor, quantity of memory cells, number of move register, ...
the question is not neligible when ⍵ go up to a very big number.
between alien and bigfoot, a strange function
{ ⍳⍵ } 3
1 2 3
may be it is more quicker than the simple iota with biggest number
for the iota symetric around 0
it is a sorted suite of 3 list :
{ (⌽¯1×⍳⍵) , 0 , (⍳⍵) } 3
¯3 ¯2 ¯1 0 1 2 3
or a list with 7 items and a decalage
{ (¯1×(⍵+1)) + ⍳1+2×⍵ } 3
¯3 ¯2 ¯1 0 1 2 3
i have tried also with
{ ⎕io ← ¯1×⍵ ⋄ ⍳1+2×⍵ } 3
DOMAIN ERROR
i dislike to change ⎕io.
now, this way is more readable (for me)
{ 0 , (⍳⍵) , (¯1×⍳⍵) } 3
0 1 2 3 ¯1 ¯2 ¯3
sort ← { ⍵[ ⍋⍵ ] }
series ← { 0 , (⍳⍵) , (¯1×⍳⍵) }
{ sort series ⍵ } 4
¯4 ¯3 ¯2 ¯1 0 1 2 3 4
and a curiosity to finish
series ← { 0, (, (1 ¯1) ×[1] (2 ⍵ ⍴ ⍳ ⍵)) }
{ sort series ⍵ } 4
¯4 ¯3 ¯2 ¯1 0 1 2 3 4
it is just a starter to discover iota
Regards,
Yves