Vocabulary/plusdot

From J Wiki
Jump to navigation Jump to search

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

+. y Real / Imaginary

Rank 0 -- operates on individual atoms of y, producing a result of higher rank -- WHY IS THIS IMPORTANT?


Decomposes complex numbers into real and imaginary parts

   +. 3j5
3 5
   +. 3j5 4j7
3 5
4 7
   +. 2 2$ 3j5 4j7 2j1 8
3 5
4 7

2 1
8 0

Common uses

Real/Imaginary video

Complex arithmetic.


Related Primitives

Signum (Unit Circle) (* y), Length/Angle (*. y), Magnitude (* y), Imaginary * Complex (j.), Circle Functions (x o. y), Angle * Polar (r.)


x +. y GCD (Or)

Rank 0 0 -- operates on individual atoms of x and y, producing a result of the same shape -- WHY IS THIS IMPORTANT?


The logical operation Or between two Boolean nouns x and y.

In the more general case where x or y are not Boolean, the result is the Greatest Common Divisor (GCD) of x and y.

   0 0 1 1 +. 0 1 0 1
0 1 1 1
   (0 1) +./ (0 1)      NB. Truth-table of: +.
0 1
1 1
   (0 1) +.table (0 1)  NB. Truth-table with borders
+--+---+
|+.|0 1|
+--+---+
|0 |0 1|
|1 |1 1|
+--+---+
   +. table i.13        NB. table defaults x to: y
+--+-----------------------------+
|+.| 0 1 2 3 4 5 6 7 8 9 10 11 12|
+--+-----------------------------+
| 0| 0 1 2 3 4 5 6 7 8 9 10 11 12|
| 1| 1 1 1 1 1 1 1 1 1 1  1  1  1|
| 2| 2 1 2 1 2 1 2 1 2 1  2  1  2|
| 3| 3 1 1 3 1 1 3 1 1 3  1  1  3|
| 4| 4 1 2 1 4 1 2 1 4 1  2  1  4|
| 5| 5 1 1 1 1 5 1 1 1 1  5  1  1|
| 6| 6 1 2 3 2 1 6 1 2 3  2  1  6|
| 7| 7 1 1 1 1 1 1 7 1 1  1  1  1|
| 8| 8 1 2 1 4 1 2 1 8 1  2  1  4|
| 9| 9 1 1 3 1 1 3 1 1 9  1  1  3|
|10|10 1 2 1 2 5 2 1 2 1 10  1  2|
|11|11 1 1 1 1 1 1 1 1 1  1 11  1|
|12|12 1 2 3 4 1 6 1 4 3  2  1 12|
+--+-----------------------------+

Common uses

To form a conditional statement

if. (0=#y) +. (y=0) do.
  ...

Note that both sides of x +. y are always evaluated. There is no primitive that suppresses evaluation of one side if the other side produces 1.

To test if x and y are relatively-prime (result will be 1 if so)

   12 +. 20     NB. factor 4 is the largest both numbers share (GCD)
4
   21 +. 20     NB. both numbers are composite, but co-prime (no common prime factors)
1

More Information

Or video

Related primitives

Not-Or (x +: y), LCM (And) (x *. y), Not-And (x *: y), Not (-. y), Boolean Functions (m b.)


Use These Combinations

Combinations using x +. y that have exceptionally good performance include:

What It Does Type;

Precisions;
Ranks

Syntax Primitives permitted in place of f Variants;

Restrictions

Benefits;

Bug Warnings

Is  x f y true anywhere? Permitted: Boolean, integer, floating point, byte, symbol (not unicode).


x and y need not be the same precision.

x ([: +./ f) y x +./@:f y = ~: < <: > >: e. E. Permitted: (f!:0) (parentheses obligatory!) to force exact comparison.


J recognizes FLO only if f returns an atom or list.

Avoids computing entire  x f y


Bug warning: if f is e. it does (,@e.) rather than e. regardless of ranks of arguments

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Do any cells of y match an m-item? +./@e.&m y Bug warning: it does (,@e.) rather than e.
Boolean reductions on infixes Boolean x +./\ y x positive

*. = ~: in place of +.

much faster than alternatives
Boolean reductions on partitions Boolean x +//. y = <. >. +. * *. ~: in place of + avoids building argument cells
Polynomial Multiplication (Boolean) Boolean x ~://.@(*./) y

x ~://.@(+./) y
x +//.@(*./) y
x +//.@(+./) y

avoids building argument cells
Boolean reductions along diagonals Boolean +.//. y *. = ~: < <: > >: in place of +. avoids building argument cells