J Labs

Families of Functions

(1 of 24) INTRODUCTION

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)

(2 of 24) INTRODUCTION (ctd)

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.

(3 of 24) POLYNOMIALS

The functions $3x^2 + 2x^3$ and $3 + 2x + x^3$ are examples of polynomials, which are united in a single family under the dyadic function p. as illustrated below:


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

(4 of 24) OPERATORS

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

(5 of 24) OPERATORS (ctd)

The expression f t. produces a function which applied to indices produces corresponding coefficients of a polynomial f. Thus f t. 0 gives the leading (zeroth) coefficient, and f t. 0 1 2 3 4 5 6 7 8 gives the first 9.


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

(6 of 24) EXPERIMENTS

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.

(7 of 24) EXPERIMENTS (ctd)

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.

(8 of 24) EXPERIMENTS (ctd)

Try some of the following experiments concerning the production of multiplication tables, and return to them with new functions encountered in later sections, such as the rising factorial rf=: ^!.1. Thus:


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

(9 of 24) EXPONENTIAL FUNCTION

The expression $e^x$ is commonly used to denote the exponential function. As suggested by the notation, the result is a quantity e raised to the power of the argument x

The quantity e is called the number of Euler, and is denoted here by 1x1 . Thus:


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

(10 of 24) EXPONENTIAL FUNCTION (ctd)

The symbol ^ has been used thus far to denote a function of two arguments. Used monadically (with only one argument) it denotes the function e&^, that is, the exponential. Thus:


In [ ]:
^ i

In [ ]:
^ t. i

(11 of 24) EXPONENTIAL FUNCTION (ctd)

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.

(12 of 24) EVEN AND ODD PARTS

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

(13 of 24) EVEN AND ODD PARTS (ctd)

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

(14 of 24) EVEN AND ODD PARTS (ctd)

The even and odd parts of the exponential function are the hyperbolic cosine and hyperbolic sine, respectively. Thus:


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)

(15 of 24) COS AND SIN

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

(16 of 24) COS AND SIN (ctd)

It should be noted that although the cos function was defined by cosh@j., the sin was defined by a different operator &.. To appreciate the reason for this try applying sinh@j. to y, and then use F1 to examine the definition of the "dual" operator &..

(17 of 24) STOPES

The product */x+i.n will be called a "stope" because the n factors x+i.n rise like the steps of a mine stope following a sloping vein of ore. The corresponding function */@([+i.@]) is also called a "rising factorial function". For example:


In [ ]:
x=: 6

In [ ]:
n=: 4

In [ ]:
i.n

In [ ]:
x+i.n

In [ ]:
*/x+i.n

In [ ]:
rf=: */@([+i.@])

In [ ]:
x rf n

(18 of 24) STOPES (ctd)

A falling factorial may be defined analogously by multiplying the integers i.n by _1; and the power function itself can be obtained by multiplying by zero. Thus:


In [ ]:
*/x+_1*i.n     NB. Falling factorial

In [ ]:
*/x+1*i.n      NB. Rising factorial

In [ ]:
*/x+0*i.n      NB. Power function

(19 of 24) STOPES (ctd)

These definitions may be united in a single family by the "fit" operator !. as illustrated below:


In [ ]:
rf=: ^!.1

In [ ]:
ff=: ^!._1

In [ ]:
po=: ^!.0

In [ ]:
x (rf,po,ff) n

(20 of 24) STOPE POLYNOMIALS

The fit operator can be similarly applied to the polynomial function p. to produce polynomials based upon falling and rising factorials as well as upon the power function. Thus:


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

(21 of 24) RATIONAL FUNCTIONS

If f and g are polynomials, their quotient q=:f%g is a rational function. For example:


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

(22 of 24) RATIONAL FUNCTIONS (ctd)

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.

(23 of 24) HYPERGEOMETRICS

The hypergeometric operator H. applies to lists to produce a rational function whose limiting value, for a large number of terms, may represent a wide variety of important functions. For example:


In [ ]:
1 H. 1 i.6       NB. The exponential function

In [ ]:
1 H. 1 t. i.6

(24 of 24) HYPERGEOMETRICS (ctd)

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.

End of Lab


In [ ]: