Vocabulary/ltco

From J Wiki
Jump to navigation Jump to search

>> <<   Down to: Dyad   Back to: Vocabulary Thru to: Dictionary

<: y Decrement

Rank 0 -- operates on individual atoms of y, producing a result of the same shape -- WHY IS THIS IMPORTANT?


Equivalent to y-1

   <: _5 1 0 5
_6 0 _1 4

Common uses

1. Simplify a phrase which decrements a given value

   y=. <:y             NB. decrement y

   z=: '[a,b]'
   (<: z i. ',') { z   NB. pick the letter BEFORE the comma
a

2. Simplify an unwieldy phrase

   z=: 10
   (100-z)-1
89
   <: 100-z
89

3. Compile a simpler tacit definition from a given explicit (verb) definition

the verb below computes the common mathematical expression: (y-1)/y

   13 : '(y-1)%y'
] %~ 1 -~ ]
   13 : '(<:y)%y'
<: % ]

Related Primitives

Increment >: y


x <: y Less Or Equal

Rank 0 0 -- operates on individual atoms of x and y, producing a result of the same shape -- WHY IS THIS IMPORTANT?


Compares x and y atom-by-atom. See Equal (=) for the details.

Wherever x is less than, or equal to, y, returns 1 in that position, else 0.

   z=: 7 8 9
   z <: 8
1 1 0

x and y must both be numeric, else you get a domain error

   'a' <: 9
|domain error
|   'a'    <:9
|[-0]

This differs from what happens with [[Vocabulary/eq|Equal]] (`=`)

{{{   'a' = 9
0

Less Or Equal (<:) uses tolerant comparison in the same way as Equal (=).

To require exact comparison, use (<:!.0) in place of (<:) to temporarily set the comparison tolerance to zero

   2.00000000000001 <: 2
1
   2.00000000000001 (<:!.0) 2
0

Common uses

1. Make a conditional phrase in a verb definition (explicit definition)

if. x<:y do.  'x y'=. y;x  end.

2. Make a mask of the same shape as array, to process array in some chosen way

   array=: 3 1 4 1 5 9 2 6
   mask=: array <: 5

   array ,: mask

3 1 4 1 5 9 2 6
1 1 1 1 1 0 1 0

   mask # array       NB. keep only the atoms that are <: 5
3 1 4 1 5 2

NOTE: The Boolean atoms of mask are not only truth values but also valid numbers, 0 or 1. Therefore you can use mask directly to process array like this:

   array + 3 * mask   NB. add 3 to the atoms that are <: 5
6 4 7 4 8 9 5 6

Related Primitives

Equal (x = y), Less Than (x < y), Larger Than (x > y), Larger Or Equal (x >: y), Not-Equal (x ~: y)


More Information

1. If an argument to x <: y is complex, its imaginary part must be tolerantly equal to 0, using the default tolerance of 2^_44 even if the comparison x <: y itself uses a different tolerance.


Performance Note

Comparisons are fastest when the precisions are identical. If an atom is compared against an array, it helps to choose the right precision for the atom.

   0. <: %: i. 10  NB. float list: faster than 0 <:
   00 <: i. 10  NB.  integer list: faster than 0 <:

Use These Combinations

Combinations using x <: y that have exceptionally good performance include those shown in Searching and Matching Items: Fast List Operations (FLOs), as well as the following:

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Boolean reductions along diagonals Boolean +.//. y *. = ~: < <: > >: in place of +. avoids building argument cells