Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Rich H.J for C programmers.2006.pdf
Скачиваний:
19
Добавлен:
23.08.2013
Размер:
1.79 Mб
Скачать

The conjunction H. is used in the form m H. n where m is the numerator list and n is the denominator list. The resulting verb m H. n has rank 0. The monad m H. n y takes the limit of the sum of the generalized hypergeometric series; the dyad

x m H. n y takes the sum of the first x terms. Formally, the generalized hypergeometric function is

(m 0 )k (m1 )k K(m <:#m )k

 

y

k

 

 

 

where (a)k =a(a +1)K(a + k 1)

(n0 )k (n1 )k K(n<:#n )k

 

k !

k =0

 

 

If m contains 2 items and n contains 1 item, m H. n defines a hypergeometric function.

Generalized hypergeometric functions can be used to calculate a great many functions of interest: Legendre polynomials, Laguerre polynomials, Chebyshev polynomials, and Bessel functions of the first kind are all special cases of hypergeometric functions. Ewart Shaw, in http://www.ewartshaw.co.uk/data/jhyper.doc, gives a number of examples of uses of H. . For example, the error function and the cumulative distribution function are given by

erf =: 3 : '(((2p_0.5)*y.) % (^*:y.)) * 1 H. 1.5 *: y.' n01cdf =: 3 : '-: >: erf y. % %:2' NB. CDF of N(0,1)

where I have rewritten Shaw's formulas to use elementary J. 2p_0.5 is 2/sqrt(π).

Sparse Arrays: Monad and Dyad $.

$. y converts the array y into a sparse-matrix representation which can save a lot of space and time if most of the atoms of y have the same value. $.^:_1 y converts sparse y back to normal (dense) form. A large but incomplete subset of operations is supported on sparse arrays; look at the description of $. if you think you'd like to use them.

Random Numbers: ?

Monad ? has rank 0. If y is 0, ? y is a random floating-point number uniformly distributed in the interval 0 <= ? y < 1. If y is positive, ? y is a random element of

i.y . An example use is

?3 3 $ 1000

755 458 532

218 47 678

679 934 383

Dyad ? has rank 0. x ? y is a list of x items selected without repetition from

i.y, as if the list i. y were shuffled and the first x elements were taken:

5 ? 52

24 8 48 46 22

The ? verbs use the Mersenne Twister generator by default. Foreigns, described.in the Dictionary page for ?, allow selection of other generators.

188

Computational Addons

The web site at www.jsoftware.com has several addons that you can download. These are executable libraries, along with J scripts to call functions in them, that offer efficient implementations of often-used functions. Two of interest in applied mathematics are the LAPACK addon and the FFT addon. If you want a fast implementation of the singular value decomposition referred to earlier, install the LAPACK addon; then you can use

require 'addons\lapack\lapack' require 'addons\lapack\dgesvd' dgesvd_jlapack_ yourmatrix

which will quickly return the desired singular values and singular vectors.

Useful Scripts Supplied With J

The directory yourJdirectory/system/packages contains a number of subdirectories full of useful scripts. The /math and /stats subdirectories have scripts for mathematics and statistics; other subdirectories cover topics such as finance, printing, graphics, and interfacing to Windows.

189