The joy of interval index.

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
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 !

The joy of interval index.

Postby paulmansour on Mon Jan 21, 2019 9:43 pm

If I were a twit I would tweet this:

How did we ever live before
in both its monadic and dyadic forms?
paulmansour
 
Posts: 282
Joined: Fri Oct 03, 2008 4:14 pm

Re: The joy of interval index.

Postby ArrayMac227 on Tue Jan 22, 2019 6:55 pm

Life before ⍸ was via:

where←{⍵/⍳≢⍵}
IntIx←{(-≢⍺)↓+\(⍋⍺,⍵)∊⍳≢⍺}
ArrayMac227
 
Posts: 47
Joined: Sat Sep 12, 2015 1:40 pm

Re: The joy of interval index.

Postby paulmansour on Tue Jan 22, 2019 9:25 pm

Nope:

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: 282
Joined: Fri Oct 03, 2008 4:14 pm

Re: The joy of interval index.

Postby Veli-Matti on Wed Jan 23, 2019 2:28 pm

_Not_ originally mine, but:
      3 6 9 (+⌿∘.{</⍋⍺⍵})   ⍳10
0 0 1 1 1 2 2 2 3 3

- Veli-Matti
Veli-Matti
 
Posts: 41
Joined: Sat Nov 28, 2009 3:12 pm

Re: The joy of interval index.

Postby ArrayMac227 on Thu Jan 24, 2019 2:15 pm

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: 47
Joined: Sat Sep 12, 2015 1:40 pm

Re: The joy of interval index.

Postby Veli-Matti on Thu Jan 24, 2019 4:54 pm

Yes, that solution works for numeric arguments, but

      'abcdefghijklmnopqrstuvwxyz' ⍸ 'adx'
1 4 24
'abcdefghijklmnopqrstuvwxyz' (+⌿∘.{</⍋⍺⍵}) 'adx'
1 4 24


-Veli-Matti
Veli-Matti
 
Posts: 41
Joined: Sat Nov 28, 2009 3:12 pm

Re: The joy of interval index.

Postby paulmansour on Fri Jan 25, 2019 1:34 pm

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: 282
Joined: Fri Oct 03, 2008 4:14 pm

Re: The joy of interval index.

Postby paulmansour on Fri Jan 25, 2019 2:09 pm

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:

      binr←{⍺⍸⍵+~⍵∊⍺}


I'm wondering what practical use this is? (I'm sure there is, I just don't know what it is!)
paulmansour
 
Posts: 282
Joined: Fri Oct 03, 2008 4:14 pm

Re: The joy of interval index.

Postby Phil Last on Sun Jan 27, 2019 3:38 pm

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
wondering what practical use this is?
But if it were
      {(⍺⍸⍵)+~⍵∊⍺}
(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 ←→ ⌊x
where x is ≥⎕io and ≤n into
      (⍳n) {(⍺⍸⍵)+~⍵∊⍺} x ←→ ⌈x
User avatar
Phil Last
 
Posts: 485
Joined: Thu Jun 18, 2009 6:29 pm

Re: The joy of interval index.

Postby paulmansour on Sun Jan 27, 2019 6:31 pm

Yes, I forgot the parens.
paulmansour
 
Posts: 282
Joined: Fri Oct 03, 2008 4:14 pm

Next

Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest