Contents - J Introduction and Dictionary Introduction Sample Topics Dictionary Vocabulary Foreign Conjunction References Acknowledgments Copyright J User Manual Introduction Contents 1 Introduction 2 Mnemonics 3 Ambivalence 4 Verb and Adverbs 5 Punctuation 6 Forks 7 Programs 8 Bond Conjunction 9 Atop Conjunction 10 Vocabulary 11 Housekeeping 12 Power and Inverse 13 Reading and Writing 14 Format 15 Partitions 16 Defined Adverbs 17 Word Formation 18 Names and Displays 19 Explicit Definition 20 Tacit Equivalents 21 Rank 22 Gerund and Agenda 23 Recursion 24 Iteration 25 Trains 26 Permutations 27 Linear Functions 28 Obverse and Under 29 Identity Functions 30 Secondaries Sample Topics Contents Sample Topics Spelling Alphabet & Numbers Grammer Function Tables Bordering a Table Tables (Letter Frequency) Tables Classification Disjoint Classification Classification (Inner Product) Classification (Sets) Sorting Compositions (Conjunctions) Composition (Forks) Junctions Partitions (Adverbs) Partitions (Cuts) Geometry Symbolic Functions Directed Graphs Distance Polynomials (Coefficients) Polynomials (Roots) Polynomials (Newtons Method) Polynomials (Kerners Method) Polynomials (Stopes) Dictionary Contents Dictionary Alphabet and Words Grammar Nouns Verbs Adverbs and Conjunctions Comparitives Parsing and Execution Trains Frets and Scripts Locatives Errors and Suspension Definitions Vocabulary = Self-Classify - Equal =. Is (Local) =: Is (Global) < Box - Less Than <. Floor - Lesser of <: Decrem - Less Or Eq > Open - Larger Than >. Ceiling - Larger of >: Increm - Larg Or Eq _ Negative Sign /Infinit _. Indeterminate _: Infinity + Conjugate - Plus +. Real/Imag - GCD (Or) +: Double - Not-Or * Signum - Times *. Len/Angle - LCM (And) *: Square - Not-And - Negate - Minus -. Not (1) - Less -: Halve - Match % Reciprocal - Divided by %. Matrix Inv - Mat Divide %: Square Root - Root ^ Exponential - Power ^. Natural Log - Logarithm ^: Power $ Shape Of - Shape $. $: Self-Reference ~ Reflex-Pass-EVOKE ~. Nub ~: Nub Sieve - Not-Eq | Magnitude - Residue |. Reverse - Rotate (Shift) |: Transpose . Det - Dot Product .. Even .: Odd : Explicit - Monad/Dyad :. Obverse :: Adverse , Ravel - Append ,. Ravel Items - Stitch ,: Itemize - Laminate ; Raze - Link ;. Cut ;: Word formation # Tally - Copy #. Base 2 - Base #: Antibase 2 - Antib ! Factorial - Out Of !. Fit (Customize) !: Foreign / Insert-Table-INSERT /. Oblique-Key-APPEND /: Grade Up - Sort \ Prefix-Infix-TRAIN \. Suffix - Outfix \: Grade Down - Sort [ Same - Left [. Lev [: Cap ] Same - Right ]. Dex ]: { Catalogue - From {. Head - Take {: Tail } Item Amend - Amend }. Behead - Drop }: Curtail " Rank - CONSTANT ". Do ": Format ` Tie (Gerund) `. `: Evoke Gerund @ Atop @. Agenda @: At & Bond /Compose &. Under (Dual) &: Appose ? Roll - Deal ?. ?: a. Alphabet a: Ace (boxed empty) A. Atomic Permute b. Boolean/Basic c. Characteristic values C. Cycle-Dir - Perm D. Derivative D: Secant Slope e. Raze In - Memb E. - Member of Interval f. Fix i. Integ - Index Of j. Imaginary - Complex NB. Comment o. Pi Times - Circlr p. Polynomial r. Angle - Polar t. Taylor coef T. Taylor Function x. Left Argument y. Right Argument Constant functions Constants 1: INTRODUCTION J is a general-purpose programming language available on a wide variety of computers. Although it has a simple structure and is readily learned by anyone familiar with mathematical notions and notation, its distinctive features may make it difficult for anyone familiar with more conventional programming languages. This introduction is designed to present J in a manner that makes it easily accessible to programmers, by emphasizing those aspects that distinguish it from other languages. These include: 1. A mnemonic one- or two-character spelling for primitives. 2. No order-of-execution hierarchy among functions. 3. The systematic use of ambivalent functions that, like the minus sign in arithmetic, can denote one function when used with two arguments (subtraction in the case of -), and another when used with one argument (negation in the case of -). 4. The adoption of terms from English grammar that better fit the grammar of J than do the terms commonly used in mathematics and in programming languages. Thus, a function such as addition is also called a verb (because it performs an action), and an entity that modifies a verb (not available in most programming languages) is accordingly called an adverb. 5. The systematic use of adverbs and conjunctions to modify verbs, so as to provide a rich set of operations based upon a rather small set of verbs. For example, +/a denotes the sum over a list a, and */a denotes the product over a, and a */ b is the multiplication table of a and b. 6. The treatment of vectors, matrices, and other arrays as single entities. 7. The use of functional or tacit programming that requires no explicit mention of the arguments of a function (program) being defined, and the use of assignment to assign names to functions (as in sum=.+/ and mean=.sum % #). The following lessons are records of actual J sessions, accompanied by commentary that should be read only after studying the corresponding session (and perhaps experimenting with variations on the computer). The lessons should be studied with the Jásystem and dictionary at hand. The reckless reader may go directly to the sample topics on page 31. 2: MNEMONICS The left side of the page shows an actual computer session with the result of each sentence shown at the left margin. First cover the comments at the right, and then attempt to state in English the meaning of each primitive so as to make clear the relations between related symbols. For example, < is less than and <. is lesser of (that is, minimum). Then uncover the comments and compare with your own. 7<5 Less than 0 A zero is interpreted as false. 7<.5 Lesser of 5 7>5 Greater than 1 A one is true (€ la George Boole) 7>.5 Greater of 7 10^3 Power (€ la Augustus de Morgan) 1000 10^.1000 Logarithm 3 7=5 Equals 0 b=. 5 Is (assignmentáor copula) 7<. b 5 Min=. <. Min is <. power=. ^ Power is ^ gt=. > gt is > 10 power (5 Min 3) 1000 Exercises: 2.1 Enter the following sentences on the computer, observe the results, give suitable names to any new primitives (such as * and +. and *.), and comment on their behaviour. a=.0 1 2 3 b=.3 2 1 0 a+b a*b a-b a%b a^b a^.b ab (ab) (ab) Compare your comments with the following: a) Negative 3 is denoted by _3. The underbar _ is part of the representation of a negative number in the same sense that the decimal point is part of the representation of one-half when written in the form 0.5, and the negative sign _ must not be confused with the symbol used to denote subtraction (i.e., -). b) Division (%) by zero yields infinity, denoted by the underbar alone. c) Log of 2 to the base 1 is infinite, and log of 0 to the base 3 is negative infinity (__). d) Since the relation 5<7 is true, and the result of 5<7 is 1, it may be said that true and false are represented by the ordinary integers 1 and 0. George Boole used this same convention, together with the symbol + to represent the booleanáfunction or. We use the distinct representation +. to avoid conflict with the analogous (but different) addition (denoted by +). 2.2 Following the example Min=. <. , invent, assign, and use names for each of the primitives encountered thus far. 3: AMBIVALENCE Cover the comments on the right and provide your own. 7-5 The function in the sentence 7-5 applies to two 2 arguments to perform subtraction, but in the sentence -5 it applies to a single argument to -5 perform negation. _5 Adopting from chemistry the term valence, we say that the symbol - is ambivalent, its effective 7%5 binding power being determined by context. 1.4 %5 The ambivalence of - is familiar in arithmetic; 0.2 it is here extended to other functions. 3^2 9 ^2 Exponential (that is, 2.71828^2) 7.38906 a=. i. 5 The function integer or integer list a 0 1 2 3 4 Listáor vector a i. 3 1 The function index or index of 3 1 b=. 'Canada' Enclosing quotes denote literal characters b i. 'da' 4 1 $ a Shape function 5 3 4 $ a Reshape function 0 1 2 3 Table or matrix 4 0 1 2 3 4 0 1 3 4 $ b Cana daCa nada %a Functions apply to lists _ 1 0.5 0.333333 0.25 The symbol _ alone denotes infinity Exercises: 3.1 Enter the following sentences (and perhaps related sentences using different arguments), observe the results, and state what the two cases (monadicáand dyadic) of each function do: a=. 3 1 4 1 5 9 b=. 'Canada' #a 1 0 1 0 1 3 # a 1 0 1 0 1 3 # b /: a /:b a /: a a /: b b /: a b /: b c=. 'can''t' c #c c /: c 3.2 Make a summary table of the functions used thus far. Then compare it with the following table (in which a dot separates the monadic case from the dyadic, as in Negate . Subtract): . : + . Add . Or - Negate . Subtract * .Times . And % Reciprocal . Divide ^ Exponential . Power . Log < . Less Than . Lesser Of > . Greater Than . Greater Of = . Equals Is (Copula) i Integers . Index Of $ Shape . Reshape / Grade . Sort # Number of items . Replicate 3.3 Try to fill some of the gaps in the table of Exercise 3.2 by experimenting on the computer with appropriate expressions. For example, enter ^. 10 and ^.á2.71828 to determine the missing (monadic) case of ^. and enter %: 4 and %: -4 and +%: -4 to determine the case of % followed by a colon. However, do not waste time on matters (such as, perhaps, complex numbers or the boxed results produced by the monad <) that are still beyond your grasp; it may be better to return to them after working through later lessons. Note that the effects of certain functions become evident only when applied to arguments other than positive integers: try <.1 2 3 4 and <.3.4 5.2 3.6 to determine the effect of the monad <. . 3.4 If b=.3.4 5.2 3.6 , then <.b yields the argument b rounded down to the nearest integer. Write and test a sentence that rounds the argument b to the nearest integer. ANSWER: <.(b+0.5) or <.b+0.5 or <.b+1r2 3.5 Enter 2 4 3 $ i. 5 to see an example of a rank 3 array or report (for two years of four quarters of three months each). 3.6 Enter ?9 repeatedly and state what the function ? does. Then enter t=. ?3 5 $ 9 to make a table for use in further experiments. ANSWER: ? is a (pseudo-) random number generator; ?n produces an element from the population i.n 4: VERBS AND ADVERBS In the sentence %a of Lesson 3, the % acts upon a to produce a result, and %a is therefore analogous to the notion in English of a verb acting upon a noun or pronoun. We will hereafter adopt the term verb instead of (or in addition to) the mathematical term function used thus far. The sentence +/ 1 2 3 4 is equivalent to 1+2+3+4; the adverb / applies to its verb argument + to produce a new verb whose argument is 1 2 3 4, and which is defined by inserting the verb + between the items of its argument. Other arguments of the insert adverb are treated similarly: */b=.2 7 1 8 2 8 1792 <./b 1 >./b 8 The verb resulting from the application of an adverb may (like a primitive verb) have both monadic and dyadic cases. In the present instance of / the dyadic case produces a table. For example: 2 3 5 +/ 0 1 2 3 2 3 4 5 3 4 5 6 5 6 7 8 The verbs over=.({.;}.)@":@, and by=.' '&;@,.@[,.] can be entered as utilities (for use rather than for immediate study), and can clarify the interpretation of function tables such as the addition table produced above. For example: a=. 2 3 5 b=. 0 1 2 3 a by b over a +/ b b by b over b and the lesser-of and greater-of. 4.3 Apply the verbs |. and |: to various tables, and try to state what they do. 4.4 The transpose function |: changes the subtraction table, but appears to have no effect on the multiplication table. State the property of those functions whose tables remain unchanged when transposed. ANSWER: They are commutative 4.5 Enter d by d over d!/d and state the definition of the dyad ! . ANSWER: ! is the binomial coefficientáor outoffunction 3!5 is the number of ways that three things can be chosen from five. 5: PUNCTUATION English employs various symbols to punctuate a sentence, to indicate the order in which its phrases are to be interpreted. Thus: The teacher said he was stupid. The teacher, said he, was stupid. Math also employs various devices (primarily parentheses) to specify order of interpretation or, as it is usually called, order of execution. It also employs a set of rules for an unparenthesized phrase, including a hierarchy amongst functions. For example, power is executed before times, which is executed before addition. J uses only parentheses for punctuation, together with the following rules for unparenthesized phrases: The right argument of a verb is the value of the entire phrase to its right. Adverbs are applied first. Thus, the phrase a */ b is equivalent to a (*/) b, not to a (*/b). For example: a=.5 b=.3 (a*a)+(b*b) 34 a*a+b*b 70 a*(a+(b*b)) 70 (a+b)*(a-b) 16 a (+*-) b 16 The last sentence above includes the isolated phrase +*- which has thus far not been assigned a meaning. It is called a trident or fork , and is equivalent to the sentence that precedes it. A fork also has a monadic meaning, as illustrated for the mean below: c=.2 3 4 5 6 (+/ % #) c The verb # yields the number 4 of items in its argument. (+/c)%(#c) 4 Exercises: 5.1 In math, the expression 3x4+4x3+5x2 is called a polynomial. Enter: x=. 2 (3*x^4)+(4*x^3)+(5*x^2) to evaluate the polynomial for the case where x is 2. 5.2 Note that the hierarchy among functions used in math is such that no parentheses are necessary in writing a polynomial. Write an equivalent sentence using no parentheses. ANSWER: +/3 4 5 * x ^ 4 3 2 or (first assigning names to the coefficients 3 4 5 and the exponents 4 3 2), as +/c*x^e 6: FORKS As illustrated in the preceding lesson, an g g isolated sequence of three verbs is called / \ / \ a fork; its monadic and dyadic cases are f h f h defined by: | | / \ / \ y y x y x y (f g h) y is (f y) g (h y) x (f g h) y is (x f y) g (x h y) The diagrams at the upper right provide visual images of the fork. Before reading the notes at the right (and by using the facts that %: denotes the root function and ] denotes the identity function), try to state in English the significance of each of the following sentences: a=. 8 7 6 5 4 3 b=. 4 5 6 7 8 9 2 %: b Square root of b 2 2.23607 2.44949 2.64575 2.82843 3 3 %: b Cube root of b 1.5874 1.70998 1.81712 1.91293 2 2.08008 (+/ % #) b Arithmetic mean or average 6.5 (# %: */) b Geometric mean 6.26521 (] - (+/ % #)) b Centre on mean (two forks) _2.5 _1.5 _0.5 0.5 1.5 2.5 (] - +/ % #) b Two forks (fewer parentheses) _2.5 _1.5 _0.5 0.5 1.5 2.5 a (+ * -) b Dyadic case of fork 48 24 0 _24 _48 _72 (a^2)-(b^2) 48 24 0 _24 _48 _72 a (< +. =) b Less than or equal 0 0 1 1 1 1 a./) b=. 2 7 1 8 2 ANSWER: #b repetitions of the maximum over b 6.2 Cover the comments on the right, write your own interpretation of each sentence, and then compare your statements with those on the right: (+/ % #) b Mean of b (# # +/ % #) b (n=.#b) repetitions of mean +/(##+/%#) b Sum of n means (+/b)=+/(##+/%#) b Tautology (*/b)= */(###%:*/) b The product over b is the product over n repetitions of the geometric mean of b. 7: PROGRAMS A program handed out at a musical evening describes the sequence of musical pieces to be performed. As suggested by its roots gram and pro, a program is something written in advance of the events it prescribes. Similarly, the fork +/ % # of the preceding lesson is a program that prescribes the computation of the mean of its argument when it is applied, as in the sentence (+/%#)b. However, we would not normally call the procedure a program until we assign a name to it, as illustrated below: mean=. +/ % # mean 2 3 4 5 6 4 (geomean=. # %: */) 2 3 4 5 6 3.72792 Since the program mean is a new verb, we also refer to a sentence such as mean=. +/ % # as verb definition (or definition), and to the resulting verb as a definedáverb or function. Defined verbs can be used in the definition of further verbs in a manner sometimes referred to as structured programming. For example: MEAN=. sum % # sum=. +/ MEAN 2 3 4 5 6 4 Entry of a verb alone (without an argument) displays its definition, and the foreign conjunction can be used to specify the form of the display: boxed, tree, or linear: mean +/ % # 9!:3 (2 4 5) mean õıııııÃıÃıÀ şõıÃıÀş%ş#ş şş+ş/şş ş ş şÁıÂıãş ş ş ÁıııııÂıÂıã õı / ııı + ııÊı % Áı # +/ % # Exercises: 7.1 Enter AT=. i. +/ i. and use expressions such as AT 5 to determine the behaviour of the program AT. 7.2 Define and use similar function tables for other dyadic functions. 7.3 Define the programs: tab=. +/ ft=. i. tab i. test1=. ft = AT Then apply test1 to various integer arguments to test the proposition that ft is equivalent to AT of Exercise 7.1, and enter ft and AT alone to display their definitions. 7.4 Define aft=. ft f. and use test2=. aft = ft to test their equivalence. Then display their definitions and state the effect of the adverb f. ANSWER: The adverb f. fixes the verb to which it applies, replacing each name used by its definition. 7.5 Redefine tab of Exercise 7.3 by entering tab=. */ and observe the effects on ft and its fixed alternative aft. 7.6 Define mean=. +/ % # and state its behaviour when applied to a table, as in mean t=. (i. !/ i.) 5. ANSWER: The result is the average of, not over, the rows of a table argument. 7.7 Write an expression for the mean of the columnsáof t. ANSWER: mean |: t or mean"1 t 8: BOND CONJUNCTION A dyad such as ^ can be used to provide a family of monadic functions: ]b=. i.7 0 1 2 3 4 5 6 b^2 Squares 0 1 4 9 16 25 36 b^3 Cubes 0 1 8 27 64 125 216 b^0.5 Square roots 0 1 1.41421 1.73205 2 2.23607 2.44949 The bond conjunction & can be used to bind an argument to a dyad in order to produce a corresponding defined verb. For example: square=. ^&2 Square (power and 2) square b 0 1 4 9 16 25 36 (sqrt=. ^&0.5) b Square root function 0 1 1.41421 1.73205 2 2.23607 2.44949 A left argument can be similarly bound: Log=. 10&^. Base-10 Logarithm Log 2 4 6 8 10 100 1000 0.30103 0.60206 0.778151 0.90309 1 2 3 Such defined verbs can of course be used in forks. For example: in29=. 2&< *. <&9 Interval test in29 0 1 2 5 8 13 21 0 0 0 1 1 0 0 IN29=. in29 # ] Interval selection IN29 0 1 2 5 8 13 21 5 8 LOE=. <+.= 5 LOE 3 4 5 6 7 0 0 1 1 1 integertest=. <. = ] The monad <. is integer part or floor integertest 0 0.5 1 1.5 2 2.5 3 1 0 1 0 1 0 1 int=. integertest int (i.13)%3 1 0 0 1 0 0 1 0 0 1 0 0 1 Exercises: 8.1 The verb # is used dyadically in the program IN29. Enter expressions such as (j=. 3 0 4 0 1) # i.5 to determine the behaviour of #, and state the result of #j#i.5. (Also try 1j1#i.5.) ANSWER: +/j 8.2 Cover the answers on the right and apply the following programs to lists to determine (and state in English) the purpose of each: test1=. >&10 *. <&100 Test if in 10 to 100 int=. ] = <. Test if integer test2=. int *. test1 Test if integer and in 10 to 100 test3=. int +. test1 Test if integer or in 10 to 100 sel=. test2 # ] Select integers in 10 to 100 8.3 Cover the program definitions on the left of the preceding exercise, and make new programs for the stated effects. 8.4 Review the use of the fix adverb in Exercises 7.4-5, and experiment with its use on the programs of Exercise 8.2. 9: ATOP CONJUNCTION The conjunction @ applies to two verbs to produce a verb that is equivalent to applying the first atop the second. For example: TriplePowersOf2=. (3&*)@(2&^) TriplePowersOf2 0 1 2 3 4 3 6 12 24 48 CubeOfDiff=. (^&3)@- 3 4 5 6 CubeOfDiff 6 5 4 3 _27 _1 1 27 f=. ^@- The rightmost function is first applied monadically; the second is applied dyadically if possible. 5 f 3 7.38906 f 3 0.0497871 g=. -@^ 5 g 3 _125 g 3 _20.0855 A conjunction, like an adverb, is executed before verbs; the leftáargument of either is the entire verb phrase that precedes it. Consequently, some (but not all) of the parentheses in the foregoing definitions can be omitted. For example: COD=. ^&3@- 3 4 5 6 COD 6 5 4 3 _27 _1 1 27 TPO2=. 3&*@(2&^) TPO2 0 1 2 3 4 3 6 12 24 48 tpo2=. 3&*@2&^ An error because the conjunction @ is defined |domain error only for a verb right argument | tpo2=. 3&*@2&^ Exercises: 9.1 Cover the comments on the right, and state the effects of the programs. Then cover the programs and rewrite them from the English statements: mc=. (+/%#)@|: Means of columns of table f=. +/@*: Sum of squares of list g=. %:@f Geometric length of list h=.{&' *'@(:&2 Interval test 2 to 9 (inclusive) f4=. f3 *. <. = ] In 2 to 9 and integer f5=. f3 +. <. = ] In 2 to 9 or integer g1=. %&1.8 Divide by 1.8 g2=. g1^:_1 Multiply by 1.8 g3=. -&32 Subtract 32 g4=. g3^:_1 Add 32 g5=. g1@g3 Celsius from Fahrenheit g6=. g5^:_1 Fahrenheit from Celsius h1=. >./ Maximum over list (monad) h2=. h1-<./ Spread. Try h2 b with the parabola: b=.(-&2 * -&3) -:i.12 h3=. h1@]-i.@[*h2@]%<:@[ Grid. Try 10 h3 b h4=. h3 <:/ ] Barchart. Try 10 h4 b h5=. {&' *' @ h4 Barchart. Try 10 h5 b After entering the foregoing definitions, enter each verb name alone to display its definition, and learn to interpret the resulting displays. To see several forms of display, first enter 9!:3 (2 4 5). Cover the left side of the page, and translate the English definitions on the right back into J. Exercises: 13.1 These exercises are grouped by topic and organized like the lesson, with programs that are first to be read and then to be rewritten. However, a reader already familiar with a given topic might begin by writing. A. Properties of numbers pn=. >:@i. Positive numbers (e.g. pn 9) rt=. pn |/ pn Remainder table dt=. 0&=@rt Divisibility table nd=. +/@dt Number of divisors prt=. 2&=@nd Prime test prsel=. prt # pn Prime select N=. >:@pn Numbers greater than 1 rtt=. ,@(N */ N) Ravelled times table aprt=. -.@(N e. rtt) Alternative test and selection (primes do not occur in the times table for N) apsel=. aprt # N B. Coordinate Geometry Do experiments on the vector (or point) p=. 3 4 and the triangle represented by the table tri=. 3 2$ 3 4 6 5 7 2 L=. %:@(+/)@*:"1 Length of vector (See rank in the dictionary or in Lesson 21) LR=.L"1 Length of rows in table disp=. ] - 1&|. Displacement between rows LS=. LR@disp Lengths of sides of figure sp=. -:@(+/)@LS Semiperimeter (try sp tri) H=. %:@(*/)@(sp,sp-LS) Herons formula for area det=. -/ . * Determinant (See dictionary) SA=. det@(,.&0.5) Signed area; negative if plotted vertices are in clockwise order sa=.det@(],.%@!@<:@#) General signed volume; try it on the tetrahedron tet=. ?4 3$9 as well as on the triangle tri . 14: FORMAT A numeric table such as: ]t=.(i.4 5)%3 0 0.333333 0.666667 1 1.33333 1.66667 2 2.33333 2.66667 3 3.33333 3.66667 4 4.33333 4.66667 5 5.33333 5.66667 6 6.33333 can be rendered more readable by formatting it to appear with a specified width for each column, and with a specified number of digits following the decimal point. For example: ]f=. 6.2 ": t 0.00 0.33 0.67 1.00 1.33 1.67 2.00 2.33 2.67 3.00 3.33 3.67 4.00 4.33 4.67 5.00 5.33 5.67 6.00 6.33 The integer part of the left argument of the format function specifies the column width, and the first digit of the fractional part specifies the number of digits to follow the decimal point. Although the formatted table looks much like the original table t, it is a table of characters, not of numbers. For example: $t 4 5 $f 4 30 +/t 10 11.3333 12.6667 14 15.3333 +/f domain error However, the verb do or execute (".) applied to such a character table yields a corresponding numeric table: ". f 0 0.33 0.67 1 1.33 1.67 2 2.33 2.67 3 3.33 3.67 4 4.33 4.67 5 5.33 5.67 6 6.33 3* ". f 0 0.99 2.01 3 3.99 5.01 6 6.99 8.01 9 9.99 11.01 12 12.99 14.01 15 15.99 17.01 18 18.99 Exercises: 14.1 Using the programs defined in Lesson 13, experiment with the following expressions: 5.2 ": d=. %: i.12 5.2 ":,.d fc=. 5.2&":@,.á fc d 20 (fc@h3 ,. h5) d 20 (fc@h3 ,. '|'&,.@h5) d plot=. fc@h3,.'|'&,.@h5 20 plot d 15: PARTITIONS The function sum=. +/ applies to an entire list argument; to compute partial sums or subtotals, it is necessary to apply it to each prefix of the argument. For example: a=. 1 2 3 4 5 6 sum=. +/ sum a sum\ a 21 1 3 6 10 15 21 The symbol \ denotes the prefix adverb, which applies its argument (in this case sum) to each prefix of the eventual argument. The adverb \. applies similarly to suffixes: sum\. a 21 20 18 15 11 6 The monad < simply boxes its arguments, and the verbs <\ and <\. therefore show the effects of partitions with great clarity. For example: <1 2 3 õıııııÀ ş1 2 3ş Áıııııã (<1),(<1 2),(<1 2 3) õıÃıııÃıııııÀ ş1ş1 2ş1 2 3ş ÁıÂıııÂıııııã <\ a õıÃıııÃıııııÃıııııııÃıııııııııÃıııııııııııÀ ş1ş1 2ş1 2 3ş1 2 3 4ş1 2 3 4 5ş1 2 3 4 5 6ş ÁıÂıııÂıııııÂıııııııÂıııııııııÂıııııııııııã <\. a õıııııııııııÃıııııııııÃıııııııÃıııııÃıııÃıÀ ş1 2 3 4 5 6ş2 3 4 5 6ş3 4 5 6ş4 5 6ş5 6ş6ş ÁıııııııııııÂıııııııııÂıııııııÂıııııÂıııÂıã The oblique adverb /. partitions a table along diagonal lines. Thus: ]t=.1 2 1 */ 1 3 3 1 sum/. t 1 3 3 1 1 5 10 10 5 1 2 6 6 2 10 #. sum/. t 1 3 3 1 161051 121*1331 words p Nobly , nobly , Cape St. Vincent Exercises: 17.1 Choose sentences such as pp=.+//.@(*/) from earlier exercises, enclose them in quotes, and observe the effects of word-formation (;:) upon them. 18: NAMES AND DISPLAYS In addition to the normal names used thus far, there are three further classes: 1) $: is used for self-reference, allowing a verb to be defined recursively without necessarily assigning a name to it; as illustrated in Lesson 23. 2) The names x. and y. are used in explicit definition, discussed in Lesson 19. They denote the arguments used in explicit definition. 3) A name that ends with an underbar ( _ ) is a locative. Names used in a locale F can be referred to in another locale G by using the suffix F in a locative name of the form pqr_F_ , thus avoiding conflict with otherwise identical names in the locale G. See Section H of Part II for further details. The form of the display invoked by entering a name alone is established by 9!:3, as described in the appendix. For example: mean=. +/ % # 9!:3 (4) NB. Tree form mean õı / ııı + ııÊı % Áı # 9!:3 (5) NB. Linear form mean +/ % # Multiple displays are also possible: 9!:3 (5 4 2) mean +/ % # õı / ııı + ııÊı % Áı # õıııııÃıÃıÀ şõıÃıÀş%ş#ş şş+ş/şş ş ş şÁıÂıãş ş ş ÁıııııÂıÂıã Exercises: 18.1 Experiment with the use of locatives. 19: EXPLICIT DEFINITION The sentences in the example: m=. '3 %: y.' d=. 'x.%: y.' that were executed in Lesson 17, can be used with the explicit definitionáconjunction : to produce a verb: script=. 0 : 0 3 %: y. : x.%: y. ) roots=. 3 : script roots 27 4096 3 16 4 roots 27 4096 2.27951 8 Adverbs and conjunctions may also be defined explicitly. For example: table=. 1 : 0 [ by ] over x./ Verbs by and over from Lesson 4 ) 2 3 5 ^ table 0 1 2 3 õıÃııııııııııÀ ş ş0 1 2 3ş ÈıÊıııııııııı³ ş2ş1 2 4 8ş ş3ş1 3 9 27ş ş5ş1 5 25 125ş ÁıÂııııııııııã Control structures may also be used. For example: f=. 3 : 0 factorial=. 3 : 0 if. y.<0 a=. 1 do. *:y. while. y.>1 else. %:y. do. a=. a*y. end. y.=. y.-1 ) end. a ) f"0 (_4 4) factorial"0 i. 6 16 2 1 1 2 6 24 120 Exercises: 19.1 Experiment with and display the functions roots=. 3 : script and 13 : script (which are equivalent). 19.2 See the discussion of control structures in the dictionary, and use them in defining further verbs. 19.3 Define the following adverb, and experiment with it in expressions such as ! d b=. i.7 d=. 1 : 0 +:@x. ) 19.4 Using the program pol from Exercise 15.2, perform the following experiments and comment on their results: g=. 11 7 5 3 2 & pol e=. 11 0 5 0 2 & pol o=. 0 7 0 3 0 & pol (g = e + o) b=. i.6 (e = e@-) b (o = -@o@-) b ANSWER: The function g is the sum of the functions e and o . Moreover, e is an even function (whose graph is reflected in the vertical axis), and o is an odd function (reflected in the origin). 19.5 Review Section G of Part III and use line texts to make further explicit definitions. 19.6 Enter the following explicit definition of the adverb even and perform the suggested experiments with it, using the functions defined in the preceding exercise: even=. 2 : 0 -:@(x.f. + x.f.@-) ) ge=. g even (e = ge) b (e = e even) b 19.7 Define an adverb odd and use it in the following experiments: exp=. ^ sinh=. 5&o. cosh=. 6&o. (sinh = exp odd) b (sinh = exp .: -) b The primitive odd adverb .: - (cosh = exp even) b (exp = exp even + exp odd) b 19.8 The following experiments involve complex numbers, and should perhaps be ignored by anyone unfamiliar with them: sin=. 1&o. cos=. 2&o. (cos = ^@j. even) b (j.@sin = ^@j. odd) b 20: TACIT EQUIVALENTS Verbs may be defined either explicitly or tacitly. In the case of a one-sentence explicit definition, of either a monadic or dyadic case, the corresponding tacit definition may be obtained by using the adverb 13 : as illustrated below. First enter 9!:3 ] 2 5 so as to obtain both the boxed and linear displays of verbs: s=. 0 : 0 (+/y.) % (#y.) ) mean=. 3 : s MEAN=. 13 : s mean MEAN õıÃıÃııııııııııııııÀ õıııııÃıÃıÀ ş3ş:ş(+/y.) % (#y.)ş şõıÃıÀş%ş#ş ÁıÂıÂııııııııııııııã şş+ş/şş ş ş 3 : '(+/y.) % (#y.)' şÁıÂıãş ş ş ÁıııııÂıÂıã +/ % # The explicit form of definition is likely to be more familiar to computer programmers than the tacit form. Translations provided by the adverb 13 : may therefore be helpful in learning tacit programming. An explicit definition of a conjunction may be translated similarly by the adverb 12á:. For example: t=. 0 : 0 y.^:_1 @ x.&y. ) under=. 2 : t times=. + under ^. 3 times 4 12 3 + (u=. 12 : t) ^. 4 12 u õıııııııııııııııııÃıÃııÀ şõııııııııııÃıÃııÀş&ş].ş şşõııÃııÃııÀş@ş[.şş ş ş şşş].ş^:ş_1şş ş şş ş ş şşÁııÂııÂııãş ş şş ş ş şÁııııııııııÂıÂııãş ş ş ÁıııııııııııııııııÂıÂııã ]. ^: _1 @ [. & ]. Exercises: 20.1 Use the display of the tacit definition of MEAN to define an equivalent function called M. ANSWER: M=. +/ % # 21: RANK The shape ($), tally (#), and rank (#@$), of a noun are illustrated by the noun report, which may be construed as a report covering two years of four quarters of three months each: ]report=. i. 2 4 3 0 1 2 $report 3 4 5 2 4 3 6 7 8 #report 9 10 11 2 #@$report 12 13 14 3 15 16 17 18 19 20 21 22 23 The last k axes determine a k-cell of a noun; the 0-cells of report are the atoms (such as 4 and 14), the 1-cells are the three-element quarterly reports, and the two-cells (or major cells or items) are the two four-by-three yearly reports. The rank conjunction " is used in the phrase f"k to apply a function f to each of the k-cells of its argument. For example: ,report 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ,"2 report 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <@i. s=. 2 5 <@i."0 s õıııııııııÀ õıııÃıııııııııÀ ş0 1 2 3 4ş ş0 1ş0 1 2 3 4ş ş5 6 7 8 9ş ÁıııÂıııııııııã Áıııııııııã Both the left and right ranks of a dyad may be specified. Thus: i,"0 1 i=.0 1 2 i,"1 1 i 0 0 1 2 0 1 2 0 1 2 1 0 1 2 ,"1~i 2 0 1 2 0 1 2 0 1 2 The basic characteristics adverb b. is very useful in analyzing functions (or expressions that define them) with respect to their ranks. For example: # b. 0 +/\ b. 0 (+/\ % #) b. 0 _ 1 _ _ 0 _ _ 1 _ Exercises: 21.1 Observe the results of the following uses of the monads produced by the rank conjunction, and comment on them: a=. i. 3 4 5 <"0 a <"1 a <"2 a <"3 a < a <"_1 a <"_2 a mean=. +/ % # mean a mean"1 a mean"2 a ANSWER: <"k applies < to each cell of rank k, with <"(#$a) a being equivalent to c Open, reverse, and then box õıııııÃıııÃıııııÀ ş3 2 1ş5 4ş8 7 6ş ÁıııııÂıııÂıııııã Exercises: 28.1 Use the following as exercises in reading and writing. Try using arguments such as a=. 2 3 5 7 and b=. 1 2 3 4 and c=. <@i."0 i. 3 4 : f=. +&.^. Multiplication by addition of natural logs g=. +&.(10&^.) Multiplication using base-10 logs h=. *&.^ Addition from multiplication i=. |.&.> Reverse each box j=. +/&.> Sum each box k=. +/&> Sum each box and leave open 29: IDENTITY FUNCTIONS The monads 0&+ and %&1 are identity functions, and 0 and 1 are said to be identity elements of the dyads + and % respectively. Insertion on an empty list yields the identity element of the dyad inserted. For example: +/ i.0 +/'' +/0{. 2 3 5 0 0 0 */i.0 */'' */0{. 2 3 5 1 1 1 These results are useful in partitioning lists; they ensure that certain obvious relations continue to hold even when one of the partitions is empty. For example: +/ a=. 2 3 5 7 11 28 (+/4{.a)+(+/4}.a) 28 (+/0{.a)+(+/0}.a) 28 */a 2310 (*/4{.a)*(*/4}.a) 2310 (*/0{.a)*(*/0}.a) 2310 The identity functions and other basic characteristics of functions (such as rank) are given by the adverb b. . For example: ^ b. _1 NB. Inverse ^. ^ b. 0 NB. Ranks _ 0 0 ^ b. 1 NB. Identity function $&1@(}.@$) Exercises: 29.1 Predict and test the results of the following expressions: */'' <./'' >./'' >./0 4 4 $ 0 +/ . */ 0 4 4 $ 0 +&.^./ 29.2 Experiment with the dyad {@; and give the term used to describe it in mathematics. ANSWER: Cartesian product 29.3 Test the assertion that the monads(%:@~. +/ . * =) and %:are equivalent, and state the utility of the former when applied to a list such as 1 4 1 4 2 that has repeated elements. ANSWER: The function %: (which could be a function costly to execute) is applied only to the distinct elements of the argument (as selected by the nub function ~.) 29.4 Comment on the following experiments before reading the comments on the right: a=. 2 3 5 [ b=. 1 2 4 a (f=. *:@+) b Square of sum a (g=. +&*: + +:@*) b Sum of squares plus double product a (f=g) b Expression of the identity of the functions a (f-:g) b f and g in a tautology (whose result is taut=. f-:g always true; that is, 1). 29.5 A phrase such as f-:g may be a tautology for the dyadic case only, for the monadic case only, or for both. Use the following tautologies as reading and writing exercises, including statements of applicability (Dyad only, etc.): t1=. >: -: > +. = (Dyad only) The primitive >: is identical to greater than or equal t2=. <. -: -@>.&- (Both) Lesser-of is neg on greater-of on neg; Floor is neg on ceiling on neg t3=. <. -: >.&.- Same as t2 but uses under t4=. *:@>: -: *: + +: + 1: (Monad) Square of a+1 is square of a plus twice a plus 1 t5=.*:@>:-:#.&1 2 1"0 Same as t4 using polynomial t6=. ^&3@>:-:#.&1 3 3 1"0 Like t5 for cube bc=. i.@>: ! ] Binomial coefficients t7=.(>:@]^[)-:(]#.bc@[)"0 Like t6 with k&t7 for kth power s=. 1&o. [. c=. 2&o. Sine and Cosine t8=.s@+-:(s@[*c@])+(c@[*s@]) (Dyad) Addition and Subtraction t9=.s@--:(s@[*c@])-(c@[*s@]) Formulas for sine det=. -/ . * Determinant perm=. +/ . * Permanent sct=. 1 2&o."0@(,"0) Sine and cosine tables t10=. s@- -: det@sct Same as t9 but using the determinant of the sin and cos table t11=. s@+ -: perm@sct Like t8 using the permanent S=. 5&o. [. C=. 6&o. Hyperbolic sine and cosine SCT=. 5 6&o."0@(,"0) Sinh and Cosh table t12=. S@+ -: perm@SCT Addition theorem for sinh SINH=. ^ .: - Odd part of exponential COSH=. ^ .. - Even part of exponential t13=. SINH -: S Sinh is odd part of exponential t14=. COSH -: 6&o. Cosh is the even part of exponential sine=. ^&.j. .: - Sine is the odd part of exponential t15=. sine -: s under multiplication by 0j1 29.6 Comment on the following expressions before reading the comments on the right: g=. + > >. Test if sum exceeds maximum 5 g 2 True for positive arguments 5 g _2 _1 0 1 2 but not true in general f=. *.&(0&<) Test if both arguments exceed 0 theorem=. f <: g The truth value of the result of f does not exceed that of g. This may also be stated as If f (is true) then g (is true) or as f implies g 5 theorem _2 _1 0 1 2 30: SECONDARIES It is convenient to supplement the primitives or primaries provided in a language by secondaries whose names belong to an easily recognized class. The following examples use names beginning with a capital letter: Ad=. ["_ 0:}-@>:@$@]{.] Append diagonal scalar Ai=. >:@i. Augmented integers Area=. [: Det ] ,. %@!@#"1 Area (Vol) try Area tet=.0,=i.3 Bc=. i. !/ i. Binomial coefficients Bca=. %.@Bc Binomial coeffs (alternating) By=. ' '&;@,.@[ ,. ] By (format) Cpa=. ]%.i.@#@]^/Ei@[ Coeffs of poly approx CPA=. (@])%.i.@#@]^/Ei@[ Coeffs of poly approx (adverb) Det=. -/ . * Determinant Dpc=. 1: }. ] * i.@# Differentiate poly coeffs D1=. ("0)(D.1) Derivative (scalar, first) Ei=. i.@(+*+0&=) Extended integers Epc=. Bc@# X ] Expand poly coeffs Ipc=. 0: , ] % Ai@# Integrate poly coeffs Inv=. ^:_1 Inverse Id=. =@i. Identity matrix Mat=. ] -: /:~ Monotone ascending test Mdt=. ] -: \:~ Monotone descending test Mrg=. +&$ {. ,@(|:@,:) Merge Over=. ({.;}.)@":@, Over (format) Pad=. 2 :'x.%.]^/Ei@(y."_)' Polynomial approx of degree Pp=. +//.@(*/) Polynomial coeffs product Si=. (Ei@+: - |) : (-/ i.) Symmetric and subsiding int Span=. 2 : 'y."_ x.\ ]' Span of apply of left arg S1=. |:@|@(^!._1/~%.^/~)@i. Stirling numbers (1st kind) S2=. |:@ (^/~%.^!._1/~)@i. Stirling numbers (2nd kind) Ta=. 1 : '[By]Over x./' Table adverb Thr=. ] * 0.1&^@[ <: |@] Threshold for non-zero Tile=. $@]{.[$~$@]+2:|1:+$@] Tile (try 0 1 Tile i. 2 3 4) X=. +/ . * Times (matrix product) XA=. -/ . * Times (alternating) Exercises: 30.1 Enter the definitions of the secondaries listed in Lesson 30 (or at least those used in these exercises), and then enter the following expressions: (Ai 2 3);(Ai 2 _3);(Ei 2 3);(Ei 2 _3) (i.;i.@-;Ai;Ai@-;Ei;Ei@-) 4 (Si 4);(7 4 Si 4) +Ta~@i. 4 (S1;S2) 7 (];X/;%/;%./;(%./%{.)) y=. (Bc ,: Bca) 5 (0 1&Cb;1 _1&Cb) i. 2 3 4 30.2 Perform further experiments with the secondaries of Lesson 30. SAMPLE TOPICS This section provides examples of the use of J in various topics; it is designed to be used in conjunction with the dictionary and at the keyboard of a J system. It is also designed to be used inductively, as follows: * Read one or two sentences and their results (which begin at the left margin), and attempt to state clearly in English what each sentence does. * Enter similar sentences to test the validity of your statements. * Consult the dictionary to confirm your understanding of the meaning of primitives such as i. (used both with one argument and with two). Use the Vocabulary at the end of the book as an index to pages in the dictionary. * Enter partsáof a complex sentence, such as i. 28 and j+/i.28 in the case of (j+/i.28){a. used on the following page. SPELLING phr=.'index=.a.i.''aA''' ;:phr õıııııÃııÃııÃııÃııııÀ şindexş=.şa.şi.ş'aA'ş ÁıııııÂııÂııÂııÂııııã $ ;:phr 5 >;:phr index =. a. i. 'aA' (do=. ".) phr 97 65 do 'abc =. 3 1 4 2' 3 1 4 2 abc 3 1 4 2 ALPHABET and NUMBERS $ a. ] j=. a. i. 'aA' 256 97 65 j +/ i. 8 97 98 99 100 101 102 103 104 65 66 67 68 69 70 71 72 (j+/i.28){a. "Non-printing" and abcdefghijklmnopqrstuvwxyz{| control characters ABCDEFGHIJKLMNOPQRSTUVWXYZ[\ make odd displays, õııııııııııııııııııııııııııııııııÀ but spaces are sub- ş ş stituted for them in ş !"#$%&'()*+,-./0123456789:;<=>?ş displays of boxed ş@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ş arrays. ş`abcdefghijklmnopqrstuvwxyz{|}~ ş ş ş ş ş ş ş ş ş Áııııııııııııııııııııııııııııııııã 1 2 3{ 8 32$a. The major alphabet !"#$%&'()*+,-./0123456789:;<=>? @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ `abcdefghijklmnopqrstuvwxyz{|}~ á i. 2 5 Table of integers 0 1 2 3 4 5 6 7 8 9 r=. 0j1 _1 0j_1 1 Square roots of plus and minus 1 + r (Complex) conjugates 0j_1 _1 0j1 1 r * +r 1 1 1 1 r */ r Multiplication table of roots of unity _1 0j_1 1 0j1 0j_1 1 0j1 _1 1 0j1 _1 0j_1 0j1 _1 0j_1 1 GRAMMAR fahrenheit =. 50 (fahrenheit - 32) * 5%9 10 prices =. 3 1 4 2 orders =. 2 0 2 1 orders * prices 6 0 8 2 +/ orders * prices 16 +/ \ 1 2 3 4 5 1 3 6 10 15 2 3 * / 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 (cube=. ^&3) i. 9 0 1 8 27 64 125 216 343 512 PARTS OF SPEECH 50 fahrenheit Nouns/Pronouns + - * % cube Proverbs / \ Adverbs & Conjunction =. Copula ( ) Punctuation FUNCTION TABLES Just as the behaviour of addition is made clear by addition tablesáin elementary school, so the behaviour of other verbs (or functions) can be made clear by function tables. The next few pages show how to make function tables, and how to use the utility functions over and by to border them with their arguments to make them easier to interpret. Study the tables shown, and make tables for other functions (such as < <. and %) suggested by the Vocabulary. TABLES n=. 0 1 2 n +/ n Addition table 0 1 2 1 2 3 2 3 4 */ ~ n Times table 0 0 0 0 1 2 0 2 4 ^/ ~ i. 4 Power table 1 0 0 0 1 1 1 1 1 2 4 8 1 3 9 27 +./~ 0 1 Or table 0 1 1 1 BORDERING A TABLE over=. ({.;}.)@":@, Utilityáfunctions, intended for use by=. ' '&;@,.@[,.] rather than for immediate study primes=. 2 3 5 [ i=. 0 1 2 3 4 primes by i over primes */ i õıÃııııııııııııÀ ş ş0 1 2 3 4ş ÈıÊıııııııııııı³ ş2ş0 2 4 6 8ş ş3ş0 3 6 9 12ş ş5ş0 5 10 15 20ş ÁıÂııııııııııııã tba=. 1 : '[ by ] over x./' primes * tba i NB. Table adverb õıÃııııııııııııÀ ş ş0 1 2 3 4ş ÈıÊıııııııııııı³ ş2ş0 2 4 6 8ş ş3ş0 3 6 9 12ş ş5ş0 5 10 15 20ş ÁıÂııııııııııııã 7 11 ^ tba i õııÃıııııııııııııııııııÀ ş ş0 1 2 3 4ş ÈııÊııııııııııııııııııı³ ş 7ş1 7 49 343 2401ş ş11ş1 11 121 1331 14641ş ÁııÂıııııııııııııııııııã TABLES (Letter Frequency) text=. ' i sing of olaf glad and big' alph=. ' abcdefghijklmnopqrstuvwxyz' 10{.alph=/text 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 '01'{~10{.alph=/text 1010000100100001000010001000 0000000000000100001001000000 0000000000000000000000000100 0000000000000000000000000000 0000000000000000000100010000 0000000000000000000000000000 0000000001000010000000000000 0000001000000000100000000001 0000000000000000000000000000 0100100000000000000000000010 ]LF=. 2 13 $ +/"1 alph =/ text Letter frequency table 7 3 1 0 2 0 2 3 0 3 0 0 2 0 2 2 0 0 0 1 0 0 0 0 0 0 +/+/LF 28 $text 28 TABLES div=. 0=rem=. i |/i=. i.7 Divisibility and remainder tables (,.i) ; rem ; div õıÃıııııııııııııÃıııııııııııııÀ ş0ş0 1 2 3 4 5 6ş1 0 0 0 0 0 0ş ş1ş0 0 0 0 0 0 0ş1 1 1 1 1 1 1ş ş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ş ÁııııııııııÂııııııııÂııııııÂııııÂııã :>./,arcs) CM arcs 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 1 1 1 0 1 0 (+/cm);(+/"1 cm); (+/+/cm);(#arcs);(#~.arcs) õıııııııııııııııÃıııııııııııııııÃııÃııÃııÀ ş3 1 4 4 1 1 2 3ş0 2 3 2 2 4 1 5ş19ş22ş19ş ÁıııııııııııııııÂıııııııııııııııÂııÂııÂııã The foregoing results are the in, out, and total degrees; followed by the number of arcs, and the number of distinct arcs. A boolean vector b may be used to represent the nodes b#nodes, and the inner product bá+./ . *. cm gives the same representation of the nodes reachable from them. The immediate family (which includes the original points themselves) is therefore given by the function imfam : imfam=. [ +. +./ . *. (b=. 1 0 0 0 0 0 0 1) imfam cm 1 0 1 1 1 0 1 1 Just as b imfam cm produces the immediate family of b, so does the phrase cmáimfam cm produce the immediate families of each of the rows of cm. We will, however, use a new sparser connection matrix that will be more instructive, and will use powers of imfam to produce families of further generations, including an infinite power to give the closure of the connection matrix; that is, the connection matrix for all points reachable by a path of any length: cm=. (i. =/ <:@i.) 8 <"2 cm imfam^:0 1 2 _ cm õıııııııııııııııÃıııııııııııııııÃıııııııııııııııÃıııııııııııııııÀ ş0 1 0 0 0 0 0 0ş0 1 1 0 0 0 0 0ş0 1 1 1 0 0 0 0ş0 1 1 1 1 1 1 1ş ş0 0 1 0 0 0 0 0ş0 0 1 1 0 0 0 0ş0 0 1 1 1 0 0 0ş0 0 1 1 1 1 1 1ş ş0 0 0 1 0 0 0 0ş0 0 0 1 1 0 0 0ş0 0 0 1 1 1 0 0ş0 0 0 1 1 1 1 1ş ş0 0 0 0 1 0 0 0ş0 0 0 0 1 1 0 0ş0 0 0 0 1 1 1 0ş0 0 0 0 1 1 1 1ş ş0 0 0 0 0 1 0 0ş0 0 0 0 0 1 1 0ş0 0 0 0 0 1 1 1ş0 0 0 0 0 1 1 1ş ş0 0 0 0 0 0 1 0ş0 0 0 0 0 0 1 1ş0 0 0 0 0 0 1 1ş0 0 0 0 0 0 1 1ş ş0 0 0 0 0 0 0 1ş0 0 0 0 0 0 0 1ş0 0 0 0 0 0 0 1ş0 0 0 0 0 0 0 1ş ş0 0 0 0 0 0 0 0ş0 0 0 0 0 0 0 0ş0 0 0 0 0 0 0 0ş0 0 0 0 0 0 0 0ş ÁıııııııııııııııÂıııııııııııııııÂıııııııııııııııÂıııııııııııııııã The closure of cm can therefore be expressed as cm imfam^:_ cm, and a monadic closure function can be defined as follows: closure=. imfam^:_ ~ closure cm 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 The complete definition of the closure function may now be displayed as follows: closure f. ([ +. +./ .*.)^:_~ DISTANCE The street distance between two points will be defined as the sum of the magnitudes of the difference of their coordinates along each axis. Thus: d=. +/@|@:-"1 p=. 3 5 1 [ q=. 7 4 0 p d q 6 table=. #: i. 2^3 (]; d/~) table Table and distances between each pair of points in it õıııııÃıııııııııııııııÀ ş0 0 0ş0 1 1 2 1 2 2 3ş ş0 0 1ş1 0 2 1 2 1 3 2ş ş0 1 0ş1 2 0 1 2 3 1 2ş ş0 1 1ş2 1 1 0 3 2 2 1ş ş1 0 0ş1 2 2 3 0 1 1 2ş ş1 0 1ş2 1 3 2 1 0 2 1ş ş1 1 0ş2 3 1 2 1 2 0 1ş ş1 1 1ş3 2 2 1 2 1 1 0ş ÁıııııÂıııııııııııııııã g=. [ * [ = d/~@] (];(d/~);(1&g);(2&g)) table õıııııÃıııııııııııııııÃıııııııııııııııÃıııııııııııııııÀ ş0 0 0ş0 1 1 2 1 2 2 3ş0 1 1 0 1 0 0 0ş0 0 0 2 0 2 2 0ş ş0 0 1ş1 0 2 1 2 1 3 2ş1 0 0 1 0 1 0 0ş0 0 2 0 2 0 0 2ş ş0 1 0ş1 2 0 1 2 3 1 2ş1 0 0 1 0 0 1 0ş0 2 0 0 2 0 0 2ş ş0 1 1ş2 1 1 0 3 2 2 1ş0 1 1 0 0 0 0 1ş2 0 0 0 0 2 2 0ş ş1 0 0ş1 2 2 3 0 1 1 2ş1 0 0 0 0 1 1 0ş0 2 2 0 0 0 0 2ş ş1 0 1ş2 1 3 2 1 0 2 1ş0 1 0 0 1 0 0 1ş2 0 0 2 0 0 2 0ş ş1 1 0ş2 3 1 2 1 2 0 1ş0 0 1 0 1 0 0 1ş2 0 0 2 0 2 0 0ş ş1 1 1ş3 2 2 1 2 1 1 0ş0 0 0 1 0 1 1 0ş0 2 2 0 2 0 0 0ş ÁıııııÂıııııııııııııııÂıııııııııııııııÂıııııııııııııııã {&' .+*' &.> (];(d/~);(1&g);(2&g);(3&g)) table õıııÃııııııııÃııııııııÃııııııııÃııııııııÀ ş ş ..+.++*ş .. . ş + ++ ş *ş ş .ş. +.+.*+ş. . . ş + + +ş * ş ş . ş.+ .+*.+ş. . . ş + + +ş * ş ş ..ş+.. *++.ş .. .ş+ ++ ş * ş ş. ş.++* ..+ş. .. ş ++ +ş * ş ş. .ş+.*+. +.ş . . .ş+ + + ş * ş ş.. ş+*.+.+ .ş . . .ş+ + + ş * ş ş...ş*++.+.. ş . .. ş ++ + ş* ş ÁıııÂııııııııÂııııııııÂııııııııÂııııııııã POLYNOMIALS The monadic function M=. 3: * ] ^ 2: is a multiple of an integral power of its argument, and is called a monomial; and a sum of monomials such as SM=.á(3:*]^2:)+(2.5"_*]^4:)+(_5"_*]^0:) is a polynomial. Any polynomial can be expressed in the standard form c&p, where c is a suitable list of coefficients, and where p=. +/@([*]^i.@#@[)"1 0. For example: SM=.á(3:*]^2:)+(2.5"_*]^4:)+(_5"_*]^0:) p=. +/@([*]^i.@#@[)"1 0 c=. _5 0 3 0 2.5 x=. _2 _1 0 1 2 (SM x),(c p x),:(c&p x) 47 0.5 _5 0.5 47 47 0.5 _5 0.5 47 47 0.5 _5 0.5 47 The primitive p. is equivalent to the function p defined above, and will be used hereafter. The polynomial c&p.is very important for a number of reasons, including: 1. It applies to any numeric argument, real or complex (and the parameter c may also be complex). 2. It can be used to approximate a wide range of functions. 3. It is closed under a number of operations; that is, the sum, difference, product, the composition @, the derivative, and the integral of polynomials are themselves polynomials. 4. The coefficients of the results of each case listed in 3 are easily expressed. For example, if #c equals #d, then c&p. + d&p. is equal to (c+d)&p. . More generally, it is equal to (+/c,:d)&p. . Thus: ps=. +/@,: Polynomial sum pd=. -/@,: Polynomial difference pp=. +//.@(*/) Polynomial product D=. ("0)(D.1) Scalar (rank 0) first derivative pD=. 1: }. ] * i.@# Polynomial derivative pI=. 0: , ] % 1: + i.@# Polynomial integral For example: c=. 1 2 1 [ d=. 1 3 3 1 x=. 2 1 0 _1 _2 ,.&.>((c pp d);((c pp d)&p. x);((c&p.*d&p.)x)) õııÃıııÃıııÀ ş 1ş243ş243ş ş 5ş 32ş 32ş ş10ş 1ş 1ş ş10ş 0ş 0ş ş 5ş _1ş _1ş ş 1ş ş ş ÁııÂıııÂıııã ,.&.>((d&p.D x);(pD d);((pD d)&p. x);(pI d);(pD pI d)) õııÃıÃııÃııııÃıÀ ş27ş3ş27ş 0ş1ş ş12ş6ş12ş 1ş3ş ş 3ş3ş 3ş 1.5ş3ş ş 0ş ş 0ş 1ş1ş ş 3ş ş 3ş0.25ş ş ÁııÂıÂııÂııııÂıã ]e=. c(ps pp pd)d 0 _2 _9 _16 _14 _6 _1 e&p. x _648 _48 0 0 0 ((c&p.+d&p.)*(c&p.-d&p.)) x _648 _48 0 0 0 f=. c&p.(+*-) d&p. f x _648 _48 0 0 0 ]g=. pD c pp d 5 20 30 20 5 g&p. x 405 80 5 0 5 (c&p.*d&p.) D x 405 80 5 0 5 POLYNOMIALS In terms of roots The product */y-r is called a polynomial in terms of the roots r, because it can also be expressed as a polynomial applied to the argument y, and because r is the list of rootsáor zeros of the resulting function. For example: y=. 7 [ r=. 2 3 5 [ x=. 7 6 5 4 3 2 */y-r 40 pp=. +//.@(*/) c=. pp/monomials=. (- ,. 1:) r cfr=. [: pp/ - ,. 1: Coefficients from roots pir=. */@(]-[)"1 0 Polynomial in terms of roots ,.&.>(r;monomials;c;(cfr r);(c&p. y);(r pir x)) õıÃııııÃıııÃıııÃııÃııÀ ş2ş_2 1ş_30ş_30ş40ş40ş ş3ş_3 1ş 31ş 31ş ş12ş ş5ş_5 1ş_10ş_10ş ş 0ş ş ş ş 1ş 1ş ş_2ş ş ş ş ş ş ş 0ş ş ş ş ş ş ş 0ş ÁıÂııııÂıııÂıııÂııÂııã Since the last (highest order) coefficient produced by cfr is necessarily 1, the function pir cannot produce a general polynomial, but it can if provided with a multiplier. We therefore re-define cfr and pir to apply to a boxed list of multiplier and roots as follows: CFR=. (* cfr)&>/ PIR=. CFR@[ p. ] CFR 3;r _90 93 _30 3 (3;r) PIR x 120 36 0 _6 0 0 We now illustrate the use of a polynomial in approximation: ]ce=. ^ t. i. 7 First seven terms of Taylor series for exponential 1 1 0.5 0.166667 0.0416667 0.00833333 0.00138889 (^ - ce&p.) _1 _0.5 0 0.5 1 Comparison with exponential _0.000176114 _1.45834e_6 0 1.65264e_6 0.000226273 pD ce The exponential function is equal to its own derivative 1 1 0.5 0.166667 0.0416667 0.00833333 POLYNOMIALS Roots from coefficients (Newtons Method) Because the polynomials (m;r)&PIR and (c=.CFR (m;r))&p.are identical, the parameters m;r and c are said to be different representations of the same function. Each representation has its own useful properties. For example, addition of polynomials is easy in the coefficient representation but difficult in the root representation; the identification of the zeros of the function is difficult in the coefficient representation but trivial in the root representation. It is therefore useful to have functions that transform each representation to the other. CFR serves for one direction; the inverse problem is approached by methods of successive approximation. For any function f, the difference (f r)-(f a) for nearby points r and a is approximately equal to the difference r-a multiplied by the slope of the tangent to the graph of f at the point a,f a, that is, the derivative of f at a. Conversely, the difference r-a is approximated by ((f r)-(f a))%f D a, and r is approximated by a+((f r)-(f a))%f D a. If f is the polynomial c&p. and r is one of its roots, then f r is zero, and if a is an approximation to r, the expression for r reduces to a-(f a)%f D a. This may provide a better approximation to r, and is embodied in Newtons method, defined as an adverb, and illustrated as follows: newton=. 1 : 0 ] - x. % x.D ) f=. (c=. 12 _10 2)&p. f a=. 2.4 f newton a _0.48 1.2 f newton ^:0 1 2 3 4 _ a f 2 2.4 1.2 1.75385 1.9594 1.99848 2 0 ]a=. (^ - 4:) newton ^: 0 1 2 3 _ a=. 1 1 1.47152 1.38982 1.3863 1.38629 ^ {: a 4 For the particular case of polynomials, we may define an adverb that applies to coefficients and uses the polynomial derivative pD instead of the general derivative D: pD= .1: }. ] * i.@# NEWTON=. 1 : 0 ] - x.&p. % (pD x.)&p. ) c NEWTON ^:0 1 2 3 4 _ a=. 2.4 2.4 1.2 1.75385 1.9594 1.99848 2 POLYNOMIALS Roots from coefficients (Kerners Method) Newton's method applies only to one root at a time and usually requires a rather good starting approximation. Kerners method is a generalization that gives all the roots, starting from a list a and dividing each element of the residual f a by the derivative with respect to the corresponding root. The method applies only to a polynomial whose highest order coefficient is 1, and we first normalize the coefficients by dividing by the last, yielding a polynomial having the same roots. Moreover, the method will converge to complex roots only if at least one of the initial approximations is complex. We will use the Taylor series approximation to the exponential function, because the corresponding polynomial has complex roots: ]d=. ^ t. i.6 1 1 0.5 0.166667 0.0416667 0.00833333 ]c=. (norm=. % {:) d 120 120 60 20 5 1 +. a=. (init=. r.@}.@i.@#) c |a 0.540302 0.841471 1 1 1 1 1 _0.416147 0.909297 _0.989992 0.14112 _0.653644 _0.756802 0.283662 _0.958924 deriv=. [: */ 0&=@{.}@(-/~ ,: 1:) kerner=. 1 : 0 ] - x.&p. % deriv@] ) r=. c k ^:_ a +.(/:|) r _2.18061 _1.03444e_36 _1.6495 _1.69393 _1.6495 1.69393 0.239806 _3.12834 0.239806 3.12834 >./|c p. r 8.98756e_17 Newton's method may also be used for for a complex root: +. d NEWTON ^:0 1 2 3 _ a=. 1j1 1 1 0.0166065 0.99639 _0.990523 0.992532 _1.95338 1.10685 _1.6495 1.69393 POLYNOMIALS Stopes The expression */ x + s * i. n is often called a factorial function but, to avoid confusion with the function !, we will call it a stope; the factors occurring in its definition differ by steps of size s, like the steps in a mine stope. Stopes are useful in actuarial work and in the difference calculus. The stope is a variant of the power ^ (being equivalent for the case s=.0), and is provided by the fit conjunction in the variant ^!.s. For example: x=. 7 [ n=. 5 [ s=. _1 x + s * i. n 7 6 5 4 3 (*/x + s * i. n);(x ^!.s n);(x ^!.0 n);(x^n) õııııÃııııÃıııııÃıııııÀ ş2520ş2520ş16807ş16807ş ÁııııÂııııÂıııııÂıııııã The expression +/c * x^!.s i.#c is called a stope polynomial, just as +/c*x^i.#c may be called a power polynomial. We define an adverb P that applies to any step size s to provide the corresponding stope polynomial: P=. 1 : '+/@([ * ] ^!. x. i.@#@[)"1 0' c=. 1 3 3 1 [ d=. 1 7 6 1 [ x=. 0 1 2 3 4 (c p. x);(c 0 P x);(d _1 P x);(d p.!._1 x) õıııııııııııııÃıııııııııııııÃıııııııııııııÃıııııııııııııÀ ş1 8 27 64 125ş1 8 27 64 125ş1 8 27 64 125ş1 8 27 64 125ş ÁıııııııııııııÂıııııııııııııÂıııııııııııııÂıııııııııııııã As illustrated above, stope polynomials are (for a suitable choice of coefficients) equivalent to ordinary polynomials. Moreover, the transformations between them are provided by a matrix product as follows VM=. 1 : '[ ^!.x./ i.@#@]' TO=. 2 : '(x. VM %. y. VM)~ @i.@#' (0 TO _1 c) +/ . * c 1 7 6 1 The matrices 0 TO _1 and _1 TO 0 are mutually inverse, and are simply related to Stirling numbers: (0 TO _1 i.5);(_1 TO 0 i.5) õıııııııııÃııııııııııııÀ ş1 0 0 0 0ş1 0 0 0 0ş ş0 1 1 1 1ş0 1 _1 2 _6ş ş0 0 1 3 7ş0 0 1 _3 11ş ş0 0 0 1 6ş0 0 0 1 _6ş ş0 0 0 0 1ş0 0 0 0 1ş ÁıııııııııÂııııııııııııã DICTIONARY J is a dialect of APL, a formal imperative language. Because it is imperative, a sentence in J may also be called an instruction, and may be executed to produce a result. Because it is formal and unambiguous it can be executed mechanically by a computer, and is therefore called a programming language. Because it shares the analytic properties of mathematical notation, it is also called an analytic language. APL originated in an attempt to provide consistent notation for the teaching and analysis of topics related to the application of computers, and developed through its use in a variety of topics, and its implementation in computer systems [1-5]. J is implemented in C (as detailed in Hui [6]), and is ported to a number of different host computer systems. The effect of the specific host is minimal, and communication with it is confined to the single foreign conjunctionádetailed in the Appendix. See Burke [7] for other host facilities such as Windows. The Introduction in this book provides guidance to beginners. References [8-10] use J in the exposition of various mathematical topics. I: ALPHABET and WORDS The alphabet is standard ASCII, comprising digits, letters (of the English alphabet), the underline (used in names and numbers), the (single) quote, and others (which include the space) to be referred to as graphics. Alternative spellings for the national use characters (which differ from country to country) appear on page 180. Numbers are denoted by digits, the underbar (for negative signs and for infinity and minus infinity when used alone or in pairs), the period (used for decimal points and necessarily preceded by one or more digits), the letter e (as in 2.4e3 to signify 2400 in exponential form), and the letter j to separate the real and imaginary parts of a complex number, as in 3e4j_0.56. Also see page 201. A numeric list or vector is denoted by a list of numbers separated by spaces. A list of ASCII characters is denoted by the list enclosed in single quotes, a pair of adjacent single quotes signifying the quote itself: 'can''t' is the five-character abbreviation of the six-character word 'cannot'. The ace a: denotes the boxed empty list <$0 . Names (used for pronouns and other surrogates, and assigned referents by the copula, as in prices=. 4.5 12) begin with a letter and may continue with letters, underlines, and digits. A name that ends with an underline is a locative, as discussed in Section II.H. A primitive or primary may be denoted by any single graphic (such as + for plus) or by any graphic modified by one or more following inflections (a period or colon), as in +. and +: for or and nor. A primary may also be an inflected name, as in e. and o. for membershipand pi times. A primary cannot be assigned a referent by a copula. II. GRAMMAR The following sentences illustrate the six parts of speech: fahrenheit=. 50 (fahrenheit-32)*5%9 10 prices=. 3 1 4 2 orders=. 2 0 2 1 orders * prices 6 0 8 2 PARTS of SPEECH +/orders*prices 16 50 fahrenheit Nouns/Pronouns +/\1 2 3 4 5 + - * % bump Verbs/Proverbs 1 3 6 10 15 / \ Adverbs bump=. 1&+ & Conjunction bump prices ( ) Punctuation 4 2 5 3 =. Copula Verbs act upon nouns to produce noun results; the nouns to which a particular verb applies are called its arguments. A verb may have two distinct (but usually related) meanings according to whether it is applied to one argument (to its right), or to two arguments (left and right). For example, 2%5 yields 0.4, and %5 yields 0.2. An adverb acts on a single noun or verb to its left. For example, +/ is a derived verb (which might be called plus over) that sums an argument list to which it is applied, and */ yields the product of a list. A conjunction applies to two arguments, either nouns or verbs. Punctuation is provided by parentheses that specify the sequence of execution as in elementary algebra. The word =. behaves like the copulas is and are in English, and is read as such, as in area is 3 times 4 for area=. 3*4. The name area thus assigned is a pronoun and, as in English, it plays the role of a noun. Similar remarks apply to names assigned to verbs, adverbs, and conjunctions. Entry of a name alone displays its value. Errors are discussed in Section I. A. NOUNS Nouns are classified in three independent ways: numeric or literal; open or boxed; arrays of various ranks. In particular, arrays of ranks 0, 1, and 2 areácalled atom, list, and table, or, in mathematics, scalar, vector, and matrix. Numbers and literals are represented as stated in Part I. Arrays. A single entity such as 2.3 or _2.3j5 or 'A' or '+' is called an atom. The verb denoted by comma chains its arguments to form a list whose shape (given by the verb $) is equal to the number of atoms combined. For example: $ date=. 1,7,7,6 4 word=. 's','a','w' |. word |. date was 6 7 7 1 The verb |. used above is called reverse. The phrase s$b produces an array of shape s from the list b. For example: (3,4) $ date,1,8,6,7,1,9,1,7 1 7 7 6 1 8 6 7 1 9 1 7 table=. 2 3$ word,'bat' table $table saw 2 3 bat The number of atoms in the shape of a noun is called its rank. Each position of the shape is called an axis of the array, and axes are referred to by indices 0, 1, 2, etc. For example, axis 0 of table has length 2 and axis 1 has length 3. The last k axes of an array b determine rank-k cells or k-cells of b. The rest of the shape vector is called the frame of b relative to the cells of rank k; if $c is 2á3á4á5, then c has the frame 2 3 relative to cells of rank 2, the frame 2á3á4á5 relative to 0-cells (atoms), and an empty frame relative to 4-cells. If: ] b=.2 3 4 $ 'abcdefghijklmnopqrstuvwx' abcd efgh ijkl mnop qrst uvwx then the list abcd is a 1-cell of b, and the letters are each 0-cells. A cell of rank one less than the rank of b is called an item of b; an atom has one item, itself. For example, the verb from (denoted by {) selects items from its right argument, as in: 0{b 1{b 0{0{b abcd mnop abcd efgh qrst ijkl uvwx 2 1{0{b 1{2{0{b 0{3 ijkl j 3 efgh Moreover, the verb grade (denoted by /:) provides indices to { that bring items to lexical order. Thus: g=. /: n=. 4 3$3 1 4 2 7 9 3 2 0 n g g{n 3 1 4 1 0 3 2 2 7 9 2 7 9 3 1 4 3 2 0 3 1 4 3 1 4 3 2 0 Negative numbers, as in _2-cell and _1-cell (an item), are also used to refer to cells whose frames are of the length indicated by the magnitude of the number. For example, the list abcd may be referred to either as a _2-cell or as a 1-cell of b. Open and Boxed. The nouns discussed thus far are called open, to distinguish them from boxed nouns produced by the verb box denoted by < . The result of box is an atom, and boxed nouns are displayed in boxes. Box allows one to treat any array (such as the list of letters that represent a word) as a single entity, or atom. Thus: words=.(<'I'),(<'was'),(<'it') letters=. 'I was it' $words $letters 3 8 |. words |. letters õııÃıııÃıÀ ti saw I şitşwasşIş ÁııÂıııÂıã 2 3$words,|.words õııÃıııÃııÀ şI şwasşitş ÈııÊıııÊıı³ şitşwasşI ş ÁııÂıııÂııã B. VERBS Monads and Dyads. Verbs have two definitions, one for the monadic case (one argument), and one for the dyadic case. The dyadic definition applies if the verb is preceded by a suitable left argument, that is, any noun that is not itself an argument of a conjunction; otherwise the monadic definition applies. The monadic case of a verb is also called a monad, and we speak of the monad % used in the phrase %4, and of the dyad % used in 3%4. Either or both cases may have empty domains. Ranks of Verbs. The notion of verb rank is closely related to that of noun rank: a verb of rank k applies to each of the k-cells of its argument. For example (using the array b from Section A): ,b abcdefghijklmnopqrstuvwx ,"2 b ,"_1 b abcdefghijkl abcdefghijkl mnopqrstuvwx mnopqrstuvwx Since the verb ravel (denoted by ,) applies to its entire argument, its rank is said to be unbounded. The rank conjunction " used in the phrase ,"2 produces a related verb of rank 2 that ravels each of the 2-cells to produce a result of shape 2 by 12. The shape of a result is the frame (relative to the cells to which the verb applies) catenated with the shape produced by applying the verb to the individual cells. Commonly these individual shapes agree, but if not, they are first brought to a common rank by adding leading unit axes to any of lower rank, and are then brought to a common shape by padding with an appropriate fill element: space for a character array, 0 for a numeric array, and a boxed empty list for a boxed array. For example: i."0 s=. 2 3 4 >'I';'was';'here' 0 1 0 0 I 0 1 2 0 was 0 1 2 3 here The dyadic case of a verb has two ranks, governing the left and right arguments. For example: p=. 'abc' q=. 3 5$'wake read lamp ' p,"0 1 q awake bread clamp Finally, each verb has three intrinsic ranks: monadic, left, and right. The definition of any verb need specify only its behaviour on cells of the intrinsic ranks, and the extension to arguments of higher rank occurs systematically. The ranks of a verb merely place upper limits on the ranks of the cells to which it applies, and its domain may include arguments of lower rank. For example, matrix inverse (%.) has monadic rank 2, but treats degenerate cases of vector and scalar arguments as one-column matrices. Agreement. In the phrase p v q, the arguments of v must agree in the sense that their frames (relative to the ranks of v) must be a prefix of the other, as in p,"0 1 q above, and in the following examples: p," 1 1 q 3 4 5*i. 3 4 abcwake 0 3 6 9 abcread 16 20 24 28 abclamp 40 45 50 55 (i.3 4)*3 4 5 0 3 6 9 16 20 24 28 40 45 50 55 If a frame contains 0, the verb is applied to a cell of fills. For example: ($ #"2 i. 1 0 3 4);($ 2 3 %"1 i. 0 2) õıııÃıııÀ ş1 0ş0 2ş ÁıııÂıııã ($ $"2 i. 1 0 3 4);($ 2 3 %/"1 i. 0 4) õıııııÃıııııÀ ş1 0 2ş0 2 4ş ÁıııııÂıııııã C. ADVERBS AND CONJUNCTIONS Unlike verbs, adverbs and conjunctions have fixed valence: an adverb is monadic (applying to a single argument to its left), and a conjunction is dyadic. Conjunctions and adverbs apply to noun or verb arguments; a conjunction may produce as many as four distinct classes of results. For example, u&v produces a composition of the verbs u and v; and ^&2 produces the square by bonding the power function with the right argument 2; and 2&^ produces the function 2-to-the-power. The conjunction & may therefore be referred to by different names for the different cases, or it may be referred to by the single term and (or with), which roughly covers all cases. D. COMPARATIVES The comparison x=y is treated like the everyday use of equality (that is, with a reasonable relative tolerance), yielding 1 if the difference x-y falls relatively close to zero. Tolerant comparison also applies to other relations and to floor and ceiling (<. and >.); a precise definition is given in Part III under equal (=). An arbitrary tolerance t can be specified by using the fit conjunction (!.), as in x =!.t y. E. PARSING & EXECUTION A sentence is evaluated by executing its phrases in a sequence determined by the parsing rules of the language. For example, in the sentence 10%3+2, the phrase 3+2 is evaluated first to obtain a result that is then used to divide 10. In summary: 1. Execution proceeds from right to left, except that when a right parenthesis is encountered, the segment enclosed by it and its matching left parenthesis is executed, and its result replaces the entire segment and its enclosing parentheses. 2. Adverbs and conjunctions are executed before verbs; the phrase ,"2-a is equivalent to (,"2)-a, not to ,"(2-a). Moreover, the left argument of an adverb or conjunction is the entire verb phrase that precedes it. Thus, in the phrase +/ . */b, the rightmost adverb / applies to the verb derived from the phrase +/ . *, not to the verb *. 3. A verb is applied dyadically if possible; that is, if preceded by a noun that is not itself the right argument of a conjunction. 4. Certain trains form verbs, adverbs, and conjunctions, as described in º F. 5. To ensure that these summary parsing rules agree with the precise parsing rules prescribed below, it may be necessary to parenthesize any adverbial or conjunctival phrase that produces anything other than a noun or verb. One important consequence of these rules is that in an unparenthesized expression the right argument of any verb is the result of the entire phrase to the right of it. The sentence 3*p%q^|r-5 can therefore be read from left to right: the overall result is 3 times the result of the remaining phrase, which is the quotient of p and the part following the %, and so on. Parsing proceeds by moving successive elements (or their values in the case of pronouns and other names) from the tail end of a queue (initially the original sentence prefixed by a left marker º) to the top of a stack, and eventually executing some eligible portion of the stack and replacing it by the result of the execution. For example, if a=. 1 2 3, then b=.+/2*a would be parsed and executed as follows: º b =. + / 2 * a º b =. + / 2 * 1 2 3 º b =. + / 2 * 1 2 3 º b =. + / 2 * 1 2 3 º b =. + / 2 * 1 2 3 º b =. + / 2 4 6 º b =. + / 2 4 6 º b =. + / 2 4 6 º b =. 12 º b =. 12 º 12 º 12 The foregoing illustrates two points: 1) Execution of the phrase 2á*á1á2á3 is deferred until the next element (the /) is transferred; had it been a conjunction, the 2 would have been its argument, and the monad * would have applied to 1 2 3; and 2) Whereas the value of the name a moves to the stack, the name b (because it precedes a copula) moves unchanged, and the pronoun b is assigned the value 12. The executions in the stack are confined to the first four elements only, and eligibility for execution is determined only by the class of each element (noun, verb, etc., an unassigned name being treated as a verb), as prescribed in the following parse table. The classes of the first four elements of the stack are compared with the first four columns of the table, and the first row that agrees in all four columns is selected. The bold italic elements in the row are then subjected to the action shown in the final column, and are replaced by its result. If no row is satisfied, the next element is transferred from the queue. EDGE VERB NOUN ANY Monad EDGE+AVN VERB VERB NOUN Monad EDGE+AVN NOUN VERB NOUN Dyad EDGE+AVN VERB+NOUN ADV ANY Adverb EDGE+AVN VERB+NOUN CONJ VERB+NOUN Conj EDGE+AVN VERB VERB VERB Trident EDGE CAVN CAVN CAVN Trident EDGE CAVN CAVN ANY Bident NAME+NOUN ASGN CAVN ANY Is LPAR CAVN RPAR ANY Punct Legend: AVN denotes ADV+VERB+NOUN CAVN denotes CONJ+ADV+VERB+NOUN EDGE denotes MARK+ASGN+LPAR F. TRAINS An isolated sequence, such as (+ */), which the normal parsing rules (other than the three labelled trident and bident) 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)*(5-3), 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 and fork are infinite. Trains may also produce adverbs and conjunctions, and trains of two and three elements are called bidents, and tridents, respectively; hooks and forks are special cases. Tree displays illustrate the choice of the names fork and trident: mean=. +/ % # conj=. ]. , [. tree=. 5!:4@< tree 'mean' õı / ııı + ııÊı % Áı # tree 'conj' õı ]. ııÊı , Áı [. The following tables define all possible tridents and bidents, using light italics to denote the optional left arguments of (ambivalent) verbs : N0 V1 N2 noun x V1 y V0 V1 V2 verb (x V0 y) V1 (x V2 y) V0 V1 C2 conj V0 V1 (x C2 y) A0 V1 V2 adv (x A0) V1 V2 C0 V1 V2 conj (x C0 y) V1 V2 C0 V1 C2 conj (x C0 y) V1 (x C2 y) A0 A1 V2 conj (x A0) (y A1) V2 A0 A1 A2 adv ((x A0) A1) A2 C0 A1 A2 conj ((x C0 y) A1) A2 N0 C1 N2 verb x (N0 C1 N2) y N0 C1 V2 verb x (N0 C1 V2) y N0 C1 A2 adv N0 C1 (x A2) N0 C1 C2 conj N0 C1 (x C2 y) V0 C1 N2 verb x (V0 C1 N2) y V0 C1 V2 verb x (V0 C1 V2) y V0 C1 A2 adv V0 C1 (x A2) V0 C1 C2 conj V0 C1 (x C2 y) A0 C1 N2 adv (x A0) C1 N2 A0 C1 V2 adv (x A0) C1 V2 A0 C1 A2 conj (x A0) C1 (y A2) A0 C1 C2 conj (x A0) C1 (x C2 y) C0 C1 N2 conj (x C0 y) C1 N2 C0 C1 V2 conj (x C0 y) C1 V2 C0 C1 A2 conj (x C0 y) C1 (y A2) C0 C1 C2 conj (x C0 y) C1 (x C2 y) N0 A1 verb x (N0 A1) y N0 C1 adv N0 C1 x V0 N1 noun V0 N1 V0 V1 verb x (or y) V0 V1 y V0 A1 verb x (V0 A1) y V0 C1 adv V0 C1 x A0 V1 adv (x A0) V1 A0 A1 adv (x A0) A1 A0 C1 adv (x A0) C1 x C0 N1 adv x C0 N1 C0 V1 adv x C0 V1 C0 A1 conj (x C0 y) A1 G. FRETS AND SCRIPTS Host systems commonly use the line-feed or carriage return characters 10{a. or 13{a. (or both together) as frets to mark divisions into individual lines. A character list provided with zero or more frets will be called a script. As detailed in the appendix, a script t may be filed and retrieved by expressions of the form t 1!:2 <'abc' and t=. 1!:1 <'abc', and may be executed by the expression 0!:11 <'abc'. Convenient entry of scripts is provided by the phrase 0 : 0; succeeding keystrokes are accepted as literal characters; the enter key that would normally terminate the entry is accepted as a fret; and the entry is terminated by a lone right parenthesis that is accepted as a final fret. For example: s=. 0 : 0 y.*%:y. : x.*!y. ) a. i. s The character with index 10 marks the end of each line 121 46 42 37 58 121 46 10 58 10 120 46 42 33 121 46 10 Boxed and table representations of a script s may be obtained as follows: ]b=. <;._2 s Cut on the final fret and exclude the frets õıııııııÃıÃııııııÀ şy.*%:y.ş:şx.*!y.ş ÁıııııııÂıÂııııııã ]t=. >b y.*%:y. : x.*!y. Any one of these representations r may be used as the right argument to the explicit definition conjunction to produce an adverb (1 : r), conjunction (2 : r), or verb (3 : r). The left arguments 11-13 produce equivalent results, but in tacit form if possible. For example: f=. 3 : s f 9 The colon in the script separates the monadic and dyadic cases 12 3 f 4 The x. and y. refer to the left and right arguments 72 The phrases a=. 1 : 0 and c=. 2 : 0 and v=. 3 : 0 provide direct entry of adverbs, conjunctions, and verbs. Files of scripts may define functions and other entities that can serve to supplement the primaries of J. They are commonly refered to as secondary or tertiary functions according to their relative generality. H. LOCATIVES The name abc_def_ is called a locative, and is said to refer to abc in locale def. For example: b=. 1 Rome=. 2 Rome_NewYork_=. 20 f_NewYork_=. 3 : '3*b=: Rome+y.' f_NewYork_ 10 90 b,Rome 1 2 b_NewYork_ 30 A locale holds and references names without conflicting with names in other locales. A script file can be used to populate a locale. For example, if the file stats contains the following script: mean=. sum % # sum=. +/ then: exec_a_=. 0!:11 Do exec in locale a exec_a_ <'stats' Populate locale a mean=. sum % # sum=. +/ mean=. 34 mean_a_ 3 4 5 4 sexec_a_=. 0!:10 Silent execution sexec_a_ <'stats' The name f_abc_ is executed in locale abc in the sense that any name referenced in f is sought therein. If f does not occur in abc, it is inheritedáfrom the special locale z, but is executed in the child locale abc. The name f in the base locale (as in f or f__) is treated similarly. Specifically: 1. A named entity is evaluated in the indicated locale (or in the base locale if the name is not full). 2. An expression in a script file is evaluated in the locale that it serves to populate. 3. All other expressions are evaluated in the base locale. Defining or expunging a name in a child locale does not affect definitions in the parent locale, and inherited names do not occur in the namelist of a child. Defining f_abc_ does, of course, override the use of an inherited name in subsequent use of the name f_abc_. For example: mean_stats_=. +/ % # mean_z_ =. # %: */ mean_stats_ 4 5 6 7 Arithmetic mean 5.5 mean_z_ 4 5 6 7 Geometric mean 5.38356 centre_z_=. - mean centre_z_ 4 5 6 7 _1.38356 _0.383563 0.616437 1.61644 centre_stats_ 4 5 6 7 _1.5 _0.5 0.5 1.5 Scripts are commonly used to populate a locale with secondary and tertiary functions that supplement the primaries of J. I. ERRORS AND SUSPENSION Execution of a sentence suspends when an error occurs, and an error message and context information are then displayed. Four blanks indicate where parsing stopped. Suspension may occur in immediate execution, in the execution of a script file, or in the execution of an explicitly defined function, as illustrated by the following examples: Immediate execution 2+'a' |domain error | 2 +'a' Execution of a script file t=. '2*3',(10{a.),'2+''a''',(10{a.),'2+3' t A script 2*3 2+'a' 2+3 t 1!:2 <'test' Write script file 0!:11 <'test' Execute script file 2*3 6 2+'a' |domain error | 2 +'a' |[-1] | 0!:11<'test' 2+3 5 Explicitly defined function g=. 3 : ('1+y.' ; ':' ; '2+x.+y.') 3+g 'a' |domain error | 1 +y. |g[0] | 3+ g'a' f=. 3 : '1+g y.' f 'a' |domain error | 1 +y. |g[0] | 1+ g y. |f[0] | f'a' Sentences can be executed in the suspended environment, local values can be accessed, and execution can be resumed. The cases of the foreign conjunction used to control suspension are assigned convenient names by execution of the script file debug.js as follows: dbr=. 13!:0 Reset stack and disable (0) or enable (1) suspension dbs=. 13!:1 Display stack dbsq=. 13!:2 Stop query dbss=. 13!:3 Stop set dbrun=. 13!:4 Run again dbnxt=. 13!:5 Run next dbret=. 13!:6 Exit and return dbjmp=. 13!:7 Continue at line number specified by argument Each function requires a right argument, which is ignored except in the cases of dbr, dbss, dbret, and dbjmp. Errors do not cause suspension unless debugging (invoked by the phrase 13!:0 (1)) is in effect. When suspension is in effect, the input prompt is six spaces. Explicit stops are requested by name and line number in the argument of dbss, which contains zero or more stop specifications separated by semicolons. Each stop specification indicates a function name, line numbers for the monadic case, and (following a :) line numbers for the dyadic case. An asterisk indicates all lines. For example: dbss 'f 0' NB. f monadic line 0 dbss 'f :2' NB. f dyadic line 2 dbss 'f 0 2:1' NB. f monadic 0 2, dyadic 1 dbss 'f 0;g 1' NB. f monadic 0 and g monadic 1 dbss 'f *:*' NB. f all monadic and dyadic dbss '* 0:0' NB. all monadic 0 and dyadic 0 dbsq '' NB. query stops * 0:0 dbr 1 f=. 3 : 0 10 11 12 : 20 21 22 ) dbss=. 13!:3 dbss 'f 1' f '' şstop ş 11 şf[1] ş f'' DEFINITIONS Each main entry in the body of the dictionary is headed by a line beginning with the informal name of the monadic case of the function, and ending with the informal name of the dyadic case. The line also contains the formal name of the function, consisting of one character or two, the last of which is a period or colon. In the case of a conjunction, the formal name is preceded by m or by u (denoting a noun or a verb argument) and is followed by n or v. An adverb has no symbol to its right. The three ranks (in the order monadic, left, and right) are also indicated, using the symbol _ for an infinite (unbounded) rank, and with ranks dependent on the ranks of argument verbs shown as mu, lv, etc. Examples are provided with each definition, and the more complex of them may use auxiliary functions as yet unfamiliar. These examples may be approached by ignoring all but the immediately relevant aspects of such auxiliaries, and by examining (and perhaps entering for execution) component phrases that can be used to build up the final result bit-by-bit. For example, in the discussion of the adverb / , the sentences below display various uses of it for convenient comparison: x=. 1 2 3 4 5 [ y=. 7 5 3 (,.x);(x+/y);y;(x*/y);(+/y);(*/y) õıÃıııııııÃıııııÃııııııııÃııÃıııÀ ş1ş 8 6 4ş7 5 3ş 7 5 3ş15ş105ş ş2ş 9 7 5ş ş14 10 6ş ş ş ş3ş10 8 6ş ş21 15 9ş ş ş ş4ş11 9 7ş ş28 20 12ş ş ş ş5ş12 10 8ş ş35 25 15ş ş ş ÁıÂıııııııÂıııııÂııııııııÂııÂıııã Even if the auxiliary functions ; and ,. are unfamiliar, their relevant effects are probably evident; if not, they may be clarified by the following experiments: x;y ,.7 8 $,.7 8 õıııııııııÃıııııÀ 7 2 1 ş1 2 3 4 5ş7 5 3ş 8 ÁıııııııııÂıııııã Although a name (such as foreign for !:) is suggested for each word, others can be used in addition to or instead of them. Thus, joy might be used for ! since the exclamation mark derives from an I placed above an o, an abbreviation of the Latin io. Similarly, iota might be used instead of integersáand index of for i.. Self-classify = _ 0 0 Equal =y classifies the items of the nub of y (that is, ~.y) according to equality with the items of y, producing a boolean table of shape #~.y by #y. For example: y=. 3 3 $ 'abcdef' y ; (~.y) ; (=y)õıııÃıııÃıııııÀşabcşabcş1 0 1şşdefşdefş0 1 0şşabcş ş şÁıııÂıııÂıııııã x=y is 1 if x is equal to y, and is otherwise 0. The comparison is made with a tolerance t, normally 2 to the power _44 but also controlled by the fit conjunction !., as in x=!.0 y. Formally, x=y is 1 if the magnitude of x-y do es not exceed t times the larger of the magnitudes of x and y.Tolerance applies similarly to other verbs as indicated for each, notably to Match (-:), to Floor (<.), and to Signum (*), but not to Grade (/:). Both the monadic and dyadic cases of the verb = apply to nouns of any rank, and to boxed as well as simple nouns. For example: ]a=. ;: 'Try and try and try again.'õıııÃıııÃıııÃıııÃıııÃııııııÀşTryşandştryşandştryşagain.şÁıııÂıııÂıııÂıııÂıııÂııııııã ~. aõıııÃıııÃıııÃııııııÀşTryşandştryşagain.şÁıııÂıııÂıııÂııııııã =a a= <'and'1 0 0 0 0 0 0 1 0 1 0 00 1 0 1 0 00 0 1 0 1 00 0 0 0 0 1Because of the limited precision of the computer, results which should agree (such as 1 44*(13%144) and 13) may not; the tolerant comparison allows the comparison of it with 13 to show agreement (a result 1). More or less stringent comparisons may be made by using the conjunction !. to specify a tolerance t, as in the functioneq=. =!.t. Copulas (Is) =. Local =: Global The copula is used to assign a referent to a name, as in a=.3 and in sum=.á+/. The copula =. is local as discussed under Explicit Definition (:), and =: is global. For example: f=. 3 : 0 a=. +:y. b=: *:a 10*b ) a=. b=. 678 a,b 678 678 f 3 360 a,b 678 36 Copulas may also be used indirectly. For example: ]x=. 'abc';'de' õıııÃııÀ şabcşdeş ÁıııÂııã (x) =. 3 4 ; 5 6 7 abc 3 4 de 5 6 7 'abc'=. i.3 a 0 b 1 c 2 Note that the parentheses around the name x force it to be evaluated before the assignment specified by the copula is effected. Box < _ 0 0 Less Than . xa 2 0 0 3 5 0 7 11 13 The cut has several uses (chosen by the right argument). For example: box=. < ;. _1 t=. '/i sing/of olaf/' box t õııııııÃıııııııÃÀ şi singşof olafşş ÁııııııÂıııııııÂã The display of a boxed array would normally be corrupted by control characters (such as carriage returns and linefeeds) occurring within it; in the display they are replaced by spaces. For example, try < 8 32 $ a. Floor (Integer Part) <. _ 0 0 Lesser Of (Min) <.y gives the floor or integer part of y, that is, the largest integer less than or equal to y. For example: <. 4.6 4 _4 _4.64 4 _4 _5The implied comparison with integers is tolerant, as discussed under Equal (=), and is controlled by <.!.t. See McDonnell [11] for the treatment of complex arguments. x<.y is the lesser of x and y. For example: 3 <. 4 _43 _4 <./7 8 5 9 22 <./\7 8 5 9 27 7 5 5 2 The floor applied to the argument increased by one-half gives the nearest integer: ]x=. 2 + 3 %~ i. 2 5 2 2.33333 2.66667 3 3.33333 3.66667 4 4.33333 4.66667 5 x + 1r2 2.5 2.83333 3.16667 3.5 3.83333 4.16667 4.5 4.83333 5.16667 5.5 <. x + 1r2 2 2 3 3 3 4 4 4 5 5 The number of digits needed to represent an integer is given by one plus the floor of its base ten logarithm. For example: logs=. 10 ^. a=. 9 10 11 99 100 101 ((6.3&":);<.;(1: + <.)) logs õııııııııııııııııııııııııııııııııııııÃıııııııııııÃıııııııııııÀ ş 0.954 1.000 1.041 1.996 2.000 2.004ş0 1 1 1 2 2ş1 2 2 2 3 3ş ÁııııııııııııııııııııııııııııııııııııÂıııııııııııÂıııııııııııãâââ– The floor <. y is equivalent to ->.-y. In other words, it is the dual of ceiling with respect to (that is, under) arithmetic negation: <.&.- is equivalent to >. and >.&.- is equivalent to <. For example: ((>.&.-);(<.)) 4.6 4 _4 _4.6 õıııııııııÃıııııııııÀ ş4 4 _4 _5ş4 4 _4 _5ş ÁıııııııııÂıııııııııã Decrement <: _ 0 0 Less than or Equal <:y is y-1. For Example: <: 2 3 5 7 1 2 4 6Also see Not (-.) x<:y is 1 if x is less than or equal to y, and is otherwise 0. See Equal (=) for a discussion of tolerance. See Equal (=) for a definition of tolerance. The fit conjunction applies to <: . The inverse of <: is >: (increment). For example: n=. 5 <: ^: _1 n 6 <: ^: _1 >: <:^: 0 1 2 n Here ^: applies to a noun right argument (0 1 2) 5 4 3 <: ^: i. n Here ^: applies to a verb right argument (i.) 5 4 3 2 1 */ <: ^: i. n 120 f=. */ @ (<: ^: i.) f n 120 f"0 i. n 1 1 2 6 24 (f"0 = !) i. n 1 1 1 1 1 Open > 0 0 0 Larger Than Open is the inverse of box, that is, >áy is 1 if x is tolerantly larger than y. See Equal (=) for a discussion of tolerance. For example: 1 2 3 4 5 > 5 4 3 2 10 0 0 1 1 Tolerance t is provided by >!.t. Since the rank of open is 0, it applies to each atom of its argument. For example: ]a=. 1 2 3;4 5 6;7 8 9 õıııııÃıııııÃıııııÀ ş1 2 3ş4 5 6ş7 8 9ş ÁıııııÂıııııÂıııııã >a 1 2 3 4 5 6 7 8 9 Results of different shapes are padded as defined in Section II B. For example: (>1;2 3;4 5 6);(>'a';'bc';'def');(<\i.4);(><\i.4) õıııııÃıııÃıııııııııııııııııııııÃıııııııÀ ş1 0 0şa şõıÃıııÃıııııÃıııııııÀş0 0 0 0ş ş2 3 0şbc şş0ş0 1ş0 1 2ş0 1 2 3şş0 1 0 0ş ş4 5 6şdefşÁıÂıııÂıııııÂıııııııãş0 1 2 0ş ş ş ş ş0 1 2 3ş ÁıııııÂıııÂıııııııııııııııııııııÂıııııııã Ceiling >. _ 0 0 Larger Of (Max) >.y gives the ceiling of y, that is, the smallest integer greater than or equal to y. Thus: >. 4.6 4 _4 _4.65 4 _4 _4The implied comparison with integers is tolerant, as discussed under Equal (=), and is controlled by >.!.t. See McDonnell [11] for the treatment of complex arguments. x>.y is the larger of x and y. For example: 3>.4 _44 3 >./7 8 5 9 29 >./\7 8 5 9 27 8 8 9 9 The comparison x = >. x determines whether x is an integer. Thus: Integer_test=. ] = >. See the definition of fork in Section II F. Integer_test 3 3.14 _5 1 0 1 f=. = >. The same function may be defined by a hook. f 3 3.14 _5 1 0 1 The ceiling >. y is equivalent to -<.-y. In other words, it is the dual of floor with respect to (that is, under) arithmetic negation: >.&.- is equivalent to <. and <.&.- is equivalent to >. . For example: ((<.&.-);(>.)) 4.6 4 _4 _4.6 õıııııııııÃıııııııııÀ ş5 4 _4 _4ş5 4 _4 _4ş ÁıııııııııÂıııııııııã Increment >: _ 0 0 Larger or Equal >:y is y+1. For Example: >: 2 3 5 7 3 4 6 8Also see Not (-.) x>:y is 1 if x is tolerantly greater than or equal to y. See Equal (=) for a discussion of tolerance. >:!.t uses tolerance t. +: i. 6 Even numbers 0 2 4 6 8 10 >: +: i. 6 Odd numbers 1 3 5 7 9 11 odds=. >:@+:@i. odds 10 1 3 5 7 9 11 13 15 17 19 +/ odds 10 100 (+/@odds , *:) 10 Sum of first n odds equals the square of n. 100 100 Negative Sign and Infinity _ The symbol _ followed by a digit denotes a negative number (as in _3.4), and denotes infinity when used alone, or negative infinity (in __ ). It is also used in names, as discussed in Part I and in Part II Section H. For example: 2 % 0 Two divided by zero _ 10 ^. 0 Base ten logarithm of zero __ _2 _ 3+5 3 _ 8 integer_test=. =<. Use of break in name integer_test 3 3.5 1 0 Although -2 may sometimes be used instead of _2, it is important to understand that the former is the application of a function to the number 2, whereas the symbol _ is an indivisible part of the number representation, just as the period is an indivisible part of a number such as 8.9. Indeterminate _. The indeterminate _. results from expressions such as _-_ (infinity minus infinity) and from expressions (such as 3+_.) in which an indeterminate argument occurs. Infinity _: _ _ _ Infinity _: is a constant function that yields an infinite result, that is, _: y is _ _: is a constant function that yields an infinite result, that is, x_:y is _ For example: y=. 1 2 3 4 _: y _ _:"0 y Rank zero applies to each element _ _ _ _ Other constant functions include _9: and _8: etc. to 9:. More generally, the expression x"r defines a constant function of rank r that yields the constant value x . For example, 3.14"0 y 3.14 3.14 3.14 3.14 3.14"1 y 3.14 The specific constant functions mentioned can therefore be written alternatively as _"_ and _9"_ and 0"_ and 9"_ , etc. Conjugate + _ 0 0 Plus + y is the conjugate of y. For example, +3j4 is 3j_4 . + is defined as in elementary arithmetic, and is extended to complex numbers as usual. A complex number y multiplied by its conjugate produces a real number equal to the square of its magnitude |y. For example: 3j4 * 3j_4 25 The function j. multiplies its argument by the square root of negative one. For example: ]i=. i. 5 0 1 2 3 4 j. i 0 0j1 0j2 0j3 0j4 y=. i + 2 * j. i y 0 1j2 2j4 3j6 4j8 +y 0 1j_2 2j_4 3j_6 4j_8 y * +y 0 5 20 45 80 %: y * +y 0 2.23607 4.47214 6.7082 8.94427 |y 0 2.23607 4.47214 6.7082 8.94427 The conjugate of y can also be expressed as (|y*y)%y. For example: (|y*y)%y 0 1j_2 2j_4 3j_6 4j_8 Real / Imaginary +. _ 0 0 GCD (Or) +.y yields a two-element list of the real and imaginary parts of its argument. For example, +.3j5 is 3á5, and +.3 is 3á0. Applied to a list, +. produces a table of the two-element results. x +. y is the greatest common divisor of x and y. If the arguments are boolean (0 or 1), the functions +. and *. are equivalent to logical or and and. The function -. similarly restricted is not. ]y=. i+2*j. i=. i.4 0 1j2 2j4 3j6 +. y 0 0 1 2 2 4 3 6 The greatest common divisor divides both of its arguments x and y to produce results that have no common factor, that is, the GCD of the quotients is 1. Moreover, these quotients represent the fraction x%y in lowest form. For example: x=. 24 [ y=. 60 x;y;(x +. y);((x , y) % (x +. y)) õııÃııÃııÃıııÀ ş24ş60ş12ş2 5ş ÁııÂııÂııÂıııã lff=. , % +. Gives lowest form of fraction x;y;(x lff y);(%/x lff y);(%/x,y);(+./x lff y) õııÃııÃıııÃıııÃıııÃıÀ ş24ş60ş2 5ş0.4ş0.4ş1ş ÁııÂııÂıııÂıııÂıııÂıã Since the functions =| and =<. (tests for non-negative and for integer) produce boolean results, the function test=. (=|) +. (=<.) is a test for non-negative or integer. For example: (test=. (=|) +. (=<.)) _2 _2.4 3 3.5 1 0 1 1 The duality of or and and may be shown as follows: ((+./~&-.);(+./~&.-.);(*./~)) d=. 0 1 õıııÃıııÃıııÀ ş1 1ş0 0ş0 0ş ş1 0ş0 1ş0 1ş ÁıııÂıııÂıııã Double +: _ 0 0 Not-Or +: y is twice y. For example: +: 3 0 _26 0 _4 x +: y is the negation of x or y. For example, 0 +: 0 is 1. Since the product of the sum of two arguments equals the sum of their squares and twice their product , the following functions are equivalent: f=. + * + g=. *:@[ + +:@* + *:@] For example: x=. 7 6 3 [ y=. 6 5 3 x (f ; g ; (f=g) ; (f-:g)) y õııııııııııÃııııııııııÃıııııÃıÀ ş169 121 36ş169 121 36ş1 1 1ş1ş ÁııııııııııÂııııııııııÂıııııÂıã Since the domain of not-or is limited to zero and one, its entire behaviour can be seen in the following function tables: d=. 0 1 Domain of nor d +:/ d Table of nor 1 0 0 0 d +./ d Table of or 0 1 1 1 -. d +./ d Negation of table of or 1 0 0 0 (+:&.-."0/~d) ; (*:/~d) Nand and nor are duals under not õıııÃıııÀ ş1 1ş1 1ş ş1 0ş1 0ş ÁıııÂıııã Signum * _ 0 0 Times *y is _1 if y is negative, 0 if it is zero, 1 if it is positive. For example: *_3 0 5 3j4 is _1 0 1 0.6j0.8 More precisely, the comparison with zero is tolerant, as defined by the following expression (using t to denote the tolerance): (y%|y)*t<:|y . The fit conjunction applies to signum, as in *!.t. * denotes multiplication, defined as in elementary mathematics and extended to complex numbers as usual: t=.+.x,y [ x=.2j4 [ y=.5j3 r=.-/*/t [ i=.+/ . * t (x,:y);t;r;i;(r j. i);(x*y) õıııÃıııÃııÃııÃıııııÃıııııÀş2j4ş2 4ş_2ş26ş_2j26ş_2j26şş5j3ş5 3ş ş ş ş şÁıııÂıııÂııÂııÂıııııÂıııııã Signum is useful in effecting selections. For example: * y=. _4 0 4 _1 0 1 >:@* y 0 1 2 f=. %: f ^: * " 0 y Inverse of f, Identity, or f 16 0 2 (* y) { ;:'Yes No Maybe' Select using indexing ({) õıııııÃıııÃııÀ şMaybeşYesşNoş ÁıııııÂıııÂııã g=. <:`-:`+:@.*"0 See agenda (@.) g y _8 _1 2 The dyad * used on a list and a table illustrates the significance of agreement, as discussed in Section II B: m=. i. 3 4 [ v=. 3 2 1 m ; (v*m) ; (m*v) ; (+/ m*v) ; (v +/ . * m) õıııııııııÃııııııııııÃııııııııııÃıııııııııııÃıııııııııııÀ ş0 1 2 3ş0 3 6 9ş0 3 6 9ş16 22 28 34ş16 22 28 34ş ş4 5 6 7ş8 10 12 14ş8 10 12 14ş ş ş ş8 9 10 11ş8 9 10 11ş8 9 10 11ş ş ş ÁıııııııııÂııııııııııÂııııııııııÂıııııııııııÂıııııııııııã Length / Angle *. _ 0 0 LCM (And) *.y is a two-element list of the length and angle (in radians) of the hypotenuse of a triangle with base and altitude equal to the real and imaginary parts of the argument. For example, *. 3j4 is 5 0.927295. x*.y is the least common multiple of x and y. For boolean arguments (0 and 1) it is equivalent to and. Thus:0 0 1 1*.0 1 0 1 is 0 0 0 1 Some properties of the length / angle are illustrated in the following, including the fact that the length (i.e. magnitude) of the product of two complex numbers is the product of their lengths, and the angle of the product is the sum of their angles: ({.@*. , |) y=. 3j4 Length is magnitude 5 5 x=. 2j_6 *. x,y Polar coordinates 6.32456 _1.24905 5 0.927295 f=. */@:({."1) , +/@:(}."1) Product over first column and sum over last f *. x , y 31.6228 _0.321751 *. x * y Length and angle of product 31.6228 _0.321751 The least common multiple is the product divided by the GCD. For example: x=. 24 [ y=. 60 x +. y 12 (x * y) % x +. y 120 x *. y 120 ((*./~);(+./~&.-.)) 0 1 And and or are dual under negation õıııÃıııÀ ş0 0ş0 0ş ş0 1ş0 1ş ÁıııÂıııã Square *: _ 0 0 Not-And *: y is the square of y. x *: y is the negation of x and y. For example 0 +: 0 is 1. The inverse of the square is the square root. For example: *: ^: _1 %: *: ^: _1 (_2 _1 0 1 2) 0j1.41421 0j1 0 1 1.41421 Since the domain of nand is limited to zero and one, its entire behaviour can be seen in the following function tables: d=. 0 1 Domain of nand d *:/ d Table of nand 1 1 1 0 d *./ d Table of and 0 0 0 1 -. d *./ d 1 1 1 0 Nand, Not and, and the dual of Nor all agree, as illustrated below: (*:/~ ; -.@*./~ ; +:&.-."0/~) d õıııÃıııÃıııÀ ş1 1ş1 1ş1 1ş ş1 0ş1 0ş1 0ş ÁıııÂıııÂıııã Negate - _ 0 0 Minus -y is the negative of y. That is, it is defined as 0á-áy . Thus, -2á0 _2 is _2 0 2 . - is defined as subtraction as in elementary arithmetic, and is extended to complex numbers as usual. The function - is self-inverse, that is, -^: _1 is - . Although -2 may often be used instead of _2, it is important to understand that the former is the application of a function to the number 2, whereas the symbol _ is an indivisible part of the number representation, just as the period is an indivisible part of a number such as 8.9 . Not -. _ _ _ Less -.y is 1-y; for a boolean argument it is the complement (not); for a probability, it is the complementary probability. Items of x-.y are all of the items of x except for those that are cells of y. The function less applies to any pair of arguments. For example: (i. 9) -. 2 3 5 7 0 1 4 6 8 'abcdefghij' -. 'aeiou' bcdfghj m=. i. 4 5 m 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 m -. 5 6 7 8 9 0 1 2 3 4 10 11 12 13 14 15 16 17 18 19 b=. <\ 'abcdefg' b õıÃııÃıııÃııııÃıııııÃııııııÃıııııııÀ şaşabşabcşabcdşabcdeşabcdefşabcdefgş ÁıÂııÂıııÂııııÂıııııÂııııııÂıııııııã b -. 'abc';'abcde';'cba' õıÃııÃııııÃııııııÃıııııııÀ şaşabşabcdşabcdefşabcdefgş ÁıÂııÂııııÂııııııÂıııııııã 2 3 4 5 -. 'abcdef' 2 3 4 5 Halve -: _ _ _ Match -:y is one half of y . For example: -: i. 50 0.5 1 1.5 2 x -: y yields 1 if its arguments match: in shapes, boxing, and elements; but using tolerant comparison. See Equal (=).Matching with a tolerance t can be obtained using the phrase -: !. t . For example: -: ^:_1 +: x=. 0 1 2 3 4 5 ,.&.> (] ; -: ; +:@-: ; (%&2) ; (2: %~ ])) x õıÃıııÃıÃıııÃıııÀ ş0ş 0ş0ş 0ş 0ş ş1ş0.5ş1ş0.5ş0.5ş ş2ş 1ş2ş 1ş 1ş ş3ş1.5ş3ş1.5ş1.5ş ş4ş 2ş4ş 2ş 2ş ş5ş2.5ş5ş2.5ş2.5ş ÁıÂıııÂıÂıııÂıııã x = +: -: x 1 1 1 1 1 1 x -: +: -: x 1 Reciprocal % _ 0 0 Divided by % y is the reciprocal of y, that is, 1%y. For example, %4 is 0.25. x % y is division of x by y as defined in elementary math, except that 0%0 is 0. See McDonnell [12], and the resulting pattern in the middle column and middle row of the table below. We will illustrate the divide function by tables, using a function to generate lists symmetric about zero: sym=. i.@>:@+: - ] Symmetric integers a=. sym 3 a _3 _2 _1 0 1 2 3 |. a %/ a _1 _1.5 _3 _ 3 1.5 1 _0.666667 _1 _2 _ 2 1 0.666667 _0.333333 _0.5 _1 _ 1 0.5 0.333333 0 0 0 0 0 0 0 0.333333 0.5 1 __ _1 _0.5 _0.333333 0.666667 1 2 __ _2 _1 _0.666667 1 1.5 3 __ _3 _1.5 _1 6.2 ": |. a %/ a _1.00 _1.50 _3.00 _ 3.00 1.50 1.00 _0.67 _1.00 _2.00 _ 2.00 1.00 0.67 _0.33 _0.50 _1.00 _ 1.00 0.50 0.33 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.33 0.50 1.00 __ _1.00 _0.50 _0.33 0.67 1.00 2.00 __ _2.00 _1.00 _0.67 1.00 1.50 3.00 __ _3.00 _1.50 _1.00 The final use of the format function gives a more readable result, with a width of six spaces per column, and a uniform two digits after the decimal point. Matrix Inverse %. 2 _ 2 Matrix Divide If y is a non-singular matrix, then %.y is the inverse of y. For example: mp=. +/ . * Matrix product (%. ; ] ; (%. mp ]))i.2 2õııııııııÃıııÃıııÀş_1.5 0.5ş0 1ş1 0şş 1 0ş2 3ş0 1şÁııııııııÂıııÂıııãMore generally, %.y is defined in terms of the dyadic case, with the left argument =i.{:$y (an identity matrix) or, equally, by the relation(%.y)mp xx %. y . The shape of %.y is |.$y. The degenerate vector and scalar cases are defined by using the matrix ,.y, but the shape of the result is $y. F or a non-zero vector y, the result of %.y is a vector collinear with y whose length is the reciprocal of that of y; it is called the reflection of y in the unit circle (or sphere). Thus: (%.,:(] % %.)) y=.2 3 4 0.0689655 0.103448 0.137931 29 29 29 If y is non-singular, then x %. y is (%.y) mp x. More generally, if the columns of y are linearly independent and if #x and #y agree, then x %. y minimizes the difference: d=. x - y mp x %. y in the sense that the magnitudes +/ d*+d are minimized. Degenerate cases of y are treated as the one-column matrix ,.y.Geometrically, y mp x %. y is the projection of the vector x on the column space of y; the point nearest to x in the space spanned by the columns of y. Common uses of %. are in the solution of linear equations, and in the approximation of functions by polynomials, as in the expression c=.á(f x)%. x ^ / i.4.We will illustrate the use of %. in function fitting by the sine function, showing, in particular, the maxim um over the magnitudes of the differences from the function being approximated: sin =. 1&o. [. x=. 5 %~ i. 6 Function to be approximated c=. (sin x) %. x ^/ i. 4 Use of matrix divide ,.&.>@(] ; c"_ ; sin ; c&p. ; >./@|@(sin-c&p.)) x õıııÃıııııııııııÃıııııııııÃıııııııııııÃııııııııııııÀ ş 0ş_5.30503e_5ş 0ş_5.30503e_5ş0.0001679919ş ş0.2ş 1.00384ş0.1986693ş 0.1988263ş ş ş0.4ş_0.01845296ş0.3894183ş 0.3893211ş ş ş0.6ş _0.1439224ş0.5646425ş 0.5645231ş ş ş0.8ş ş0.7173561ş 0.7175241ş ş ş 1ş ş 0.841471ş 0.8414157ş ş ÁıııÂıııııııııııÂıııııııııÂıııııııııııÂııııııııııııã Square Root %: _ 0 0 Root %: y is the square root of y. If y is negative, the result is an imaginary number. For example, %:-4 is 0j2. x %: y is the x root of y. Thus, 3á%: 8 is 2, and 2%:y is %:y. In general,x %: y is y^%x. For example: y=. i. 7 y 0 1 2 3 4 5 6 2 %: y 0 1 1.41421 1.73205 2 2.23607 2.44949 %: y 0 1 1.41421 1.73205 2 2.23607 2.44949 r=. 1 2 3 4 z=. r %:/ y z 0 1 2 3 4 5 6 0 1 1.41421 1.73205 2 2.23607 2.44949 0 1 1.25992 1.44225 1.5874 1.70998 1.81712 0 1 1.18921 1.31607 1.41421 1.49535 1.56508 r ^~ z See agreement in Section II B, and note use of ~ . 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 Exponential ^ _ 0 0 Power ^y is equivalent to e^y, where e is Euler's number ^1 (approximately 2.71828). The natural logarithm (^.) is inverse to ^ (that is, y=^.^y and y=^^.y).The monad x&^ is inverse to the monad x&^. . For example: 10&^. ^:_1õııÃıÃıÀş10ş&ş^şÁııÂıÂıã 10&^ 10&^. 1 2 3 4 51 2 3 4 5 10&^. 10&^ 1 2 3 4 51 2 3 4 5 x^2 and x^3 and x^0.5 are the square, cube, and square root of x.The general definition of x^y is ^y*^.x, applying for complex numbers as well as real. For a non-negative integer y, the ph rase x ^ y is equivalent to */y # x; in particular, */ on an empty list is 1, and x^0 is 1 for any x, including 0.The fit conjunction applies to ^ to yield a stope defined as follows: xá^!.k n is */x + k*i. n. In particular, ^!._1 is the falling factorial function. The last result in the first example below illustrates the falling factorial function, formed by the fit conjunction. See Chapter 4 of [9] for the use of stope functions, stope polynomials, and Stirling numbers in the difference calculus: e=. ^ 1 [ x=. 4 [ y=. 0 1 2 3 ,.&.> x (e"_;e&^@];^;^@(] * ^.@]);(]^]);(^!._1)) y õıııııııÃıııııııÃııÃııÃııÃııÀ ş2.71828ş 1ş 1ş 1ş 1ş 1ş ş ş2.71828ş 4ş 1ş 1ş 4ş ş ş7.38906ş16ş 4ş 4ş12ş ş ş20.0855ş64ş27ş27ş24ş ÁıııııııÂıııııııÂııÂııÂııÂııã S2=. %.@S1=. (^!._1/~ %. ^/~) @ i. (S1;S2) 5 Signed Stirling numbers (transform õııııııııııııÃıııııııııÀ between ordinary and stope polynomials) ş1 0 0 0 0ş1 0 0 0 0ş ş0 1 _1 2 _6ş0 1 1 1 1ş ş0 0 1 _3 11ş0 0 1 3 7ş ş0 0 0 1 _6ş0 0 0 1 6ş ş0 0 0 0 1ş0 0 0 0 1ş ÁııııııııııııÂıııııııııã Natural Log ^. _ 0 0 Logarithm The natural logarithm (^.) is inverse to the exponential ^ (i.e., y=^.^y and y=^^.y). The base-x logarithm x^.y is the inverse of power (^) in the sense thaty = x^.x^y and y = x^x^.y. Certain properties of logarithms are illustrated below: ^. ^: _1 ^ x=. 4 [ y=. 0 1 2 3 (x^y);(x^.x^y);(x^.y);(x^x^.y) õıııııııııÃıııııııÃııııııııııııııııııÃıııııııÀ ş1 4 16 64ş0 1 2 3ş__ 0 0.5 0.7924813ş0 1 2 3ş ÁıııııııııÂıııııııÂııııııııııııııııııÂıııııııã logtable=. ^./~@i. <6.2 ": logtable 6 õııııııııııııııııııııııııııııııııııııÀ ş _. 0.00 0.00 0.00 0.00 0.00ş ş __ 0.00 _ _ _ _ş ş __ 0.00 1.00 1.58 2.00 2.32ş ş __ 0.00 0.63 1.00 1.26 1.46ş ş __ 0.00 0.50 0.79 1.00 1.16ş ş __ 0.00 0.43 0.68 0.86 1.00ş Áııııııııııııııııııııııııııııııııııııã The derivative of the natural logarithm is the reciprocal. For example: D=. ("0)(D.1) ^. D y=. 0 1 2 3 4 5 6 _ 1 0.5 0.333333 0.25 0.2 0.166667 % ^. D y 0 1 2 3 4 5 6 POWER u ^: n _ _ _ (see next topic) Two cases occur: a numeric integer n, and a gerund n. Numeric case. The verb u (or x&u) is applied n times. For example: (];+/\;+/\^:2;+/\^:0 1 2 3 _1 _2 _3 _4) y=. 1 2 3 4 5 õıııııııııÃıııııııııııÃııııııııııııÃıııııııııııııÀ ş1 2 3 4 5ş1 3 6 10 15ş1 4 10 20 35ş1 2 3 4 5ş ş ş ş ş1 3 6 10 15ş ş ş ş ş1 4 10 20 35ş ş ş ş ş1 5 15 35 70ş ş ş ş ş1 1 1 1 1ş ş ş ş ş1 0 0 0 0ş ş ş ş ş1 _1 0 0 0ş ş ş ş ş1 _2 1 0 0ş ÁıııııııııÂıııııııııııÂııııııııııııÂıııııııııııııã An infinite power n produces the limit of the application of u. For example, if x=. 2 and y=. 1, then x o.^:_ y is 0.73908, the solution of the equation y=Cos y. If n is negative, the obverse u^:_1 is applied |n times. The obverse (which is normally the inverse) is specified for five cases: 1. The pairs in the following lists: < <: + +. +: +~ - -. *. *: *~ % > >: + j./"1"_ -: -: - -. r./"1"_ %: %: % --------------------------------------------------------------------------------------------------------------------- %. ^ |. |: ,: ,~ %. ^. |. |: {. (<.@-:@#)&{. ------------------------------------------------------------------------------------------------------------------- ;: #. ". ;~ 3!:1 3!:3 ;@(,&' '&.>"1) #: ": >@{. 3!:2 3!:2 ----------------------------------------------------------------------------------------------------------------- /: \: [ ] o. C. j. p. r. /: /:@|. [ ] %&(o.1) C. %&0j1 p. %&0j1@^. 2. Obviously invertible monads such as -&3 and 10&^. and 1á0á2&|: and 3&|. and 1&o. and a.&i. as well as u@v and u&v and u&.v if u and v are invertible. 3. Monads of the form v/\ and v/\. where v is one of + * % = ~: 4. Obverses specified by :. 5. All others by a linear approximation Gerund case. (Compare with the gerund case of the adverb }) x u^:(v0`v1`v2)y (x v0 y)u^:(x v1 y) (x v2 y) x u^:( v1`v2)y x u^: ([` v1`v2) y u^:( v1`v2)y u^: ( v1 y) ( v2 y) POWER u ^: v _ _ _ (see previous) The case of ^: with a verb right argument is defined in terms of the noun right argument case (u ^: n) as follows: x u ^: v y is x u^: (x v y) y u ^: v y is u^: (v y) y For example: x=. 1 3 3 1 y=. 0 1 2 3 4 5 6 x p. y 1 8 27 64 125 216 343 x p. ^: (]>3:)"1 0 y 0 1 2 3 125 216 343 a=. _3 _2 _1 0 1 2 3 %: a 0j1.73205 0j1.41421 0j1 0 1 1.41421 1.73205 * a _1 _1 _1 0 1 1 1 %: ^: * " 0 a 9 4 1 0 1 1.41421 1.73205 *: a 9 4 1 0 1 4 9 The following monads are equivalent: g=. u ^: p ^: _ h=. 3 : 't=. y. while. p t do. t=. u t end.' (See the example of ^ T. _ in the definition of the Taylor series T.) u=. -&3 [. p=. 0&< (g"0 ; h"0) i. 10 õıııııııııııııııııııııııııÃıııııııııııııııııııııııııÀ ş0 _2 _1 0 _2 _1 0 _2 _1 0ş0 _2 _1 0 _2 _1 0 _2 _1 0ş ÁıııııııııııııııııııııııııÂıııııııııııııııııııııııııã Shape Of $ _ 1 _ Shape $ y yields the shape of y as defined in II A. For example, the shape of a 2-by-3 matrix is 2 3, and the shape of the scalar 3 is an empty list (whose shape is 0).The rank of an argument is given by #@$. For example: rank=. #@$ (rank 3) , (rank ,3)0 1 (rank 3 4),(rank i.2 3 4)1 3 The shape of x$y is x,siy where siy is the shape of an item of y. For example: y=.3 4$'abcdefghijkl' y ; 2 2$ yõııııÃııııÀşabcdşabcdşşefghşefghşşijklş şş şijklşş şabcdşÁııııÂııııãThis example shows ho w the result is formed from the items of y, the last1-cell (abcd) showing that the selection is cyclic. The fit conjunction ($!.f) provides fill specified by the items of f. Since x $ y uses items from y, it is sometimes useful to ravel the right argument, as in x $ ,y. For example (using the y defined above): 2 3 $ ,y abc def The fit conjunction is often useful for appending zeros or spaces. For example: 8 $!.0 (2 3 4) 2 3 4 0 0 0 0 0 ]z=. 8$!.' ' 'abc' abc |. z cba 2 5$!.(<'');: 'zero one two three four five six' õııııÃıııÃıııÃıııııÃııııÀ şzeroşoneştwoşthreeşfourş ÈııııÊıııÊıııÊıııııÊıııı³ şfiveşsixş ş ş ş ÁııııÂıııÂıııÂıııııÂııııã SELF-REFERENCE $: _ _ _ $: is a proxy that assumes the result of the phrase in which it occurs, the phrase being terminated on the left by a copula or by the completion of the sentence. For example: 1:`(] * $:@<:)@.* 5120In the foregoing expression, the agenda chooses the verb ] * $:@<: as long as the argument (reduced by one each time by the application of the decrement) remains non-zero. When the argument becomes zero, the result of the right argument of @. is zero, and the constant function 1: is chosen.If $:@ wer e omitted from the expression, it would execute once only as follows: 1:`(] * <:)@.* 520The inclusion of self-reference ensures that the entire function is re-executed after decrementing the argument. EVOKE m ~ _ (see next topic) If m is a proverb (that is, the name of a verb), then 'm'~y equals m y. If: m=. +/ and a=. 1 2 3 4, then 'm' ~ a is 10 (that is, máa). REFLEXIVE u ~ _ ru lu PASSIVE (see previous) u~ y is y u y. For example, ^~á3 is 27, and +/~ i. n is an addition table. ~ commutes or crosses connections to arguments: x u~ y y u x. Certain uses of the reflexive and passive are illustrated below: x=. 1 2 3 4 [ y=. 4 5 6 x (,.@[ ; ^/ ; ^/~ ; ^/~@[ ; ]) y õıÃıııııııııııııÃıııııııııııııÃıııııııııııÃıııııÀ ş1ş 1 1 1ş4 16 64 256ş1 1 1 1ş4 5 6ş ş2ş 16 32 64ş5 25 125 625ş2 4 8 16ş ş ş3ş 81 243 729ş6 36 216 1296ş3 9 27 81ş ş ş4ş256 1024 4096ş ş4 16 64 256ş ş ÁıÂıııııııııııııÂıııııııııııııÂıııııııııııÂıııııã into=. %~ (i. 6) % 5 0 0.2 0.4 0.6 0.8 1 5 into i. 6 0 0.2 0.4 0.6 0.8 1 from=. -~ (i.6) - 5 _5 _4 _3 _2 _1 0 5 from i.6 _5 _4 _3 _2 _1 0 (x %/ y);(x %~/ y);(x %/~ y) õııııııııııııııııııÃıııııııııııııııııııÃııııııııııııııııııÀ ş0.25 0.2 0.1666667ş 4 5 6ş4 2 1.33333 1ş ş 0.5 0.4 0.3333333ş 2 2.5 3ş5 2.5 1.66667 1.25ş ş0.75 0.6 0.5ş1.33333 1.66667 2ş6 3 2 1.5ş ş 1 0.8 0.6666667ş 1 1.25 1.5ş ş ÁııııııııııııııııııÂıııııııııııııııııııÂııııııııııııııııııã Nub ~. _ ~.y selects the nub of y, that is, all of its distinct items. For example: y=. 3 3 $ 'ABCABCDEF' y;(~.y);(~.3);($~.3)õıııÃıııÃıÃıÀşABCşABCş3ş1şşABCşDEFş ş şşDEFş ş ş şÁıııÂıııÂıÂıã More precisely, the nub is found by selecting the leading item, suppressing from the argument all items tolerantly equal to it, selecting the next remaining item, and so on. The fit conjunction applies to nub to specify the tolerance used. If f is a costly function, it may be quicker to evaluate f y by first evaluating f~. y (which yields all of the distinct results required), and then distributing them to their appropriate positions. The inner product with the self-classification table (produced by =) can be used to effect this distribution. For example: f=. *: f y=. 2 7 1 8 2 8 1 8 4 49 1 64 4 64 1 64 ,.&.>(~. ; f@~. ; = ; (f@~.(+/ .*)=) ; f)y õıÃııÃıııııııııııııııÃııÃııÀ ş2ş 4ş1 0 0 0 1 0 0 0ş 4ş 4ş ş7ş49ş0 1 0 0 0 0 0 0ş49ş49ş ş1ş 1ş0 0 1 0 0 0 1 0ş 1ş 1ş ş8ş64ş0 0 0 1 0 1 0 1ş64ş64ş ş ş ş ş 4ş 4ş ş ş ş ş64ş64ş ş ş ş ş 1ş 1ş ş ş ş ş64ş64ş ÁıÂııÂıııııııııııııııÂııÂııã NUB=. 1 : '(x.@~. +/ . * =)' Adverb *: NUB y 4 49 1 64 4 64 1 64 nubindex=. ~. i. ] (nubindex ; (nubindex { ~.)) y õıııııııııııııııÃıııııııııııııııÀ ş0 1 0 2 0 1 3 2ş8 1 8 2 8 1 7 2ş ÁıııııııııııııııÂıııııııııııııııã Nub Sieve ~: _ 0 0 Not Equal ~:y is the boolean list b such that b#y is the nub of y. For example: ~: 'Mississippi'1 1 1 0 0 0 0 0 1 0 0 x~:y is 1 if x is tolerantly unequal to y. See Equal (=). The fit conjunction may be used to specify tolerance, as in ~:!.t . The result of nub-sieve can be used to select the nub as follows: y=. 8 1 8 2 8 1 7 2 ~. y 8 1 2 7 ~: y 1 1 0 1 0 0 1 0 (~: y) # y 8 1 2 7 y #~ ~: y 8 1 2 7 The dyad ~: applies to any argument, but for booleans it is called exclusive-or. For example: d=. 0 1 d ~:/ d 0 1 1 0 Not-equal, not equal, and the dual of equal with respect to not, all agree as illustrated below. (~:/ ; -.@=/ ; =&.-."0/)~ d õıııÃıııÃıııÀ ş0 1ş0 1ş0 1ş ş1 0ş1 0ş1 0ş ÁıııÂıııÂıııã Magnitude | _ 0 0 Residue |y is %:y*+y. For example: | 6 _6 3j46 6 5 The familiar use of residue is in determining the remainder on dividing a non-negative integer by a positive. Thus: 3 | 0 1 2 3 4 5 6 70 1 2 0 1 2 0 1. The definition y-x*<. y % x+0=x extends the residue to a zero left argument, and to negative and fractional arguments. For example: x=. 3 2 1 0 _1 _2 _3 [ y=. 0 1 2 3 4 5 6 7 8 x (,.@[ ; |/ ; ]) y õııÃııııııııııııııııııııııııÃıııııııııııııııııÀ ş 3ş0 1 2 0 1 2 0 1 2ş0 1 2 3 4 5 6 7 8ş ş 2ş0 1 0 1 0 1 0 1 0ş ş ş 1ş0 0 0 0 0 0 0 0 0ş ş ş 0ş0 1 2 3 4 5 6 7 8ş ş ş_1ş0 0 0 0 0 0 0 0 0ş ş ş_2ş0 _1 0 _1 0 _1 0 _1 0ş ş ş_3ş0 _2 _1 0 _2 _1 0 _2 _1ş ş ÁııÂııııııııııııııııııııııııÂıııııııııııııııııã To produce a true zero for cases such as (%3)|(2%3) the residue is made tolerant as shown in the definition of res below: res=. f`g@.agenda"_ 0 0 agenda=. ([ = 0:) +. (<. = >.)@S S=. ] % [ + [ = 0: f=. ] - [ * <.@S [. g=. ] * [ = 0: 0.1 res 2.5 3.64 2 _1.6 0 0.04 0 0 (,. ; res/~ ; |/~) a=. 2 -~ i.5 õııÃııııııııııııÃııııııııııııÀ ş_2ş 0 _1 0 _1 0ş 0 _1 0 _1 0ş ş_1ş 0 0 0 0 0ş 0 0 0 0 0ş ş 0ş_2 _1 0 1 2ş_2 _1 0 1 2ş ş 1ş 0 0 0 0 0ş 0 0 0 0 0ş ş 2ş 0 1 0 1 0ş 0 1 0 1 0ş ÁııÂııııııııııııÂııııııııııııã The dyad | applies to complex numbers, as discussed in McDonnell [11]. Moreover, the fit conjunction may be applied to control the tolerance used. Reverse |. _ 1 _ Rotate (Shift) |. y reverses the order of the items of y. For example: |. t=. 'abcdefg'gfedcbaThe right shift is the dyadic case of |.!.f with the left argument _1. For example: |.!.'#' t#abcdef |.!.10 i.3 3 10 10 10 0 1 2 3 4 5 x|.y rotates successive axes of y by successive elements of x. Thus: 1 2 |. i. 3 5 7 8 9 5 612 13 14 10 11 2 3 4 0 1 The phrase x |.!.f y produces a shift: the items normally brought around by the cyclic rotation are replaced by f unless f is empty (0=#f), in which case they are replaced by the normal fill defined under {. : 2 _2 |.!.'#'"0 1 tcdefg####abcde y=. a.{~ (a. i. 'A') + i. 5 6 p=. (] ; 2&|. ; _2&|. ; 2&|."1 ; 2&(|.!.'*'"1)) y q=. (] ; |. ; |."1 ; |.!.'*'"1 ; (2: |. ])) y p ,&< q õııııııııııııııııııııııııııııııııııııÃııııııııııııııııııııııııııııııııııııÀ şõııııııÃııııııÃııııııÃııııııÃııııııÀşõııııııÃııııııÃııııııÃııııııÃııııııÀş şşABCDEFşMNOPQRşSTUVWXşCDEFABşCDEF**şşşABCDEFşYZ[\]^şFEDCBAş*ABCDEşMNOPQRşş şşGHIJKLşSTUVWXşYZ[\]^şIJKLGHşIJKL**şşşGHIJKLşSTUVWXşLKJIHGş*GHIJKşSTUVWXşş şşMNOPQRşYZ[\]^şABCDEFşOPQRMNşOPQR**şşşMNOPQRşMNOPQRşRQPONMş*MNOPQşYZ[\]^şş şşSTUVWXşABCDEFşGHIJKLşUVWXSTşUVWX**şşşSTUVWXşGHIJKLşXWVUTSş*STUVWşABCDEFşş şşYZ[\]^şGHIJKLşMNOPQRş[\]^YZş[\]^**şşşYZ[\]^şABCDEFş^]\[ZYş*YZ[\]şGHIJKLşş şÁııııııÂııııııÂııııııÂııııııÂııııııãşÁııııııÂııııııÂııııııÂııııııÂııııııãş ÁııııııııııııııııııııııııııııııııııııÂııııııııııııııııııııııııııııııııııııã 1 _2 |. !. '*' 3{. y **GHIJ **MNOP ****** Transpose |: _ 1 _ Transpose |: reverses the order of the axes of its argument. For example: (] ; |:) i. 3 4õıııııııııÃııııııÀş0 1 2 3ş0 4 8şş4 5 6 7ş1 5 9şş8 9 10 11ş2 6 10şş ş3 7 11şÁıııııııııÂııııııã x|:y moves axes x to the tail end. If x is boxed, the axes in each box are run together to produce a single axis: y=. 3 4$'abcdefghijkl' y;(1 0|:y);(0|:y);((<0 1)|:y)õııııÃıııÃıııÃıııÀşabcdşaeişaeişafkşşefghşbfjşbfjş şşijklşcgkşcgkş şş şdhlşdhlş şÁııııÂıııÂıııÂıııã For example: y=. a.{~ (a. i. 'a') + i. 2 3 4 z=. y;(2 1 |: y);((<2 1) |: y);(|: i. 4 5) z ,&< |:&.> z õııııııııııııııııııııııııÃıııııııııııııııııııııııııÀ şõııııÃıııÃıııÃıııııııııÀşõııÃııÃııÃııııııııııııııÀş şşabcdşaeişafkş0 5 10 15şşşamşamşamş 0 1 2 3 4şş şşefghşbfjşmrwş1 6 11 16şşşeqşbnşfrş 5 6 7 8 9şş şşijklşcgkş ş2 7 12 17şşşiuşcoşkwş10 11 12 13 14şş şş şdhlş ş3 8 13 18şşş şdpş ş15 16 17 18 19şş şşmnopş ş ş4 9 14 19şşşbnş ş ş şş şşqrstşmquş ş şşşfrşeqş ş şş şşuvwxşnrvş ş şşşjvşfrş ş şş şş şoswş ş şşş şgsş ş şş şş şptxş ş şşşcoşhtş ş şş şÁııııÂıııÂıııÂıııııııııãşşgsş ş ş şş ş şşkwşiuş ş şş ş şş şjvş ş şş ş şşdpşkwş ş şş ş şşhtşlxş ş şş ş şşlxş ş ş şş ş şÁııÂııÂııÂııııııııııııııãş ÁııııııııııııııııııııııııÂıııııııııııııııııııııııııã DETERMINANT u . v 2 _ _ DOT PROD The phrases -/ . * and +/ . * are the determinant and permanent of square matrix arguments. More generally, the phrase u . v is defined in terms of a recursive expansion by minors along the first column, as discussed below. For vectors and matrices, the phrase xá+/á.á*áy is equivalent to the dot, inner, or matrix product of math; other rank-0 verbs such as <. and *. are treated analogously. In general, u . v is defined by u@(v"(1+lv,_)), restated in English below. 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 CUT u ;. n _ 1/2 _ CUT The fret 0{y (the leading item of y) marks the start of an interval of items of y; the phrase u;. 1 y applies u to each such interval. The phrase u;._1 y differs only in that frets are excluded from the result. In u;.2 and u;._2 the fret is the last item, and marks the ends of intervals.u;.0 y applies u to y after reversing y along each axis; it is equivalent to(0 _1 */$y) u;.0 y.The monads u;.3 and u;._3 apply u to tessellation by maximal cubes, that is, they are defined by their dyadic cases using the left argument ($$y)$<./$y. x u;.0 y applies u to a rectangle or cuboid of y with one vertex at the point in y indexed by v=.0{x, and with the opposite vertex determined as follows: the dimension is |1{x, but the rectangle extends back from v along any axis for which the index k{v is negative. Finally, the order of the selected items is reversed along each axis k for which k{1{x is negative. If x is a vector. it is treated as the matrix 0,:xThe frets in the dyadic cases 1, _1, 2, and _2 are determined by the 1s in the boolean argument x. The cases u;.3 and u;._3 yield (possibly overlapping) tessellations. x u;._3 y applies u to each complete rectangle of size |1{x beginning at integer multiples of (each item of) the movement vector 0{x. As in the monad u;.0, reversal occurs along each axis for which the size 1{x is negative. The degenerate case of a list x is equivalent to 1,:x, and therefore provides a complete tesselation of sizex . The case u;.3 differs in that shards o f length less than |1{x are included. <;.2 y=.'worlds on worlds ' õıııııııÃıııÃıııııııÀ şworlds şon şworlds ş ÁıııııııÂıııÂıııııııã ($;._2 y) ; (3 5 $ i.10) ; (+/ ;.1 (3 5 $ i.10)) õıÃıııııııııÃıııııııııııÀ ş6ş0 1 2 3 4ş5 7 9 11 13ş ş2ş5 6 7 8 9ş0 1 2 3 4ş ş6ş0 1 2 3 4ş ş ÁıÂıııııııııÂıııııııııııã x ; (x=. 1 _2,:_2 3) +;.0 i. 5 5 õıııııÃııııııııÀ ş 1 _2ş11 12 13ş ş_2 3ş 6 7 8ş ÁıııııÂııııııııã (y=. a. {~ (a. i. 'a') + i. 4 4);(a=. 1 1 ,: 2 2) õııııÃıııÀ şabcdş1 1ş şefghş2 2ş şijklş ş şmnopş ş ÁııııÂıııã (<;.3 y);(((($$y)$<./$y)<;.3 y));(a <;.3 y);<(a <;._3 y) õıııııııııııııııÃıııııııııııııııÃııııııııııııÃııııııııııÀ şõııııÃıııÃııÃıÀşõııııÃıııÃııÃıÀşõııÃııÃııÃıÀşõııÃııÃııÀş şşabcdşbcdşcdşdşşşabcdşbcdşcdşdşşşabşbcşcdşdşşşabşbcşcdşş şşefghşfghşghşhşşşefghşfghşghşhşşşefşfgşghşhşşşefşfgşghşş şşijklşjklşklşlşşşijklşjklşklşlşşÈııÊııÊııÊı³şÈııÊııÊıı³ş şşmnopşnopşopşpşşşmnopşnopşopşpşşşefşfgşghşhşşşefşfgşghşş şÈııııÊıııÊııÊı³şÈııııÊıııÊııÊı³şşijşjkşklşlşşşijşjkşklşş şşefghşfghşghşhşşşefghşfghşghşhşşÈııÊııÊııÊı³şÈııÊııÊıı³ş şşijklşjklşklşlşşşijklşjklşklşlşşşijşjkşklşlşşşijşjkşklşş şşmnopşnopşopşpşşşmnopşnopşopşpşşşmnşnoşopşpşşşmnşnoşopşş şÈııııÊıııÊııÊı³şÈııııÊıııÊııÊı³şÈııÊııÊııÊı³şÁııÂııÂııãş şşijklşjklşklşlşşşijklşjklşklşlşşşmnşnoşopşpşş ş şşmnopşnopşopşpşşşmnopşnopşopşpşşÁııÂııÂııÂıãş ş şÈııııÊıııÊııÊı³şÈııııÊıııÊııÊı³ş ş ş şşmnopşnopşopşpşşşmnopşnopşopşpşş ş ş şÁııııÂıııÂııÂıãşÁııııÂıııÂııÂıãş ş ş ÁıııııııııııııııÂıııııııııııııııÂııııııııııııÂııııııııııã Word Formation ;: 1 ;:y is the list of boxed words in the list y according to the rhematic rules of Section I. The function also applies reasonably well to ordinary text. For example: s=. '*: @ -: @ i. 2 3' do=. ". do s 0 0.25 1 2.25 4 6.25 ;: s õııÃıÃııÃıÃııÃıııÀ ş*:ş@ş-:ş@şi.ş2 3ş ÁııÂıÂııÂıÂııÂıııã ; ;: s *:@-:@i.2 3 p=. 'When eras die, their legacies/' q=. 'are left to strange police' r=. 'Professors in New England guard' s=. 'the glory that was Greece' ;: p õııııÃııııÃıııÃıÃıııııÃııııııııÃıÀ şWhenşerasşdieş,ştheirşlegaciesş/ş ÁııııÂııııÂıııÂıÂıııııÂııııııııÂıã > ;: p,q When eras die , their legacies / are left to strange police |.&.;: p / legacies their , die eras When Tally # _ 1 _ Copy #y is the number of items in y. Thus: (#'');(#'a');(#'ab')õıÃıÃıÀş0ş1ş2şÁıÂıÂıã (#3);(#,3);(# 3 4)õıÃıÃıÀş1ş1ş2şÁıÂıÂıã (#i.4 5 6);(#$i.4 5 6)õıÃıÀş4ş3şÁıÂıã If the arguments have an equal number of items, then x#y copies +/x items from y, with i{x repetitions of item i{y. Otherwise, if one is an atom it is repeated to make the item count of the arguments equal. The complex left argument a j. b copies a items followed by b fills.The fit conjunction provides specified fills, as in #!.f . Copy is illustrated by the following examples: 0 1 2 3 4 5 # 0 1 2 3 4 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 t=. 3 4 $'abcdefghijkl' [ n=. i. 3 4 t ; n ; (3 0 1 # t);(3 0 1 # n) õııııÃıııııııııÃııııÃıııııııııÀ şabcdş0 1 2 3şabcdş0 1 2 3ş şefghş4 5 6 7şabcdş0 1 2 3ş şijklş8 9 10 11şabcdş0 1 2 3ş ş ş şijklş8 9 10 11ş ÁııııÂıııııııııÂııııÂıııııııııã k=. 2j1 0 1j2 (k # t);(k # n);(k #!.'*' t);(k #!.4 n) õııııÃıııııııııÃııııÃıııııııııÀ şabcdş0 1 2 3şabcdş0 1 2 3ş şabcdş0 1 2 3şabcdş0 1 2 3ş ş ş0 0 0 0ş****ş4 4 4 4ş şijklş8 9 10 11şijklş8 9 10 11ş ş ş0 0 0 0ş****ş4 4 4 4ş ş ş0 0 0 0ş****ş4 4 4 4ş ÁııııÂıııııııııÂııııÂıııııııııã Base Two #. 1 1 1 Base #.y is the base-2 value of y, that is, 2#.y. For example: #. 1 0 1 010 #. 2 3$ 0 0 1,1 0 11 5 x#.y is a weighted sum of the items of y; that is, +/w*y, where w is the product scan */\.}.x,1. For example, if a=.1 2 3, and b=.24á60 60, then 10 #. a is 123, and b #. a is 3723. Further examples: ]a=. i. 3 4 0 1 2 3 4 5 6 7 8 9 10 11 10 #.a 123 4567 9011 8 #. a 83 2423 4763 ]time=. 0 1 3,1 1 3,:2 4 6 0 1 3 1 1 3 2 4 6 x=. 24 60 60 x #. time 63 3663 7446 x,1 24 60 60 1 ]w=. */\.}. x,1 3600 60 1 w *"1 time 0 60 3 3600 60 3 7200 240 6 +/"1 w *"1 time 63 3663 7446 w +/@:* "1 time 63 3663 7446 Antibase Two #: _ 1 0 Antibase #: y is the binary representation of y, and is equivalent to (m#2)#:y, where m is the maximum of the number of digits needed to represent the atoms of y in base 2. For example: i. 80 1 2 3 4 5 6 7 #: i. 80 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1 In simple cases, r&#: is inverse tor&#. . Thus, if r=.24 60 60, thenr #: r #. 2 3 4 is 2á3á4. But ifr #. y exceeds (*/r)-1 (the largest integer representable in the radix r), then the result of r #: y is reduced modulo */r. For example: r #: r #. 29 3 45 3 4 A representation in an arbitrary base that is analogous to the base-2 representation provided by the monadic use of #: may be provided as illustrated below: ndr=. 1: + <.@^. Number of digits required 10 ndr y=. 9 10 11 100 99 100 1 2 2 3 2 3 (y#:~10 #~ >./10 ndr y);(y#:~8 #~ >./8 ndr y) õıııııÃıııııÀ ş0 0 9ş0 1 1ş ş0 1 0ş0 1 2ş ş0 1 1ş0 1 3ş ş1 0 0ş1 4 4ş ş0 9 9ş1 4 3ş ş1 0 0ş1 4 4ş ÁıııııÂıııııã Factorial ! _ 0 0 Out Of (Combinations) For a non-negative integer argument y, the definition is */>:i.y. In general, !y is (1+y). Thus: (*/1 2 3 4 5) , (!5)120 120 ]x=. 2 %~ 3 -~ i. 2 4_1.5 _1 _0.5 0 0.5 1 1.5 2 !x_3.54491 _ 1.77245 10.886227 1 1.32934 2 ]fi=.!^:_1(24 25 2.1 9876)4 4.02705 2.05229 7.33019 ! fi24 25 2.1 9876 For non-negative arguments x!y is the number of ways that x things can be chosen out of y. More generally, x!y is (!y)%(!x)*(!y-x) with the under-standing that infinities (occasioned by ! on a neg ative integer) cancel if they occur in both numerator and denominator. Thus: 3!510 (!5)%(!3)*(!5-3)10 2&!^:_1 (45 4.1 30 123)10 3.40689 8.26209 16.1924 !&10^:_1 (2.5 45)0.3433618 2 The first table below illustrates the relation between the dyad ! and the table of binomial coefficients; the last two illustrate its relation to the figurate numbers: h=. 0,i=. i.5 [ j=. -1+i.5 [k=. 5#1 tables=. (,.h);(i,i!/i);(j,i!/j);(k,i(+/\^:)k) format=. ({.,:&<}.)@":&.> format tables õıııÃıııııııııııÃıııııııııııııııııııÃııııııııııııııÀ şõıÀşõıııııııııÀşõıııııııııııııııııÀşõııııııııııııÀş şş0şşş0 1 2 3 4şşş_1 _2 _3 _4 _5şşş1 1 1 1 1şş şÈı³şÈııııııııı³şÈııııııııııııııııı³şÈıııııııııııı³ş şş0şşş1 1 1 1 1şşş 1 1 1 1 1şşş1 1 1 1 1şş şş1şşş0 1 2 3 4şşş_1 _2 _3 _4 _5şşş1 2 3 4 5şş şş2şşş0 0 1 3 6şşş 1 3 6 10 15şşş1 3 6 10 15şş şş3şşş0 0 0 1 4şşş_1 _4 _10 _20 _35şşş1 4 10 20 35şş şş4şşş0 0 0 0 1şşş 1 5 15 35 70şşş1 5 15 35 70şş şÁıãşÁıııııııııãşÁıııııııııııııııııãşÁııııııııııııãş ÁıııÂıııııııııııÂıııııııııııııııııııÂııııııııııııııã Figurate numbers of order zero are all ones, and those of successive orders result from successive applications of subtotals (that is, sums over prefixes, or +/\). Consequently, those of order two are the triangular numbers, resulting from subtotals over the integers beginning with one. FIT (CUSTOMIZE) !. This conjunction modifies certain verbs in ways prescribed in their definitions. For example, =!.t is the relation of equality using tolerance t, and ^!.r is the factorial function so defined that x ^!.r n is */x + r * i. n . Consequently, ^!._1 is the falling factorial function. Fit applies to the following verbs (to produce variants). The monadic case is shown before a bullet, and the dyadic case after it: < <: >: > -: | +. *. E. i. Tolerance <. >. * Tolerance +. *. #: Tolerance = ~. #: e. ~: Tolerance Tolerance ^ p. Stope function and polynomial based thereon $ |. # {. Fill ": Print precision FOREIGN !: This conjunction is used to communicate with the host system as well as with the keyboard (as an input file) and with the screen (as an output file). It is also used to provide a variety of extra-lingual facilities, such as setting the form of function display, determining the class of a name (noun, verb, adverb, or conjunction), and listing all existing names in specified classes. (mean=. +/ % #) a=. 2 3 5 7 11 13 6.83333 mean +/ % # 9!:3 (4) mean õı / ııı + Tree display of verb ııÊı % Áı # 9!:3 (2 4 5) mean õıııııÃıÃıÀ Boxed display şõıÃıÀş%ş#ş şş+ş/şş ş ş şÁıÂıãş ş ş ÁıııııÂıÂıã õı / ııı + Tree display ııÊı % Áı # +/ % # Linear display 4!:0 'a';'mean' Classes of names (noun 0, verb 3) 0 3 4!:1 (3) List of names in class 3 õııııÀ şmeanş Áııııã The appendix shows all uses of the foreign conjunction. INSERT m / u / _ _ _ TABLE If m is a gerund, then m/y inserts successive verbs from m between items of y. Thus, +`*/i.6 is 0+1*2+3*4+5. The gerund m may extend cyclically. For the verb case, u/y applies the dyad u between the items of y. Thus: m=. i. 3 2 m;(+/m);(+/"1 m);(+/2 3 4)õıııÃıııÃıııııÃıÀş0 1ş6 9ş1 5 9ş9şş2 3ş ş ş şş4 5ş ş ş şÁıııÂıııÂıııııÂıã If x and y are numeric lists, then xá*/ y is their multiplication table.For example: 1 2 3 */ 4 5 6 7 4 5 6 7 8 10 12 1412 15 18 21In general, each cell of x is applied to the entire y. Thus x u/ y is equivalent to xáu"(lu,_) y.The case */ is called outer product in tensor analysis. If y has no items (that is, 0=#y), the result of u/y is the identity elementáof the function u. An identity element of a function u is a value e such that either xáuáeáis x, or eáuáx is x for every x in the domain (or perhaps some significant sub-domain such as boolean) of u. This definition of insertion over an argument having zero items extends partitioning identities of the form (+/y) is (+/k{.y)+ +/k}.y to the cases k=.0 and k=.#y. The identity function of u is a function ifu such that (ifu y) is (u/y) if 0=#y. The identity functions used are: Identity function For $&0@}.@$ < > + - +. ~: | (2 4 5 6 b.) $&1@}.@$ = <: >: * % *. %: ^ ! (1 9 11 13 b.) $&_@}.@$ <. $&__@}.@$ >. i.@(0&,)@(2&}.)@$ , i.@(1&{.)@}.@$ C. { =@i.@(1&{.)@}.@$ %. +/ . * ifu@# u/ $&(v^:_1 ifu$0)@}.@$ u&.v OBLIQUE m /. u /. _ _ _ KEY m/.y applies each element of the gerund m to each item of y. Thus: !`*:/. 3 is 6 9. Also see `:.u/.y applies u to each of the oblique lines of a table y. For example: ;: 'When eras die' j=. <./UcLc i."1 _ x x ; (x/:x) ; (x/:j) ; UcLc õııııÃııııÃııııÃıııııııııııııııııııııııııııÀ şWhenşWhenşdie ş ABCDEFGHIJKLMNOPQRSTUVWXYZş şerasşdie şerasş abcdefghijklmnopqrstuvwxyzş şdie şerasşWhenş ş ÁııııÂııııÂııııÂıııııııııııııııııııııııııııã TRAIN m \ _ _ _ (see next topic) m\ is equivalent to the train of verbs represented by the gerund m. For example: ] g=. ]`-`(+/)`%`# õıÃıÃıııııııÃıÃıÀ ş]ş-şõıÃıııÀş%ş#ş ş ş şş/şõıÀşş ş ş ş ş şş şş+şşş ş ş ş ş şş şÁıãşş ş ş ş ş şÁıÂıııãş ş ş ÁıÂıÂıııııııÂıÂıã g\ ] - +/ % # g\ a=. 2 3 4 5 6 _2 _1 0 1 2 (1}.g)\ a _2 _1 0 1 2 (2}.g)\ a 4 PREFIX u \ _ 0 _ INFIX (see previous) u\y has #y items resulting from applying u to each of the prefixes k{.y, for k from 1 to #y. If a>0, the items of a u\ y result from applying u to each infix of length a. If a is negative, u is applied to non-overlapping infixes of length |a, including any final shard. +/\a=. 1 2 4 8 16 Subtotals, or partial sums 1 3 7 15 31 */\a Partial products 1 2 8 64 1024 <\a õıÃıııÃıııııÃıııııııÃııııııııııÀ ş1ş1 2ş1 2 4ş1 2 4 8ş1 2 4 8 16ş ÁıÂıııÂıııııÂıııııııÂııııııııııã <\i.3 4 õıııııııÃıııııııÃıııııııııÀ ş0 1 2 3ş0 1 2 3ş0 1 2 3ş ş ş4 5 6 7ş4 5 6 7ş ş ş ş8 9 10 11ş ÁıııııııÂıııııııÂıııııııııã +/\^:_1 +/\ a */\.^:_1 a 1 2 4 8 16 0.5 0.5 0.5 0.5 16 The following examples illustrate the use of the dyad infix: ((2: -/\ ]) ; (2: -~/\ ])) a Backward and forward differences õıııııııııııÃıııııııÀ ş_1 _2 _4 _8ş1 2 4 8ş ÁıııııııııııÂıııııııã ((3: <\ ]) ,&< (_3: <\ ])) b=. 'abcdefgh' õıııııııııııııııııııııııııÃııııııııııııÀ şõıııÃıııÃıııÃıııÃıııÃıııÀşõıııÃıııÃııÀş şşabcşbcdşcdeşdefşefgşfghşşşabcşdefşghşş şÁıııÂıııÂıııÂıııÂıııÂıııãşÁıııÂıııÂııãş ÁıııııııııııııııııııııııııÂııııııııııııã SUFFIX u \. _ 0 _ OUTFIX u\.y has #y items resulting from applying u to suffixes of y, beginning with one of length #y (that is, y itself), and continuing through a suffix of length 1. If x>0 in x u\. y, then u applies to outfixes of y obtained by suppressing successive infixes of length x. If x<0, the outfixes result from suppressing non-overlapping infixes, the last of which may be a shard. */\. y=. 1 2 3 4 5 120 120 60 20 5 <\. y õıııııııııÃıııııııÃıııııÃıııÃıÀ ş1 2 3 4 5ş2 3 4 5ş3 4 5ş4 5ş5ş ÁıııııııııÂıııııııÂıııııÂıııÂıã ((3: <\. ]) ; (_3: <\.])) b=. 'abcdefgh' õıııııııııııııııııııııııııııııııııııııÃıııııÃıııııÃııııııÀ şõıııııÃıııııÃıııııÃıııııÃıııııÃıııııÀşdefghşabcghşabcdefş şşdefghşaefghşabfghşabcghşabcdhşabcdeşş ş ş ş şÁıııııÂıııııÂıııııÂıııııÂıııııÂıııııãş ş ş ş ÁıııııııııııııııııııııııııııııııııııııÂıııııÂıııııÂııııııã The phrase */x-roots[x=.5[roots=.3 7 4 8 is a polynomial in terms of its roots (with value 12). The factors, the factors with one removed, and the negation of their products (the derivative of the polynomial with respect to each of the roots) are given by: (x-roots);(1 <\.x - roots);(- 1 */\. x - roots) õıııııııııÃıııııııııııııııııııııııııııııııÃııııııııııÀ ş2 _2 1 _3şõıııııııÃııııııÃıııııııÃııııııÀş_6 6 _12 4ş ş şş_2 1 _3ş2 1 _3ş2 _2 _3ş2 _2 1şş ş ş şÁıııııııÂııııııÂıııııııÂııııııãş ş ÁıııııııııÂıııııııııııııııııııııııııııııııÂııııııııııã (BM=. (box=. <"2)@minors=. 1&(|:\.)"2^:2) i. 3 3 õıııÃıııÃıııÀ ş4 5ş3 5ş3 4ş ş7 8ş6 8ş6 7ş ÈıııÊıııÊııı³ ş1 2ş0 2ş0 1ş ş7 8ş6 8ş6 7ş ÈıııÊıııÊııı³ ş1 2ş0 2ş0 1ş ş4 5ş3 5ş3 4ş ÁıııÂıııÂıııã Grade Down \: _ _ _ Sort (Down) \: grades its argument, yielding a permutation vector; (\:y){y sorts y in descending order. For example: ]g=.\:y=.3 1 4 2 1 3 3 2 0 5 6 3 1 4 g{y4 3 3 3 2 1 1 x\:y is (\:y){x; i.e., x is sorted to an order specified by y. In particular, y\:yá(or \:~y) sorts y. For example: \:~"1 'dozen',:'disk'zonedskid Elements of \:y that select equal elements of y are in ascending order. If y is a table, \:y grades the base value of the rows, using a base larger than twice the magnitude of any of the elements. Higher ranks are treated as ,.y (as if the items were each ravelled). If y is literal, \:y grades according to the collating sequence specified by the alphabet a. ; another collating sequence cs can be imposed by grading csái.áy. For example: ]n=. 3 1 4 1 6,2 7 1 8 3,:6 1 8 0 3 3 1 4 1 6 2 7 1 8 3 6 1 8 0 3 \: n 2 0 1 \:~ t=. >;:'when eras die, their legacies' when their legacies eras die , Same [ ] _ _ _ Left, Right The monads [ and ] are each identity functions; each yields its argument. x [ y (left bracket) yields the left argument x, and x ] y yields the right argument y. For example: n=. i. 2 3 a=. 'abcde' ]n 0 1 2 3 4 5 [a abcde n[a 0 1 2 3 4 5 n]a abcde ([\ ; ]\ ; [\. ; ]\.) 'ABCDEF' õııııııÃııııııÃııııııÃııııııÀ şA şA şABCDEFşABCDEFş şAB şAB şBCDEF şBCDEF ş şABC şABC şCDEF şCDEF ş şABCD şABCD şDEF şDEF ş şABCDE şABCDE şEF şEF ş şABCDEFşABCDEFşF şF ş ÁııııııÂııııııÂııııııÂııııııã See the corresponding conjunctions [. and ]. (Lev and Dex) LEV, DEX [. ]. [. is a conjunction that yields the left argument and ]. is a conjunction that yields its right argument. For example: sqrt=. %: [. sqr=. *: sqrt 1 2 3 1 1.41421 1.73205 sqr 1 2 3 1 4 9 Cap [: _ _ _ Cap [: caps a left branch of a fork, as described in Section II F. For example, the function p=. [: +/ + * - applies the monad +/ to the result of the fork + * - . Caps make it possible to define a wider range of functions as unbroken trains. For example, the maximum divided by the product of the sum and difference would be defined by a single train, whereas (without the use of the cap) the definition of the maximum divided by the (monad) floor of the product of the sum and difference would require the use of trains interrupted by the monad. Thus: f=. >. % + * - g=. >. % <. @ (+ * -) 2.5 f 4 _0.410256 2.5 g 4 _0.4 The cap makes possible the use of an unbroken train as follows: h=. >. % [: <. + * - 2.5 h 4 _0.4 Since the domain of the cap is empty, it can be used (with :) to define a function whose monadic or dyadic case invokes a domain error. For example: abs=. | : [: res=. [: : | abs _4 0 5 4 0 5 3 res _4 0 5 2 0 2 3 abs _4 0 5 |domain error | 3 abs _4 0 5 Catalogue { 1 0 _ From {y forms a catalogue from the atoms of its argument, its shape being the chain of the shapes of the opened items of y. The common shape of the boxed results is $y. For example: { 'ht';'ao';'gtw'õıııÃıııÃıııÀşhagşhatşhawşÈıııÊıııÊııı³şhogşhotşhowşÁıııÂıııÂıııãõıııÃıııÃıııÀştagştatştawşÈıııÊıııÊııı³ştogştotştowşÁıııÂıııÂıııã If x is an integer in the range from -#y to <:#y, then x{y selects item (#y)|x from y. Thus: 2 0 _1 _3 { 'abcdefg'cage 1{t=.3 4$'abcdefghijkl'efghMore generally, >x ma y be a list whose successive elements are (possibly) boxed arrays that specify selection along successive axes of y. Finally, if any r=.>j{>x used in the selection is itself boxed, selection is made by the indices along that axis that do not occur in >r.Note that the result in the very last dyadic example is all except the last item (indexed by _1): t;(1{t);(1{"1 t);(2 0{t);((<2 0){t);((<2 0;1 3){t) õııııÃııııÃıııÃııııÃıÃııÀ şabcdşefghşbfjşijklşişjlş şefghş ş şabcdş şbdş şijklş ş ş ş ş ş ÁııııÂııııÂıııÂııııÂıÂııã (_1{m);(_1{"2 m);(_1{"1 m);(<<<_1){m=.i.2 3 4 õıııııııııııÃıııııııııııÃııııııııÃıııııııııÀ ş12 13 14 15ş 8 9 10 11ş 3 7 11ş0 1 2 3ş ş16 17 18 19ş20 21 22 23ş15 19 23ş4 5 6 7ş ş20 21 22 23ş ş ş8 9 10 11ş ÁıııııııııııÂıııııııııııÂııııııııÂıııııııııã CP=. {@(,&<) is called the Cartesian product. Thus: 0 1 CP 0 1 õıııÃıııÀ ş0 0ş0 1ş ÈıııÊııı³ ş1 0ş1 1ş ÁıııÂıııã Head {. _ 1 _ Take {. selects the leading item of its argument. For example: a=. i. 3 2 3 a;({.a);({."2 a);({."1 a)õııııııııÃıııııÃııııııııÃıııııÀş 0 1 2ş0 1 2ş 0 1 2ş 0 3şş 3 4 5ş3 4 5ş 6 7 8ş 6 9şş ş ş12 13 14ş12 15şş 6 7 8ş ş ş şş 9 10 11ş ş ş şş ş ş ş şş12 13 14ş ş ş şş15 16 17ş ş ş şÁııııııııÂıııııÂııııııııÂıııııã ]b=. ;/aõıııııÃıııııııÃııııııııÀş0 1 2ş6 7 8ş12 13 14şş3 4 5ş9 10 11ş15 16 17şÁııııı ıııııııÂııııııııã {.&> b 0 1 2 6 7 812 13 14 If x is an atom, x{.y takes from y an interval of |x items; beginning at the front if x is positive, ending at the tail if it is negative.In an overtake (in which the number to be taken exceeds the number of items), extra items consist of fills; zeros if y is numeric, j: if it is boxed, and spaces otherwise. The fill f is also specified by fit, as in {. !. f . Finally, if $y is 0,s, then the fill items are s$0 . In general, if y is not an atom, x may be a list of length not more than $$y, and if y is an atom, it is replaced by ((#x)$1)$y. Element k produces (k{x){."(($$y)-k) y. The following examples illustrate the use of the dyad take: y=. i. 3 4 y;(2{.y);(5{.y);(_5{.y);(_6{.'abcd');(2 _3{.y) õıııııııııÃıııııııÃıııııııııÃıııııııııÃııııııÃıııııÀ ş0 1 2 3ş0 1 2 3ş0 1 2 3ş0 0 0 0ş abcdş1 2 3ş ş4 5 6 7ş4 5 6 7ş4 5 6 7ş0 0 0 0ş ş5 6 7ş ş8 9 10 11ş ş8 9 10 11ş0 1 2 3ş ş ş ş ş ş0 0 0 0ş4 5 6 7ş ş ş ş ş ş0 0 0 0ş8 9 10 11ş ş ş ÁıııııııııÂıııııııÂıııııııııÂıııııııııÂııııııÂıııııã 6{.'ab';'cde';'fghi' õııÃıııÃııııÃÃÃÀ şabşcdeşfghişşşş ÁııÂıııÂııııÂÂÂã Tail {: _ {: selects the last item of its argument. For example: ]y=. a.{~ (a.i.'A') + i.4 5 ABCDE FGHIJ KLMNO PQRST f=. }: ; {: f y õıııııÃıııııÀ şABCDEşPQRSTş şFGHIJş ş şKLMNOş ş ÁıııııÂıııııã g=. }: ,. @; {: g y õıııııÀ şABCDEş şFGHIJş şKLMNOş Èııııı³ şPQRSTş Áıııııã h=. {. ,. @; }. h y õıııııÀ şABCDEş Èııııı³ şFGHIJş şKLMNOş şPQRSTş Áıııııã ITEM AMEND m } _ _ _ AMEND If m is numeric, and z=. m} y, then $z equals $m, which equals the shape of an item of y, that is, $"_1 y . If i is an atom of m, the corresponding atom of z is the corresponding atom of the item i{y : y=.a.{~(a.i.'A')+i.4 5 m=. 4| i. 5 y ; m ; m}yõıııııÃıııııııııÃıııııÀşABCDEş0 1 2 3 0şAGMSEşşFGHIJş ş şşKLMNOş ş şşPQRSTş ş şÁıııııÂıııııııııÂıııııã If m is not a gerund, x m} y is formed by replacing by x those parts of y selected by m&{. Thus: y ;'%*'(1 3;2 _1)} yõıııııÃıııııÀşABCDEşABCDEşşFGHIJşFGH%JşşKLMNOşKLMN*şşPQRSTşPQRSTşÁıııııÂıııııã$x must be a suffix of $m{y, and x has the same effect as ($m{y)$,x. Thus: y;'think' 1 2} yõıııııÃıııııÀşABCDEşABCDEşşFGHIJşthinkşşKLMNOşthinkşşPQRSTşPQRSTşÁıııııÂıııııã If m is a gerund, one of its elements determines the index argument to the adverb }, and the others modify the arguments x and y: x (v0`v1`v2)} y is (x v0 y) (x v1 y)} (x v2 y) (v0`v1`v2)} y is ( v1 y)} ( v2 y) ( v1`v2)} y is ( v1 y)} ( v2 y) For example, the following functions E1, E2, and E3 interchange two rows of a matrix, multiply a row by a constant, and add a multiple of one row to another: E1=. <@] C. [ [. E2=. f`g`[} [. E3=. F`g`[} f=. {:@]*{.@] { [ [. F=. [:+/(1:,{:@])*(}:@] { [) g=. {.@] M=. i. 4 4 M;(M E1 1 3);(M E2 1 10);(M E3 1 3 10) õıııııııııııÃıııııııııııÃıııııııııııÃıııııııııııııııÀ ş 0 1 2 3ş 0 1 2 3ş 0 1 2 3ş 0 1 2 3ş ş 4 5 6 7ş12 13 14 15ş40 50 60 70ş124 135 146 157ş ş 8 9 10 11ş 8 9 10 11ş 8 9 10 11ş 8 9 10 11ş ş12 13 14 15ş 4 5 6 7ş12 13 14 15ş 12 13 14 15ş ÁıııııııııııÂıııııııııııÂıııııııııııÂıııııııııııııııã ITEM AMEND u } _ _ _ AMEND u } is defined in terms of the noun case m }, the verb u applying to the argument or arguments to provide the numeric indices required by it. For example: x=. 100 + i. 2 4 u=. (*/@$@]) | (5: * i.@$@[) y=. i. 3 2 4 x ; y ; (x u y) ; (x u} y) õıııııııııııııııÃıııııııııııÃııııııııııÃıııııııııııııııÀ ş100 101 102 103ş 0 1 2 3ş 0 5 10 15ş100 105 2 3ş ş104 105 106 107ş 4 5 6 7ş20 1 6 11ş 4 101 106 7ş ş ş ş ş ş ş ş 8 9 10 11ş ş 8 9 102 107ş ş ş12 13 14 15ş ş 12 13 14 103ş ş ş ş ş ş ş ş16 17 18 19ş ş 16 17 18 19ş ş ş20 21 22 23ş ş104 21 22 23ş ÁıııııııııııııııÂıııııııııııÂııııııııııÂıııııııııııııııã The positions selected by x u} y may be made to depend on either or both of the arguments x and y, and related adverbs can be defined for convenient use in common cases. For example: A=. @(i.@$@]) u=. (<0 1)&|: x=. 'DIAG' [y=. a. {~ (a. i. 'a') + i. 4 5 x;y;(x u A y);(x u A} y) õııııÃıııııÃıııııııııÃıııııÀ şDIAGşabcdeş0 6 12 18şDbcdeş ş şfghijş şfIhijş ş şklmnoş şklAnoş ş şpqrstş şpqrGtş ÁııııÂıııııÂıııııııııÂıııııã Also see the case m } for the use of gerunds. .Behead }. _ 1 _ Drop }. drops the leading item of its ar-gument. x }. y drops (at most) |x items from y , dropping from the front if x is positive, and from the tail if it is negative.More generally, x may be a list of not more than r=. $$y elements; the effect of element k is (k{x)á}."(r-k) y.If y is atomic, the result is (0=x)$y. ]y=. a. {~ (a. i. 'A') + i. 4 5 ABCDE FGHIJ KLMNO PQRST f=. }. ; {. f y õıııııÃıııııÀ şFGHIJşABCDEş şKLMNOş ş şPQRSTş ş ÁıııııÂıııııã g=. }. ,. @; {. g y õıııııÀ şFGHIJş şKLMNOş şPQRSTş Èııııı³ şABCDEş Áıııııã (2 }. y) ; (_2 }. y) ; (6 }. y) ; ($ 6 }. y) õıııııÃıııııÃıııııÃıııÀ şKLMNOşABCDEş ş0 5ş şPQRSTşFGHIJş ş ş ÁıııııÂıııııÂıııııÂıııã : Curtail }: _ }:y drops the last item of y, and is equivalent to _1 }. y . Thus: ]y=. a. {~ (a. i. 'A') + i. 4 5 ABCDE FGHIJ KLMNO PQRST f=. }: ; {: f y õıııııÃıııııÀ şABCDEşPQRSTş şFGHIJş ş şKLMNOş ş ÁıııııÂıııııã g=. }: ,. @; {: g y õıııııÀ şABCDEş şFGHIJş şKLMNOş Èııııı³ şPQRSTş Áıııııã h=. {. ,. @; }. h y õıııııÀ şABCDEş Èııııı³ şFGHIJş şKLMNOş şPQRSTş Áıııııã RANK m " n (see next topics) The verb m"n produces the constant result m for each cell to which it applies. The rank used is 3 $&.|. n . For example, if n=.2, the three ranks are 2 2 2, and if n=. 2 3, they are 3 2 3. Thus: v=. 2 3 5 7 m=. i. 2 3 m ; (m"0 v) ; (m"1 v); (m"1 m) õıııııÃıııııÃıııııÃıııııÀ ş0 1 2ş0 1 2ş0 1 2ş0 1 2ş ş3 4 5ş3 4 5ş3 4 5ş3 4 5ş ş ş ş ş ş ş ş0 1 2ş ş0 1 2ş ş ş3 4 5ş ş3 4 5ş ş ş ş ş ş ş ş0 1 2ş ş ş ş ş3 4 5ş ş ş ş ş ş ş ş ş ş0 1 2ş ş ş ş ş3 4 5ş ş ş ÁıııııÂıııııÂıııııÂıııııã v m" 1 2 m 0 1 2 3 4 5 The verbs _9: through 9: are constant verbs, equivalent to _9"_ through 9"_. For example: odds=. 1: + 2: * i. odds 5 1 3 5 7 9 RANK u " n (see adjacent topics) The verb u"n applies u to each cell as specified by the rank n. The full form of the rank used is 3 $&.|. n . For example, if n=.2, the three ranks are 2á2 2, and if n=.2á3, they are 3 2 3. The following examples show uses of the rank conjunction. (] ; , ; ,"2) y=. a. {~ (a.i.'A') + i. 2 3 4 õııııÃııııııııııııııııııııııııÃııııııııııııÀ şABCDşABCDEFGHIJKLMNOPQRSTUVWXşABCDEFGHIJKLş şEFGHş şMNOPQRSTUVWXş şIJKLş ş ş ş ş ş ş şMNOPş ş ş şQRSTş ş ş şUVWXş ş ş ÁııııÂııııııııııııııııııııııııÂııııııııııııã (<"0 ; <"1 ; <@<"2 ; <@<"3) y Boxing of ranks 0, 1, 2, 3 õıııııııııÃııııııııııııııııÃıııııııııııııııÃııııııÀ şõıÃıÃıÃıÀşõııııÃııııÃııııÀşõııııııÃııııııÀşõııııÀş şşAşBşCşDşşşABCDşEFGHşIJKLşşşõııııÀşõııııÀşşşABCDşş şÈıÊıÊıÊı³şÈııııÊııııÊıııı³şşşABCDşşşMNOPşşşşEFGHşş şşEşFşGşHşşşMNOPşQRSTşUVWXşşşşEFGHşşşQRSTşşşşIJKLşş şÈıÊıÊıÊı³şÁııııÂııııÂııııãşşşIJKLşşşUVWXşşşş şş şşIşJşKşLşş şşÁııııãşÁııııãşşşMNOPşş şÁıÂıÂıÂıãş şÁııııııÂııııııãşşQRSTşş ş ş ş şşUVWXşş şõıÃıÃıÃıÀş ş şÁııııãş şşMşNşOşPşş ş ş ş şÈıÊıÊıÊı³ş ş ş ş şşQşRşSşTşş ş ş ş şÈıÊıÊıÊı³ş ş ş ş şşUşVşWşXşş ş ş ş şÁıÂıÂıÂıãş ş ş ş ÁıııııııııÂııııııııııııııııÂıııııııııııııııÂııııııã ('*#' ,"0 1 ' abcde') ; (+/"2 i. 2 3 4) õıııııııÃıııııııııııÀ ş* abcdeş12 15 18 21ş ş# abcdeş48 51 54 57ş ÁıııııııÂıııııııııııã ASSIGN RANK m " v u " v mv lv rv (see previous) The verbs m"v and u"v are equivalent to m"r and u"r, where r is the list of ranks of v. The results may be examined by using the basic characteristics adverb b. to obtain ranks. For example: , b. 0 _ _ _ %. b. 0 2 _ 2 ravel=. , " %. ravel b. 0 2 _ 2 ]y=. a. {~ (a. i. 'A') + i. 2 3 4 ABCD EFGH IJKL MNOP QRST UVWX ,y ABCDEFGHIJKLMNOPQRSTUVWX ravel y ABCDEFGHIJKL MNOPQRSTUVWX Do ". 1 If y is a valid sentence, then ".y executes it. If a=.".y, then a is assigned a noun resulting from the execution; if the result of execution is not a noun, then a is assigned an empty vector. However, any assignments made within the execution are valid. For example: s=. '5 * a=. 3 + i. 6' ". s 15 20 25 30 35 40 a 3 4 5 6 7 8 do=. ". do s 15 20 25 30 35 40 t=. '3 % 5' do t 0.6 do |. t 1.66667 $ do '' 0 ]program=. 'a=. 2^3' ,: '5*a' a=. 2^3 5*a do program 8 40 $ do 'sum=. +/' 0 sum 1 2 3 4 10 Default Format ": _ 1 1 Format ": y is equal to x ": y, where x is chosen to provide a minimum of one space between columns. Default output is identical to this monadic case. For example: ]text=. ": i. 2 50 1 2 3 45 6 7 8 9 $ text2 9 3 + text|domain error| 3 +text '*#' ,"0 1 text*0 1 2 3 4#5 6 7 8 9 ": 'abcd'abcd $ ": ''0 x ": y produces a literal representation of y in a format specified by x. Each element e of x controls the representation of the corresponding element of y as follows:w=. <.|e specifies th e total width allocated; if this space is inadequate, the entire space is filled with asterisks. If w is zero, enough space is allocated.d=.<.10*(|e)-w specifies the num-ber of digits following the decimal point (itself included only if d is not zero).Any negative sign is placed just before the leading digit.If e>:0, the result is right-justified in the space w.If e<0, the result is put in exponential form (with one digit before the decimal point) and is left-justified except for two fixed spac es allowed on the left (including one for a possible negative sign). For example: n ; 6.2 ": n=. % i. 2 4 õııııııııııııııııııııııııııııÃııııııııııııııııııııııııÀ ş _ 1 0.5 0.3333333ş _ 1.00 0.50 0.33ş ş0.25 0.2 0.1666667 0.1428571ş 0.25 0.20 0.17 0.14ş ÁııııııııııııııııııııııııııııÂııııııııııııııııııııııııã (7.2 ": -n) ; (3.2 ": n) õııııııııııııııııııııııııııııÃııııııııııııÀ ş __ _1.00 _0.50 _0.33ş _*********ş ş _0.25 _0.20 _0.17 _0.14ş************ş ÁııııııııııııııııııııııııııııÂııııııııııııã The fit conjunction specifies the number of digits for floating-point numbers. For example: ":!.4 (5%3) 1.667 TIE m`n m`v u`n u`v In English, a gerund is a noun that carries the force of a verb, as does the noun cooking in the art of cooking. The tie applies to two verbs to produce a gerund. Gerunds are commonly used with insert (/) and with agenda (@.): ]g=. +`* õıÃıÀ ş+ş*ş ÁıÂıã (g/1 2 3 4 5) ; (1+2*3+4*5) õııÃııÀ ş47ş47ş ÁııÂııã More generally, tie produces gerunds as follows: u`v is au,av, where au and av are the (boxed noun) atomic representations of u and v. Moreover, m`n is m,n and m`v is m,av and u`n is au,n. See Bernecky and Hui [13]. Gerunds may also be produced directly by boxing. Thus: ]h=. '+' ; '*' õıÃıÀ ş+ş*ş ÁıÂıã h/1 2 3 4 5 47 The atomic representation of a noun (used so as to distinguish a noun such as '+' from the verb +) is given by the following function: (ar=. [: < (,'0')"_ ; ]) '+' õıııııÀ şõıÃıÀş şş0ş+şş şÁıÂıãş Áıııııã *`(ar '+') õıÃıııııÀ ş*şõıÃıÀş ş şş0ş+şş ş şÁıÂıãş ÁıÂıııııã EVOKE GERUND m `: n _ _ _ This adverb is defined for three cases:m `: 0 Append Appends the results of the individual verbs; the ranks are the maxima over their ranks. Equivalent to m/.m `: 3 Insert Inserts verbs between items. Equivalent to m/m `: 6 Train Result is the train of individual verbs. Equivalent to m\ For example: <+:`-:`% `: 0 a=. 1 2 3 4 5 õııııııııııııııııııııııııııÀ ş 2 4 6 8 10ş ş0.5 1 1.5 2 2.5ş ş 1 0.5 0.3333333 0.25 0.2ş Áııııııııııııııııııııııııııã (+ b.0);( %. b.0);(+`%.`:0 b.0) õıııııÃıııııÃıııııÀ ş_ 0 0ş2 _ 2ş_ _ _ş ÁıııııÂıııııÂıııııã (+`* `:3 a);(+`*/a);(1+2*3+4*5) õııÃııÃııÀ ş47ş47ş47ş ÁııÂııÂııã (+`*`- `: 6 a) ; (+`*`- \ a) õııııııııııııııııÃııııııııııııııııÀ ş_1 _4 _9 _16 _25ş_1 _4 _9 _16 _25ş ÁııııııııııııııııÂııııııııııııııııã ATOP u @ v mv lv rv u@v y is u v y. For example, +:@- 7 is _14 (double the negation). Moreover, the monadic uses of u@v and u&v are equivalent . x u@v y is u x v y. For example,3 +:@- 7 is _8 (double the difference). Because adverbs and conjunctions are (as stated more precisely in Section II E) executed before verbs, phrases involving them are commonly used in trains without parentheses. For example: mean=. +/ % # mean 1 2 3 4 2.5 f=. +:@*: +/ -:@%: Addition table of doubled square and f 1 2 3 4 halved square root 2.5 2.70711 2.86603 3 8.5 8.70711 8.86603 9 18.5 18.7071 18.866 19 32.5 32.7071 32.866 33 Because a conjunction applies to the entity immediately to its right, expressions to the right of conjunctions commonly require parenthesization. For example: g=. *:@(+/) h=. *:@+/ g 1 2 3 4 100 h 1 2 3 4 6770404 k=. *:@+ k/1 2 3 4 6770404 Compare the behaviour of @ with that of @:. They differ only in the ranks of the verbs that they produce. AGENDA m @. n m @. v mv lv rv m@.n is a verb defined by the gerund m with an agenda specified by n; that is, the verb represented by the train selected from m by the indices n. If n is boxed, the train is parenthesized accordingly. The case m@.v uses the result of the verb v to perform the selection. For example: dorh=. +: ` -: @. (]>9:) Double or halve (Case statement) dorh " 0 primes=. 2 3 5 7 11 13 17 19 4 6 10 14 5.5 6.5 8.5 9.5 _:`%:`*: @. * "0 a=. 2 1 0 _1 _2 1.41421 1 _ 1 4 g=. +`-`* [. x=. 1 2 3 [ y=. 6 5 4 (x g@.2: y) 6 10 12 (] * <:) y=. 5 4 3 2 1 0 Basis of factorial 20 12 6 2 0 0 1:`(] * <:) @. (1: < ]) "0 y Case statement 20 12 6 2 1 1 1:`(] * $:@<:)@.(1: < ])"0 y Self-reference for recursion 120 24 6 2 1 1 +`-`*`% @. (1 0 3;2 0) (- + %) (* +) 3 +`-`*`% @. (1 0 3;2 0) 4 _12.8125 all=. b <@(<;.1) ] b=. 1:,.[:#:[:i. 2&^@<:@# all 0 1 2 õıııııııÃıııııııÃıııııııÃıııııııÀ şõıııııÀşõıııÃıÀşõıÃıııÀşõıÃıÃıÀş şş0 1 2şşş0 1ş2şşş0ş1 2şşş0ş1ş2şş şÁıııııãşÁıııÂıãşÁıÂıııãşÁıÂıÂıãş ÁıııııııÂıııııııÂıııııııÂıııııııã all +`-`* õıııııııııÃıııııııııııÃıııııııııııÃıııııııııııııÀ şõıııııııÀşõıııııÃıııÀşõıııÃıııııÀşõıııÃıııÃıııÀş şşõıÃıÃıÀşşşõıÃıÀşõıÀşşşõıÀşõıÃıÀşşşõıÀşõıÀşõıÀşş şşş+ş-ş*şşşşş+ş-şşş*şşşşş+şşş-ş*şşşşş+şşş-şşş*şşş şşÁıÂıÂıãşşşÁıÂıãşÁıãşşşÁıãşÁıÂıãşşşÁıãşÁıãşÁıãşş şÁıııııııãşÁıııııÂıııãşÁıııÂıııııãşÁıııÂıııÂıııãş ÁıııııııııÂıııııııııııÂıııııııııııÂıııııııııııııã AT u @: v _ _ _ @: is equivalent to @ except that ranks are infinite. For example: x=. 1 2 3 4 y=. 7 5 3 2 x */ @: + y Applies product over sums to the entire lists 2016 x */ @ + y Applies product over sums to each item of the list 8 7 6 6 + b. 0 _ 0 0 */ @: + b. 0 _ _ _ */ @ + b. 0 _ 0 0 BOND m & v u & n _ (see next topic) m&v y is defined as m v y; in other words, the left argument m is bonded with the dyad v to produce a monadic function. For example: 10&^. 2 3 10 100 200 0.30103 0.477121 1 2 2.30103 sine=. 1&o. sine o. 0 0.25 0.5 1.5 2 0 0.707107 1 _1 0 Similarly, u&n y is defined as y u n; in other words, as the dyad u provided with the right argument n to produce a monadic function (that is, a function whose dyadic case has an empty domain). For example: ^&3 (1 2 3 4 5) 1 8 27 64 125 ^&2 3"0 (1 2 3 4 5) 1 1 4 8 9 27 16 64 25 125 Use of the bond conjunction is often called Currying in honour of Haskell Curry. COMPOSE u & v mv lv rv (see previous) u&v y is u v y. Thus, +:&- 7 is _14 (double the negation). Moreover, the monadic uses of u&v and u@v are equivalent . x u&v y is (v x) u (v y).For example, 3 +&! 4 is 30, the sum of factorials. The monadic case is equivalent to the composition used in mathematics, but the dyadic case opens up other possibilities. For example: 3 +&^. 4 Sum of natural logarithms 2.48491 ^ 3 +&^. 4 Multiplication using natural logs 12 3 +&(10&^.) 4 Sum of base ten logarithms 1.07918 10 ^ 3 +&(10&^.) 4 Multiplication using base ten logs 12 3 +&.^. 4 See the related conjunction under (&.). 12 3 +&.(10&^.) 4 12 Compare the behaviour of & with that of &:. They differ only in the ranks of the verbs that they produce. UNDER u &. v mv mv mv The verb u &.v is equivalent to the composition u & v except that the verb obverse to v is applied to the result for each cell. The obverse is normally the inverse, as discussed more fully under the power conjunction ^: . For example: 3 + &. ^. 4 Inverse of natural log is the exponential 12 (^. ^: _1) 3 + & ^. 4 12 ( An adverb (<|. &. > b),(<|. each b) Reversal under open õıııııııııııııııııııııÃıııııııııııııııııııııÀ şõıııııÃıııııııÃıııııÀşõıııııÃıııııııÃıııııÀş şş3 2 1ş7 5 3 2şedcbaşşş3 2 1ş7 5 3 2şedcbaşş şÁıııııÂıııııııÂıııııãşÁıııııÂıııııııÂıııııãş ÁıııııııııııııııııııııÂıııııııııııııııııııııã In mathematics, certain cases of under are called dual or, dual with respect to: f=. +. &. -. Dual with respect to boolean negation f"0/~ d=. 0 1 0 0 0 1 D=. (&. -.) ("0) The adverb dual with respect to negation (+.D/~d);(*./~d);(=D/~d);(~:/~d) õıııÃıııÃıııÃıııÀ ş0 0ş0 0ş0 1ş0 1ş ş0 1ş0 1ş1 0ş1 0ş ÁıııÂıııÂıııÂıııã DWL=. (&. ^.) ("0) Dual with respect to natural logarithm DAN=. (&. -) ("0) Dual with respect to arithmetic negation (3 + DWL 4),(3*4),(3 <. DAN 4) , (3 >. 4) 12 12 4 4 Min and max are duals with respect to arithmetic negation APPOSE u &: v _ _ _ &: is equivalent to & except that the ranks of the resulting function are infinite; the relation is similar to that between @: and @ . For example: a=. 'abcd' ; 'efgh' b=. 'ABCD' ; 'EFGH' a ,&:> b abcd efgh ABCD EFGH a ,&> b abcdABCD efghEFGH > b. 0 0 0 0 , & > b. 0 0 0 0 , &: > b. 0 _ _ _ Roll ? _ 0 0 Deal ? y yields a uniform random selection from the population i. y. x ? y is a list of x items randomly chosen without repetition from i.y. For example: ?6 0 ?6 6 6 6 6 6 6 6 4 2 3 1 0 4 4 5 6 ? 6 A random permutation 3 2 0 4 1 5 mean=. +/ % # mean ? 1000 # 6 2.503 mean ? 1000 # 6 2.522 m=. ? 4 4 $ 9 A random matrix for experimentation m 7 4 6 1 2 0 3 7 8 5 5 5 8 6 1 4 -/ . * m _93 f=. ?@$ % ] - 1: <3 6 f 9 Random 3 by 6 table in range zero to one with resolution 9 õıııııııııııııııııııııııııııııııÀ ş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&": (format ,.y);(format +. r.y);(format +. 2 r.y) õııııııııÃııııııııııııııııÃııııııııııııııııÀ ş 0.000ş 1.000 0.000ş 2.000 0.000ş ş 0.785ş 0.707 0.707ş 1.414 1.414ş ş 1.571ş 0.000 1.000ş 0.000 2.000ş ş 2.356ş _0.707 0.707ş _1.414 1.414ş ş 3.142ş _1.000 0.000ş _2.000 0.000ş ş 3.927ş _0.707 _0.707ş _1.414 _1.414ş ş 4.712ş 0.000 _1.000ş 0.000 _2.000ş ÁııııııııÂııııııııııııııııÂııııııııııııııııã TAYLOR COEFFICIENT u t. 0 0 0 u t. y is the yth coefficient in the Taylor series approximation to the function u. The domain of the adverb t. is the same as the left domain of the derivative D. x u t.y is the product of (x^y) and u t. y . For example: f=. 1 2 1&p. [. g=. 1 3 3 1&p. x=. 10%~i=. i.8 ]c=. (f*g) t. i 1 5 10 10 5 1 0 0 6.2 ":(c p. x),:(f*g) x 1.00 1.61 2.49 3.71 5.38 7.59 10.49 14.20 1.00 1.61 2.49 3.71 5.38 7.59 10.49 14.20 (c p. x)=(f*g) x 1 1 1 1 1 1 1 1 ]d=. f@g t. i 4 12 21 22 15 6 1 0 (d p. x)=(f g x) 1 1 1 1 1 1 1 1 sin=. 1&o. [. cos=. 2&o. 8.4":t=. (^ t. i),(sin t. i),:(cos t. i) 1.0000 1.0000 0.5000 0.1667 0.0417 0.0083 0.0014 0.0002 0.0000 1.0000 0.0000 _0.1667 0.0000 0.0083 0.0000 _0.0002 1.0000 0.0000 _0.5000 0.0000 0.0417 0.0000 _0.0014 0.0000 * t 1 1 1 1 1 1 1 1 0 1 0 _1 0 1 0 _1 1 0 _1 0 1 0 _1 0 ((sin*sin)+(cos*cos)) t. i 1 0 0 0 _2.71051e_20 0 0 0 8.4": (^ t. i),:(1r2 t. i) 1.0000 1.0000 0.5000 0.1667 0.0417 0.0083 0.0014 0.0002 1.0000 0.5000 0.1250 0.0208 0.0026 0.0003 0.0000 0.0000 TAYLOR APPROXIMATION u T. n u T. n is the n-term Taylor approximation to the function u. For example: 6.2 ": ^ T. 8 x=. 2 %~ i.8 1.00 1.65 2.72 4.48 7.38 12.13 19.85 32.23 6.2 ": ^ x 1.00 1.65 2.72 4.48 7.39 12.18 20.09 33.12 ^ T. _ õııııııııııııııııııııııııııııııııııııııııııııııııııııÃıÃıÀ şõıÃıÃııııııııııııııııııııııııııııııııııııııııııııııÀş"ş0ş şş3ş:şg +:^:(g ~: g@+:)^:_ ] 1 [. g=.p.&y.@(^ t.)@i.şş ş ş şÁıÂıÂııııııııııııııııııııııııııııııııııııııııııııııãş ş ş ÁııııııııııııııııııııııııııııııııııııııııııııııııııııÂıÂıã (^ = ^T._) i. 5 1 1 1 1 1 Compare the Taylor coefficient conjunction T. with the Taylor coefficient adverb t. . LEFT ARGUMENT x. x. denotes the left argument in an explicit definition, using the conjunction:. Since x. and y. may also be used as ordinary names, they may be used in experiments leading up to an explicit definition. For example: x.=. 3 [ y.=. 7 x.*y.-x. 12 text=. 'x.*y.-x.' do=. ". do text 12 f=. 3 : 0 : x.*y.-x. ) 3 f 7 12 10 f 17 70 RIGHT ARGUMENT y. y. denotes the right argument in an explicit definition, using the conjunction :. Since x. and y. may also be used as ordinary names, they may be used in experiments leading up to an explicit definition. For example: x.=. 3 [ y.=. 7 x.*y.-x. 12 text=. 'x.*y.-x.' do=. ". do text 12 f=. 3 : (':';text) 3 f 7 12 10 f 17 70 CONSTANT FUNCTIONS _9: to 9: _ _ _ The results are _9 and _8 and _7 and so on to 9. For example: x=. 1 2 3 [ y=. 4 5 6 2: y 2 x 9: y 9 The rank conjunction " applies to any noun to make a constant function of specified rank. The particular constant functions illustrated above are therefore special cases of the form i"_ . For example: 2"_ y 2 2"0 y 2 2 2 2"1 i. 2 3 4 2 2 2 2 2 2 2p1"0 y 6.28319 6.28319 6.28319 1p1 1p_1 1x1"0 y A constant function with a vector result 3.14159 0.3183099 2.71828 3.14159 0.3183099 2.71828 3.14159 0.3183099 2.71828 0 0 0"1 y The zero vector in a space of three dimensions 0 0 0 CONSTANTS The form of a numeric constant defined and illustrated in Part I is elaborated by the use of further letters, as in 2r3 for two-thirds, 2p1 for two pi, and 2r3p1 for two-thirds pi. The complete scheme of numeric constants obeys the following hierarchy : . The decimal point is obeyed first _ The negative sign is obeyed next e Exponential (scientific) notation r Rational number ad ar j Complex (magnitude and angle) in degrees or radians ; Complex number p x Numbers based on pi (o.1) and on Eulers number (the exponential ^1) b Base value (using a to z for 10 to 35) For example, 2.3 denotes two and three-tenths and _2.3 denotes its negation; but _2j3 denotes a complex number with real part _2 and imaginary part 3, not the negation of the complex number 2j3. Furthermore, symbols at the same level of the hierarchy cannot be used together: 1p2x3 is an ill-formed number. The following lists illustrate the main points: 2.3e2 2.3e_2 2j3 2r3 230 0.023 2j3 0.666667 2p1 1r2p1 1r4p1 1p_1 6.28319 1.5708 0.785398 0.31831 1x2 2x1 1x_1 7.38906 5.43656 0.367879 2e2r4j2e2r2 2e2r4j2e2r2p1 2ad45 2ar0.785398 50j100 157.08j314.159 1.41421j1.41421 1.41421j1.41421 16b1f 10b23 _10b23 1r10b23 1e2b23 2b111.111 31 23 _17 3.2 203 7.875 Negative integers following p and x indicate the use of reciprocals. For example, 2p_2 is two divided by pi squared, and 2x_2 is two divided by the square of Eulers number. REFERENCES 1. Falkoff, A. D., and K. E. Iverson, The Design of APL, IBM Journal of R&D, July, 1973. 2. " , The Evolution of APL, ACM Sigplan Notices, August 1978. 3. Iverson, K.E., A Dictionary of APL, ACM APL Quote-Quad, September, 1987. 4. McIntyre, D.B., Language as an Intellectual Tool: From Hieroglyphics to APL, IBM Systems Journal, December, 1991. 5. Iverson, K.E., A Personal View of APL, IBM Systems Journal, December, 1991. 6. Hui, R.K.W., An Implementation of J, ISI, 1992. 7. Burke, C. J User Manual, ISI, 1994. 8. Iverson, K.E., Tangible Math, ISI, 1991 9. " , Arithmetic, ISI, 1991 10. " , Calculus, ISI, 1994 11. McDonnell, E.E., Complex Floor, APL73, ACM 12. McDonnell, E.E., Zero Divided by Zero, APL76, ACM 13. Bernecky, Robert, and R.K.W. Hui, Gerunds and Representations, APL91, ACM ACKNOWLEDGMENTS I am indebted to Roger Hui for his rapid development of a flexible, reliable, and highly portable implementation of J, for his close collaboration in the design of the language, for critical reading of successive drafts of the dictionary, and for significant contributions to the treatments of certain topics, in particular, the identity functions. I am also indebted to Eric Iverson for the design and implementation of locatives, control structures, and the Windows interface. Copyright Author: Kenneth E. Iverson J Introduction and Dictionary Copyright 1991 - 1995 All Right Reserved Iverson Software Inc. 33 Major Street Toronto, Ontario Canada M5S 2K9 ISBN 1-895721-08-3 Foreign Conjunction The conjunction !: applies to integer scalar left and right arguments to produce verbs, with the exception that the case 5!:0 produces an adverb. These verbs behave like any other verb: they may be assigned names, may serve as arguments to adverbs and conjunctions, and must be used with an argument even though (as in 6!:0 '') it may have no significance. Where these verbs take names as arguments, the names are boxed, as in 4!:55 'a';'bc' to erase the names a and bc. A bracketed left argument indicates that it is optional. 0 Scripts 1 Files 2 Host 3 Storage Types 4 Name Classes and Lists 5 Representations 6 Time 7 Space 8 Screens, Fonts and Edit 9 Global Parameters 11 Window Driver 13 Debug 14 Data Driver 15 Dynamic Link Library 128 Numerical Functions 0 Scripts [x] 0!:k y The script y is executed according to the digits (zero or one) in the 3-digit decimal representation of k, and the resulting execution log is appended to the file named x (if specified): 1st digit 2nd digit 3rd digit 0 From file or noun Stop on error Silent 1 From noun Continue on error Display For example, 0!:111 abc executes the noun abc, completes, and displays. If y is 1, input is from the keyboard: (<'f2')0!:1(1) files the execution log in f2. [x] 0!:2 y tests a script that is expected to be a sequence of tautologies; it is like 0!:1, but stops if any result is other than all 1s. Sessions begin with (silent, stop) execution of 0!:0<'profile.js' 1 Files Except as otherwise noted, a file may be specified by a name (such as <'sub\abc.q') or by an integer file number obtained from open ( 1!:21á<'sub\abc.q'). 1!:0 y Directory. y is a string of the path search expression (a boxed string is also accepted); the result is a 5-column table of the file name, modification time, size, permission, and attributes, individually boxed. For example, try 1!:0 '*.*'. The permission and attribute columns are system dependent. For example, in DOS and Windows: 1!:0 'jsm.exe' õıııııııÃııııııııııııııııııÃııııÃıııÃııııııÀ şjsm.exeş1994 10 31 3 57 46ş3125şrwxş-----aş ÁıııııııÂııııııııııııııııııÂııııÂıııÂııııııã Permission is a 3-letter string indicating the read, write, and execute permissions. Attributes is a 6-letter string indicating read-only, hidden, system, volume label, directory, and archive. 1!:1 y Read. y is a file name, file number, or the number 1 (indicating the keyboard); the result is a string of the file contents. For example, try 1!:1 <'abc.q' x 1!:2 y Write. x is a string of the new contents of the file; y is a file name, or number, or the number 2 for screen output x 1!:3 y Append. like x 1!:2 y, but appends rather than replaces 1!:4 y Size 1!:5 y Create directory: y is a (boxed) directory name [x] 1!:6 y Query/Set Attributes [x] 1!:7 y Query/Set Permissions 1!:11 y Indexed Read. y is a list of a boxed file name (or number) and a boxed index and length. The index may be negative. If the length is elided, the read goes to the end. For example: 1!:11 'abc.x';1000 20 f=. 1!:21 <'abc.x' 1!:11 f,1000 20 x 1!:12 y Indexed Write. Like indexed read; x specifies the string to be written 1!:20 y File Numbers and Names. A 2-column table of the open file numbers and names. (The argument y is required but ignored) 1!:21 y Open. Open file named y, creating it if necessary; the result is a file number 1!:22 y Close. Close file named or numbered y. Any locks are released 1!:30 y Locks. A 3-column integer table of the file number, index, and length of file locks. The argument y is required but ignored 1!:31 y Lock. y is a 3-element integer vector of the file number, index, and length of the file region to be locked; the result is 1 if the request succeeded, and 0 if it did notá 1!:32 y Unlock. y is a 3-element integer vector of the file number, index, and length of the file region to be unlocked 1!:55 y Erase File/Directory. e.g., 1!:55<'careful' 2 Host Commands 2!:0 y Host. The list y is executed by the host system, and the result is returned. For example, 2!:0 'dir *.exe' . Not available for Windows or Macintosh 2!:1 y Spawn. Like 2!:0, but yields '' without waiting for the host to finish. Any output is ignored. For example, 2!:1 can be used to invoke a text-editor. Not available for Windows or Macintosh 2!:55 y Terminate session. y is an integer return code 3 Storage Types 3!:0 y Type. Type of the noun y, encoded as 2^i.6 for boolean, literal, integer, floating, complex, boxed 3!:1 y Convert to binary representation. A string of the binary representation of a noun y. The result is machine-dependent 3!:2 y Convert from binary representation. Inverse of 3!:1 and of 3!:3 3!:3 y Hex representation. Like 3!:1, but the result is a literal matrix of the hexadecimal representation 3!:4 y If ic=. 3!:4 (integer conversion) and fc=. 3!:5 3!:5 y (floating conversion), then: 2 ic y is J integers to binary long integers _2 ic y binary long integers to J integers 1 ic y J integers to binary short integers _1 ic y binary short integers to J integers 0 ic y binary unsigned short integers to J integers 2 fc y is J floats to binary doubles _2 fc y binary doubles to J floats 1 fc y J floats to binary short floats _1 fc y binary short floats to J floats All ranks are infinite and all inverses of k&ic and k&fc exist 4 Name Classes and Lists 4!:0 y Class. Class of (boxed) name: _2 if unused, _1 if not valid, and 0 to 3 for noun, adverb, conjunction, verb, and 6 for locale [x] 4!:1 y List. Result is a vector of boxed names belonging to the classes 0 to 3 as defined under 4!:0. The optional left argument lists the initial letters of names to be included 4!:3 y Scripts. List of script names that have been invoked using 0!: (The argument y is required but ignored) 4!:4 y Script Index. Index (in 4!:3 '') of script that defined y 4!:55 y Erase 5 Representatons 5!:1 <'y' yields the atomic (or gerundial) representation of any named entity. The result is a single box containing a one- or two-element list of boxed characters (that may be further boxed). For example: 5!:1 <'n' [. f=. +/ . * [. n=. 1 2 3 õıııııııııÀ şõıÃıııııÀş şş0ş1 2 3şş şÁıÂıııııãş Áıııııııııã 5!:1 <'f' õıııııııııııııııÀ şõıÃıııııııııııÀş şş.şõıııııııÃıÀşş şş şşõıÃıııÀş*şşş şş şşş/şõıÀşş şşş şş şşş şş+şşş şşş şş şşş şÁıãşş şşş şş şşÁıÂıııãş şşş şş şÁıııııııÂıãşş şÁıÂıııııııııııãş Áıııııııııııııııã The atomic representation is used in the representation of gerunds, and three further representations, 5!:2 (Boxed), 5!:4 (Tree), and 5!:5 (Linear) are also based upon it. The structures of all may be best appreciated from the tree form (which uses the box-drawing characters controlled by 9!:6 and 9!:7). For example: 5!:4 <'nub' [. nub=. (i.@# = i.~) # ] õı i. õı @ ıÂı # õıııÊı = ş Áı ~ ııı i. ııÊı # Áı ] The linear representation is a string which, when interpreted, produces the named object. For example: 5!:5 <'a' [ a=. o. i. 3 4 3.14159265358979324*i.3 4 For all but the noun case, the default displays established by 9!:3 provide convenient experimentation with all representations. For example: 9!:3 (5 4 2 1) cube=. ^&3 cube ^&3 õı ^ ıı & ıÂı 3 õıÃıÃıÀ ş^ş&ş3ş ÁıÂıÂıã õıııııııııııııÀ şõıÃıııııııııÀş şş&şõıÃıııııÀşş şş şş^şõıÃıÀşşş şş şş şş0ş3şşşş şş şş şÁıÂıãşşş şş şÁıÂıııııãşş şÁıÂıııııııııãş Áıııııııııııııã 6 Time 6!:0 y Current. in order YMDHMS (with fractional seconds). 6!:1 y Session. Seconds since start of session [x] 6!:2 y Execute. Seconds to execute sentence y (mean of x times with default once) 6!:3 y Delay . for y seconds. For example, 6!:3 (60) 7 Space 7!:0 y Current. Amount of space currently in use 7!:1 y Session. Maximum space used since start of session 7!:2 y Execute. Space required to execute sentence y 8 Screens, Fonts and Edit 8!:0 y Mode. Query CGA (Except as noted, 8!: is only for PCs) 8!:1 y Mode. Set non-CGA if y=.0; CGA if 1 8!:4 y Query Screen: Query screen attributes; a 4 by 2 table of values 0 to 15 interpreted (as in DOS) as follows: Input area backgroundOutput area backgroundCursor bar backgroundStatus line background Input area foregroundOutput area foregroundCursor bar foregroundStatus line foreground 0 Black 4 Red1 Blue 5 Magenta2 Green 6 Yellow3 Cyan 7 White8+i Bright (backgd) Flashing (foregd) 8!:5 y Set Screen Attributes 8!:7 y Refresh Screen 8!:9 y Edit: Applies editor to y, a string with lines delimited by the line-feed (10{a.). Press F1 for help 8!:16 y Query Font attributes. (MAC only) 8!:17 y Set Font attributes. (MAC only). Attributes are a 3-element integer list of the Font number, Style (a sum of one or more of 1 : Bold, 2 : Italic, 4 : Underline, 8á:áOutline), and Size. Font attributes may also be set by Font, under the Edit menu 8!:19 y Print screen (MAC only) 9 Global Parameters Query Set 9!:0 y Random Seed 9!:1 y 9!:2 y Default displays (See 5!:n) 9!:3 y 9!:4 y Input prompt 9!:5 y 9!:6 y Box-drawing characters 9!:7 y Default values for the box-drawing characters are: õ à ÀÈ Ê ³Á  ã | (For PC) +++++++++|- (For others) 9!:8 y Error messages 9!:9 y For example, replace English messages (default) by French. 9!:10 y Print Precision 9!:11 y 11 Window Driver See J User Manual 11!:0 y Window driver 13 Debug See º I of Part II of Dictionary 13!:0 Reset. Reset stack and disable (0) or enable (1) suspension 13!:1 Display stack 13!:2 Stop query 13!:3 Stop set 13!:4 Run again 13!:5 Run next 13!:6 Exit and return 13!:7 Continue at line number specified by argument 14 Data Driver See J User Manual 14!:0 y Source names 14!:1 y Disconnect 14!:2 y SQL 14!:3 y Fetch 14!:4 y Columns 14!:5 y Column names 14!:6 y Source names 14!:7 y Select 14!:8 y End 14!:9 y Error 14!:10 y Transaction begin 14!:11 y Commit transaction 14!:12 y Roll back transaction 14!:13 y Table 15 Dynamic Link Library See J User Manual x 15!:0 y Call DLL function. 15!:1 y Memory read x 15!:2 y Memory write 15!:3 y Allocate memory 15!:4 y Free memory 128 Numerical Functions 128!:0 y QR decomposition of a complex matrix y in the domain of matrix inverse (%.). The result is an Hermitian matrix and a square upper triangular matrix, individually boxed 128!:1 y Invert square upper-triangular matrix