Essays/The TAO of J

From J Wiki
Jump to navigation Jump to search

The TAO (total array ordering) of J is, from the /: page of the dictionary:

The types: numeric or empty, symbol, literal (1 byte or 2 byte characters), and boxed, are so ordered; within them, a lower rank precedes a higher, and arrays to be compared are padded with fills if necessary to have the same shape. Complex arguments are ordered by real part, then by imaginary. Boxed arrays are ordered according to the opened elements.

A set of relations that are consistent with the comparison used in the standard sort can be defined simply:

ge=: 0 1 -: \:@,&<
gt=: 1 0 -: /:@,&<
le=: 0 1 -: /:@,&<
lt=: 1 0 -: \:@,&<
eq=: -:!.0

Equality is defined with a tolerance of 0 because the comparison in sorting proceeds on that basis.

   1 2 3 gt 0 1 2 3 4
1
   1 2 3 gt i.2 5
0
   1 2 3 gt i.2 5
0
   123 gt '123'
0
   3j4 gt 2j7
1



See also



Contributed by Roger Hui.