The adoption of the notations $x^2$ and $x^3$ for the square and the cube functions united these two monadic functions in a single dyadic "power" function. Moreover, the notation suggested fruitful extensions from the exponents 2 and 3 to negative, fractional, and even complex, numbers.
Adopting De Morgans symbol ^ for the power, we can bring the expression for powers to the form used for other dyadic functions, as in x+3 and x-3 and x*3. Thus:
In [ ]:
5^2
In [ ]:
5^3
In [ ]:
5^2 3 0.5
In [ ]:
(5^2)*(5^3)
In [ ]:
5^5
In [ ]:
5^_3
In [ ]:
(5^_3)*(5^3)
As illustrated above, the power function unites a variety of monadic functions in a single family, providing insight into relations among the family members, as well as economy of notation.
In what follows, we will define further families based on the power function, including polynomials, rationals, rising and falling factorial functions, hypergeometrics, the exponential, and circular and hyperbolic sines and cosines.
In [ ]:
x=: 2
In [ ]:
(3*x^2)+(2*x^3)
In [ ]:
0 0 3 2 p. x
In [ ]:
3+(2*x)+(x^3)
In [ ]:
3 2 0 1 p. x
An operator applies to verbs and nouns, i.e. functions and variables, to produce a function. In what follows, we will use operators to define new families, but will also introduce the Taylor operator (t.) for the purpose of clarifying the definitions and uses of certain functions.
We begin with some simple examples of operators:
In [ ]:
f=: 0 0 3 2 & p. NB. &(And or With) bonds the argument with p.
In [ ]:
f x
In [ ]:
g=: 3 2 0 1 & p.
In [ ]:
g x
In [ ]:
f g x
In [ ]:
h=: f@g NB. @ (Atop) applies f atop the result of g
In [ ]:
h x
In [ ]:
i=: 0 1 2 3 4 5 6 7 8
In [ ]:
f t. i
In [ ]:
g t. i
In [ ]:
(f@g) t. i
In [ ]:
(f*g) t. i NB. Product of polynomials
In [ ]:
0 0 9 12 4 3 2 0 0 p. x
In [ ]:
(f x)*(g x)
In [ ]:
(f*g) x
In [ ]:
(f+g) t. i NB. Sum of polynomials
To gain deeper understanding, experiment with variations on the expressions used in each section. For example, enter the last expression from the preceding section, that is:
```(f+g) t. i```
Then enter the following two sentences, separately:
```i.4```
```(f+g) t. i.4```
To facilitate accurate re-entry, use the up arrow key to move the cursor up to any desired expression on the screen and then press the ENTER key to bring it down to the entry area for possible revision before again pressing ENTER to execute it.
Revision may be done by using the backspace key and the left and right arrow keys.
Do not hesitate to enter any experiment that occurs to you -- the worst that can occur is an error message of some kind. However, do not waste too much time on expressions whose results you do not understand. It is better to return to them after gaining more familiarity with the language.
In [ ]:
i.5
In [ ]:
2 3 5 7 */ i.5 NB. A multiplication table
In [ ]:
2 3 5 7 *table i.5 NB. Bordered by args for easy reading
In [ ]:
(i. */ i.) 5
In [ ]:
*/~@i. 5
In [ ]:
e=: 1x1
In [ ]:
e
In [ ]:
i=: 0 1 2 3 4 5 6
In [ ]:
e^i
In [ ]:
exp=: e&^
In [ ]:
exp i
In [ ]:
exp t. i
In [ ]:
1 % exp t. i NB. % denotes division
In [ ]:
!i NB. The coefficients are the reciprocal factorials
In [ ]:
^ i
In [ ]:
^ t. i
The exponential will now be used to generate a family of functions that includes the familiar sine and cosine, as well as the less familiar hyperbolic sine and hyperbolic cosine.
To obtain the hyperbolics we will employ the odd and even operators; to obtain the trigonometric functions we will apply the hyperbolics to complex arguments.
The expression f@- applies f atop negation, and the result of f@- x is therefore the result of applying f to the negative of x
The function g=: f + f@- is therefore an "even" function such that g x equals g -x Graphically, this implies that g is "reflected in the vertical axis". For example:
In [ ]:
f=: 3 1 4 2 5 & p.
In [ ]:
g=: f + f@-
In [ ]:
i=: 0 1 2 3 4 5 6
In [ ]:
g i
In [ ]:
g -i
In [ ]:
g t. i NB. Non-zero coefficients only in even positions
Similarly, the function h=: f - f@- is odd, and its graph is reflected in the origin.
The even and odd parts of f are defined to be one-half of the functions g and h, so that their sum gives the original function. The operators even=: ..- and odd=: .:- give these even and odd parts. For example:
In [ ]:
even=: ..-
In [ ]:
odd=: .:-
In [ ]:
ep=: f even
In [ ]:
op=: f odd
In [ ]:
ep i
In [ ]:
op i
In [ ]:
(ep+op) i
In [ ]:
f i
In [ ]:
ep t. i
In [ ]:
cosh=: ^ even
In [ ]:
sinh=: ^ odd
In [ ]:
y=: 0 1 2 3 4
In [ ]:
cosh y
In [ ]:
sinh y
In [ ]:
((cosh y)^2) - ((sinh y)^2)
The ordinary cosine and sine may be expressed by applying the corresponding hyperbolic to an imaginary argument.
The expression ix is commonly used to denote the "imaginary" value obtained by multiplying x by the square root of minus one i.e. denoted here by 0j1. We will instead use j.x, where j. denotes a function that multiplies its argument by the square root of minus one. For example:
In [ ]:
y=: 0 1 2 3 4 5
In [ ]:
j. y
In [ ]:
cos=: cosh@j.
In [ ]:
cos y
In [ ]:
sin=: sinh&.j.
In [ ]:
sin y
In [ ]:
x=: 6
In [ ]:
n=: 4
In [ ]:
i.n
In [ ]:
x+i.n
In [ ]:
*/x+i.n
In [ ]:
rf=: */@([+i.@])
In [ ]:
x rf n
In [ ]:
*/x+_1*i.n NB. Falling factorial
In [ ]:
*/x+1*i.n NB. Rising factorial
In [ ]:
*/x+0*i.n NB. Power function
In [ ]:
rf=: ^!.1
In [ ]:
ff=: ^!._1
In [ ]:
po=: ^!.0
In [ ]:
x (rf,po,ff) n
In [ ]:
ffp=: p.!._1 NB. Falling factorial polynomial
In [ ]:
rfp=: p.!.1 NB. Rising factorial polynomial
In [ ]:
1 2 3 (ffp,p.,rfp) 5
In [ ]:
5 ff 0 1 2
In [ ]:
+/ 1 2 3 * 5 ff 0 1 2
In [ ]:
f=: 1 2 1&p.
In [ ]:
g=: 1 3 3 1&p.
In [ ]:
q=: f%g
In [ ]:
x=: 0 1 2 3 4 5 6
In [ ]:
q x
In [ ]:
q t. x
In [ ]:
(g%f) x
In [ ]:
(g%f) t. x
In [ ]:
(0 1&p. % 1 _1 _1&p.) t. i.6 5
The table of Fibonacci numbers in the preceding section illustrates the fact that the Taylor coefficients of rational functions present surprising and interesting patterns. For further discussion of this see the "CONCRETE MATH COMPANION", available from website www.jsoftware.com.
In [ ]:
1 H. 1 i.6 NB. The exponential function
In [ ]:
1 H. 1 t. i.6
Although the hypergeometric function is a ratio of two polynomials, the limbs of the ratio are normally expressed as products over rising factorials, which are equivalent to polynomials. For further details on the definition of the operator H., use key F1 to display the vocabulary, and select the appropriate item.
For further discussion of the hypergeometric see Section 15 of the National Bureau of Standards "Handbook of Mathematical Functions", edited by Abramowitz and Stegun.
In [ ]: