Vocabulary/gtco

From J Wiki
Jump to navigation Jump to search

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

>: y Increment

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
_4 2 1 6

Common uses

1. Simplify a phrase which increments a given value

   y=. >:y             NB. increment y

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

2. Simplify an unwieldy phrase

   z=: 10
   (100-z)+1
91
   >: 100-z
91

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

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

   13 : '(1+y)%y'
] %~ 1 + ]
   13 : '(>:y)%y'
>: % ]

Related Primitives

Decrement (<:)


Use These Combinations

Combinations using  >:y that have exceptionally good performance include:

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Create list of integers from 1 to # y, or the reverse #\ y also #\. which is the reverse faster than >:@i.@# y


x >: y Larger 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 greater than, or equal to, y, returns 1 in that position, else 0.

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

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

   'a' >: 9
|domain error
|   'a'    >:9

This differs from what happens with Equal (=)

   'a' = 9
0

Larger 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

   1.99999999999999 >: 2
1
   1.99999999999999 (>:!.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
0 0 0 0 1 1 0 1

   mask # array       NB. keep only the atoms that are >: 5
5 9 6

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
3 1 4 1 8 12 2 9

Related Primitives

Less Than (x < y), Equal (x = y), Not-Equal (x ~: y), Less Or Equal (x <: y), Larger Than (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