Chapter 20: Scalar Numerical Functions
In this chapter we look at built-in scalar functions for computing numbers from numbers. This chapter is a straight catalog of functions, with links to the sections as follows:
Dyadic + 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.
Dyadic - is arithmetic subtraction.
Monadic - is "Negate".
Monadic >: is called "Increment". It adds 1 to its argument.
Monadic <: is called "Decrement". It subtracts 1 from its argument.
Dyadic * 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.
Dyadic % is division.
1 % 0 is "infinity" but 0 % 0 is 0
Monadic % is the "reciprocal" function.
Monadic +: is the "double" verb.
Monadic -: is the "halve" verb:
Monadic <. (left-angle-bracket 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
Dyadic ^ is the "power" verb: (x^y) is x raised-to-the-power 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
Monadic *: is "Square".
Monadic %: is "Square Root".
If x is integral, then x %: y is the "x'th root" of y:
More generally, (x %: y) is an abbreviation for (y ^ % x)
Dyadic ^. is the base-x logarithm function, that is, (x ^. y) is the logarithm of y to base x :
Monadic ^. is the "natural logarithm" function.
The factorial function is monadic !.
The number of combinations of x objects selected out of y objects is given by the expression x ! y
Monadic | 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:
The 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 +..
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 (x|y) GCD x. Here is a verb E, to model the algorithm.
E =: (| E [) ` [ @. (]=0:)
There is a built-in verb o. (lower-case o dot). Monadic o. is called "Pi Times"; it multiplies its argument by 3.14159...
20.17 Trigonometric and Other Functions
If 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
There 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)
_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)
This is the end of chapter 20
Table of Contents
The examples in this chapter
were executed using J version 601-o-beta.
This chapter last updated 9 Jul 2006 .
Copyright © Roger Stokes 2006. This material may be freely reproduced, provided that this copyright notice is also reproduced.