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
iota (can we play with...)
Re: iota (can we play with...)
in general manipulating a (possibly long) list of numbers should be avoided if at all possible. You will end up allocating memory, performing operations which will cost time and space. You may dislike using ⎕IO but your best bet in this case may be using it! As in
Note that you can also use a namespace to perform operations using a specific system variable. For example you could have
This may not be the best solution, it all depends on the situation.
As for the other pieces I would code something separate. In the "range around 0" case it might be best to simply compute an offset and subtract it from the toal range as in
In fact you could even have a more general function that includes steps and starting position:
but this is difficult to assess, you need to determine what your needs are more specifically.
Code: Select all
I0←{⎕IO←0 ⋄ ⍳⍵}
Note that you can also use a namespace to perform operations using a specific system variable. For example you could have
Code: Select all
I0←⎕NS ⍬ ⋄ I0.⎕IO←0
I0.⍳9
0 1 2 3 4 5 6 7 8
This may not be the best solution, it all depends on the situation.
As for the other pieces I would code something separate. In the "range around 0" case it might be best to simply compute an offset and subtract it from the toal range as in
Code: Select all
I0.range←{(⍳1+2×⍵)-⍵}
I0.range 3
¯3 ¯2 ¯1 0 1 2 3
In fact you could even have a more general function that includes steps and starting position:
Code: Select all
I0.NSO←{(n s o)←3↑⍵,(⍴,⍵)↓0 1 0 ⋄ n=0:⍬ ⋄ (o-1↑t)+t←s×(⍳1+2×n)-n}
but this is difficult to assess, you need to determine what your needs are more specifically.
Re: iota (can we play with...)
Hi Dan, John, & All,
yes of course...
but the nth of the collection for all solutions of sudoku.... is not a short number.
exactly. i explore different way to reduce costs.
i had never used a special NS like this. thanks for the suggestion.
you're right. but i try all my ideas, whatever reasonnable or foolish.
APL is a beautyfull way to explore universe, discover new horizon...
to joke Star Trek, i can said about APL :
"where no mind has gone before..."
have a nice day,
Yves
DanB|Dyalog wrote:in general manipulating a (possibly long) list of numbers should be avoided if at all possible.
yes of course...
but the nth of the collection for all solutions of sudoku.... is not a short number.
Code: Select all
⍳ 50000 ⍝ it is not rare
DanB|Dyalog wrote:You will end up allocating memory, performing operations which will cost time and space
exactly. i explore different way to reduce costs.
Code: Select all
I0←⎕NS ⍬ ⋄ I0.⎕IO←0
I0.range←{(⍳1+2×⍵)-⍵}
I0.range 3
¯3 ¯2 ¯1 0 1 2 3
i had never used a special NS like this. thanks for the suggestion.
DanB|Dyalog wrote:but this is difficult to assess, you need to determine what your needs are more specifically.
you're right. but i try all my ideas, whatever reasonnable or foolish.
APL is a beautyfull way to explore universe, discover new horizon...
to joke Star Trek, i can said about APL :
"where no mind has gone before..."
have a nice day,
Yves
- StephenTaylor
- Posts: 31
- Joined: Thu May 28, 2009 8:20 am
Re: iota (can we play with...)
You might like to use an operator to localise the use of origin 0.
I0←{⎕IO←0 ⋄ ⍺←⊢ ⋄ ⍺ ⍵⍵ ⍵}
⍳I0 3
0 1 2
2⊃I0 'abcd'
c