The joy of interval index.
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
11 posts
• Page 1 of 2 • 1, 2
The joy of interval index.
If I were a twit I would tweet this:
How did we ever live before
How did we ever live before
⍸in both its monadic and dyadic forms?
- paulmansour
- Posts: 418
- Joined: Fri Oct 03, 2008 4:14 pm
Re: The joy of interval index.
Life before ⍸ was via:
where←{⍵/⍳≢⍵}
IntIx←{(-≢⍺)↓+\(⍋⍺,⍵)∊⍳≢⍺}
where←{⍵/⍳≢⍵}
IntIx←{(-≢⍺)↓+\(⍋⍺,⍵)∊⍳≢⍺}
- ArrayMac227
- Posts: 62
- Joined: Sat Sep 12, 2015 1:40 pm
Re: The joy of interval index.
Nope:
Try again!
- Code: Select all
3 6 9 {(-≢⍺)↓+\(⍋⍺,⍵)∊⍳≢⍺} ⍳10
0 0 1 1 1 1 2 2 2 2
3 6 9 ⍸ ⍳10
0 0 1 1 1 2 2 2 3 3
Try again!
- paulmansour
- Posts: 418
- Joined: Fri Oct 03, 2008 4:14 pm
Re: The joy of interval index.
_Not_ originally mine, but:
- Veli-Matti
3 6 9 (+⌿∘.{</⍋⍺⍵}) ⍳10
0 0 1 1 1 2 2 2 3 3
- Veli-Matti
- Veli-Matti
- Posts: 93
- Joined: Sat Nov 28, 2009 3:12 pm
Re: The joy of interval index.
Veli-Matti wrote:_Not_ originally mine, but:3 6 9 (+⌿∘.{</⍋⍺⍵}) ⍳10
0 0 1 1 1 2 2 2 3 3
- Veli-Matti
3 6 9(+⌿∘.≤)⍳10 ⍝⍝ also works, in this case.
⍝⍝ TAO might justify {</⍋⍺⍵}, however
0 0 1 1 1 2 2 2 3 3
To the interpretation of the original question: how do you live without a to-be-builtin feature? You build that feature, and develop as if it is there, because it is there.
- ArrayMac227
- Posts: 62
- Joined: Sat Sep 12, 2015 1:40 pm
Re: The joy of interval index.
Yes, that solution works for numeric arguments, but
-Veli-Matti
'abcdefghijklmnopqrstuvwxyz' ⍸ 'adx'
1 4 24
'abcdefghijklmnopqrstuvwxyz' (+⌿∘.{</⍋⍺⍵}) 'adx'
1 4 24
-Veli-Matti
- Veli-Matti
- Posts: 93
- Joined: Sat Nov 28, 2009 3:12 pm
Re: The joy of interval index.
To the interpretation of the original question: how do you live without a to-be-builtin feature? You build that feature, and develop as if it is there, because it is there.
ArrayMac227
I think you miss the point of my rhetorical question. It's more a long the lines of how did we live before indoor plumbing and electricity? We all know how it was done. The point is, wow, isn't it great to have it.
Particularly interval index, though I have already found the seemingly trivial where function affecting my approach to problems.
I had a non-outer product solution for interval index that I think I lifted from Gary Berquist. The new primitive just dropped right in - they where exactly the same. (I'll post it later when I have a chance). I used it to bucket data for aggregation. But I never really thought of using it for anything else.
But the very act of making it a primitive has changed that. Now when I approach a problem, interval index is in my primary toolbox, and I'll think about it. It turns out there are interesting applications I never would have thought of. Obviously there would be, or Roger Hui would not have made it primitive. Much better minds than mine have thought about this stuff.
Which gets to my next point, the importance of symbolic primitives. The fact that they are strictly limited, as opposed to key words, means that each one has to be important, and deeply useful. I think Hui said about Whitney (who takes limited symbols in K to extreme) to that if he uses a symbol for something it bears watching - that's a bad paraphrase, but you get the idea. (Though in q this economy is unfortunately lost in a welter of unpronounceable key words.)
- paulmansour
- Posts: 418
- Joined: Fri Oct 03, 2008 4:14 pm
Re: The joy of interval index.
Interesting that in q, there is bin and binr. I thought bin stood for putting things in "bins", but it's named for binary search. That must reflect my limited understanding of its uses.
Anyway, I think binr is defined as:
I'm wondering what practical use this is? (I'm sure there is, I just don't know what it is!)
Anyway, I think binr is defined as:
binr←{⍺⍸⍵+~⍵∊⍺}
I'm wondering what practical use this is? (I'm sure there is, I just don't know what it is!)
- paulmansour
- Posts: 418
- Joined: Fri Oct 03, 2008 4:14 pm
Re: The joy of interval index.
By experiment your algorithm switches a member of ⍵ in range ≥ ⍺[i] and < ⍺[i+1] that is also ≥ ⍺[i+1]-1 into the range ≥ ⍺[i+1] and < ⍺[i+2] but I too am
But if it werewondering what practical use this is?
{(⍺⍸⍵)+~⍵∊⍺}(note the parentheses) then it would redefine the ranges as > ⍺[j] and ≤ ⍺[j+1]. i.e. inclusive of upper bound rather than lower. (There's probably a word for that.) Which could be useful I suppose. It would change the equality:
(⍳n) ⍸ x ←→ ⌊xwhere x is ≥⎕io and ≤n into
(⍳n) {(⍺⍸⍵)+~⍵∊⍺} x ←→ ⌈x
-
Phil Last - Posts: 624
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: The joy of interval index.
Yes, I forgot the parens.
- paulmansour
- Posts: 418
- Joined: Fri Oct 03, 2008 4:14 pm
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group