Hi Boyko, I routinely use a similar idiom that I grabbed from the phrase pages on the website.
http://www.jsoftware.com/help/phrases/intervals.htm The equivalent phrase is: CO=: ({...@] <: [)*.([ < {:@]) A quick test shows that it is faster and almost as lean. ts'(-:-:i.1000000) CO (100000 200000)' 0.0416398 2.83142e7 ts'(-:-:i.1000000) (</@:<)"0 1 (100000 200000)' 0.367399 2.62194e7 -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Boyko Bantchev Sent: Wednesday, October 28, 2009 10:55 AM To: [email protected] Subject: [Jprogramming] x ∈ [y1,y2) Here is a simple idiom for testing whether a number x is contained within a semi-open interval [y1,y2). The problem itself is so simple and commonplace that this solution is probably known to others, but I don't recall to have seen it on J's web pages and it occurred to me only yesterday, so here it is: </@:< . E.g.: 2.4 (</@:<) 2 3 1 (-:-:i.10) (</@:<)"0 1 (1 2) 0 0 0 0 1 1 1 1 0 0 The simplicity of the expression I attribute to the algebraic elegance characteristic for semi-open intervals. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
