cancel
Showing results for 
Search instead for 
Did you mean: 

Re: bin Operator Questions

erik_friis
New Contributor
OK after careful consideration these make sense to me and I guess there's a rule that 4 < 4 5 6 and 4 5 < 4 5 6.

I would still like to know the rules regarding general lists containing items of mixed rank:

q)((0 0;0 0);(0 0;0 5)) bin ((0 0;0 5); 2 1)

1 1


It seems that according to these results that:


2 1 > (0 0;0 5)


q)((0 0;0 0);(0 0;0 5)) bin ((0 0;0 5); 0 0 0; 0 0; 0; ((0 0;0 0);(0 0;0 0)))

1 1 1 -1 -1


And:


0 0 0 > (0 0;0 5)

0 0 > (0 0;0 5)

0 < (0 0;0 0)

((0 0;0 0);(0 0;0 0)) < (0 0;0 0)


Does not appear that when the shapes are the same, but the ranks are different that item-wise extension kicks in.


7 REPLIES 7

erik_friis
New Contributor

q)(::;((0 0;0 0);(0 0;0 0))) bin (::;0;0 0;(0 0;0 0);((0 0;0 0);(0 0;0 0)))

1 -1 1 1 1


Two more questions:

1.  Why does the null item return a 1

2.  Are atoms handled differently than lists?  I would have expected 1 being returned from the 0 in the right operand.

erik_friis
New Contributor

q)5 2 3 1 4 bin 1 2 3 4 5

-1 1 3 4 4


Is the result undefined if the left operand is not sorted?

Flying
New Contributor III
These two cases seem straightforward?

If there is no match the result is the count of the left argument.

On Wednesday, July 22, 2015 at 1:16:44 PM UTC+8, Erik Friis wrote:
OK these two results I still don't understand--I would have thought they'd be -1

q)(1 1;1 3;1 5)? 0 1

3


q)(1 1;1 3;1 5)? 0 0

3


erik_friis
New Contributor
Yes, sorry about that I'd typed the ? operator by mistake instead of the bin operator.  I realized it late last night and deleted the original post as it makes perfect sense without the typo.  My other questions, however, still stand.  Thanks!

Flying
New Contributor III
I think the result, while incorrect, is understandable.

bin requires its left operand to be sorted. But (::;((0 0;0 0);(0 0;0 0))) is not sorted (try asc it). So when q performs binary search, it might actually start by comparing ((0 0;0 0);(0 0;0 0)) from the left operand with :: first, which will result in a value of 1 being returned.

Flying
New Contributor III
I think the result, while incorrect, is understandable.

bin requires its left operand to be sorted. But (::;((0 0;0 0);(0 0;0 0))) is not sorted (try asc it). So when q performs binary search, it might actually start by comparing ((0 0;0 0);(0 0;0 0)) from the left operand with :: first, which will result in a value of 1 being returned.

erik_friis
New Contributor
Flying,

I do think you're right regarding the fact that the left operand is not sorted being the culprit.  So can we assume that if the left operand is not sorted that the result of bin is undefined?