Vocabulary/bangdot

From J Wiki
Jump to navigation Jump to search

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

u !. n Fit (Customize) Conjunction

The customized verb u!.n is a predetermined variant of primitive verb u according to the (noun) operand n.

Only when u is one of these primitives can it be customized with !.

monadic * Adjust the Absolute Tolerance to (n)
monadic <. >. ~. = ~: #: e. x: Adjust the Relative Tolerance to (n)
dyadic < <: > >: +. *. -. -: | E. i. i: = ~: #: e. u/. u/.. Adjust the Tolerance to (n)
dyadic ^ p. Stope Function
monadic ; Change the Fill Atom to (n)
dyadic $ |. , ,. ,: # {. Change the Fill Atom to (n)
monadic ": Set the Print Precision for floating-point values to (n)
monadic +/ +/!.0 uses compensated summation for the summation
dyadic +/@:*"1 +/@:*"1!.0 uses high precision for the calculation
dyadic i. i.!.1 requires the items of the argument cells to be sorted into nondescending order, and is faster if those cells are integer lists.

Common Uses

1. When v is 0, use intolerant comparison for a number primitive, e.g. Equal (=). Comparisons will require exact equality:

   1 = 1.00000000000001  NB. close is good enough by default
1
   1 =!.(0) 1.00000000000001  NB. but it's not exact
0

In many cases specifying intolerant comparison causes the interpreter to use faster code.

To guarantee using the faster code v must be specified as 0 or (0), not as an equivalent numeric value.

2. Alter the comparison tolerance of a number primitive, e.g. Equal (=).

This is a generalization of the case 1 above.

In J terms this means: make a new customized verb (=!.n) which treats two numbers as equal if their difference is  n*z or less, where z is the greater of the magnitudes (absolute values) of x and y.

except for * y, where a number is treated as equal to 0 if its magnitude is less than n

   ] n=: 2^_34       NB. choose a value for the tolerance
5.82077e_11
   2 = 2+n           NB. Default tolerance is much smaller: 2^_44
0
   2 (=!.n) 2+n      NB. But (=!.n) treats 2 and (2+n) as equal
1
   2 (=!.n) 2+n+n    NB. Still equal! (See below)
1
   2 (=!.n) 2+n+n+n
0

Note: J will not accept values of n greater than  2^_34 . To learn why not, see Essays/Tolerant Comparison. This essay also explains why 2 and 2+n+n are tolerated as effectively equal above.

3. Change the fill atom used for filling empty places during [x] {. y and x |. y

   _5 {. 'abc'
  abc
   _5 {.!.'*' 'abc'
**abc

4. Change the fill atom used for filling empty places when an array is extended by x , y, x ,. y, x ,: y, or ; y to match the shape of the result

   'ab' ,: 'abc'
ab 
abc
   'ab' ,:!.'*' 'abc'
ab*
abc

Note that these verbs always replicate atoms rather than using fill:

   'a' ,: 'abc'
aaa
abc
   'a' ,:!.'*' 'abc'
aaa
abc

5. +/!.0 y uses Kahan's compensated summation algorithm. This gives more accurate totals for long sums.

6. When a verb operates on an arguments whose rank is higher than the verb's, the verb is executed on each cell separately, and the results are assembled into a single array. During assembly, the results are brought to a common shape by adding fill as required. There is no way to alter the atom used for this fill. It is always either 0, ' ', a:, or s: '' depending on the type of the value being filled.


More Information

1. These primitives:  +. *. | #: have an implied tolerant comparison, such as Residue  x | y which tolerantly decides whether the quotient  y % x is an integer or not.