From 2afb23928e1984d475cc460e1672e8f6fa0e4dbe Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 11 Aug 2021 17:21:31 -0400 Subject: Allow clicking on header to get fragment link --- docs/doc/group.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/doc/group.html') diff --git a/docs/doc/group.html b/docs/doc/group.html index 1e3afd03..03357675 100644 --- a/docs/doc/group.html +++ b/docs/doc/group.html @@ -4,7 +4,7 @@ BQN: Group -

Group

+

Group

BQN replaces the Key operator from J or Dyalog APL, and many forms of partitioning, with a single (ambivalent) Group function . This function is somewhat related to the K function = of the same name, but results in an array rather than a dictionary.

@@ -29,7 +29,7 @@ -

Definition

+

Definition

Group operates on a list of atomic-number indices 𝕨 and an array 𝕩, treated as a list of its major cells, to produce a list of groups, each containing some of the cells from 𝕩. The two arguments have the same length, and each cell in 𝕩 is paired with the index in 𝕨 at the same position, which indicates which result group should include that cell.

↗️
    01201  "abcde"  # Corresponding indices and values
 ┌─                     
@@ -102,7 +102,7 @@
           ┘
 

Here, the index 2 appears at indices 0 and 3 while the index 3 appears at index 1.

-

Multidimensional grouping

+

Multidimensional grouping

Dyadic Group allows the right argument to be grouped along multiple axes by using a nested left argument. In this case, the left argument must be a list of numeric lists, and the result has rank 𝕨 while its elements—as always—have the same rank as 𝕩. The result shape is 1+⌈´¨𝕨, while the shape of element i𝕨𝕩 is i+´=¨𝕨. If every element of 𝕨 is sorted ascending and contains only non-negative numbers, we have 𝕩≡∾𝕨𝕩, that is, Join is the inverse of Partition.

Here we split up a rank-2 array into a rank-2 array of rank-2 arrays. Along the first axis we simply separate the first pair and second pair of rows—a partition. Along the second axis we separate odd from even indices.

↗️
    0011,0101010  (10×↕4)+7
@@ -119,7 +119,7 @@
 

Each group i𝕨𝕩 is composed of the cells j<¨𝕩 such that ij¨𝕨. The groups retain their array structure and ordering along each argument axis. Using multidimensional Replicate we can say that i𝕨𝕩 is (i=𝕨)/𝕩.

The monadic case works similarly: Group Indices always satisfies 𝕩 ←→ 𝕩⊔↕≠1𝕩. As with , the depth of the result of Group Indices is always one greater than that of its argument. A depth-0 argument is not allowed.

-

Properties

+

Properties

Group is closely related to the inverse of Indices, /. In fact, inverse Indices called on the index argument gives the length of each group:

↗️
    ¨ 2312
 ⟨ 0 1 2 1 ⟩
@@ -137,7 +137,7 @@
 "caeb"
 

Group can even be implemented with the same techniques as a bucket sort, making it branchless and fast.

-

Applications

+

Applications

The obvious application of Group is to group some values according to a known or computed property. If this property isn't a natural number, it can be turned into one using Classify (), which numbers the unique values in its argument by first occurrence.

↗️
    ln  "Phelps""Latynina""Bjørgen""Andrianov""Bjørndalen"
     co  "US"    "SU"      "NO"     "SU"       "NO"
@@ -171,7 +171,7 @@
   "ZW" ⟨⟩                          
                                   ┘
 
-

Partitioning

+

Partitioning

In examples we have been using a list of strings stranded together. Often it's more convenient to write the string with spaces, and split it up as part of the code. In this case, the index corresponding to each word (that is, each letter in the word) is the number of spaces before it. We can get this number of spaces from a Plus-Scan on the boolean list which is 1 at each space.

↗️
    ' '(+`=⊔⊢)"BQN uses notation as a tool of thought"
 ⟨ "BQN" " uses" " notation" " as" " a" " tool" " of" " thought" ⟩
-- 
cgit v1.2.3