õıııııııııııııııııııııııııııııııÀ ş0.375 0.5 0.875 0 0 0.5ş ş 0.75 0 0.375 0 0.375 0.75ş ş0.625 1 0.875 0.5 0 0.625ş Áıııııııııııııııııııııııııııııııã The random seed (a beginning value for the pseudo-random number generator) is set by the foreign conjunction using 9!:1. Alphabet/Ace a. a: a. is a list of the elements of the alphabet; it determines the collating sequence used in grading and sorting (/: and \:). The content of a. as well as the ordering of its elements may differ on different computing systems. The number of elements in the alphabet is given by $a., and a 32-column display is given by an expression such as 8 32$a. . The inclusion of certain controlácharacters (such as the carriage return) and non-printing characters make such a display difficult to decipher, but the major alphabet is usually given by : 1 2 3 { 8 32 $ a. !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~The index of the carriage return is commonly 13 (as may be tested by entering 13{a.), and the indices of the space and other characters may be determined as illustrated below: a. i. 'aA +-*%'97 65 32 43 45 42 37 The ace (a unit, from Latin as) is denoted by a: It is the boxed empty list <$0.Certain of the characters in the ASCII alphabet a re designated as national use characters because they are, on typewriters in various countries, displaced by certain other symbols such as the pound currency sign. These may be entered (on any keyboard) according to the following scheme: . : . : @ AT. AT1. AT2. # NO. NO1. NO2. \ BS. BS1. BS2. ] RB. RB1. RB2. ^ CA. CA1. CA2. } RC. RC1. RC2. ` GR. GR1. GR2. $ SH. SH1. SH2. [ LB. LB1. LB2. | ST. ST1. ST2. { LC. LC1. LC2. ~ TI. TI1. TI2. Atomic Index A. 1 0 _ Atomic Permute If T is the table of all !n permutations of order n arranged in lexical order (that is, /:T is i.!n), then k is said to be the atomic representation of the permutation k{T.A. applied to any cycle or direct permutation yields its atomic representation. Thus, A. 0 3 2 1 is 5, as are A. 3 2 1 and A. <3 1 and A. 0;2;3 1 and A. <3 1 . The expression káA. b permutes items of b by the permutation of order #b whose atomic representation is k. For example: tap=. i.@! A. i. Table of all permutations (tap 3);(/: tap 3);({/\ tap 3);(/:{/\ tap 3) õıııııÃıııııııııııÃıııııÃıııııııııııÀ ş0 1 2ş0 1 2 3 4 5ş0 1 2ş0 1 5 2 4 3ş ş0 2 1ş ş0 2 1ş ş ş1 0 2ş ş1 2 0ş ş ş1 2 0ş ş2 0 1ş ş ş2 0 1ş ş1 2 0ş ş ş2 1 0ş ş1 0 2ş ş ÁıııııÂıııııııııııÂıııııÂıııııııııııã In particular, 1áA.ábá transposes the last two items of b, and _1 A. b reverses the list of items, and 3 A. b and 4 A. b rotate the last three items of b. For example: b=. 'ABCD' (0 3 2 1{b);(0 3 2 1 C.b);((<3 1)C.b);(3 4 A.b) õııııÃııııÃııııÃııııÀ şADCBşADCBşADCBşACDBş ş ş ş şADBCş ÁııııÂııııÂııııÂııııã (A. 0 3 2 1) , (A. <3 1) 5 5 (_19 A. b) ; (_19 |~ ! # b) õııııÃıÀ şADCBş5ş ÁııııÂıã BOOLEAN m b. _ 0 0 (see next topic) If f is a dyadic boolean function and d=. 0 1, then d f/ d (or f/~d) is its complete table. For example the tables for or, nor, and,áand not-and (followed by their ravels) appear as follows: (+./~ ; +:/~ ; *./~ ; *:/~) d=. 0 1õıııÃıııÃıııÃıııÀş0 1ş1 0ş0 0ş1 1şş1 1ş0 0ş0 1ş1 0şÁıııÂıııÂıııÂıııã ,&.> (+./~ ; +:/~ ; *./~ ; *:/~) dõıııııııÃıııııııÃıııııııÃıııııııÀş0 1 1 1ş1 0 0 0ş0 0 0 1ş1 1 1 0şÁıııııııÂıııııııÂıııııııÂıııııııãIf ordered by their ravels, each of the sixteen possible boolean dy ads can be characterized by its index k; the phrase k b. produces the corresponding function. Moreover, negative indexing may be used. For example: (7 b./~;8 b./~;1 b./~;14 b./~;_2 b./~) dõıııÃıııÃıııÃıııÃıııÀş0 1ş1 0ş0 0ş1 1ş1 1şş1 1ş0 0ş0 1ş1 0ş1 0şÁıııÂıııÂıııÂıııÂıııãThe adverb b. also applies to array arguments. For example: (<"2) 2 0 1 |: 7 8 1 15 b./~ d õıııÃıııÃıııÃıııÀş0 1ş1 0ş0 0ş1 1şş1 1ş0 0ş0 1ş1 1şÁıııÂıııÂıııÂıııãThe monad (as in m b. y) is equivalent to a zero left argument (a s in 0ámáb.áy). BASIC CHARACTERISTICS u b. _ (see previous) u b. y gives the obverse of u if y is _1; its ranks if y is 0; and its identity function if y is 1. For example: ^ b. _1 ^. ^ b. 0 _ 0 0 ^ b. 1 $&1@(}.@$) g=. +&2@(*&3@*:) ]y=. g 5 77 g ^:_1 y 5 g b. _1 %:@(%&3)@(-&2) %:@(%&3)@(-&2) y 5 g b. 0 _ 0 0 Characteristic or Eigenvalues c. 2 0 2 c. y yields the characteristic, own, or eigen values of its argument, arranged in ascending order on imaginary part within real within magnitude. An atom or list y is treated as the table ,.y. 0 c. y is a diagonal matrix with the eigenvalues c. y on the diagonal. Also, _1 c. y and 1ác. y are the left and right eigenvectors. If i=. _1 0 1, then +/ . */ i c. y is y. Not implemented in Release 2 Cycle-Direct C. 1 1 _ Permute If p is a permutation of the atoms of i.n, then p is said to be a permutation vector of order n, and if n=#b, then p{b is a permutation of the items of b. C.p yields a list of boxed lists of the atoms of i.#p, called the standard cycle representation of the permutation p. Thus, if p=.4 5 2 1 0 3, then C.p is (,2);4 0;5 3 1 because the per-mutation p moves to position 2 the item 2, to 4 the item 0, to 0 the item 4, to 5 the item 3, to 3 the item 1, and to 1 the item 5. The monad C. is self-inverse; applied to a standard cycle it gives the corresponding direct representation. A given permutation could be repre-sented by cycles in a variety of ways; the standard form is made unique by the following restrictions: the cycles are dis-joint and exhaustive (i.e., the atoms of the boxed elements together form a per-mutation vector); each boxed cycle is rotated to begin with its largest element; and the boxed cycles are put in ascending order on their leading elements.C. is extended to non-negative non-standard cases by treating any argument q as a representation of a permutation of order 1+>./; q. If p and c are standard and cycle representa tions of order #b, then páC.b and c C.b produce the permutation of b. The arguments p and cácan be non-standard in ways to be defined. In particular, negative integers down to-#b may be used, and are treated as their residues modulo #b. If q is not boxed, and the elements of (#b)|q are distinct, then qáC.b is equivalent to p C.b, where p is the standard form of q that is given by p=.á((i.n) -. n|q),n|q, where n=.#b. In other words, positions occurring in q are moved to the tail end. If q is b oxed, the elements of (#b)|>j{q must be distinct for each j, and the boxes are applied in succession:. For example: (2 1;3 0 1) C. i.51 2 3 0 4 (<2 1) C. (<3 0 1) C. i.51 2 3 0 4 q=. C. p=. 1 2 3 0 4 [ a=. 'abcde' q ; (q C. a) ; p ; (p C. a) ; (p { a) õıııııııııııÃıııııÃıııııııııÃıııııÃıııııÀ şõıııııııÃıÀşbcdaeş1 2 3 0 4şbcdaeşbcdaeş şş3 0 1 2ş4şş ş ş ş ş şÁıııııııÂıãş ş ş ş ş ÁıııııııııııÂıııııÂıııııııııÂıııııÂıııııã DERIVATIVE u D. n mu u D. n is the nth derivative of u: cube=. ^&3"0 [. y=. 2 3 4 (cube D.1;cube D.2;cube D.3)yõııııııııÃııııııııÃıııııÀş12 27 48ş12 18 24ş6 6 6şÁııııııııÂııııııııÂıııııã The derivative applies to constant functions, polynomials, the exponential ^ , and the integral powers ^&n. It also applies to functions derived from these by addition, subtraction, multiplication, and division (u+v, etc.); by the composition u@v; and by the inverse u^:_1. Since functions such as j. and - (negation) and %:(square root) and 1&o. (sin) and 6&o. (cosh) may all be so derived, they are also in the domain of the derivative. The same domain restrictions apply to the Taylor conjunction t.. Other functions are treated by approximation. The derivative of an arbitrary function may also be treated by a polynomial approximation, (provided by the matrix divide), or by approximations using the secant slope D:. If the argument rank of u is a and the result rank is r, then the argument rank of uáD.1 is also a, but its result rank is r+a: the result of u D.1 is the derivative of each atom of the result of u with respect to each element of its argument, giving what is commonly referred to as the partial derivatives. For example: volume=. */"1 [. VOLUMES=. */\"1 (volume;volume D.1;VOLUMES;VOLUMES D.1) y õııÃııııııÃııııııÃııııııÀ ş24ş12 8 6ş2 6 24ş1 3 12ş ş ş ş ş0 2 8ş ş ş ş ş0 0 6ş ÁııÂııııııÂııııııÂııııııã determinant=. -/ . * [. permanent=. +/ . * (];(determinant D.1);(permanent D.1))m=.*:i.3 3 õııııııııÃııııııııııııııÃııııııııııııııÀ ş 0 1 4ş_201 324 _135ş2249 1476 1017ş ş 9 16 25ş 132 _144 36ş 260 144 36ş ş36 49 64ş _39 36 _9ş 89 36 9ş ÁııııııııÂııııııııııııııÂııııııııııııııã The adverbs D=.("0)(D.1)and VD=.("1)(D.1)assign ranks to their arguments, then take the first derivative; they are convenient for use in scalar and vector calculus: sin=. 1&o. [. x=. 1r2p1 _1r4p1 (*/\ VD y);(sin x);(sin D x);(sin D D x) õııııııÃııııııııııııÃıııııııııııÃııııııııııııÀ ş1 3 12ş1 _0.7071068ş0 0.7071068ş_1 0.7071071ş ş0 2 8ş ş ş ş ş0 0 6ş ş ş ş ÁııııııÂııııııııııııÂıııııııııııÂııııııııııııã u D: n mu mu SECANT SLOPE x u D: 1 y is the secant slope of the function u through the points y and y+x. The secant slope is generalized to the case x u D. n y in the manner of the derivative D.. The argument x may be a list, giving several slopes. In the general case, each item of x has the shape {. $$"r y, where r is the rank of u, therefore specifying the increment in each possible direction. An argument x of lower rank is extended in the usual manner. For example, x=. 1e_8 provides the same increment in eac h direction and, because of the small magnitude, yields an approximation to the derivative. log=. ^."0 y=. 2 3 4 1 log D:1 y 0.4054651 0.2876821 0.2231436 incr=. 1 0.1 0.01 1e_8 incr log D:1/y 0.4054651 0.2876821 0.2231436 0.4879016 0.3278982 0.2469261 0.4987542 0.332779 0.249688 0.5 0.3333333 0.25 log D.1 y %y 0.5 0.3333333 0.25 0.5 0.3333333 0.25 f=. +/@*:"1 [. g=. +/@*:\"1 (f y) ; (1 f D:1 y) ; (1 0.1 1e_8 f D:1 y) õııÃıııııÃıııııııÀ ş19ş5 7 9ş5 6.1 8ş ÁııÂıııııÂıııııııã (g y) ; (1 g D:1 y) õıııııııÃıııııÀ ş4 13 29ş5 5 5ş ş ş0 7 7ş ş ş0 0 9ş ÁıııııııÂıııııã Raze In e. _ _ _ Member (In) e.y produces a boolean result that determines for each atom of y whether its open contains each item of the raze of y. If x has the shape of an item of y, thenx e. y is 1 if x matches an item of y. In general, x e. y is (#y)>y i. x . For example: ]y=.'abc';'dc';'a' õıııÃııÃıÀ şabcşdcşaş ÁıııÂııÂıã ;y abcdca e. y 1 1 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 1 f=. ] e.~&>/ ; f y 1 1 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 1 'cat' e. 'abcd' 1 1 0 ]z=. 2 3$'catdog' cat dog 'cat' e. z 1 E. _ _ Member of Interval The ones in b=. x E. y indicate the beginning points of occurrences of the pattern x in y. For example: 'co' E. 'cocoa' 1 0 1 0 0 FIX u f. If y=. x f., then the function y is equivalent to the function x, except that any names that occur in the definition of x are (recursively) replaced by their referents. Consequently, any subsequent change in these referents that might change the definition of x will not affect the definition of y. For example: sum=. +/ mean=. sum % # norm=. - mean norm a=. 2 3 4 5 _1.5 _0.5 0.5 1.5 N=. norm f. N a _1.5 _0.5 0.5 1.5 norm - mean N - (+/ % #) sum=. -/ norm a 2.5 3.5 4.5 5.5 N a _1.5 _0.5 0.5 1.5 Integers i. 1 _ _ Index Of The shape of i.y is |y, and its atoms are the first */|y non-negative integers. A negative element in y causes reversal of the atoms along the corresponding axis. For example: i. 50 1 2 3 4 i. 2 _54 3 2 1 09 8 7 6 5 If rix is the rank of an item of x, then the shape of the result of xái.y is(-rix)}.$y. Each atom of the result is either #x or the index of the first occurrence among the items of x of the corresponding rix-cell of y. The comparison in xái.áy is tolerant, and fit can be us ed to specify the tolerance, as in i.á!. t . (i.4);(i._4);(i.2 3 4);(i.2 _3 4);(i.'') õıııııııÃıııııııÃıııııııııııÃıııııııııııÃıÀ ş0 1 2 3ş3 2 1 0ş 0 1 2 3ş 8 9 10 11ş0ş ş ş ş 4 5 6 7ş 4 5 6 7ş ş ş ş ş 8 9 10 11ş 0 1 2 3ş ş ş ş ş ş ş ş ş ş ş12 13 14 15ş20 21 22 23ş ş ş ş ş16 17 18 19ş16 17 18 19ş ş ş ş ş20 21 22 23ş12 13 14 15ş ş ÁıııııııÂıııııııÂıııııııııııÂıııııııııııÂıã A=. 'abcdefghijklmnopqrstuvwxyz' (A i. 'Now');(A i. 'now');(A {~ A i. 'now') õııııııııÃııııııııÃıııÀ ş26 14 22ş13 14 22şnowş ÁııııııııÂııııııııÂıııã m=. 5 4 $ 12{. A m;(m i. 'efgh');(1{m);(4{m) õııııÃıÃııııÃııııÀ şabcdş1şefghşefghş şefghş ş ş ş şijklş ş ş ş şabcdş ş ş ş şefghş ş ş ş ÁııııÂıÂııııÂııııã Imaginary j. _ 0 0 Complex j. y is 0j1 * y. x j. y is x + j. y . For example: j. 4 0j4 3 j. 4 3j4 a=. i. 3 3 a;(j. 2*a);(a j. 2*a) õıııııÃııııııııııııııÃııııııııııııııÀ ş0 1 2ş 0 0j2 0j4ş 0 1j2 2j4ş ş3 4 5ş 0j6 0j8 0j10ş 3j6 4j8 5j10ş ş6 7 8ş0j12 0j14 0j16ş6j12 7j14 8j16ş ÁıııııÂııııııııııııııÂııııııııııııııã (+ a j. 2*a);(|a j. 2*a) õıııııııııııııııııÃıııııııııııııııııııııııÀ ş 0 1j_2 2j_4ş 0 2.23607 4.47214ş ş 3j_6 4j_8 5j_10ş 6.7082 8.94427 11.1803ş ş6j_12 7j_14 8j_16ş13.4164 15.6525 17.8885ş ÁıııııııııııııııııÂıııııııııııııııııııııııã 1 2 3 j./ 4 5 6 7 1j4 1j5 1j6 1j7 2j4 2j5 2j6 2j7 3j4 3j5 3j6 3j7 j./?2 3 4$1000 A table of random complex numbers 756j436 991j766 365j477 247j237 982j274 722j359 753j166 651j486 72j897 631j909 884j60 272j904 COMMENT NB. The rest of the line following NB. is ignored. For example: text=. 'i. 3 4 NB. 3-by-4 table' ;: text õııÃıııÃııııııııııııııııÀ şi.ş3 4şNB. 3-by-4 tableş ÁııÂıııÂııııııııııııııııã ". text 0 1 2 3 4 5 6 7 8 9 10 11 Pi Times o. _ 0 0 Circle Functions o. y yields pi times y. Thus o. 1 is approximately 3.14159. If k>:0, then k o.y yields one of the circular, hyperbolic, or pythagorean functions, as follows: k Function k Function 0 %:1-y^2 4 %:1+y^21 Sine y 5 Sinh y2 Cosine y 6 Cosh y 3 Tangent y 7 Tanh y 8 %:-1+y^2 (-k) o. y is inverse to k o. y. The cases _1o.y and _4o.y and _8o.y are Arcsine y and %:_1+y^2 and%:-1+y^2.Arguments of sine, cosine, and tangen t (and the results of their inverses) are in radians.It may be noted that odd indices denote odd functions, and even indices denote even functions. For example: o. 1 3p_1 3p_2 3.14159 3 0.95493 rfd=. %&180 @ o. rfd 0 90 180 0 1.5708 3.14159 sin=. 1&o. SIN=. sin@rfd sin 0 1.5708 0 1 SIN 0 90 0 1 Roots-Coefficients p. 1 1 0 Polynomial p. is a self-inverse transformation between an open list of coefficients of a polynomial and the corresponding boxed list of a multiplier and a list of roots. The functions y & p. and (p.áy) & p. are equivalent. If x is open, then x p. y is the result of the polynomial in y with coefficients x; i.e., +/x*y^i.#x. If x is boxed, thenx p y is the polynomial in terms of a multiplier >{.x and roots >{:x; that is, (>{.x)**/y-(>{:x). The monadic case of p. not implemented in Release 2. Examples: c=. 1 3 3 1 [ y=. 0 1 2 3 4 5 c p. y 1 8 27 64 125 216 (y+1)^3 1 8 27 64 125 216 poly=. +/@([ * ] ^ i.@#@[) " 1 0 c poly y 1 8 27 64 125 216 bc=. !~/~i.5 bc;(bc p./ y);((i.5) ^~/ y+1) õıııııııııÃııııııııııııııııııııÃııııııııııııııııııııÀ ş1 0 0 0 0ş1 1 1 1 1 1ş1 1 1 1 1 1ş ş1 1 0 0 0ş1 2 3 4 5 6ş1 2 3 4 5 6ş ş1 2 1 0 0ş1 4 9 16 25 36ş1 4 9 16 25 36ş ş1 3 3 1 0ş1 8 27 64 125 216ş1 8 27 64 125 216ş ş1 4 6 4 1ş1 16 81 256 625 1296ş1 16 81 256 625 1296ş ÁıııııııııÂııııııııııııııııııııÂııııııııııııııııııııã c&p. D. 1 y 3 12 27 48 75 108 The variant p.!.s is a stope polynomial; it differs from p. in that its definition is based upon the stope ^!.s instead of on the power ^ . Angle r. _ 0 0 Polar r.y is ^j.y x r. y is x*r. y . The result of r. y is a complex number of magnitude 1, whose real and imaginary parts are coordinates of the point on the unit circle at an angle of y radians. For example: r. 2 _0.416147j0.909297 +. r. 2 _0.416147 0.909297 | r. 2 1 y=. 4 %~ o. i.7 Multiples of one-quarter pi format=. 8.3&":