
Chapter 20: Scalar Numerical FunctionsIn this chapter we look at builtin scalar functions for computing numbers from numbers. This chapter is a straight catalog of functions, with links to the sections as follows:
20.1 Plus and ConjugateDyadic + is arithmetic addition.
Monadic + is "Conjugate". For a real number y, the conjugate is y. For a complex number xjy (that is, x + 0jy), the conjugate is x  0jy.
20.2 Minus and NegateDyadic  is arithmetic subtraction.
Monadic  is "Negate".
20.3 Increment and DecrementMonadic >: is called "Increment". It adds 1 to its argument.
Monadic <: is called "Decrement". It subtracts 1 from its argument.
20.4 Times and SignumDyadic * is multiplication.
Monadic * is called "Signum". For a real number y, the value of (* y) is _1 or 0 or 1 as y is negative, zero or positive.
More generally, y may be real or complex, and the signum is equivalent to y %  y. Hence the signum of a complex number has magnitude 1 and the same angle as the argument.
20.5 Division and ReciprocalDyadic % is division.
1 % 0 is "infinity" but 0 % 0 is 0
Monadic % is the "reciprocal" function.
20.6 Double and HalveMonadic +: is the "double" verb.
Monadic : is the "halve" verb:
20.7 Floor and CeilingMonadic <. (leftanglebracket dot) is called "Floor". For real y the floor of y is y rounded downwards to an integer, that is, the largest integer not exceeding y.
For complex y, the floor lies within a unit circle center y, that is, the magnitude of (y  <. y) is less than 1.
This condition (magnitude less than 1) means that the floor of say 3.8j3.8 is not 3j3 but 4j3 because 3j3 does not satisfy the condition.
Monadic >. is called "Ceiling". For real y the ceiling of y is y rounded upwards to an integer, that is, the smallest integer greater than or equal to y. For example:
Ceiling applies to complex y
20.8 Power and ExponentialDyadic ^ is the "power" verb: (x^y) is x raisedtothepower y
Monadic ^ is exponentiation (or antilogarithm): ^y means (e^y) where e is Euler's constant, 2.71828...
Euler's equation, supposedly engraved on his tombstone is: e ^{ i π} +1 = 0 (^ 0j1p1) + 1 0j1.22465e_16 20.9 SquareMonadic *: is "Square".
20.10 Square RootMonadic %: is "Square Root".
20.11 RootIf x is integral, then x %: y is the "x'th root" of y:
More generally, (x %: y) is an abbreviation for (y ^ % x)
20.12 Logarithm and Natural LogarithmDyadic ^. is the basex logarithm function, that is, (x ^. y) is the logarithm of y to base x :
Monadic ^. is the "natural logarithm" function.
20.13 Factorial and OutOfThe factorial function is monadic !.
The number of combinations of x objects selected out of y objects is given by the expression x ! y
20.14 Magnitude and ResidueMonadic  is called "Magnitude". For a real number y the magnitude of y is the absolute value:
More generally, y may be real or complex, and the magnitude is equivalent to (%: y * + y).
The dyadic verb  is called "Residue". the remainder when y is divided by x is given by (x  y).
If x  y is zero, then x is a divisor of y:
The "Residue" function applies to complex numbers:
20.15 GCD and LCMThe greatest common divisor (GCD) of x and y is given by (x +. y). Reals and rationals are in the domain of +..
Complex numbers are also in the domain of +..
The Least Common Multiple of x and y is given by (x *. y).
20.16 Pi TimesThere is a builtin verb o. (lowercase o dot). Monadic o. is called "Pi Times"; it multiplies its argument by 3.14159...
20.17 Trigonometric and Other FunctionsIf y is an angle in radians, then the sine of y is given by the expression 1 o. y. The sine of (π over 6) is 0.5
The general scheme for dyadic o. is that (k o. y) means: apply to y a function selected by k. Giving conventional names to the available functions, we have: sin =: 1 & o. NB. sine cos =: 2 & o. NB. cosine tan =: 3 & o. NB. tangent sinh =: 5 & o. NB. hyperbolic sine cosh =: 6 & o. NB. hyperbolic cosine tanh =: 7 & o. NB. hyperbolic tangent asin =: _1 & o. NB. inverse sine acos =: _2 & o. NB. inverse cosine atan =: _3 & o. NB. inverse tangent asinh =: _5 & o. NB. inverse hyperbolic sine acosh =: _6 & o. NB. inverse hyperbolic cosine atanh =: _7 & o. NB. inverse hyperbolic tangent
20.18 Pythagorean FunctionsThere are also the "pythagorean"functions:0 o. y means %: 1  y^2 4 o. y means %: 1 + y^2 8 o. y means %:  1 + y^2 _4 o. y means %: _1 + y^2 _8 o. y means  %:  1 + y^2
and a further group of functions on complex numbers: 9 o. xjy means x (real part) 10 o. xjy means %: (x^2) + (y^2) (magnitude) 11 o. xjy means y (imag part) 12 o. xjy means atan (y % x) (angle)
and finally _9 o. xjy means xjy (identity) _10 o. xjy means x j y (conjugate) _11 o. xjy means 0j1 * xjy (j. xjy) _12 o. a means (cos a)+(j. sin a) (inverse angle)For example:
This is the end of chapter 20 
The examples in this chapter
were executed using J version j701/beta/20101124/22:45.
This chapter last updated 22 Dec 2010
Copyright © Roger Stokes 2010.
This material may be freely reproduced,
provided that this copyright notice is also reproduced.