Vocabulary/bar

From J Wiki
Jump to navigation Jump to search

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

| y Magnitude

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


The absolute value of numeric y. If y is complex, |y is the magnitude of y.

   |5
5
   |_5                 NB. absolute value
5
   i:3
_3 _2 _1 0 1 2 3
   |i:3                NB. absolute values
3 2 1 0 1 2 3
   |3j_4               NB. magnitude of complex number
5

Common Uses

To separate out the absolute values and the signs of a list of numbers

   (| ; *) i:3
+-------------+----------------+
|3 2 1 0 1 2 3|_1 _1 _1 0 1 1 1|
+-------------+----------------+

Related Primitives

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


x | y Residue

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


The remainder when dividing a given number y by another given number x.

   7 | 50
1
   7 | 49
0

Common uses

1. Detect odd numbers in a given list of numbers

   i.7
0 1 2 3 4 5 6
   2 | i.7
0 1 0 1 0 1 0

2. Detect perfect multiples in a given list of numbers

   0= 3 | i.7
1 0 0 1 0 0 1

Related Primitives

Antibase ((0,x) #: y)


More Information

1. If you want both the quotient and remainder from a division, look at Antibase ((0,x) #: y).


Details

1. For finite x, x | y is extended to negative and complex numbers by the definition x|y ==> y-x*<. y % x+0=x. For infinite x, see below.

2. The result will be between 0 and x, with equality possible only on the 0 side.

  • if x=0, the result is the same as y.
  • if x is real and infinite, the result is y if y has the same sign as x, x if y has opposite sign, 0 if y=0.
  • if x is complex it may not have an infinite real or imaginary part.

3. There is an implied tolerant comparison in the computation of the residue. If y % x is tolerantly equal to an integer, the result of x | y is 0. You can force intolerant comparison using |!.0.


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

Powers mod(m) integer, extended integer x m&|@^ y

m&|@(n&^) y

Avoids the large result of exponentiation
Integer [quotient/]remainder of power of 2 integer x | y with x a power of 2 If x is positive, (-x) 17 b. y is better to get remainder
x #: y with x in the form (0,power of 2)