Vocabulary/slashdot

From J Wiki
Jump to navigation Jump to search

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

u/. y Oblique Adverb

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


(u/.y) applies verb u to the oblique diagonals of table y

   ] y=: 4 4 $ i.3
0 1 2 0
1 2 0 1
2 0 1 2
0 1 2 0
   </. y
+-+---+-----+-------+-----+---+-+
|0|1 1|2 2 2|0 0 0 0|1 1 1|2 2|0|
+-+---+-----+-------+-----+---+-+

Common Uses

1. As part of the idiom for polynomial multiplication

    (1 2) */ (3 4 2)         NB. consider this product
3 4 2
6 8 4
   +/ /. (1 2) */ (3 4 2)    NB. sum up the oblique diagonals
3 10 10 4
   pmul =: +//.@(*/)         NB. define a dyadic verb to calculate the coefficients
   1 2 pmul 3 4 2            NB. of e.g. (2x+1)(2x^2+4x+3)=4x^3+10x^2+10x+3
3 10 10 4

More Information

1. u can be a cyclic gerund.


Details

1. The arguments to the invocations of u are lists of (_2)-cells of y

2. If y has no items, the result of u/. y will also have no items.

However, u will be executed once on a cell of 0 _2-cells to establish the shape of a result of u, and then the result of  u/. y will be a list of 0 of that shape

   $ ]/. i. 0 3    NB. u is executed on a cell of shape 0
0 0
   $ ]/. i. 0 3 4  NB. u is executed on a cell of shape 0 4
0 0 4

Use These Combinations

Combinations using u/. y that have exceptionally good performance are shown in Diagonals and Polynomials.


x u/. y Key Adverb
x u/.. y Key dyad Adverb

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


Classifies items of x into partitions of identical items. Then y is partitioned using the partitioning that was calculated for x, and u is applied on each partition of y.

Note: x and y must have the same number of items.

Each item of x is the key of the corresponding item of y, and u is applied to each set of items of y with equal keys.

For /., noun x is used only for the partitioning and is not an argument to operand u. For /.., the key value from x becomes the x argument to u.

x is classified by tolerant comparison. The value used for the x argument to u is the first one in the partition.


   y=: 'AbcDeFGhijk'
   ] x=: y e. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'   NB. 1=uppercase, 0=lowercase
1 0 0 1 0 1 1 0 0 0 0

   x ]/. y  NB. partitions of y
ADFG
bcehijk
   x </. y
+----+-------+
|ADFG|bcehijk|
+----+-------+
   x ;/.. y  NB. key from x and partition of y
+-+-------+
|1|ADFG   |
+-+-------+
|0|bcehijk|
+-+-------+

Common Uses

1. Count the numbers of different items, using  #/.

   a =: 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
   (~.a) ,: (a #/. a)                    NB. unique digits, then frequency of each
3 1 4 5 9 2 6 8 7
2 2 1 3 3 1 1 1 1

2. Collect information from records with identical keys

   ]data =: _2 ]\ 'Fred';90;'John';75;'Fred';95;'John';85;'Susan';100;'John';86   NB. A table
+-----+---+
|Fred |90 |
+-----+---+
|John |75 |
+-----+---+
|Fred |95 |
+-----+---+
|John |85 |
+-----+---+
|Susan|100|
+-----+---+
|John |86 |
+-----+---+
   ]s =: ({."1 data) <@;/. ({:"1 data)   NB. Use first column as keys; collect second-column values
+-----+--------+---+
|90 95|75 85 86|100|
+-----+--------+---+
   (~. {."1 data) ,. s                   NB. Reinstall the name
+-----+--------+
|Fred |90 95   |
+-----+--------+
|John |75 85 86|
+-----+--------+
|Susan|100     |
+-----+--------+

More Information

1. u can be a cyclic gerund

   x tolower`toupper/. y
adfg
BCEHIJK

Details

1.  x u/. y is a member of the i.-family.

2. The argument to each invocation of u is a list of items of y (this has the same rank as y unless y is an atom).

3. The partitions are processed in the same order as the items in  ~. x .

4. The partitioning uses tolerant comparison. Use u/.!.0 for intolerant comparison.

5. If y has no items, the result of  x u/. y will also have no items.

However, u will be executed once on a cell of 0 items to establish the shape of a result of u, and then the result of  x u/. y will be a list of 0 of that shape

   $ '' ]/. ''        NB. u is executed on cell of shape 0
0 0
   $ '' {./. ''       NB. u produces an atomic result
0
   $ '' {./. i. 0 3   NB. u is executed on cell of shape 0 3
0 3

---

Oddities

If a tolerance is specified using u/.!.f, that tolerance is used as the default tolerance during the execution of u. ---

Use These Combinations

Combinations using x u/. y that have exceptionally good performance are shown in Partitions and Diagonals and Polynomials.