From dce7136fc0f17bf9c4c7a2fe8109dc9069aeb59f Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 29 Mar 2022 10:49:38 -0400 Subject: Document nested case for Group Indices --- docs/doc/group.html | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'docs') diff --git a/docs/doc/group.html b/docs/doc/group.html index 03357675..8184f09f 100644 --- a/docs/doc/group.html +++ b/docs/doc/group.html @@ -31,27 +31,30 @@

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.

-↗️
    0β€Ώ1β€Ώ2β€Ώ0β€Ώ1 ≍ "abcde"  # Corresponding indices and values
+↗️
    0β€Ώ1β€Ώ2β€Ώ0β€Ώ1 ≍ "abcde"  # Corresponding indices and values
 β”Œβ”€                     
 β•΅ 0   1   2   0   1    
   'a' 'b' 'c' 'd' 'e'  
                       β”˜
+
     0β€Ώ1β€Ώ2β€Ώ0β€Ώ1 βŠ” "abcde"  # Values grouped by index
 ⟨ "ad" "be" "c" ⟩
 
-

A few extra options can be useful in some circumstances. First, an "index" of Β―1 in 𝕨 indicates that the corresponding cell should be dropped and not appear in the result. Second, 𝕨 is allowed to have an extra element after the end, which gives a minimum length for the result: otherwise, the result will be just long enough to accomodate the highest index in 𝕨.

-↗️
    0β€ΏΒ―1β€Ώ2β€Ώ2β€ΏΒ―1 βŠ” "abcde"  # Drop c and e
+

A few extra options can be useful in some circumstances. First, an "index" of Β―1 in 𝕨 indicates that the corresponding cell should be dropped and not appear in the result. Second, 𝕨 is allowed to have an extra element after the end, which gives a minimum length for the result: otherwise, the result will be just long enough to accomodate the highest index in 𝕨 (it might seem like the last element should be treated like an index, making the minimum length one higher, but the length version usually leads to simpler arithmetic).

+↗️
    0β€ΏΒ―1β€Ώ2β€Ώ2β€ΏΒ―1 βŠ” "abcde"  # Drop c and e
 ⟨ "a" ⟨⟩ "cd" ⟩
+
     0β€Ώ1β€Ώ2β€Ώ2β€Ώ1β€Ώ6 βŠ” "abcde"  # Length-6 result
 ⟨ "a" "be" "cd" ⟨⟩ ⟨⟩ ⟨⟩ ⟩
 

A third extension is that 𝕨 doesn't really have to be a list: if not, then it groups -=𝕨-cells of 𝕩 instead of just Β―1-cells. These cells are placed in index order. This extension isn't compatible with the second option from above, because it's usually not possible to add just one extra element to a non-list array. One usage is to group the diagonals of a table. See if you can figure out how the code below does this.

-↗️
    ⊒ a ← 'a'+β₯ŠβŸœ(↕×´)3β€Ώ5
+↗️
    ⊒ a ← 'a'+β₯ŠβŸœ(↕×´)3β€Ώ5
 β”Œβ”€       
 β•΅"abcde  
   fghij  
   klmno" 
         β”˜
+
     (+βŒœΒ΄Β·β†•Β¨β‰’)βŠΈβŠ” a
 ⟨ "a" "bf" "cgk" "dhl" "eim" "jn" "o" ⟩
 
@@ -72,8 +75,9 @@

(Could we define phrase more easily? See below.)

If we'd like to ignore words of 0 letters, or more than 5, we can set all word lengths greater than 5 to 0, then reduce the lengths by 1. Two words end up with left argument values of Β―1 and are omitted from the result.

-↗️
    1 -˜ β‰€βŸœ5βŠΈΓ— β‰ Β¨ phrase
+↗️
    1 -˜ β‰€βŸœ5βŠΈΓ— β‰ Β¨ phrase
 ⟨ 2 3 ¯1 1 0 3 1 ¯1 ⟩
+
     β‰Λ˜ {1-Λœβ‰€βŸœ5βŠΈΓ—β‰ Β¨π•©}βŠΈβŠ” phrase
 β”Œβ”€                   
 β•΅ ⟨ "a" ⟩            
@@ -92,7 +96,8 @@
   ⟨⟩                 
                     β”˜
 
-

When Group is called dyadically, the left argument is used for the indices and the right is used for values, as seen above. When it is called monadically, the right argument, which must be a list, gives the indices and the values grouped are the right argument's indices, that is, ↕≠𝕩.

+

Group Indices

+

Above, Group has two arguments, and 𝕨 gives the indices and 𝕩 is the values to be grouped. In the one-argument case, 𝕩 now gives the result indices, and the values grouped are indices related to 𝕩. For a numeric list, βŠ”π•© is π•©βŠ”β†•β‰ π•©.

↗️
    β‰Λ˜ βŠ” 2β€Ώ3β€ΏΒ―1β€Ώ2
 β”Œβ”€         
 β•΅ ⟨⟩       
@@ -102,6 +107,7 @@
           β”˜
 

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

+

But 𝕩 can also be a list of numeric arrays. In this case the indices β†•βˆΎβ‰’Β¨π•© will be grouped by 𝕩 according to the multidimensional grouping documented in the next section. Since the argument to Range (↕) is now a list, each index to be grouped is a list instead of a number. As with ↕, the depth of the result of Group Indices is always one greater than that of its argument. One consequence is that for an array a of any rank, βŠ”β‹ˆa groups the indices ↕≒a.

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.

@@ -118,7 +124,6 @@ β”˜

Each group iβŠ‘π•¨βŠ”π•© is composed of the cells j<Β¨βŠΈβŠπ•© such that iβ‰’jβŠ‘Β¨π•¨. 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

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

↗️
    β‰ Β¨βŠ” 2β€Ώ3β€Ώ1β€Ώ2
-- 
cgit v1.2.3