J Introduction and Dictionary
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


Introduction
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.


Mnemonics
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

   	a<b

   	a>b

   	(a<b)+(a>b)

   	(a<b)+.(a>b)

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.


Ambivalence
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


Verb and Adverbs
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 </ b

ÚÄÂÄÄÄÄÄÄÄ¿	ÚÄÂÄÄÄÄÄÄÄ¿

³ ³0 1 2 3³	³ ³0 1 2 3³

ÃÄÅÄÄÄÄÄÄÄ´	ÃÄÅÄÄÄÄÄÄÄ´

³2³2 3 4 5³	³0³0 1 2 3³

³3³3 4 5 6³	³1³1 2 3 4³

³5³5 6 7 8³	³2³2 3 4 5³

ÀÄÁÄÄÄÄÄÄÄÙ	³3³3 4 5 6³

ÀÄÁÄÄÄÄÄÄÄÙ

Due to its two uses, the adverb / is called either insert or table.

Exercises:

4.1	Enter d=. i.5 and the sentences st=. d-/d and pt=. d^/d to produce function tables for subtraction and power.

4.2	Make tables for further functions from previous lessons, including the relations < and = and > 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.


Punctuation
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


Forks
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

0 0 0 1 1 1

a=b

0 0 1 0 0 0

a (<: = < +. =) b	A tautology (<: is less than

1 1 1 1 1 1	or equal)

2 ([: ^ -) 0 1 2	Cap yields monadic case

7.38906 2.71828 1

Exercises:

6.1	Enter 5#3 and similar expressions to determine the definition of the dyad # and then state the meaning of the following sentence:

 	(# # >./) 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.


Programs
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


Bond Conjunction
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.


Atop Conjunction
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=.{&' *'@(</)	Map of comparison (dyad)

k=. i. h i.	Map  (monad)

map=. {&'+-* %#$'	7-character map

MAP=. map@(6&<.)@<.	Extended domain of map

add=. MAP@ (i.+/i.)	Addition table map


Vocabulary
10:  VOCABULARY

Memorizing lists of words is a tedious and ineffectual way to learn a language, and better techniques should be employed:

A) Conversation with a laconic native speaker, that is, one that allows you to do most of the talking.

B) Reading material of interest in its own right.

C) Learning how to use dictionaries and grammars so as to become independent of teachers.

D) Attempting to write on any topic of interest in itself.

E) Paying attention to the structure of words so that known words will provide clues to the unknown. For example, program (already analyzed) is related to tele (far off) gram, which is in turn related to telephone. Even tiny words may possess informative structure: atom means not cuttable, from a  (not) and tom (as in tome and microtome).

In the case of J:

A) The computer provides for precise and general conversation.

B) Texts such as Tangible Math [7] and Arithmetic [8] use the language in a variety of topics.

C) The appended dictionary of J provides a complete and concise dictionary and grammar.

D) Programming in J [6] provides guidance in writing programs, and almost any topic provides problems of a wide range of difficulty.

E) Words possess considerable structure, as in +: and -: and *: and %: for double, halve, square, and  square root. Moreover,  a  beginner  can  assign  and  use  mnemonic  names appropriate  to  any  native  language,  as  in  sqrt=. %: and entier=.<. (French name) and sin=.1&o. and SIN=.1&o.@(%&180@o.)
(for sine in degrees).

We will hereafter introduce and use new primitives with little or no discussion, assuming that the reader will experiment with them on the computer, consult the dictionary to determine their meanings, or perhaps infer their meanings from their structure. For example, the appearance of the word o. suggests a circle; it was used dyadically above to define the sine (one of the circular functions), and monadically for the function pi times, that is, the circumference of a circle when applied to its diameter.

For precise oral communication it may be best to use the names (or abbreviations) of the symbols themselves, as in:

<	Left a (angle)	/	Slash	&	Amp (ersand)	%	Per( cent)

[	Left b (racket)	\	Back (slash)	@	At	;	Semi (colon)

{	Left c (urly bracket)	|	Stile	^	Caret	~	Tilde

(	Left p (arenthesis)	_	(under) Bar	`	Grave	*	Star

Exercises:

10.1 Experiment with a revised version of the program MAP of Exercise 9.1, using the remainder or residue dyad (|) instead of the minimum (<.), as in M=. map@(6&|)@<. and compare its results with those of MAP.

10.2 Experiment with the programs sin and SIN defined in this lesson.

10.3 Write programs using various new primitives found in the vocabulary at the end of the book.

10.4 Update the table of notation prepared in Exercise 3.2.


Housekeeping
11:  HOUSEKEEPING

In an extended session it may be difficult to remember the names assigned to verbs and nouns; the foreign conjunction !: (detailed in the appendix) provides facilities for displaying and erasing them. For example:

b=. 3* a=. i. 6

sum=. +/

tri=. sum\ a

names=. 4!:1

names 0	   names 3

ÚÄÂÄÂÄÄÄ¿	ÚÄÄÄÄÄÂÄÄÄ¿

³a³b³tri³	³names³sum³

ÀÄÁÄÁÄÄÄÙ	ÀÄÄÄÄÄÁÄÄÄÙ

erase=. 4!:55

erase <'tri'

1

names 0 3

ÚÄÂÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄ¿

³a³b³erase³names³sum³

ÀÄÁÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÙ

erase names 0

1 1

names 0 3

ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄ¿

³erase³names³sum³

ÀÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÙ

It is also useful to be able to save a record of a session in a file so that all results can be reconstituted. Thus:

'abc' 0!:2&< ''   	NB. To file abc from keyboard

sum=. +/

sum b=. 2 3 4

9

0!:2&< ''        	NB. Discontinue recording

(erase=. 4!:55) (names=. 4!:1) 0 3

1 1 1 1

0!:2&< 'abc'      	NB. Execute the script file abc

sum=. +/

sum b=. 2 3 4

9

Exercises:

11.1 Enter and experiment with the programs defined in this lesson.


Power and Inverse
12:  POWER AND INVERSE

The power conjunction (^:) is analogous to the power function (^ ). For example:

]a=. 10^ b=. i.5

1 10 100 1000 10000

b

0 1 2 3 4

%:a

1 3.16228 10 31.6228 100

%: %: a

1 1.77828 3.16228 5.62341 10

%: ^: 2 a

1 1.77828 3.16228 5.62341 10

%: ^: 3 a

1 1.33352 1.77828 2.37137 3.16228

%: ^: b a

1      10     100    1000   10000

1 3.16228      10 31.6228     100

1 1.77828 3.16228 5.62341      10

1 1.33352 1.77828 2.37137 3.16228

1 1.15478 1.33352 1.53993 1.77828

(cos=. 2&o.) ^: b d=.1

1 0.540302 0.857553 0.65429 0.79348

] y=. cos ^: _ d

0.739085

y=cos y

1

Successive applications of cos appear to be converging to a limiting value; the infinite power (cos ^: _) yields this limit.

A right argument of _1  produces the inverse function. Thus:

%: ^: _1 b

0 1 4 9 16

*: b

0 1 4 9 16

%: ^: (-b) b

0	1     2         3         4

0	1     4         9        16

0	1    16        81       256

0	1   256      6561     65536

0	1 65536 4.30467e7 4.29497e9

Exercises:

12.1 The square function *: is the inverse of the square root function %: and %:^:_1 is therefore equivalent to *: . Look for, and experiment with, other inverse pairs among the primitive functions in the Vocabulary.


Reading and Writing
13:  READING AND WRITING

Cover the right side of the page and make a serious attempt to translate the sentences on the left to English; that is, state succinctly in English what the verb defined by each sentence does. Use any available aids, including the dictionary and experimentation on the computer:

f1=. <:                	Decrement (monad); Less or equal

f2=. f1&9	Less or equal 9

f3=. f2 *. >:&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 .


Format
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


Partitions
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

</. t	    	161051

ÚÄÂÄÄÄÂÄÄÄÄÄÂÄÄÄÂÄ¿

³1³3 2³3 6 1³6 3³3³

ÀÄÁÄÄÄÁÄÄÄÄÄÁÄÄÄÁÄÙ

Exercises:

15.1 Define programs analogous to sum=.+/\ for progressive products, progressive maxima, and progressive minima.

15.2 Treat the following programs and comments like those of Lesson 13, that is, as exercises in reading and writing. Experiment with expressions such as
c pol x and c pp d and (c pp d) pol x with c=.1 3 3 1 and
d=.1 2 1 and x=.i.5. See the dictionary or Lesson 21 for the use of rank:

pol=. +/@([*]^i.@#@[)"1 0	Polynomial

pp=. +//.@(*/)	Polynomial product

pp11=. 1 1&pp 	Polynomial product by 1 1

pp11 d

pp11^:5 (1)

ps=. +/@,:	Polynomial sum


Defined Adverbs
16:  DEFINED ADVERBS

Names may be assigned to adverbs, as they are to nouns and verbs:

a=.1 2 3 4 5

prefix=. \

< prefix 'abcdefg'

ÚÄÂÄÄÂÄÄÄÂÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÄ¿

³a³ab³abc³abcd³abcde³abcdef³abcdefg³

ÀÄÁÄÄÁÄÄÄÁÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÄÙ

+/ prefix a

1 3 6 10 15

Moreover, new adverbs result from a string of adverbs (such as /\) and from a conjunction together with one of its arguments, as well as from other trains listed in the dictionary (II F). Such adverbs can be defined by assigning names. Thus:

IP=. /\	Insert Prefix

+ IP a

1 3 6 10 15

with3=. &3

% with3 a

0.333333 0.666667 1 1.33333 1.66667

^ with3 a

1 8 27 64 125

I=. ^: _1	Inverse adverb

*: I a

1 1.41421 1.73205 2 2.23607

+ IP I 1 3 6 10 15

1 2 3 4 5

ten=. 10&

^. ten 5 10 20 100

0.69897 1 1.30103 2

#. ten 3 6 5

365

from=. -~ [. into=. %~

10 into 17 18 19

1.7 1.8 1.9

10 from 17 18 19

7 8 9

i=. "_1	Apply to items

{. i i. 3 4

0 4 8

Exercises:

16.1	Experiment with, and explain the behaviour of, the adverbs pow=. ^&

and log=. &^.

16.2	State the significance of the following expressions, and test your

conclusions by entering them:

+/~ i=. i. 6	Addition table

ft=. /~	Function table adverb

+ ft i	Addition table

! ft i	Binomial coefficients

inv=. ^:_1	Inverse adverb

sub3=. 3&+ inv	Subtract-three function

sub3 i


Word Formation
17:  WORD FORMATION

The interpretation of a written English sentence begins with word formation. The process is based on spaces to separate the sentence into units, but is complicated by matters such as apostrophes and punctuation  marks: twas and Browns and Ross are each single units, but however, is not (since the comma is a separate unit).

The following lists of characters represent sentences in J, and can be executed by applying the do or execute function ". :

m=. '3 %: y.'

d=. 'x.%: y.'

x.=. 4

y.=. 27 4096

". m

3 16

do=. ".

do d

2.27951 8

The word formation rules of J are prescribed in Section I of the dictionary. Moreover, the word-formation function ;: can be applied to the string representing a sentence to produce a boxed list of its words:

;: m	   words=. ;:

ÚÄÂÄÄÂÄÄ¿	   words d

³3³%:³y.³	ÚÄÄÂÄÄÂÄÄ¿

ÀÄÁÄÄÁÄÄÙ	³x.³%:³y.³

ÀÄÄÁÄÄÁÄÄÙ

The rhematic rules of J apply reasonably well to English phrases:

words p=. 'Nobly, nobly, Cape St. Vincent'

ÚÄÄÄÄÄÂÄÂÄÄÄÄÄÂÄÂÄÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄ¿

³Nobly³,³nobly³,³Cape³St.³Vincent³

ÀÄÄÄÄÄÁÄÁÄÄÄÄÄÁÄÁÄÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÙ

>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.


Names and Displays
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.


Explicit Definition
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


Tacit Equivalents
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=. +/ % #


Rank
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 <a. Moreover, a negative value of k specifies a complementary rank
that is effectively |k less than the rank of the argument a.

21.2  Use the results of the following experiments to state the relation between the conjunctions @ (Atop) and @: (At), and compare your conclusions with the dictionary definition:

(g=. <"2) a=. i. 3 4 5

|. @: g a

|. @ g a

|: @: (<"1) a

|: @ (<"1) a

ANSWER: The rank of the function |. @: g is itself infinite and |. therefore

 applies to the entire list result of g a, consequently  reversing it. On the

 other hand, the function f @ g inherits the rank of g, and |. therefore

applies individually to the atoms produced by g, producing no effect.

21.3 Use the results of the following experiments to comment on the use of the rank conjunction in dyads:

b=. 'ABC'

c=. 3 5 $ 'abcdefghijklmno'

c

b,c

b ,"0 1 c

b ,"1 1 c

b ,"1 c


Gerund and Agenda
22:  GERUND AND AGENDA

In English, a gerund is a noun that carries the force of a verb, as does the noun cooking in the phrase the art of cooking; and agenda is a list of items for action.

The tie conjunction ` applies to two verbs to form a gerund, from which elements can be chosen for execution. Thus, if the agenda conjunction @. is applied to a gerund, its verb right argument provides the results that choose the elements. For example:

g=. +`^

a=.<

2 a 3

1

2 g@.a 3

8

3 g@.a 2

5

+:`-:`*:`%: @. (4&|@<.)"0 i. 10

0 0.5 4 1.73205 8 2.5 36 2.64575 16 4.5

The verb produced by g@.a is often called a case or case statement, since it selects one of the cases of the gerund for execution.

The insert adverb / applies to a gerund in a manner analogous to its application to a verb. For example:

c=.3 [ x=. 4 [ power=. _1

g/ c,x,power

3.25

3+x^_1

3.25

The elements of the gerund are repeated as required. For example:

+`*/1,x,3,x,3,x,1

125

The last sentence above corresponds to Horner's efficient evaluation of the polynomial with coefficients 1 3 3 1 and argument x.

Exercises:

22.1 Define a function f such that (x=. 4) f c=. 1 3 3 1 yields the result used as the argument to +`*/ in Horners method in Lesson 22.

ANSWER: f=. }.@,@,.


Recursion
23:  RECURSION

The factorial function ! is commonly defined by the statement that factorial n is n times factorial n-1, and by the further statement that factorial 0 is 1. Such a definition is called recursive, because the function being defined recurs in its definition.

A case statement can be used to make a recursive definition, the case that employs the function under definition being chosen repeatedly until the terminating case is encountered. For example:

factorial=. 1:`(]*factorial@<:) @. *

factorial "0 i.6

1 1 2 6 24 120

In the sentence (sum=. +/) i.5 the verb defined by the phrase +/ is assigned a name before being used, but in the sentence +/ i.5 it is used anonymously.

In the definition of factorial above, it was essential to assign a name to make it possible to refer to it within the definition. However, the word $: provides self-reference that permits anonymous recursive definition. For example:

1:`(]*$:@<:) @. * "0 i. 6

1 1 2 6 24 120

In the Tower of Hanoi puzzle, a set of n discs (each of a different size) is to be moved from post A to post B using a third post C and under the restriction that a larger disc is never to be placed on a smaller. The following is a recursive definition of the process:

   h=. b`(p,.q,.r)@.c

     c=. 1: < [

     b=. 2&,@[ $ ]

       p=. <:@[ h 1: A. ]

       q=. 1: h ]

       r=. <:@[ h 5: A. ]

   3 h x=. 'ABC'

AABACCA

BCCBABB

   0 1 2 3 4 <@h"0 1 x

ÚÂÄÂÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿

³³A³AAC³AABACCA³AACABBAACCBCAAC³

³³B³CBB³BCCBABB³CBBCACCBBAABCBB³

ÀÁÄÁÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

Exercises:

23.1  Use the following as exercises in reading and writing:

f=.1:`(+//.@(,:~)@($:@<:))@.*   	Binomial Coeffs

<@f"0 i.6	         	      	Boxed binomials

g=.1:`((],+/@(_2&{.))@$:@<:)@.* 	Fibonacci


Iteration
24:  ITERATION

The repetition of a process, or of a sequence of similar processes, is called iteration. Much iteration is implicit, as in */b and a*/b, and a*b; explicit iteration is provided by the power conjunction (^:), by agenda (@.) with self-reference, and by control structures:

(cos=. 2&o.) ^: (i.6) b=. 1

1 0.540302 0.857553 0.65429 0.79348 0.701369

]y=. cos^:_ b	     y=cos y

0.739085	  1

The example cos^:_ illustrates the fact that infinite iteration is meaningful (that is, terminates) if the process applied converges.

Controlled iteration of a process p is provided by p^:q, where the result of q determines the number of applications of p performed. A zero result from q terminates the process. The form $:@p^:q is commonly useful.

If f is a continuous function, and if f i and f j differ in sign, then there must be a root r between i and j such that f r is zero; the list b=.i,j is said to bracket a root. A narrower bracket is provided by the mean of b together with that element of b whose result on applying f differs in sign from its result . Thus:

f=. %: - 4:	A sample function

root=. 3 : 0

m=. +/ % #

while. ~:/y.

do.

if. ~:/ * f ({.,m) y.

   do. y.=. ({.,m) y.

 else. y.=. ({:,m) y.

end.

end. m y.

)

b=. 1 32

root b

16

f b,root b

_3 1.65685 1.77636e_15

Exercises:

24.1 Use the function BR of Lesson 24 to find the roots of various functions, such as
f=. 6&-@!

24.2 Experiment with the function fn=. +/\ (which produces the figurate numbers when applied repeatedly to i.n), and explain the behaviour of the function fn^:(?@3:)


Trains
25:  TRAINS

The train of nouns in the English phrase Ontario museum Egyptian collection represents a single noun. Similarly, the fork and hook discussed in Lesson 6 and its exercises permit the use of arbitrarily long trains of verbs to produce a verb.

Lesson 16 introduced the use of trains of adverbs, and of conjunctions together with nouns or verbs, to represent adverbs. Conjunctions may also be produced by trains of adverbs and conjunctions in a manner analogous to hooks and forks.

For example, the case diagrammed on the right below can be used as follows:

cj=.\@\

< cj (+/) a=.i.3 3	  	  c

ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÄÄ¿	 / \

³0 1 2³0 1 2³0  1  2³	a1 a2

³     ³3 5 7³3  5  7³	|   |

³     ³     ³9 12 15³	x   y

ÀÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÄÄÙ

(<\)@(+/\) a	      (*/) cj (+/) a

ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÄÄ¿	    0  1   2

³0 1 2³0 1 2³0  1  2³	    0  5  14

³     ³3 5 7³3  5  7³	    0 60 210

³     ³     ³9 12 15³

ÀÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÄÄÙ

The explicit form of defining conjunctions treated in the exercises of Lesson 19 can be used to produce an equivalent conjunction CJ as shown below. The corresponding tacit definition is produced by 12 : s  :

s=. 0 : 0

(x.\)@(y.\)

)

CJ=. 2 : s

(*/) CJ (+/) a

0  1   2

0  5  14

0 60 210

12 : s

\ @ \

Exercises:

25.1 Use the display of 12 : s in Lesson 25 as a guide in defining an equivalent conjunction C, and compare the resulting definition with the simpler definition
used for cj in Lesson 25.


Permutations
26:  PERMUTATIONS

Anagrams are familiar examples of the important notion of permutations:

w=. 'STOP'

3 2 0 1 { w

POST

2 3 1 0 { w

OPTS

3 0 2 1 { w

PSOT

The left arguments of { above are themselves permutations of the list i.4, and are examples of permutation vectors, used to represent permutation functions in the form p&{.

If p is a permutation vector, the phrase p&C. also represents the permutation p&{. However, other cases of the cycle function C. are distinct from the from function {. In particular, C. p yields the cycle representation of the permutation p. For example:

]c=. C. p=. 2 4 0 1 3

ÚÄÄÄÂÄÄÄÄÄ¿

³2 0³4 3 1³

ÀÄÄÄÁÄÄÄÄÄÙ

c C. 'ABCDE'	   C. c

CEABD	2 4 0 1 3

Each of the boxed elements of a cycle specify a list of positions that cycle among themselves; in the example above, the element from position 3 moves to position 4, element 1 moves to 3, and element 4 to 1.

If all !n permutations of order n are listed in a table in increasing order (when considered as base-n numbers), they can be identified by their row indices i.!n. This index is the atomic representation of the permutation; the corresponding permutation is effected by the function A.:

1 A. 'ABCDE'	   A. 0 1 2 4 3

ABCED	1

(i.!3) A. i.3	   (i.!3) A. 'ABC'

0 1 2	ABC

0 2 1	ACB

1 0 2	BAC

1 2 0	BCA

2 0 1	CAB

2 1 0	CBA

Exercises:

26.1 Use the following as exercises in reading and writing (try on a=.'abcdef' and b=.i. 6 and c=. i. 6 6):

f=. 1&A.	Interchange last two items

g=. 3&A.	Rotate last three items

h=. 5&A.	Reverse last three items

i=. <:@!@[ A. ]	k i a reverses last k items.

26.2 Experiment with the following expressions and others like them to determine the rules for using abbreviated arguments to C. and compare your conclusions with the dictionary definitions:

2 1 4 C. b=.i.6

(<2 1 4) C. b

(3 1;5 0) C. b

26.3  Make a program ac that produces a table of the cycle representations of all permutations of the order of its argument, as in ac 3.

ANSWER: ac=. C.@(i.@! A. i.)


Linear Functions
27:  LINEAR FUNCTIONS

A function f is said to be linear if f(x+y) equals (f x)+(f y) for all arguments x and y. For example:

f=.3&|.@+:@|.

]x=. i.# y=.2 3 5 7 11

0 1 2 3 4

x+y	   f x+y

2 4 7 10 15	8 4 30 20 14

(f x),:(f y)	   (f x)+(f y)

2 0  8  6  4	8 4 30 20 14

6 4 22 14 10

A linear function can be defined equivalently as follows: f is linear if f@:+ and +&f are equivalent. For example:

x f@:+ y	   x +&f y

8 4 30 20 14	8 4 30 20 14

If f is a linear function, then f y can be expressed as the matrix product  mp&M y, where

mp=. +/ . *

M=. f I=. =/~i.#y	 I is an identity matrix

mp&M y	   f y

6 4 22 14 10	6 4 22 14 10

Conversely, if m is any square matrix of order #y, then m&mp is a linear function on y, and if m is invertible, then (%.m)&mp is its inverse:

x=. 1 2 3 [ y=. 2 3 5

]m=. ? 3 3$9

5 7 3

7 2 3

4 4 2

]n=. %.m

 _1.33333 _0.333333  2.5

_0.333333 _0.333333    1

  3.33333   1.33333 _6.5

g=. mp&m

h=. mp&n

x g@:+ y	   x +&g y

82 63 40	82 63 40

g h y

2 3 5

Exercises:

27.1  For each of the following functions, determine the matrix M such that M (mp=. +/ . *) N is equivalent to the result of the function applied to the matrix N, and test it for the case N=. i. 6 6 :

|.

-

+:

(4&*-2&*@|.)

2&A.


Obverse and Under
28:  OBVERSE AND UNDER

The result of f^:_1 is called the obverse of the function f; if f=. g :. h, this obverse is h, and it is otherwise an inverse of f. Inverses are provided for over 25 primitives (including the case of the square root illustrated in Lesson 12), as well as invertible monads such as -&3 and 10&^. and 2&o. . Moreover, u@v^:_1 is given by (v^:_1)@(u^:_1). For example:

fFc=. (32&+)@(*&1.8)

]b=.fFc _40 0 100

_40 32 212

cFf=. fFc^:_1

cFf b

_40 0 100

The result of the phrase f &. g is the verb (g^:_1)@(f & g) . The function g can be viewed as preparation (which is done before and undone after) for the application of the main function f . For example:

b=. 0 0 1 0 1 0 1 1 0 0 0

sup=. </\	 	Suppress ones after the first

sup b

0 0 1 0 0 0 0 0 0 0 0

|. sup |. b	Suppress ones before the last

0 0 0 0 0 0 0 1 0 0 0

sup&.|. b	      "

0 0 0 0 0 0 0 1 0 0 0

3 +&.^. 4	Multiply by applying the exponential

12	to the sum of logarithms

(^.3)+(^.4)

2.48491

^ (^.3)+(^.4)

12

]c=. 1 2 3;4 5;6 7 8

ÚÄÄÄÄÄÂÄÄÄÂÄÄÄÄÄ¿

³1 2 3³4 5³6 7 8³

ÀÄÄÄÄÄÁÄÄÄÁÄÄÄÄÄÙ

|.&.> 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


Identity Functions
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


Secondaries
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 & Numbers
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


Grammer
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. 5

ÚÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄ¿

³1 0 0 0 0³0 1 1 1 1³1 1 1 1 1³0 1 1 1 1³

³0 1 0 0 0³0 0 1 1 1³0 1 1 1 1³1 0 1 1 1³

³0 0 1 0 0³0 0 0 1 1³0 0 1 1 1³1 1 0 1 1³

³0 0 0 1 0³0 0 0 0 1³0 0 0 1 1³1 1 1 0 1³

³0 0 0 0 1³0 0 0 0 0³0 0 0 0 1³1 1 1 1 0³

ÀÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÙ

t=. (/ ~) (@i.)	Table adverb

(=t;<t;<:t;~:t) 5

ÚÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄ¿

³1 0 0 0 0³0 1 1 1 1³1 1 1 1 1³0 1 1 1 1³

³0 1 0 0 0³0 0 1 1 1³0 1 1 1 1³1 0 1 1 1³

³0 0 1 0 0³0 0 0 1 1³0 0 1 1 1³1 1 0 1 1³

³0 0 0 1 0³0 0 0 0 1³0 0 0 1 1³1 1 1 0 1³

³0 0 0 0 1³0 0 0 0 0³0 0 0 0 1³1 1 1 1 0³

ÀÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÙ

(^t;!t;-t) 5

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿

³1 0  0  0   0³1 1 1 1 1³0 _1 _2 _3 _4³

³1 1  1  1   1³0 1 2 3 4³1  0 _1 _2 _3³

³1 2  4  8  16³0 0 1 3 6³2  1  0 _1 _2³

³1 3  9 27  81³0 0 0 1 4³3  2  1  0 _1³

³1 4 16 64 256³0 0 0 0 1³4  3  2  1  0³

ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ


CLASSIFICATION

Classification is a familiar notion. For example, the classification of letters of the alphabet as vowel, consonant, sibilant, or plosive; the classification of colours as primary and secondary; and of numbers as odd, even,  prime, and complex.

It is also very important; it provides the basis for many significant notions, such as graphs, barcharts, and sets.

A classification may be complete, (each object falling into at least one class), and it may be disjoint, (each object falling into at most one class). A graph is a disjoint classification corresponding to the non-disjoint classification used to produce a barchart.

x=. 1 2 3 4 5 6 7

]y=. (x-3) * (x-5)	                     Parabola (roots at 3 and 5)

8 3 0 _1 0 3 8

range=. >./ - 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
DISJOINT CLASSIFICATION (Graphs)

If only the final element of a boolean list b is non-zero, then (and only then) will the result of </b be non-zero. Consequently, </\ applied to b suppresses all ones after the first, and the result therefore represents a disjoint classification. For example:

cct=. #:@i.@(2: ^ #)	Complete classification table

b=. |: cct 2 3 5 7

b

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1

0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1

0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

</b

0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0

</\b

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0

0 0 1 1 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

y=. (x-3) * (x-5) [ x=. 1 2 3 4 5 6 7

range=. >./ - i.@spread

spread=. 1: + >./ - <./

bc=. (range <:/]) y

bc;(</\bc);({&'.*' </\bc)	Barchart and graphs

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄ¿

³1 0 0 0 0 0 1³1 0 0 0 0 0 1³*.....*³

³1 0 0 0 0 0 1³0 0 0 0 0 0 0³.......³

³1 0 0 0 0 0 1³0 0 0 0 0 0 0³.......³

³1 0 0 0 0 0 1³0 0 0 0 0 0 0³.......³

³1 0 0 0 0 0 1³0 0 0 0 0 0 0³.......³

³1 1 0 0 0 1 1³0 1 0 0 0 1 0³.*...*.³

³1 1 0 0 0 1 1³0 0 0 0 0 0 0³.......³

³1 1 0 0 0 1 1³0 0 0 0 0 0 0³.......³

³1 1 1 0 1 1 1³0 0 1 0 1 0 0³..*.*..³

³1 1 1 1 1 1 1³0 0 0 1 0 0 0³...*...³

ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÙ


Classification (Inner Product)
CLASSIFICATION (With Selection and Inner product)

The complete classification table can be used in a variety of ways, including use with various inner products. For example:

C=. #:@i.@(2: ^ #)

pr=. 2 3 5

1 0 1 # pr

2 5

(C <@# ]) pr

ÚÂÄÂÄÂÄÄÄÂÄÂÄÄÄÂÄÄÄÂÄÄÄÄÄ¿

³³5³3³3 5³2³2 5³2 3³2 3 5³

ÀÁÄÁÄÁÄÄÄÁÄÁÄÄÄÁÄÄÄÁÄÄÄÄÄÙ

(C */@# ]) pr

1 5 3 15 2 10 6 30

((C+/@#]),(C*/@#]),(C>./@#]),(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)
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 (Conjunctions)
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


Composition (Forks)
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³

ÀÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÁÄÄÙ

</.t

ÚÄÂÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÂÄ¿

³1³3 2³3 6 1³1 6 3³2 3³1³

ÀÄÁÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÁÄÙ

Used dyadically, they provide infix, outfix, and key classification. For example:

3 <\ a

ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÄ¿

³2 3 5³3 5 7³5 7 11³

ÀÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÄÙ

_3 <\ a

ÚÄÄÄÄÄÂÄÄÄÄ¿

³2 3 5³7 11³

ÀÄÄÄÄÄÁÄÄÄÄÙ

2<\.a

ÚÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄ¿

³5 7 11³2 7 11³2 3 11³2 3 5³

ÀÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÙ

1 2 3 1 3 *//. a

14 3 55


Partitions (Cuts)
PARTITIONS  (Based on Cut conjunction)

The left argument of the cut conjunction is a function which is applied to various types of partitions specified by the numeric right argument. We will illustrate its behaviour for the fixed function box, using the adverb <;. :

t=. 'When eras die/their legacies/are left to/strange police/'

;: t

ÚÄÄÄÄÂÄÄÄÄÂÄÄÄÂÄÂÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÂÄÄÄÂÄÄÄÄÂÄÄÂÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄ¿

³When³eras³die³/³their³legacies³/³are³left³to³/³strange³police³/³

ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÁÄÁÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÁÄÄÄÁÄÄÄÄÁÄÄÁÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÙ

cut=. <;.

_2 cut ;: t

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿

³ÚÄÄÄÄÂÄÄÄÄÂÄÄÄ¿³ÚÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿³ÚÄÄÄÂÄÄÄÄÂÄÄ¿³ÚÄÄÄÄÄÄÄÂÄÄÄÄÄÄ¿³

³³When³eras³die³³³their³legacies³³³are³left³to³³³strange³police³³

³ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÙ³ÀÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙ³ÀÄÄÄÁÄÄÄÄÁÄÄÙ³ÀÄÄÄÄÄÄÄÁÄÄÄÄÄÄÙ³

ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

}: 2 cut ;: t	Last item deleted to display on one line

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿

³ÚÄÄÄÄÂÄÄÄÄÂÄÄÄÂÄ¿³ÚÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄ¿³ÚÄÄÄÂÄÄÄÄÂÄÄÂÄ¿³

³³When³eras³die³/³³³their³legacies³/³³³are³left³to³/³³

³ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÁÄÙ³ÀÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÙ³ÀÄÄÄÁÄÄÄÄÁÄÄÁÄÙ³

ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

(i. 3 2 2);(i. 12 12)

ÚÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿

³ 0  1³  0   1   2   3   4   5   6   7   8   9  10  11³

³ 2  3³ 12  13  14  15  16  17  18  19  20  21  22  23³

³     ³ 24  25  26  27  28  29  30  31  32  33  34  35³

³ 4  5³ 36  37  38  39  40  41  42  43  44  45  46  47³

³ 6  7³ 48  49  50  51  52  53  54  55  56  57  58  59³

³     ³ 60  61  62  63  64  65  66  67  68  69  70  71³

³ 8  9³ 72  73  74  75  76  77  78  79  80  81  82  83³

³10 11³ 84  85  86  87  88  89  90  91  92  93  94  95³

³     ³ 96  97  98  99 100 101 102 103 104 105 106 107³

³     ³108 109 110 111 112 113 114 115 116 117 118 119³

³     ³120 121 122 123 124 125 126 127 128 129 130 131³

³     ³132 133 134 135 136 137 138 139 140 141 142 143³

ÀÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

(i. 3 2 2) 0 cut i. 12 12

ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄ¿

³ 1  2  3³ 53  54  55  56  57  58  59³105 106 107³

³13 14 15³ 65  66  67  68  69  70  71³117 118 119³

³        ³ 77  78  79  80  81  82  83³129 130 131³

³        ³ 89  90  91  92  93  94  95³141 142 143³

³        ³101 102 103 104 105 106 107³           ³

³        ³113 114 115 116 117 118 119³           ³

ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÙ


GEOMETRY

We will illustrate the topic of coordinate geometry by defining functions for polygons in two dimensions that give the displacements between adjacent vertices, the length of sides, the semiperimeter, and the area based on Heron's formula.

We also present a more general definition for area that not only gives the signed area (positive if the vertices appear in counter-clockwise order), but also applies to polyhedra in higher dimensions (in which case the name area might better be replaced by volume). This definition is based on the use of the determinant applied to a square matrix obtained by bordering a table of vertices t by a final row of the values %!#t . Thus:

(length=. +/&.*:) 5 12

13

disp=. ] - 1&|."1

 	sides=. length@disp

 	semiper=. -:@(+/)@sides

 	HERON=. %:@(*/)@(semiper - 0: , sides)

 	area=. -/ . * @ (] , %@!@#)

 	t=. 0 0 4 ,: 3 4 7

 	(];(1&|."1);disp;sides;semiper;HERON;area) t

ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÂÄÄ¿

³0 0 4³0 4 0³ 0 _4 4³1 5 5.65685³5.82843³2³_2³

³3 4 7³4 7 3³_1 _3 4³           ³       ³ ³  ³

ÀÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÁÄÄÙ

 	tet1=.6 0 3 0,3 6 5 8,:7 4 0 5

 	tet2=. 0,.=i.3 3

 	tet1;(area tet1);tet2;(area tet2)

ÚÄÄÄÄÄÄÄÂÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿

³6 0 3 0³11.5³0 1 0 0³_0.1666667³

³3 6 5 8³    ³0 0 1 0³          ³

³7 4 0 5³    ³0 0 0 1³          ³

ÀÄÄÄÄÄÄÄÁÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ


SYMBOLIC FUNCTIONS

For any function, a corresponding symbolic function can be defined to display the expression rather than evaluate it. For example:

minus=. [ , '-'"_ , ]

'a' minus 'b'

a-b

list=. 'abcd'

table=. 4 4$'ABCDEFGHIJKLMNOP'

minus/list

a-b-c-d

 	(minus/\list);('01'minus"0/list);(minus//.table);table

ÚÄÄÄÄÄÄÄÂÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄ¿

³a      ³0-a³A      ³ABCD³

³a-b    ³0-b³B-E    ³EFGH³

³a-b-c  ³0-c³C-F-I  ³IJKL³

³a-b-c-d³0-d³D-G-J-M³MNOP³

³       ³   ³H-K-N  ³    ³

³       ³1-a³L-O    ³    ³

³       ³1-b³P      ³    ³

³       ³1-c³       ³    ³

³       ³1-d³       ³    ³

ÀÄÄÄÄÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÙ

(list)=. 4 3 2 1

". minus/\list

4 1 3 2

3 minus/\ 'abcdefg'

a-b-c

b-c-d

c-d-e

d-e-f

e-f-g

3 minus/\. 'abcdefg'

d-e-f-g

a-e-f-g

a-b-f-g

a-b-c-g

a-b-c-d


DIRECTED GRAPHS

A directed graph is a collection of nodes with connections or arcs specified between certain pairs of nodes. It can be used to specify matters such as the precedences in a set of processes (stuffing of envelopes must precede sealing), or the structure of a tree.

The connections can be specified by a boolean connection matrix instead of by arcs, and the connection matrix can be determined from the list of arcs.

The connection matrix is very convenient for determining various properties of the graph, such as the in-degrees (number of arcs entering a node), the out-degrees, immediate descendants, and the closure, or connection to every node reachable through some path. For example:

   from=. 3 7 2 5 5 7 1 5 5 5 2 6 1 2 3 7 7 4 7 2 7 4

     to=. 5 6 0 2 6 2 7 6 0 7 3 3 2 1 7 0 4 2 3 0 0 3

$ arcs=. from,.to

22 2

|: arcs { nodes=. 'ABCDEFGH'    	Transposed for display

DHCFFHBFFFCGBCDHHEHCHE

FGACGCHGAHDDCBHAECDAAD

CM=. #. e.~ [: i. [ , [      	Connection matrix from arcs

]cm=. (>:>./,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 (Coefficients)
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 (Roots)
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 (Newtons Method)
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 (Kerners Method)
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)
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.


Alphabet and Words
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.


Grammar
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.


Nouns
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 ³

ÀÄÄÁÄÄÄÁÄÄÙ


Verbs
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³

ÀÄÄÄÄÄÁÄÄÄÄÄÙ


Adverbs and Conjunctions
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.


Comparitives
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.


Parsing and Execution
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


Trains
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


Frets and Scripts
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.


Locatives
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.


Errors and Suspension
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 does 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 0

0 1 0 1 0 0

0 0 1 0 1 0

0 0 0 0 0 1

Because of the limited precision of the computer, results which should agree (such as 144*(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 function
eq=. =!.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

<y is an atomic encoding of y, as discussed in Section II A. The result has rank 0, and is decoded by > .	x<y  is  1 if x is tolerantly less than y. See Equal (=) for a definition of tolerance. <!.t uses tolerance t.
Boxing is effected not only by <, but also by other verbs such as link (;) and word formation (;:), and by using box together with the cut conjunction (;.). Thus:

(<'abc'),(<5 7),(<i.2 3)

ÚÄÄÄÂÄÄÄÂÄÄÄÄÄ¿

³abc³5 7³0 1 2³

³   ³   ³3 4 5³

ÀÄÄÄÁÄÄÄÁÄÄÄÄÄÙ

] a=. 2;3 5;7 11 13

ÚÄÂÄÄÄÂÄÄÄÄÄÄÄ¿

³2³3 5³7 11 13³

ÀÄÁÄÄÄÁÄÄÄÄÄÄÄÙ

;: 'Now is the time'

ÚÄÄÄÂÄÄÂÄÄÄÂÄÄÄÄ¿

³Now³is³the³time³

ÀÄÄÄÁÄÄÁÄÄÄÁÄÄÄÄÙ

   >a

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.6 4 4 _4 _5 The 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 _4 3 _4    <./7 8 5 9 2 2    <./\7 8 5 9 2 7 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 6 Also 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 y. When applied to an open array (that has no boxed elements), open has no effect. Opened atoms are brought to a common shape as discussed in Sec. II B.	x>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 1 0 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.6 5 4 _4 _4 The 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 _4 4 3    >./7 8 5 9 2 9    >./\7 8 5 9 2 7 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 8 Also 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 _2 6 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. 5 0 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.  For 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 maximum 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 5 1 2 3 4 5    10&^. 10&^ 1 2 3 4 5 1 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 phrase 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 that y = 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)


^: 2
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 how the result is formed from the items of y, the last 1-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:`(] * $:@<:)@.* 5

120

In 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 $:@ were omitted from the expression, it would execute once only as follows:

   1:`(] * <:)@.* 5

20

The 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).


~ 2
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 3j4 6 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 7 0 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' gfedcba The 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  6 12 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 t cdefg## ##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 representation
t=. >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


: 2
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'    y abcd efgh    ,y abcdefgh	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 the 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 4 1 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 (<x),y if y is boxed, and (<x),<y if y is open.
]bv=. 1 2 3;4 5 6;7 8 9

ÚÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄ¿

³1 2 3³4 5 6³7 8 9³

ÀÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÙ

;bv

1 2 3 4 5 6 7 8 9

]m=. >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,:x The 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 size x . The case u;.3 differs in that shards of 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 0 10    #. 2 3$ 0 0 1,1 0 1 1 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. 8 0 1 2 3 4 5 6 7    #: i. 8 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1	In simple cases, r&#: is inverse to r&#. . Thus, if r=.24 60 60, then r #: r #. 2 3 4 is 2 3 4. But if r #. 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 4 5 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 1 0.886227 1 1.32934 2    ]fi=.!^:_1(24 25 2.1 9876) 4 4.02705 2.05229 7.33019    ! fi 24 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 negative integer) cancel if they occur in both numerator and denominator. Thus:    3!5 10    (!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 14 12 15 18 21 In 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:    </.i.3 3 ÚÄÂÄÄÄÂÄÄÄÄÄÂÄÄÄÂÄ¿ ³0³1 3³2 4 6³5 7³8³ ÀÄÁÄÄÄÁÄÄÄÄÄÁÄÄÄÁÄÙ More generally, u/.y is the result of applying u to the oblique lines of _2-cells of y. If the rank of y is less than two, y is treated as the table ,.y.	x m/.y applies each element of the gerund m to x and y. For example:    2 3 +`*/. 5 6 7 10  9 18 x u/.y  is  (=x) u@# y, that is, items of x specify keys for corresponding items of y and u is applied to each  collection of y having identical keys. For example :    i=. 1 2 3 1 3 2 1      i </.'abcdefg' ÚÄÄÄÂÄÄÂÄÄ¿ ³adg³bf³ce³ ÀÄÄÄÁÄÄÁÄÄÙ
The application of a function to diagonals of a table is commonly useful, as in correlation, in convolution, and in products of polynomial coefficients (or, equivalently, products of numbers in a fixed base). For example:

   t=. p */ q [ p=. 1 2 1 [ q=. 1 3 3 1

   t ; (+//.t) ; (1 1 &(+//.@(*/)) ^: (i.6) 1)

ÚÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿

³1 3 3 1³1 5 10 10 5 1³1 0  0  0 0 0³

³2 6 6 2³             ³1 1  0  0 0 0³

³1 3 3 1³             ³1 2  1  0 0 0³

³       ³             ³1 3  3  1 0 0³

³       ³             ³1 4  6  4 1 0³

³       ³             ³1 5 10 10 5 1³

ÀÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

]a * b [ a=. 10 #. p [ b=. 10 #. q

161051

10 #. +//. p */ q

161051

Unlike polynomial coefficients, the diagonal sums of a multiplication table of digits should be normalized if any  equal or exceed the radix.


/:
Grade Up            /:    _ _ _         Sort (Up)

/: grades  its argument, yielding a permutation vector; (/:y){y sorts y in ascending order. For example:    n=. 3 1 4 2 1 3 3    ]g=. /: n 1 4 3 0 5 6 2    g { n 1 1 2 3 3 3 4	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:    y=. 'popfly'    y /: 3 1 4 1 5 9 ofpply    y /: y floppy
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 its items were each ravelled).

If y is literal, /:y grades according to the collating sequence determined 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

1 0 2

   UcLc=. ' ',. a. {~ 65 97 +/ i. 26

   x=. words=. >;: '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³                           ³

ÀÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ


T
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


T 2
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{y 4 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' zoned skid
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' efgh More generally, >x may 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  8 12 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


" 2
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³

ÀÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÙ


" 3
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 5 0 1 2 3 4 5 6 7 8 9    $ text 2 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 the 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 spaces 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.


& 2
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

(<b),(<|. b=. 1 2 3 ; 2 3 5 7 ; 'abcde')

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿

³ÚÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄ¿³ÚÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄ¿³

³³1 2 3³2 3 5 7³abcde³³³abcde³2 3 5 7³1 2 3³³

³ÀÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÙ³ÀÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÙ³

ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

each=. &.>               	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.


a.
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 are 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.


A.
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³

ÀÄÄÄÄÁÄÙ


b.
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 dyads 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 (as in 0 m b. y).


b. 2
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


c.
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


C.
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 representations 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 boxed, 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.5 1 2 3 0 4    (<2 1) C. (<3 0 1) C. i.5 1 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³³     ³         ³     ³     ³

³ÀÄÄÄÄÄÄÄÁÄÙ³     ³         ³     ³     ³

ÀÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÙ


D.
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³            ³           ³            ³

ÀÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÙ


D:
                 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 each 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³

ÀÄÄÄÄÄÄÄÁÄÄÄÄÄÙ


e.
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, then x 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.
                                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


f.
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


i.
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. 5 0 1 2 3 4    i. 2 _5 4 3 2 1 0 9 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 used 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³ ³    ³    ³

ÀÄÄÄÄÁÄÁÄÄÄÄÁÄÄÄÄÙ


j.
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


NB.
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


o.
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^2 1 Sine y        5 Sinh y 2 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 tangent (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


p.
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, then x 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 ^ .


r.
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³

ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ


t.
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


T.
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. .


x.
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


y.
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
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


foreignconjuction
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


scripts
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'


files
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'


host commands 2!:
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


storage types
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


names and lists
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


representations
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³³³³

³³ ³³ ³ÀÄÁÄÙ³³³

³³ ³ÀÄÁÄÄÄÄÄÙ³³

³ÀÄÁÄÄÄÄÄÄÄÄÄÙ³

ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÙ


time
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)


space
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


screens
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 background Output area background Cursor bar background Status line background	Input area foreground Output area foreground Cursor bar foreground Status line foreground	0  Black   4 Red 1 Blue      5 Magenta 2 Green    6 Yellow 3 Cyan     7 White 8+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)


global
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


wd
11  Window Driver

See J User Manual

11!:0 y   	Window driver


debug
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


data driver
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


dll
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


numerical functions
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