For example: x=. 1 2 3 [ m=. >1 6 4;4 1 0;6 6 8 det=. -/ . * [. mp=. +/ . * x ([ ; ] ; det@] ; mp ; mp~ ; mp~@]) m õýýýýýÃýýýýýÃýýýýÃýýýýýýýýÃýýýýýýýÃýýýýýýýýÀ þ1 2 3þ1 6 4þ_112þ27 26 28þ25 6 42þ49 36 36þ þ þ4 1 0þ þ þ þ 8 25 16þ þ þ6 6 8þ þ þ þ78 90 88þ ÁýýýýýÂýýýýýÂýýýýÂýýýýýýýýÂýýýýýýýÂýýýýýýýýã The monad u . v is defined as illustrated below: u=. -/ [. v=. * DET=. v/@,`({."1 u .v$:@minors)@.(1&<@{:@$)"2 minors=. }."1@(1&([\.)) DET m _112 The definition u@(v"(1+lv,_)) given above for the dyadic case may be re-stated in words as follows: u is applied to the result of v on lists of left argument cells and the right argument in toto. The number of items in a list of left argument cells must agree with the number in the right argument. Thus, if v has ranks 2 3 and the shapes of x and yáare 2á3á4á5 6 and 4 7 8 9 10 11, then there are 2 3 lists of left argument cells (each shaped 4 5 6); and if the shape of a result cell is sr, the overall shape is 2á3á7á8,sr. EVEN , ODD u .. v u .: v u .. v is (u + u&v) % 2: u .: v is (u - u&v) % 2: In the most commonly used case, v is arithmetic negation, and f=. u .. v is therefore f=. (u + u&-) % 2: ; in other words, one-half the sum of uáy and uá-y. The resulting function is therefore even in the sense that f y equals f -y for any y; its graph is reflected in the vertical axis. Similarly, uá.: - is odd (f y equals -f-y), and its graph is reflected in the origin. Less commonly, v is matrix transpose (|:), and may be any monadic function. y=. _2 _1 0 1 2 1 2 3 4 5 & p. y Polynomial with odd and even terms 57 3 1 15 129 1 2 3 4 5 & p. .. - y Even part of polynomial 93 9 1 9 93 1 0 3 0 5 & p. y Polynomial with even terms only 93 9 1 9 93 E=. .. - Even adverb O=. .: - Odd adverb d=. 5.2&":@,.&.> Display as columns with two digits. d (5&o. ; ^O ; 6&o. ; ^E ; ^ ; (^E + ^O) ; 2&o. ; ^@j.E) y õýýýýýÃýýýýýÃýýýýýÃýýýýýÃýýýýýÃýýýýýÃýýýýýÃýýýýýÀ þ_3.63þ_3.63þ 3.76þ 3.76þ 0.14þ 0.14þ_0.42þ_0.42þ þ_1.18þ_1.18þ 1.54þ 1.54þ 0.37þ 0.37þ 0.54þ 0.54þ þ 0.00þ 0.00þ 1.00þ 1.00þ 1.00þ 1.00þ 1.00þ 1.00þ þ 1.18þ 1.18þ 1.54þ 1.54þ 2.72þ 2.72þ 0.54þ 0.54þ þ 3.63þ 3.63þ 3.76þ 3.76þ 7.39þ 7.39þ_0.42þ_0.42þ ÁýýýýýÂýýýýýÂýýýýýÂýýýýýÂýýýýýÂýýýýýÂýýýýýÂýýýýýã m=. ? 4 4 $ 9 (] ; ] .. |: ; ] .: |:) m õýýýýýýýÃýýýýýýýýýýýýýýýÃýýýýýýýýýýýýýýýýýýÀ þ1 6 4 4þ 1 3.5 6 2þ 0 2.5 _2 2þ þ1 0 6 6þ3.5 0 4.5 3þ_2.5 0 1.5 3þ þ8 3 4 7þ 6 4.5 4 5.5þ 2 _1.5 0 1.5þ þ0 0 4 6þ 2 3 5.5 6þ _2 _3 _1.5 0þ ÁýýýýýýýÂýýýýýýýýýýýýýýýÂýýýýýýýýýýýýýýýýýýã EXPLICIT DEFINITION m : n _ _ _ (see next topic) As defined and illustrated in Section G of Part II, the phrase s=. 0 : 0 may be used to define s as a script, and the explicit definition conjunction can be further used to produce a verb (3 : s), conjunction (2 : s), adverb (1á:ás), or noun (0 : s). The left arguments 13 to 10 may be used instead of 3 to 0 to produce equivalent results, but in tacit form if possible. The right argument 0 may be used in each case to make the corresponding definitions direct from the keyboard, that is, k : 0 is equivalent to k :(0 : 0).Moreover, the boxed representation b=. <;._2 s or the table representationt=. >b (or t=.[;._2 s) may be used in lieu of the script s in every case. The role of control structures in controlling the sequence of execution is treated below. Thus: f=. 3 : 0 For the cases 0-2, the value of the left argument is the a=: 2+b=. b*y. valence of the entity produced; for the case 3 it is the a+a*b sum of the possible valences of the verb produced. : x.*x.+y. ) a=. b=. 10 f 3 992 a,b Only the globally assigned name is changed. 32 10 As illustrated by the foregoing: The definitions of the monadic and dyadic cases are separated by a colon on a line by itself; if none occurs, the domain of the dyadic case is empty. The explicit result is the result of the last sentence executed. A name assigned by the copula =. is made local on its first assignment; values assigned to it have no effect on the use of the same name outside of the entity defined or within other entities invoked by it. A name assigned by =: is global. A locale name cannot be localized. The names x. and y. are local, and refer to the left and right arguments. The definition and use of a conjunction is illustrated below: conj=. 2 : 'x.@[ + y.@]' 3 ! conj *: 5 Factorial of left plus square of right 31 Control structures. The sequence of execution of an explicit definition may be determined by control words such as if. do. else. end. and while.. For example, a function to find the root of a function f from a two-element list that brackets the root may be written and executed as follows: root=. 3 : 0 m=.+/%#while.~:/y.do.if.~:/*f b=.(m,{.)y.do.y.=.b else.y.=.(m,{:)y.end.end.m y. ) f=. 4:-%: b=. 1 32 root b 16 Such a definition may also be written on successive lines by breaking it before or after any control word, and the foregoing definition may be made more readable as follows: root=. 3 : 0 m=. +/ % # while. ~:/y. do. if. ~:/*f b=. (m,{.) y. do. y.=. b else. y.=. (m,{:) y. end. end. m y. ) As illustrated by the foregoing, the word if. and a matching end. mark the beginning and end of a control structure, as do while. and a matching end.; such structures may be nested as is the if. structure within the while.ástructure. The four control words if. , try. , while. , and whilst. mark the beginnings of control structures that are each terminated by a matching end. In the foregoing example, do. and else. break the if. structure into three simple blocks, each comprising a sentence, whereas the do. in the while. structure breaks it into two blocks, the first being a simple sentence, and the second being itself an if. control structure. In general, a block comprises zero or more control words and sentences that are grouped together by further control words occurring within a control structure. The role of blocks is summarized as follows: if. T do. B end. if. T do. B else. B1 end. if. T do. B elseif. T1 do. B1 elseif. T2 do. B2 end. try. B catch. B1 end. while. T do. B end. whilst. T do. B end. Like while., but Skips Test first time. Words beginning with B or T denote blocks. The last sentence executed in a T block is tested for a non-zero value in its leading atom, and the result of the test determines the block to be executed next. If an error occurs in a try. block, execution continues in the matching catch. block. The final result is the result of the last sentence executed that was not in a T block. The behaviour of the remaining control words may be summarized as follows: break. Go to end of while. or whilst. control block continue. Go to top of while. or whilst. control block goto_name. Go to label of same name label_name. Target of goto_name. return. Exit the function MONAD / DYAD u : v _ _ _ (see previous) The first argument specifies the monadic case and the second argument the dyadic case. For example: y=. 10 64 100 ^. y Natural logarithm 2.30259 4.15888 4.60517 10&^. y Base ten logarithm 1 1.80618 2 log=. 10&^. : ^. log y 1 1.80618 2 8 log y 1.10731 2 2.21462 (^1) log y 2.30259 4.15888 4.60517 LOG=. 10&$: : ^. Use of self-reference LOG y 1 1.80618 2 f=. %: : ($:@-) (f y),: 100 f y 3.16228 8 10 9.48683 6 0 ABS=. | : [: ABS _4 4 3 ABS _4 The domain of dyad ABS is empty because þdomain error the domain of [: is empty þ 3 ABS _4 OBVERSE u :. v mu lu ru The result of u :. v is the verb u, but with an assigned obverse v (used as the inverse under the conjunctions &. and ^:). For example: obv=. :. I=. ^: _1 %: I *: y=. _4 0 4 3j4 rp=. <@(%: , -@%:)"0 Root pairs rp y õýýýýýýýýÃýýýÃýýýýÃýýýýýýýýýÀ þ0j2 0j_2þ0 0þ2 _2þ2j1 _2j_1þ ÁýýýýýýýýÂýýýÂýýýýÂýýýýýýýýýã rp I No assigned obverse rp^:_1 rp I rp y |length error | rp I rp y inv=. *:@{.@,@> inv rp y _4 0 4 3j4 RP=. rp obv inv Assigned obverse in RP RP I RP y _4 0 4 3j4 rc=. <@(,: +)@(, -)@%:"0 Root companions rc y õýýýýýýýýýÃýýýÃýýýýÃýýýýýýýýýýÀ þ 0j2 0j_2þ0 0þ2 _2þ 2j1 _2j_1þ þ0j_2 0j2þ0 0þ2 _2þ2j_1 _2j1þ ÁýýýýýýýýýÂýýýÂýýýýÂýýýýýýýýýýã RC=. rc obv inv RC I RC y _4 0 4 3j4 ADVERSE u :: v _ _ _ The result of u :: v is that of u, provided that u completes without error; otherwise the result is the result of v. For example: p=. 3 1 0 2 A permutation vector x=. 'ABCD' p{x DBAC ]i=. A. p Atomic index in ordered list of permutations 20 i A. x Permutation by atomic representation DBAC q=. 3 1 1 0 Not a permutation q{x DBBA A. q |index error | A.q A=. A. :: (!@#) Give index outside range in case of error A p 20 A q 24 24 A. x |index error | 24 A.x Ravel , _ _ _ Append ,y gives a list of the atoms of y in normal order; the result is ordered by items, by items within items, etc. The result shape is 1$*/$ y. Thus: y=. 2 4 $ 'abcdefgh' yabcdefgh ,yabcdefgh x,y appends items of y to items of x after: 1) Reshaping an atomic argument to the shape of the items of the other, 2) Bringing the arguments to a common rank (of at least 1) by repeatedly itemizing (,:) any of lower rank, and 3) Bringing them to a common shape by padding with fill elements in th e manner described in Section II B. ]a=. i. 2 3 3 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ,a 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ,"2 a 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 The following examples illustrate the dyadic case: ('abc','de');('abc',"0/'de');(5 6 7,i.2 3);(7,i.2 3) õýýýýýÃýýÃýýýýýÃýýýýýÀ þabcdeþadþ5 6 7þ7 7 7þ þ þaeþ0 1 2þ0 1 2þ þ þ þ3 4 5þ3 4 5þ þ þbdþ þ þ þ þbeþ þ þ þ þ þ þ þ þ þcdþ þ þ þ þceþ þ þ ÁýýýýýÂýýÂýýýýýÂýýýýýã Ravel Items ,. _ _ _ Stitch If y is an atom, then ,.y is 1 1$y; otherwise, ,.y is ,"_1 y, the table formed by ravelling each item of y. x,.y is equivalent to x,"_1 y. In other words, items of x are stitched to corresponding items of y. For example: a=. i. 2 3 2 ($,.3);(,.2 3 5 7 11);($,.<'abcd');a;(,.a) õýýýÃýýÃýýýÃýýýýýÃýýýýýýýýýýýýýÀ þ1 1þ 2þ1 1þ 0 1þ0 1 2 3 4 5þ þ þ 3þ þ 2 3þ6 7 8 9 10 11þ þ þ 5þ þ 4 5þ þ þ þ 7þ þ þ þ þ þ11þ þ 6 7þ þ þ þ þ þ 8 9þ þ þ þ þ þ10 11þ þ ÁýýýÂýýÂýýýÂýýýýýÂýýýýýýýýýýýýýã The following examples illustrate the dyadic case: b=.3 4$'abcdefghijkl' [ c=.3 4$'ABCDEFGHIJKL' b;c;(b,.c);(b,c);a;(a ,. |."1 a);(,/a);(,./a) õýýýýÃýýýýÃýýýýýýýýÃýýýýÃýýýýýÃýýýýýÃýýýýýÃýýýýýýýýýÀ þabcdþABCDþabcdABCDþabcdþ 0 1þ 0 1þ 0 1þ0 1 6 7þ þefghþEFGHþefghEFGHþefghþ 2 3þ 2 3þ 2 3þ2 3 8 9þ þijklþIJKLþijklIJKLþijklþ 4 5þ 4 5þ 4 5þ4 5 10 11þ þ þ þ þABCDþ þ 1 0þ 6 7þ þ þ þ þ þEFGHþ 6 7þ 3 2þ 8 9þ þ þ þ þ þIJKLþ 8 9þ 5 4þ10 11þ þ þ þ þ þ þ10 11þ þ þ þ þ þ þ þ þ þ 6 7þ þ þ þ þ þ þ þ þ 8 9þ þ þ þ þ þ þ þ þ10 11þ þ þ þ þ þ þ þ þ 7 6þ þ þ þ þ þ þ þ þ 9 8þ þ þ þ þ þ þ þ þ11 10þ þ þ ÁýýýýÂýýýýÂýýýýýýýýÂýýýýÂýýýýýÂýýýýýÂýýýýýÂýýýýýýýýýã Itemize ,: _ _ _ Laminate ,:y adds a leading unit axis to y, giving a result of shape 1,$y. Thus: $ ,: 2 3 41 3 An atomic argument in x,:y is first reshaped to the shape of the other (or to a list if the other argument is also atomic); the results are then itemized and catenated, as in (,:x),(,:y) . s=. 3 [ v=. 2 3 4 [ m=. i. 3 3 (,:s);($,: s);(,:v);($,:v); ($,:m); ($,:^:4 v) õýÃýÃýýýýýÃýýýÃýýýýýÃýýýýýýýýýÀ þ3þ1þ2 3 4þ1 3þ1 3 3þ1 1 1 1 3þ ÁýÂýÂýýýýýÂýýýÂýýýýýÂýýýýýýýýýã The following examples compare the dyadic cases of append, and laminate: a=. 'abcd' [ A=. 'ABCD' [ b=. 'abcdef' (a,A) ; (a,:A) ; (a,:b) ; (m,m) ; (m ,: m) õýýýýýýýýÃýýýýÃýýýýýýÃýýýýýÃýýýýýÀ þabcdABCDþabcdþabcd þ0 1 2þ0 1 2þ þ þABCDþabcdefþ3 4 5þ3 4 5þ þ þ þ þ6 7 8þ6 7 8þ þ þ þ þ0 1 2þ þ þ þ þ þ3 4 5þ0 1 2þ þ þ þ þ6 7 8þ3 4 5þ þ þ þ þ þ6 7 8þ ÁýýýýýýýýÂýýýýÂýýýýýýÂýýýýýÂýýýýýã t=. i. 3 2 2 t;(,/t);(,./t);(,:/t) õýýýýýÃýýýýýÃýýýýýýýýýýýýýÃýýýýýÀ þ 0 1þ 0 1þ0 1 4 5 8 9þ 0 1þ þ 2 3þ 2 3þ2 3 6 7 10 11þ 2 3þ þ þ 4 5þ þ þ þ 4 5þ 6 7þ þ 0 0þ þ 6 7þ 8 9þ þ 0 0þ þ þ10 11þ þ þ þ 8 9þ þ þ þ þ10 11þ þ þ 4 5þ þ þ þ þ 6 7þ þ þ þ þ þ þ þ þ þ 8 9þ þ þ þ þ10 11þ ÁýýýýýÂýýýýýÂýýýýýýýýýýýýýÂýýýýýã Raze ; _ _ _ Link ;y assembles along a leading axis the opened elements of the ravel of y . x;y is (bv 1 2 3 4 5 6 7 8 9 ;/ m õýýýýýÃýýýýýÃýýýýýÀ þ1 2 3þ4 5 6þ7 8 9þ ÁýýýýýÂýýýýýÂýýýýýã (;/1 2 3 4 5) ,&< (;/i. 3 4) õýýýýýýýýýýýÃýýýýýýýýýýýýýýýýýýýýýýýýýýýÀ þõýÃýÃýÃýÃýÀþõýýýýýýýÃýýýýýýýÃýýýýýýýýýÀþ þþ1þ2þ3þ4þ5þþþ0 1 2 3þ4 5 6 7þ8 9 10 11þþ þÁýÂýÂýÂýÂýãþÁýýýýýýýÂýýýýýýýÂýýýýýýýýýãþ ÁýýýýýýýýýýýÂýýýýýýýýýýýýýýýýýýýýýýýýýýýã ]txt=. '3 %: 4 ^. 5' 3 %: 4 ^. 5 ]s=. ;: txt Word formation õýÃýýÃýÃýýÃýÀ þ3þ%:þ4þ^.þ5þ ÁýÂýýÂýÂýýÂýã ;s 3%:4^.5 (boxifopen=. <^:(< -: {:@;~)) 3 4 õýýýÀ þ3 4þ Áýýýã (<3 4) = boxifopen <3 4 1