I created two test vectors:
integer test:
intst=: _1e10 _1 0 0 1 1e10 _1.1 _0.1 0.1 1.1 100.1 __ _ _.
Integer range test:
rgtst=:10^i.20

My original verb:

(=>.)intst

1 1 1 1 1 1 0 0 0 0 0 1 1 0

(=>.)rgtst

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1


This misses both infinities and the range test.


Hauke's verb:

((=<.)*.(~:<:)) intst

1 1 1 1 1 1 0 0 0 0 0 0 0 0

((=<.)*.(~:<:)) rgtst

1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0


This gets the integers right, but misses some of the larger integers before
they turn into floats.


Raul's verb:

MAXINT=: #.1#~31+32*IF64

MININT=: <:-MAXINT

isinteger=:(=<.)*<:&MAXINT * >:&MININT

isinteger intst

1 1 1 1 1 1 0 0 0 0 0 0 0 0

isinteger rgtst

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0


This gets both tests right.


Devon, Hauke, & Julian proposed just matching and throwing away the items
we didn't want:

([: ((= <.)) _ __ _. -.~ ])intst

1 1 1 1 1 1 0 0 0 0 0 0

([: ((= <.)) _ __ _. -.~ ])rgtst

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1


This misses the range test just like my original verb.


Raul's proposal is the only one that correctly handles the very large
integers. However, most of my uses for an integer-finding verb don't
involve very large floating point integers. Otoh, in my applications there
will occasionally be a divide by zero, producing an infinity value. So
Hauke's finiteinteger verb does the job I need in a nice, concise way. I'll
keep that in my list of handy verbs, replacing my old (=>.).

Skip

On Sun, Aug 2, 2020 at 1:44 AM Skip Cave <[email protected]> wrote:

> I use the (=<.) verb to find integers in a list:
>
>
> * (=<.)1 2.5 2.7 3 4.5 6*
>
> *1 0 0 1 0 1*
>
> * (#~(=<.))1 2.5 2.7 3 4.5 6*
>
> *1 3 6*
>
> I ran across an interesting result when infinity is in the list:
>
> * (=<.)1 2.5 __ 3 4.5 6*
>
> *1 0 1 1 0 1*
>
> * (#~(=<.))1 2.5 __ 3 4.5 6*
>
> *1 __ 3 6*
>
>
> So J is saying that the floor of infinity is infinity (and the ceiling of
> infinity is also infinity). Since infinity is not a number, it would seem
> that an error should be generated when taking the floor of infinity, or
> perhaps NAN, or a zero? In any case, this messes up my nice integer-finding
> verb. Is the\re a mathematical justification for defining the floor of
> infinity to be infinity?
> https://math.stackexchange.com/questions/981708/limit-of-floor-function-when-x-goes-infinity
>
>
> Skip
>
>
> Skip Cave
> Cave Consulting LLC
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to