Chapter 20: Scalar Numerical FunctionsIn 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:
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.
Monadic - is "Negate".
Monadic <: is called "Decrement". It subtracts 1 from its argument.
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.
1 % 0 is "infinity" but 0 % 0 is 0
Monadic % is the "reciprocal" function.
Monadic -: is the "halve" verb:
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
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
More generally, (x %: y) is an abbreviation for (y ^ % x)
Monadic ^. is the "natural logarithm" function.
The number of combinations of x objects selected out of y objects is given by the expression x ! y
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:
Complex numbers are also in the domain of +..
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 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
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)For example:
This is the end of chapter 20
Table of Contents
The examples in this chapter
were executed using J version j701/beta/2010-11-24/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.