Vocabulary/ampdot

From J Wiki
Jump to navigation Jump to 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?



u&.v is equivalent to (u&.:v)"mv , where mv is the monadic rank of v. That is,

  u&.v y  <-->          {{v^:_1 u (v y)}}"mv y
x u&.v y  <-->  x {{v^:_1 (v x) u (v y)}}"mv y

You should understand Rank (") and the rankless form of Under (&.:) before trying to understand Under (Dual) (&.).

Executes u on the argument(s) with a temporary change of viewpoint, indicated by v. First v is executed, to move to the new viewpoint; then u is executed in the new viewpoint; then the operation of v is undone, restoring the original viewpoint.
like Daylight Saving Time, or buying online in a different currency.

The operation is executed on each cell as defined by the rank of v:

  • 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.
    Some v's can be undone even though as functions they may have no mathematical inverse.

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

This contrasts with u&.:v which applies v to the entire argument(s) and then applies v^:_1@:u on the entire filled and assembled result(s) of v .

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 which is located in  ~system/main/stdlib.ijs
  • View the definition(s) in a JQt session by entering:  open '~system/main/stdlib.ijs'

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|
+---+-------+-----------+


Semiduals x u&.(a:`v) y and x u&.(v`a:) y

The operation encapsulated by u&.v is used often and is important as a notation to aid thought. When the operation is dyadic, sometimes the sequence of transforming/operating/transforming back should be applied to just one argument, with the other argument being passed unchanged into u. This can be represented by a gerund form where a: indicates which argument is to be used unmodified. The form using &. is defined in terms of the infinite-rank version &.::

  • x u&.(a:`v) y is x u&.:(a:`v)"(lu,mv) where lu is the left rank of u and mv is the monadic rank of v
  • x u&.(v`a:) y is x u&.:(v`a:)"(mv,ru) where ru is the right rank of u and mv is the monadic rank of v
   <"2 i. 3 2 4   NB. y is 3 boxes
+-------+-----------+-----------+
|0 1 2 3| 8  9 10 11|16 17 18 19|
|4 5 6 7|12 13 14 15|20 21 22 23|
+-------+-----------+-----------+
   100 200 +"_&.(a:`>) <"2 i. 3 2 4  NB. open y (but not x), add x to each contents, rebox
+---------------+---------------+---------------+
|100 101 102 103|108 109 110 111|116 117 118 119|
|204 205 206 207|212 213 214 215|220 221 222 223|
+---------------+---------------+---------------+
   +"_&.(a:`>) b. 0  NB. This works because the left rank of u&.(a:`v) comes from u
0 _ 0

u&.v y when v has no inverse

Even when v has no inverse, when v rearranges or selects from y, it may be possible to define a notional inverse that, referring to the value of y, reverses the effect of the rearrangement/selection. This surrogate inverse is defined for the following values of v:

v Inverse used
Description of operation
, ($y)&($,) Execute u on (,y), then put result into original shape of y
m&{ m}&y Execute u on selected cells of y, then put result back into those cells

u&.(m&{) y is the preferred idiom for applying u to a portion of y. If m&{ selects a contiguous section of y, the update may be performed in place.


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 .


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