Essays/Indeterminate

From J Wiki
Jump to: navigation, search

Indeterminate

The indeterminate _. is a numeric atom. It is provided to aid in dealing with NaN (not a number) in data from external sources, and should be removed from such data as soon as possible. The verb 128!:5 tests for _. .

The only ways to create _. are as follows:

  • direct entry of _.
  • ".
  • 3!:n
  • DLL call (database, LAPACK, etc.)

Primitives on arguments containing _. , that move data without interpreting the value, produce correct and consistent results. These include $ |. |: # , ,. [ ] { {. {: } }. }: . Other primitives on arguments containing _. may not produce correct or consistent results. In particular, the dyads < <: = >: > ~: -: <. >. do not produce consistent results on arguments containing _. , nor the verbs /: \: , nor the dyads i. i: e. -. , nor the monads ~. ~: , nor verbs defined in terms of these.

Primitives on arguments not containing _. signal NaN error instead of producing _. .

 x+y  x and y are infinite with different signs
 x-y  x and y are infinite with the same sign
 *y  the real and imaginary parts of y are infinite
 x%y  x and y are infinite
 x^.y  x and y are infinite or 0
 x!y  x and y are infinite
 m H. n  similar to the dyad p.
 x p. y  x and y that cause addition of infinities with opposite signs; for example 1 _ _ p. _1
 u T. n y  similar to the dyad p.

0*_ , 0*__ , and 0%0 are all defined to be 0 .

128!:5 (Is NaN)

If z=: 128!:5 y , then z has the same shape as y and an atom of z is 1 if and only if the corresponding atom of y is _. (NaN) or contains _. .

Examples:

   (128!:5) 3.45 6 _. 7
0 0 1 0
   (128!:5) t=. 2 2$1 2;3 4 5;(<<_. 7);_.
0 0
1 1
   (128!:5) < t
1
   (128!:5) ;:'Cogito, ergo sum. _.'
0 0 0 0 0

Replacing _.

_. atoms in a numeric array can be replaced by another value as follows:

   ] x=: 4 5 $ _. (3 ?.@$ 20)}20 ?.@$ 10
  6  5 9 2  4
 9 _. 7 0  4
 6  8 3 8  1
_.  8 0 0 _.

   (128!:5 x){"0 1 x,"0 v=: _999
   6    5 9 2    4
   9 _999 7 0    4
   6    8 3 8    1
_999    8 0 0 _999

Another way involves using arithmetic. This is not recommended as arithmetic on _. may not be correct or consistent.

   b=: 128!:5 x
   (v*b) + x*-.b
   6    5 9 2    4
   9 _999 7 0    4
   6    8 3 8    1
_999    8 0 0 _999



Contributed by Roger Hui. The first two sections duplicate the _. page and the 128!:5 entry of the dictionary.