Essays/Hook Rank

From J Wiki
Jump to: navigation, search

There are six composition conjunctions, which are paired by treatment of rank.

Specific Rank Infinite Rank
Atop / At @ mv lv rv @: _ _ _
Compose / Appose & mv mv mv &: _ _ _
Under / Dual &. mv mv mv &.: _ _ _

The regular hook (u v) is a composition based on trains. But it always has infinite rank _ _ _.

You can assign a specific rank to the hook, but it's a harcoded rank regarless of the ranks of the arguments.

   (; *:) i.3
+-----+-----+
|0 1 2|0 1 4|
+-----+-----+
   (; *:)"0 i.3
+-+-+
|0|0|
+-+-+
|1|1|
+-+-+
|2|4|
+-+-+

Here is a hook conjunction, which is a non-infinite rank counterpart of the hook train in the same way as the other composition conjunctions.

   h=: 2 : '(u v)"((1{u b. 0) (],[,]) {.v b.0)'

   ; h *:
(; *:)"0 _ 0
   ; h i.
(; i.)"1 _ 1

   ; h *: i.3
+-+-+
|0|0|
+-+-+
|1|1|
+-+-+
|2|4|
+-+-+
   ; h i. 1+i.2 2
+---+---------+
|1 2|0 1      |
+---+---------+
|3 4|0 1  2  3|
|   |4 5  6  7|
|   |8 9 10 11|
+---+---------+

   100 200 <@(+ h i.) 1+i.2 2
+-------+---------------+
|100 101|200 201 202 203|
|       |204 205 206 207|
|       |208 209 210 211|
+-------+---------------+
   100 200 <@(+ i.) 1+i.2 2
+---------------+
|100 101 100 100|
|100 100 100 100|
|100 100 100 100|
|               |
|200 201 202 203|
|204 205 206 207|
|208 209 210 211|
+---------------+

This is the scheme how ranks are assigned:

Monadic   u h v y ↔ y u v y mv ?  ?
Dyadic x u h v y ↔ x u v y ? lu mv
Total mv lu mv
   (; h *:) b. 0
0 _ 0
   (; @ *:) b. 0
0 0 0
   (; & *:) b. 0
0 0 0

   (+ h i.) b. 0
1 0 1
   (+ @ i.) b. 0
1 _ _
   (+ & i.) b. 0
1 1 1

Withe Conjunction

Not long after I put this together did I come across (again) the Withe conjunction of Sharp APL [1]. Naturally, it has the same rank, as we obtain here mv lu mv.

See Also

  • [1] Iverson, K.E., A Dictionary of APL, ACM APL Quote-Quad, Volume 18, Number 1, September, 1987.
  • Rank, Introduction
  • Nouns, Arrays of Nouns in Grammar
  • Verbs, Ranks of Verbs in Grammar


Contributed by Oleg Kobchenko