Vocabulary/ampdot

From J Wiki
Jump to: navigation, search

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

[x] u&.v y Under (Dual) Conjunction

Rank -- depends on the rank of v -- WHY IS THIS IMPORTANT?



Executes v on the argument(s) cell-by-cell.

  • For each cell, u is applied to the result(s) of v
  • Then v^:_1 (i.e. the obverse of v) is applied to the result of u — giving the result for that cell.

Finally the results for all cells are collected into the end result.

In mathematical terms:

  • Verb v defines a transformation of the argument(s) (x and) y into the v-domain
  • Next, verb u operates on the transformed argument(s)
  • Lastly the result is transformed back from the v-domain to the original domain.

We say that u is applied under v .

Example: Apply (i.) to the contents of each box separately, and re-box each result separately

   ] y =: 1;2;2 3
+-+-+---+
|1|2|2 3|
+-+-+---+

   u =: i.
   v =: >
   u&.v y
+-+---+-----+
|0|0 1|0 1 2|
| |   |3 4 5|
+-+---+-----+

Common uses

1. The most common use of &. is [x] u&.> y which applies the verb u inside each box of the arguments. This follows the rules above: u&.> has rank 0 regardless of u, so each box is opened separately, operated on, and then reboxed.

Examples:

Convert a list of boxed strings to uppercase

   ] z =: ;:'alpha bravo charlie'
+-----+-----+-------+
|alpha|bravo|charlie|
+-----+-----+-------+
   toupper&.> z
+-----+-----+-------+
|ALPHA|BRAVO|CHARLIE|
+-----+-----+-------+

Add the contents of corresponding boxes

   ]l =. 1;2 3;4 5 6
+-+---+-----+
|1|2 3|4 5 6|
+-+---+-----+
   ]r =. 3 1 4;1 5;9
+-----+---+-+
|3 1 4|1 5|9|
+-----+---+-+
   l +&.> r
+-----+---+--------+
|4 2 5|3 8|13 14 15|
+-----+---+--------+

The standard library defines the name each as &.>

   (<'Mr. ') , each 'Smith';'Jones'
+---------+---------+
|Mr. Smith|Mr. Jones|
+---------+---------+

each is a

  • Standard Library word(s) residing in the 'z'-locale.
  • Defined in the factory script stdlib.ijs.
  • View definition(s) by entering in the J session:  open'stdlib'

2. A useful trick is to use each when one or more arguments are not boxed. Since > y leaves y unchanged if it is not boxed, an unboxed argument will be processed as individual unboxed atoms:

   i.&.> 3 4  NB. i. on each atom, boxing results separately
+-----+-------+
|0 1 2|0 1 2 3|
+-----+-------+
   3 3 4 {. each 'Washington';'Sheffield';'Hereford'
+---+---+----+
|Was|She|Here|
+---+---+----+
   100 + each 3;1 4;1 5 9   NB. Add 100 inside each box
+---+-------+-----------+
|103|101 104|101 105 109|
+---+-------+-----------+

Related Primitives

Under (&.:)


More Information

1. Under (Dual) (&.) differs from Under (&.:) in that  u&.v applies u under v cell-by-cell, whereas  u&.:v applies u under v to the entire argument(s) (x and) y .

2. Let mv be the monadic rank of v. Then:

  •  u&.v y is the same as  (u&.:v)"mv y
  •  x u&.v y is the same as  (u&.:v)"mv y

Use These Combinations

Combinations using  &. y that have exceptionally good performance include:

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Join contents of boxed items along first axis ,&.>/ y Bug warning: Atomic replication is inaccurate. OK if contents of same rank. Better to use <@; y
Join contents of boxed items along last axis ,.&.>/ y
Bitwise operations on bytes byte u&.(a.&i.) y (u y) -: u"0 y avoids conversion to integer
(m b.)/&.(a.&i.) y

x (m b.)&.(a.&i.) y

m is 16 to 31