Vocabulary/slashco

From J Wiki
Jump to navigation Jump to search

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

/: y Grade Up Verb
\: y Grade Down Verb

Rank Infinity -- operates on x and y as a whole, by items of y -- WHY IS THIS IMPORTANT?


The permutation that sorts the items of y into ascending (/:) or descending (\:) order (numerical or lexicographical)

The atom at position i of (/: y) is the index in y of the ith-largest value of y.

   ] Wk=: ;:'Su Mo Tu We Th Fr Sa'
+--+--+--+--+--+--+--+
|Su|Mo|Tu|We|Th|Fr|Sa|
+--+--+--+--+--+--+--+
   ] p=: /: Wk
5 1 6 0 4 2 3
   p { Wk
+--+--+--+--+--+--+--+
|Fr|Mo|Sa|Su|Th|Tu|We|
+--+--+--+--+--+--+--+
   ] Wko=: > Wk
Su
Mo
Tu
We
Th
Fr
Sa
   p { Wko   NB. also works with unboxed list
Fr
Mo
Sa
Su
Th
Tu
We

Common uses

Invert the permutation q

Note that p{q is the permutation product of permutations p and q

   ] q=: 10?10
8 7 6 9 5 2 0 4 1 3
   ] p=: /:q
6 8 5 9 7 4 2 1 0 3
   p{q
0 1 2 3 4 5 6 7 8 9

Details

1. The permutations (/: y) and (\: y) produce a stable sort (identical keys stay in order).

2. Grading uses intolerant comparison.

3. Any array can be ordered. The first atom in a row is the most significant for ordering purposes; any item of rank higher than 1 is flattened into a list before ordering.

  • Characters are ordered according to the Unicode collating sequence. (For bytes, this is the same as the ordering given by a.).
  • Symbols are ordered according to the order of the character lists they represent (if one string is a prefix of the other, the shorter string comes first)
  • Complex values are ordered on real part first, then imaginary part.

Boxes are ordered according to their contents.

The order of priority for ordering-up is:


Use These Combinations

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

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Find ordinal numbers of y (the relative rank of each item of y in the sort order /:@/: y note \: is not special better than /:^:2 y
Find the index of the xth-largest value of y x is a Boolean or integer atom, y is an integer or floating-point list x ({ /:) y not \: Partitions y using a randomly-selected pivot, so time and space results are variable, even for unchanging arguments


x /: y y /: y Sort Up (Using) Verb
x \: y y \: y Sort Down (Using) Verb

Rank Infinity -- operates on x and y as a whole, by items -- WHY IS THIS IMPORTANT?


Sorts x using the order given by y.

i. e. applies to list x the permutation that sorts list y into ascending (/:) or descending (\:) order (whether numerical or lexicographical). Formally, (x /: y is ((/: y) { x).

If x and y are the same, the noun is sorted into order

   Wk=: ;:'Su Mo Tu We Th Fr Sa'   NB. As defined above
   (100+i.7) /: Wk
105 101 106 100 104 102 103

Common uses

1. Sort a list y

   sort=: /:~   NB. (/:~ y) is the same as: (y /: y)
   sort Wk
+--+--+--+--+--+--+--+
|Fr|Mo|Sa|Su|Th|Tu|We|
+--+--+--+--+--+--+--+

Note: Verb sort_z_ is defined in stdlib.ijs as

sort=: /:~ :/:

sort is a

  • Standard Library word(s) residing in the 'z'-locale
  • Defined in the factory script stdlib.ijs which is located in  ~system/main/stdlib.ijs
  • View the definition(s) in a JQt session by entering:  open '~system/main/stdlib.ijs'

This uses Monad-Dyad (:) to define two separate verbs (/:~) and (/:) for monadic and dyadic usage of the verb: sort.

2. Find the ordinal number of each item of y, that is, the position each item would have if the array were sorted.

   /:@/: 3 1 4 1 5 9
2 0 3 1 4 5

Details

1. If x is an atom, x /: y is a one-atom list.

2. Sorting uses intolerant comparison.

3. y may have fewer items than x. The result is ((/: y) { x).

Use These Combinations

Combinations using x /: y that have exceptionally good performance include:

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Find xth-largest value of y x is a Boolean or integer atom, y is an integer or floating-point list x ({ /:~) y not \: Partitions y using a randomly-selected pivot, so time and space results are variable, even for unchanging arguments