þ2þ0 1 0 1 0 1 0þ1 0 1 0 1 0 1þ þ3þ0 1 2 0 1 2 0þ1 0 0 1 0 0 1þ þ4þ0 1 2 3 0 1 2þ1 0 0 0 1 0 0þ þ5þ0 1 2 3 4 0 1þ1 0 0 0 0 1 0þ þ6þ0 1 2 3 4 5 0þ1 0 0 0 0 0 1þ ÁýÂýýýýýýýýýýýýýÂýýýýýýýýýýýýýã (i#~2=+/div);(2=+/div);(+/div) Primes, test, # of divisors õýýýýýÃýýýýýýýýýýýýýÃýýýýýýýýýýýýýÀ þ2 3 5þ0 0 1 1 0 1 0þ7 1 2 2 3 2 4þ ÁýýýýýÂýýýýýýýýýýýýýÂýýýýýýýýýýýýýã (=/~ ; ./ - i.@spread spread=. 1: + >./ - <./ spread y 10 range y 8 7 6 5 4 3 2 1 0 _1 ((range <:/ ]);{&' *'@(range<:/])) y Barcharts of y õýýýýýýýýýýýýýÃýýýýýýýÀ þ1 0 0 0 0 0 1þ* *þ þ1 0 0 0 0 0 1þ* *þ þ1 0 0 0 0 0 1þ* *þ þ1 0 0 0 0 0 1þ* *þ þ1 0 0 0 0 0 1þ* *þ þ1 1 0 0 0 1 1þ** **þ þ1 1 0 0 0 1 1þ** **þ þ1 1 0 0 0 1 1þ** **þ þ1 1 1 0 1 1 1þ*** ***þ þ1 1 1 1 1 1 1þ*******þ ÁýýýýýýýýýýýýýÂýýýýýýýã DISJOINT CLASSIFICATION (Graphs) If only the final element of a boolean list b is non-zero, then (and only then) will the result of ./ - i.@spread spread=. 1: + >./ - <./ bc=. (range <:/]) y bc;(./@#]),(C-/@#]),:((C!/@#]))) pr 0 5 3 8 2 7 5 10 1 5 3 15 2 10 6 30 __ 5 3 5 2 5 3 5 0 5 3 _2 2 _3 _1 4 1 5 3 10 2 10 3 45 ((C+/ . *]),:(C*/ . (^~)])) pr 0 5 3 8 2 7 5 10 1 5 3 15 2 10 6 30 The pattern of the matrix product is illustrated below for the case (2 3 5,:4 2 1) +/ . * |:C 3#1 : 2 3 5 | 0 5 3 8 2 7 5 10 4 2 1 | 0 1 2 3 4 5 6 7 ------|----------------- | 0 0 0 0 1 1 1 1 | 0 0 1 1 0 0 1 1 | 0 1 0 1 0 1 0 1 row0=.2 3 5 [ col3=.0 1 1 row0 * col3 0 3 5 +/ row0 * col3 8 row0 +/ . * |: C 3#1 0 5 3 8 2 7 5 10 Also see the use of the Key adverb (/.) for classification. CLASSIFICATION (Sets and Propositions) The list -.+./t appended to any classification table t will yield a complete classification table, and the function defined below therefore completes a classification table. The function tab ensures that a scalar or vector argument is treated as a one-rowed table c=. complete=. (] , (+./ {. ,:)@-.@(+./))@tab tab=. ,:^:(0:>.2:-#@$) c 0 0 1,:0 1 0 c 1 0 1,:0 1 0 0 0 1 1 0 1 0 1 0 0 1 0 1 0 0 (c 1 0 1);(c c 1 0 1);(c 0);(c 1) õýýýýýÃýýýýýÃýÃýÀ þ1 0 1þ1 0 1þ0þ1þ þ0 1 0þ0 1 0þ1þ þ ÁýýýýýÂýýýýýÂýÂýã A function that yields a single boolean list is called a proposition; its result is a one-way classification called a set. The classification can, of course, be completed by the complementary set. For example: p1=. 2&<: *. <&5 Set defined by interval p1a=. (2:<:])*.]<5: Alternative definition p2=. = <. Set of integers a=. 2 %~ i. 11 (],p1,p1a,p2,(p1+.p2),:(p1*.p2)) a 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 0 list=. 1 : 0 Adverb to list elements of set x.@] # ] ) ((p1 list);(p2 list);((p1*.p2)list)) a õýýýýýýýýýýýýýýýýýÃýýýýýýýýýýýÃýýýýýÀ þ2 2.5 3 3.5 4 4.5þ0 1 2 3 4 5þ2 3 4þ ÁýýýýýýýýýýýýýýýýýÂýýýýýýýýýýýÂýýýýýã SORTING The sort x /: y re-orders x according to the grade of y, that is, /:y: x=. 2 7 1 8 [ y=. 1 7 3 2 (/:y);((/:y){x);(x/:y);(x/:x) õýýýýýýýÃýýýýýýýÃýýýýýýýÃýýýýýýýÀ þ0 3 2 1þ2 8 1 7þ2 8 1 7þ1 2 7 8þ ÁýýýýýýýÂýýýýýýýÂýýýýýýýÂýýýýýýýã The grade and sort of literal characters is based upon the ordering of the underlying alphabet a. For example, if the name "text" is used for the present sentence (up to and including the colon), then: tdw=. >dwds=. ~. wds=. ;: text ($tdw),($dwds),($wds),($text) 21 9 21 25 103 ]alph=. a. {~ ,(i. 26) +/ (a.i.'aA') aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ tdw; (tdw /: tdw);(tdw/: alph i. tdw) õýýýýýýýýýÃýýýýýýýýýÃýýýýýýýýýÀ þFor þ" þand þ þexample þ( þcolon þ þ, þ) þexample þ þif þ, þfor þ þthe þFor þFor þ þname þand þif þ þ" þcolon þincludingþ þtext þexample þis þ þis þfor þname þ þused þif þpresent þ þfor þincludingþsentence þ þpresent þis þtext þ þsentence þname þthen: þ þ( þpresent þthe þ þup þsentence þto þ þto þtext þup þ þand þthe þused þ þincludingþthen: þ, þ þcolon þto þ" þ þ) þup þ( þ þthen: þused þ) þ ÁýýýýýýýýýÂýýýýýýýýýÂýýýýýýýýýã The middle column is the alphabetized table of distinct words, but (because the cases are not interleaved in the alphabet a.), the words for and For are widely separated; they are brought together in the last column by indexing the table by a suitable alphabet. COMPOSITIONS (Based on conjunctions) In math, the symbol is commonly used to produce a function defined as the composition of two functions: f g y is defined as f (g y). Normally, such composed functions are only defined to apply to a single scalar argument. J provides compositions effected by five distinct conjunctions, as well as compositions effected by isolated sequences of verbs: hooks and forks, and longer trains formed from them. The five conjunctions are & &. &: @ and @:, the conjunctions @ and @: being related in the same manner as & and &: . The conjunction & is closest to the composition used in math, being identical to it when used for two scalar (rank zero) functions to produce a function to be applied to a single scalar argument. However, it is also extended in two directions: 1. Applied to one verb and one noun it produces a monadic function illustrated by the cases 10&^. (Base ten logarithm) and ^&3 (Cube). 2. Applied to two verbs it produces (in addition to the monadic case used in math) a dyadic case defined by: x f&g y is (g x) f (g y). For example, x %&! y is the quotient of the factorials of x and y. The conjunction &. applies only to verbs, and f&.g is equivalent to f&g except that the inverse of g is applied to the final result. For example: 3 +&^. 4 3 +&.^. 4 2.48491 12 For scalar arguments the functions f&:g and f&g are equivalent, but for more general arguments, g applies to each cell as dictated by its ranks. In the case of f&g, the function f then applies to each result produced; in the case of f&:g it applies to the overall result of all of the cells. For example: (] ; %. ; |:&%. ; |:&:%.) i. 2 2 2 õýýýÃýýýýýýýýÃýýýýýýýÃýýýýýýýýýÀ þ0 1þ_1.5 0.5þ_1.5 1þ_1.5 _3.5þ þ2 3þ 1 0þ 0.5 0þ 1 3þ þ þ þ þ þ þ4 5þ_3.5 2.5þ_3.5 3þ 0.5 2.5þ þ6 7þ 3 _2þ 2.5 _2þ 0 _2þ ÁýýýÂýýýýýýýýÂýýýýýýýÂýýýýýýýýýã The conjunctions @ and & agree in the monadic case, that is, f@g y and f&g y are identical. However, in the phrase x f&g y, the monadic case of g is applied to each argument, and the dyadic case of f is then applied to the results; in the phrase x f@g y the function g is applied dyadically, and f is applied monadically to the single result. For example: 3 %&! 5 3 %@! 5 0.05 0.1 COMPOSITIONS (Based on hooks and forks) As stated in Section III F, An isolated sequence, such as (+ */), which the foregoing parsing rules do not resolve to a single part of speech is called a train, and may be further resolved as described below". Meanings are assigned to certain trains of two or three elements and, by implication, to trains of any length by repeated resolution. For example, the trains +-*% and +-*%^ are equivalent to +(-*%) and +(*%^) : A verb is produced by trains of three or two verbs, as defined by the following diagrams: FORK HOOK g g g g / \ / \ / \ / \ f h f h y h x h | | / \ / \ | | y y x y x y y y For example, 5(+*)3 is (5+3)*(53), but if f is a cap ([:) the capped branch simplifies the forks to g h y and g x h y. The ranks of the hook are infinite, and the ranks of the fork f g h are the maxima of corresponding ranks of f and h. The foregoing definition is from Section II F of the dictionary. The following examples concern functions used in statistics: mean=. +/%# Mean norm=. ] - +/ % # Centered on mean sqcm=. 2: ^~ ] - +/ % # Sqr of centered on mean stdv=. [: mean 2: ^~ ] - mean=. +/%# Std Deviation var=. 2:%:[:mean 2:^~]-mean=.+/%# Variance ,.&.>@(];mean;norm;sqcm;stdv;var) y=. 2 3 4 5 õýÃýýýÃýýýýÃýýýýÃýýýýÃýýýýýýýÀ þ2þ3.5þ_1.5þ2.25þ1.25þ1.11803þ þ3þ þ_0.5þ0.25þ þ þ þ4þ þ 0.5þ0.25þ þ þ þ5þ þ 1.5þ2.25þ þ þ ÁýÂýýýÂýýýýÂýýýýÂýýýýÂýýýýýýýã JUNCTIONS Four functions are commonly used to join arguments: ; , ,. and ,: . We will illustrate them for the cases of vector and matrix arguments: a=. 'pqr' [ b=. 'PQR' m=. 3 3$ 'abcdefghi' [ n=. 3 3$ 'ABCDEFGHI' a (; ; , ; ,. ; ,:) b õýýýýýýýýýÃýýýýýýÃýýÃýýýÀ þõýýýÃýýýÀþpqrPQRþpPþpqrþ þþpqrþPQRþþ þqQþPQRþ þÁýýýÂýýýãþ þrRþ þ ÁýýýýýýýýýÂýýýýýýÂýýÂýýýã m (; ; , ; ,. ; ,:) n õýýýýýýýýýÃýýýÃýýýýýýÃýýýÀ þõýýýÃýýýÀþabcþabcABCþabcþ þþabcþABCþþdefþdefDEFþdefþ þþdefþDEFþþghiþghiGHIþghiþ þþghiþGHIþþABCþ þ þ þÁýýýÂýýýãþDEFþ þABCþ þ þGHIþ þDEFþ þ þ þ þGHIþ ÁýýýýýýýýýÂýýýÂýýýýýýÂýýýã a (; ; , ; ,. ; ,:) n õýýýýýýýýýÃýýýÃýýýýÃýýýÀ þõýýýÃýýýÀþpqrþpABCþpqrþ þþpqrþABCþþABCþqDEFþ þ þþ þDEFþþDEFþrGHIþ þ þþ þGHIþþGHIþ þ þ þÁýýýÂýýýãþ þ þABCþ þ þ þ þDEFþ þ þ þ þGHIþ ÁýýýýýýýýýÂýýýÂýýýýÂýýýã m (; ; , ; ,. ; ,:) b õýýýýýýýýýÃýýýÃýýýýÃýýýÀ þõýýýÃýýýÀþabcþabcPþabcþ þþabcþPQRþþdefþdefQþdefþ þþdefþ þþghiþghiRþghiþ þþghiþ þþPQRþ þ þ þÁýýýÂýýýãþ þ þPQRþ þ þ þ þ þ þ þ þ þ þ ÁýýýýýýýýýÂýýýÂýýýýÂýýýã PARTITIONS (Adverbs) Used monadically, the results of the adverbs \ and \. and /. provide prefix, suffix, and oblique partitions. They are commonly applied to arithmetic functions such as summation (+/), product over (*/), and continued fractions ((+%)/); we will also illustrate them for box (< ), which shows their structure more clearly: a=. 2 3 5 7 11 [ t=. 1 2 1 */ 1 3 3 1 ,.&.>((+/\a) ; (+/\.a) ; ((+%)/\a) ; (+//.t);t) õýýÃýýÃýýýýýýýÃýýÃýýýýýýýÀ þ 2þ28þ 2þ 1þ1 3 3 1þ þ 5þ26þ2.33333þ 5þ2 6 6 2þ þ10þ23þ 2.3125þ10þ1 3 3 1þ þ17þ18þ2.31304þ10þ þ þ28þ11þ2.31304þ 5þ þ þ þ þ þ 1þ þ ÁýýÂýýÂýýýýýýýÂýýÂýýýýýýýã <\a õýÃýýýÃýýýýýÃýýýýýýýÃýýýýýýýýýýÀ þ2þ2 3þ2 3 5þ2 3 5 7þ2 3 5 7 11þ ÁýÂýýýÂýýýýýÂýýýýýýýÂýýýýýýýýýýã <\.a õýýýýýýýýýýÃýýýýýýýýÃýýýýýýÃýýýýÃýýÀ þ2 3 5 7 11þ3 5 7 11þ5 7 11þ7 11þ11þ ÁýýýýýýýýýýÂýýýýýýýýÂýýýýýýÂýýýýÂýýã