# J-ottings 38: Decline and Rise : a Matter of Rank

Rank is of enormous importance in J. There are two types of rank, noun rank and verb rank. The former can be applied to any object in the J universe, and is the “tally-of-the-shape” or in J :

nrank=.#@$

Verb rank is somewhat more subtle, and is of even greater importance in understanding J language constructs. Henry Rich put things with admirable conciseness in “J for C Programmers”:

“If you don’t know the rank of a verb, you don”t know the verb!”

It is not just primitive verbs which possess rank, user defined verbs also possess it, and so do compound verbs, that is verbs formed by combining or adapting primitive verbs using appropriate conjunctions and adverbs. Moreover, there is no excuse for J programmers not knowing any relevant verb ranks, since these are immediately obtainable for any verb by using the `b.` adverb with right argument 0 :

%. b. 0 NB. primitive 2 _ 2 +/ b. 0 NB. compound (adverbial) _ _ _ +.@*: b. 0 NB. compound (using conjunction) 0 0 0 mean=.+/ % # mean b. 0 NB. user defined _ _ _

Within the J literature I am not aware of any explicit categorisation of verbs by rank, which is why much of this article consists of a lengthy appendix which does just this. I hope that some readers may find this appendix helpful, perhaps long after this preamble has been forgotten.

As postings on the J conference testify, the distinction between `@` and `@:` is a stumbling block in the path of almost every new learner; what I hope to show here is how this block can be rapidly and effectively smoothed by a conscious endeavour to understand verb rank.

In general verbs have three unforced ranks, which are, in the order given in the dictionary definitions:

monadic rank, left rank, right rank

The word “unforced” acknowledges that verbs can have their basic ranks changed to an explicit value by using the rank conjunction `"` .

1. Pure scalar verbs, all three rank vector items = 0

2. Pure list verbs, all rank vector items = 1

3. Verbs with hybrid ranks, mostly specialised verbs

4. Pure structural verbs i.e. all rank vector items = infinite

4a. ‘Pure structural plus’ verbs, ranks are _ 1 _

It should be stressed that a verb rank of, say, 1 should not be read as meaning that only objects of noun rank 1 are acceptable as arguments, but rather that all arguments will be *processed* as assemblages of rank 1 objects. There is an analogy with the operation of a clinic which has a large and motley assembly in the waiting room, from which patients may either be called one by one (processing at rank 0), or by families (that is lists, rank = 1) or the whole lot may be taken together as a single block of humanity (rank infinite). The analogy goes further than this, because the method of calling is independent of what happens once the surgery is entered, in other words, rank comes first, semantics later. Immediately following the above quotation in Henry’s book is an explanation in detail of how rank is applied in particular cases, that is how rank and semantics are married together in terms of cell and frame selection. However, focussing on ranks shows that, apart from the “special algorithm” verbs, J verbs can be grouped into quite a small number of categories.

A general problem in categorising verbs by rank is that of deciding when the monadic and dyadic forms are sufficiently related to each other to justify retaining this association even if they possess different rank vectors. At one extreme monadic `>` (open) and dyadic `>` (greater than) are completely unrelated in meaning, even although all their rank vector items are zero. On the other hand verbs such as monadic `#:` (= antibase 2) and dyadic `#:` (= antibase) have a strong semantic association although formally they belong to different declensions.

The first declension is in many ways the most familiar, consisting of pure scalar verbs which fall into three broad categories: logical, arithmetic and algorithmic.

Declension 2 is the next easiest to review, since it contains verbs which make no sense other than when applied to lists, for example integers`i.`(= integers) and

`;:`(= word formation).

Declension 4 consists of the pure structural verbs, all of whose ranks are infinite, meaning that their arguments are processed in their entirety as single objects.

Declension 4a is sufficiently similar to the previous set to merit sub-classifying rather than a new declension. In each case the primary monadic form has infinite rank, but there is also a matching dyadic form which applies left arguments at the list level (i.e. left rank = 1).
Finally declension 3 consists of hybrids. Three of these are general, `#:` (monadic and dyadic) and `{` (from), the other five are specialised algorithmic verbs such as %. (= matrix inverse / divide), which are of great value to a minority of J users, and of little or no interest to the rest.

Finally, compound verbs possess rank vectors in exactly in the same way as primitive verbs, and Henry’s maxim might be extended :

“If you don’t know the rank of a compound verb, you don’t know the conjunction/adverb!”

The dictionary descriptions may seem somewhat bewildering at first, with references to mv, lv, etc. Not so! The present appendix contains a list of conjunction rank rules, together with the permissible noun-verb combinations. For each vv combination the conjunction has the form "u conjunction v", and m=monadic, l=left, r=right.

*atop* (`@`) has rank vector mv lv rv, which means that in all three cases the rank of the compound verb is identical to that of the right verb in the compound. For *at* (`@:`), however, all ranks are infinite regardless of the composed verbs. So for

2 3(+/@%)4 5 NB. rank of verb v(%) is zero

using the clinic analogy, the “patients” are called in matched pairs, and divided to give the result `0.5 0.6`. Then ` at rank 0 leaves items unchanged for a final result 0.5 0.6. However, for `

2 3(+/@:%)4 5

the patients are called in two blocks (left and right), which are divided as blocks to give 0.5 0.6, and then "plus-insert" is applied to this single block to give 1.1.

Informally the difference between atop and at is that u and v are more closely bound in the former. The name “atop” is very apt as it gives a picture of two creatures, one piggy-backing on the other, and thereby fusing to make a tight compound before any considerations of data come into play. “at” conveys less well the way in which infinite rank produces verb sequencing, that is “u following v”, is a more meaningful phrase than “u at v”. Here are some further examples of atop and at :
Compare `({:@*:)i.2 3` and `({:@:*:)i.2 3` . As above, the only rank which matters in the first case is that of `*:` (= square) which is 0. The semantic rule which extends tail when applied to scalars (i.e. at rank 0) is “no change” and so the final result is

0 1 4 9 16 25In the second case, tail with infinite rank means the tail of the list of lists arising from squaring, which gives the result list

`9 16 25`.

Compare `({:@#.)2 3$1 0 1 1 1 0 ` and `({:@:#.)2 3$1 0 1 1 1 0`

Here the rank of the rightmost verb is 1, and so in the first case tail is applied to *each* of the antibase 2s of the two three-lists which make up the right argument, giving a final result `5 6`. In the second case, tail applies to the entire result of `#.` which is a two-list, so that the final result is `6`.

Compare `2 3 4(+/@%.)m=.?2 3 3$10` and `2 3 4(+/@:%.)m`

`m`represents two sets of 3 by 3 linear equations with the same right hand side

`2 3 4`. In the first case the result is the sums of

*each*of the three solution sets (x

_{1}+ y

_{1}+ z

_{1}, x

_{2}+ y

_{2}+ z

_{2}) . In the second case summation applies to the two-list of solution values, so that the final result is (x

_{1}+ x

_{2}, y

_{1}+ y

_{2}, z

_{1}+z

_{2}) .

... and so I could continue. However, space is not unlimited, and in any case, if I have succeeded in explaining the general principles, then the reader will already have reached a point where he needs no further assistance from me!

# Appendix : Verb Ranks

## Declension 1, rank vector = 0 0 0

### Logicals (all dyadic)

= Equal | ~: | Not-Equals |

< Less Than | <: | Less than or Equal |

> Larger Than | >: | Larger or Equal |

### Arithmetics

Monadic | Dyadic | Monadic | Dyadic | Monadic | Dyadic | |||

+ | Conjugate | Plus | +. | Real/Imag | GCD(Or) | +: | Double | Not-Or |

- | Negate | Minus | -. | Not | -: | Halve | ||

* | Signum | Times | *. | Len/Angle | LCM(And) | *: | Square | Not-And |

% | Reciprocal | Divided by | %: | Sq Root | Root | |||

^ | Exponential | Power | ^. | Natural Log | Logarithm | |||

<. | Lesser of | >. | Larger of | |||||

| | Magnitude | Residue | ||||||

! | Factorial | Out Of |

### Algorithmics

Monadic | Dyadic | Monadic | Dyadic | ||

? | Roll | Deal | p: | Primes | |

j. | Imaginary | Complex | q: | Prime Factors | Prime Exponents |

o. | Pi Times | Circle Functions | r. | Angle | Polar |

## Declension 2, all rank vector items = 1

Monadic | Dyadic | |||

i. | Integers | 1 | ||

{ | Catalogue | 1 | ||

;: | Word formation | 1 | ||

#. | Base 2 | 1 | Base | 1 1 |

". | Do | 1 |

## Declension 3, hybrid ranks

Monadic | Dyadic | ||||

#: | Antibase 2 | _ | Antibase | 1 | 0 |

{ | From | 0 | _ | ||

%. | Matrix Inverse | 2 | Matrix Divide | _ | 2 |

A. | Atomic Permute | 1 | Atomic Permute | 0 | _ |

c. | Characteristic | 2 | Eigenvalues | 0 | 2 |

C. | Cycle | 1 | Permute | 1 | _ |

p. | Roots | 1 | Polynomial | 1 | 0 |

## Declension 4, all ranks = infinite

Monadic | Dyadic | ||

= | Self-Classify | -. | Less |

< | Box | -: | Match |

~. | Nub | i. | Index Of |

~: | Nub Sieve | E. | Member of Interval |

{: | Tail | ". | Numbers |

}: | Curtail | ||

L. | Level Of |

Monadic | Dyadic | Monadic | Dyadic | Monadic | Dyadic | |||

, | Ravel | Append | ,. | Ravel Items | Stitch | ,: | Itemize | Laminate |

/: | Grade Up | Sort Up | \: | Grade Down | Sort Down | |||

; | Raze | Link | e. | Raze In | Member In | |||

$. | Sparse | Sparse | $: | Self-Reference | Self-Reference | |||

[ | Same | Left | ] | Same | Right | |||

{:: | Map | Fetch |

Monadic and Dyadic | |

s: | Symbol |

u: | Unicode |

x: | Extended Precision |

Constant Functions, that is `9:, _8:,..., 0:, 1:,2:, ... 9:` and also

## Declension 4a, rank vector = inf 1 inf

Monadic | Dyadic | ||||

$ | Shape Of | _ | Shape | 1 | _ |

|. | Reverse | _ | Rotate (Shift) | 1 | _ |

|: | Default Transpose | _ | Transpose | 1 | _ |

# | Tally | _ | Copy | 1 | _ |

{. | Head | _ | Take | 1 | _ |

}. | Behead | _ | Drop | 1 | _ |

": | Default Format | _ | Format | 1 | _ |

## Conjunctions

nn | nv | vn | vv | Rank Vector | ||||

& | x | x | bond, compose | mv | mv | mv | ||

&. | x | under | mv | mv | mv | |||

&: | x | appose | _ | _ | _ | |||

@ | x | atop | mv | lv | rv | |||

@. | x | agenda (with gerund) | mv | lv | rv | |||

@: | x | at | _ | _ | _ | |||

. | x | dot | 2 | _ | _ | |||

:. | obverse | mu | lu | ru | ||||

:: | adverse | _ | _ | _ | ||||

^: | x | power | _ | _ | _ | |||

`: | x | evoke gerund | _ | _ | _ | |||

;. | x | cut | _ | 1/2 | _ * | |||

d. | x | derivative | 0 | |||||

D. | x | derivative | mu | |||||

H. | x | hypergeometric | 0 | 0 | 0 |

*1/2 is appropriate because cut is the J mechanism for partitions, for which there is a wide range of options, some of which process the left argument on a rank 1 basis, others on a rank 2 basis.

## Adverbs

Monadic | Dyadic | ||||

/ | Insert | _ | Table | _ | _ |

/. | Oblique | _ | Key | _ | _ |

\ | Prefix | _ | Infix | 0 | _ |

\. | Suffix | _ | Outfix | 0 | _ |

~/. | Reflexive | _ | Passive | ru | lu |

{./. | Item Amend | _ | Amend | _ | _ |

b./. | Basic characteristics | _ | Boolean | 0 | 0 |