
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 Numbers from Numbers20.1.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.1.2 Minus and NegateDyadic  is arithmetic subtraction.
Monadic  is "Negate".
20.1.3 Increment and DecrementMonadic >: is called "Increment". It adds 1 to its argument.
Monadic <: is called "Decrement". It subtracts 1 from its argument.
20.1.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.1.5 Division and ReciprocalDyadic % is division.
1 % 0 is "infinity" but 0 % 0 is 0
Monadic % is the "reciprocal" function.
20.1.6 Double and HalveMonadic +: is the "double" verb.
Monadic : is the "halve" verb:
20.1.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.1.8 Power and ExponentiationDyadic ^ 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 pi} +1 = 0 (^ 0j1p1) + 1 0 20.1.9 SquareMonadic *: is "Square".
20.1.10 Square RootMonadic %: is "Square Root".
20.1.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.1.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.1.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.1.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.1.15 GCD and LCMThe greatest common divisor (GCD) of x and y is given by (x +. y). Reals and rationals in the domain of +..
Complex numbers are also in the domain of +..
If x and y are complex, then x +. y may differ from y +. x.
We can see that the same result is produced by Euclid's algorithm for (x GCD y), which is: if y=0 then x, otherwise (xy) GCD x. Here is a verb E, to model the algorithm. E =: ( E [) ` [ @. (]=0:)
The Least Common Multiple of x and y is given by (x *. y).
20.2 Circle Functions20.2.1 Pi TimesThere is a builtin verb o. (lowercase o dot). Monadic o. is called "Pi Times"; it multiplies its argument by 3.14159...
20.2.2 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 (pi 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.2.3 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
This is the end of chapter 20 
Copyright © Roger Stokes 2002. This material may be freely reproduced, provided that this copyright notice is also reproduced.
last updated 16 Mar 2002