From 47c0a52e614d01eb251da9301c2961338141ab6c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 29 Jun 2022 22:38:29 -0400 Subject: Editing continues, with some deletions this time --- docs/doc/depth.html | 82 ++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 42 deletions(-) (limited to 'docs/doc/depth.html') diff --git a/docs/doc/depth.html b/docs/doc/depth.html index 6d043d8d..53518c35 100644 --- a/docs/doc/depth.html +++ b/docs/doc/depth.html @@ -64,7 +64,7 @@ -

The depth of an array is the greatest level of array nesting it attains, or, put another way, the greatest number of times you can pick an element starting from the original array before reaching an atom. The monadic function Depth () returns the depth of its argument, while the 2-modifier Depth () can control the way its left operand is applied based on the depth of its arguments. Several primitive functions also use the depth of the left argument to decide whether it applies to a single axis of the right argument or to several axes.

+

The depth of an array is the greatest level of array nesting it attains, or, put another way, the greatest number of times you can pick an element starting from the original array before reaching an atom. The monadic function Depth () returns the depth of its argument, while the 2-modifier Depth () controls the way its left operand is applied based on the depth of its arguments. Several primitive functions also check the depth of the left argument to decide whether it applies to a single axis of the right argument or to several axes.

The Depth function

To find the depth of an array, use Depth (). For example, the depth of a list of numbers or characters is 1:

↗️
     234
@@ -72,13 +72,13 @@
      "a string is a list of characters"
 1
 
-

Depth is somewhat analogous to an array's rank =𝕩, and in fact rank can be "converted" to depth by splitting rows with <1, reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape:

+

Depth is somewhat analogous to an array's rank =𝕩, and in fact rank can be "converted" to depth by splitting rows with <1 (Enclose Rank 1), reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape:

↗️
     34"characters"
 1
      (1+↕10)"characters"
 1
 
-

Also unlike rank, Depth does care about the elements of its argument: in fact, to find the depth of an array, every element must be inspected.

+

Also unlike rank, Depth does care about the elements of its argument: in fact, to find the depth of an array, every element must be inspected recursively.

↗️
     2,3,4,5
 1
      2,<3,4,5
@@ -86,18 +86,16 @@
      2,<3,4,<<<5
 4
 
-

As the above expressions suggest, the depth of an array is the maximum of its elements' depths, plus one. The base case, an atom (including a function or modifier), has depth 0.

-↗️
    'c'
+

The depth of an array is the maximum of its elements' depths, plus one. The base case, an atom (including a function or modifier), has depth 0.

+↗️
     'c'
 0
-    F+f
+    F+  f
 0
-    'c',f,2
+     'c',f,2
 1
-    5,'c',f,2⟩⟩
-2
 
-

If the function IsArray indicates whether its argument is an array, then we can write a recursive definition of Depth using the Choose modifier.

-
DepthIsArray0{1+0´Depth¨𝕩}
+

Using 0=•Type to test whether 𝕩 is an array, as well as the Choose modifier, we can write a recursive definition of Depth.

+
Depth  (0=•Type)0{1+0´Depth¨𝕩}
 

The minimum element depth of 0 implies that an empty array's depth is 1.

↗️
    ⟨⟩
@@ -106,7 +104,7 @@
 1
 

Testing depth for multiple-axis primitives

-

Several primitive functions use the left argument to manipulate the right argument along one or more axes, using the leading axis convention.

+

Several primitive functions manipulate 𝕩 along one or more axes based on 𝕨, according to the leading axis convention.

@@ -125,24 +123,24 @@
-

Functions such as Take and Drop use a single number per axis. When the left argument is a list of numbers, they apply to initial axes. But for convenience, a single number is also accepted, and applied to the first axis only. This is equivalent to deshaping the left argument before applying the function.

+

Functions such as Take and Drop accept a single number per axis in 𝕨. If given a list of numbers, they apply to initial axes. But for convenience, a single number is also accepted, and applied to the first axis only. This is equivalent to deshaping the left argument before applying the function.

↗️
    27777"abc"
 ⟨ 2 7 7 7 ⟩
     2117777"abc"
 ⟨ 2 1 1 7 ⟩
 
-

In these cases the flexibility seems trivial because the left argument has depth 1 or 0: it is an array or isn't, and it's obvious what a plain number should do. But for the second row in the table, the left argument is always an array. The general case (Select below) is that the left argument is a list and its elements correspond to right argument axes:

+

In these cases the flexibility seems trivial because 𝕨 has depth 1 or 0: it is an array or isn't, and it's obvious what a plain number should do. But for the second row in the table, 𝕨 is always an array. The general case (Select below) is that its elements are lists, each corresponding to one axis of 𝕩:

↗️
    32,141  67
 ┌─                         
 ╵ ⟨ 3 1 ⟩ ⟨ 3 4 ⟩ ⟨ 3 1 ⟩  
   ⟨ 2 1 ⟩ ⟨ 2 4 ⟩ ⟨ 2 1 ⟩  
                           ┘
 
-

This means the left argument is homogeneous of depth 2. What should an argument of depth 1, that is, an array of atoms, do? One option is to continue to require the left argument to be a list, and convert any atom argument into an array by enclosing it:

+

This means 𝕨 is homogeneous of depth 2. What should an argument of depth 1, that is, an array of atoms, do? One option is to continue to require the left argument to be a list, and convert any atom argument into an array by enclosing it:

↗️
    32,1 <(0=≡)¨ 67
 ⟨ ⟨ 3 1 ⟩ ⟨ 2 1 ⟩ ⟩
 
-

While very consistent, this extension represents a small convenience and makes it difficult to act on a single axis, which for Replicate and Group is probably the most common way the primitive is used:

+

While very consistent, this extension represents a small convenience and makes it difficult to act on a single axis, which (particularly for Replicate and Group) is probably the most common way the primitive is used:

↗️
    32123 / "abcde"
 "aaabbcddeee"
 
@@ -152,41 +150,41 @@ ⟨ ⟨ 2 1 4 0 ⟩ ⟨ 2 1 4 1 ⟩ ⟩

The Depth modifier

-

The Depth 2-modifier () is a generalization of Each that allows diving deeper into an array. To illustrate it we'll use a shape 43 array of lists of lists.

-↗️
     n  <12 4322⥊↕48
-┌─                                                                         
-╵ ⟨ ⟨ 0 1 ⟩ ⟨ 2 3 ⟩ ⟩     ⟨ ⟨ 4 5 ⟩ ⟨ 6 7 ⟩ ⟩     ⟨ ⟨ 8 9 ⟩ ⟨ 10 11 ⟩ ⟩    
-  ⟨ ⟨ 12 13 ⟩ ⟨ 14 15 ⟩ ⟩ ⟨ ⟨ 16 17 ⟩ ⟨ 18 19 ⟩ ⟩ ⟨ ⟨ 20 21 ⟩ ⟨ 22 23 ⟩ ⟩  
-  ⟨ ⟨ 24 25 ⟩ ⟨ 26 27 ⟩ ⟩ ⟨ ⟨ 28 29 ⟩ ⟨ 30 31 ⟩ ⟩ ⟨ ⟨ 32 33 ⟩ ⟨ 34 35 ⟩ ⟩  
-  ⟨ ⟨ 36 37 ⟩ ⟨ 38 39 ⟩ ⟩ ⟨ ⟨ 40 41 ⟩ ⟨ 42 43 ⟩ ⟩ ⟨ ⟨ 44 45 ⟩ ⟨ 46 47 ⟩ ⟩  
-                                                                          ┘
+

The Depth 2-modifier () is a generalization of Each that allows diving deeper into an array. To illustrate it we'll use a shape 42 array of lists of lists.

+↗️
     n  <12 4223⥊↕48
+┌─                                                             
+╵ ⟨ ⟨ 0 1 2 ⟩ ⟨ 3 4 5 ⟩ ⟩       ⟨ ⟨ 6 7 8 ⟩ ⟨ 9 10 11 ⟩ ⟩      
+  ⟨ ⟨ 12 13 14 ⟩ ⟨ 15 16 17 ⟩ ⟩ ⟨ ⟨ 18 19 20 ⟩ ⟨ 21 22 23 ⟩ ⟩  
+  ⟨ ⟨ 24 25 26 ⟩ ⟨ 27 28 29 ⟩ ⟩ ⟨ ⟨ 30 31 32 ⟩ ⟨ 33 34 35 ⟩ ⟩  
+  ⟨ ⟨ 36 37 38 ⟩ ⟨ 39 40 41 ⟩ ⟩ ⟨ ⟨ 42 43 44 ⟩ ⟨ 45 46 47 ⟩ ⟩  
+                                                              ┘
      n
 3
 

Reversing n swaps all the rows:

↗️
     n
-┌─                                                                         
-╵ ⟨ ⟨ 36 37 ⟩ ⟨ 38 39 ⟩ ⟩ ⟨ ⟨ 40 41 ⟩ ⟨ 42 43 ⟩ ⟩ ⟨ ⟨ 44 45 ⟩ ⟨ 46 47 ⟩ ⟩  
-  ⟨ ⟨ 24 25 ⟩ ⟨ 26 27 ⟩ ⟩ ⟨ ⟨ 28 29 ⟩ ⟨ 30 31 ⟩ ⟩ ⟨ ⟨ 32 33 ⟩ ⟨ 34 35 ⟩ ⟩  
-  ⟨ ⟨ 12 13 ⟩ ⟨ 14 15 ⟩ ⟩ ⟨ ⟨ 16 17 ⟩ ⟨ 18 19 ⟩ ⟩ ⟨ ⟨ 20 21 ⟩ ⟨ 22 23 ⟩ ⟩  
-  ⟨ ⟨ 0 1 ⟩ ⟨ 2 3 ⟩ ⟩     ⟨ ⟨ 4 5 ⟩ ⟨ 6 7 ⟩ ⟩     ⟨ ⟨ 8 9 ⟩ ⟨ 10 11 ⟩ ⟩    
-                                                                          ┘
+┌─                                                             
+╵ ⟨ ⟨ 36 37 38 ⟩ ⟨ 39 40 41 ⟩ ⟩ ⟨ ⟨ 42 43 44 ⟩ ⟨ 45 46 47 ⟩ ⟩  
+  ⟨ ⟨ 24 25 26 ⟩ ⟨ 27 28 29 ⟩ ⟩ ⟨ ⟨ 30 31 32 ⟩ ⟨ 33 34 35 ⟩ ⟩  
+  ⟨ ⟨ 12 13 14 ⟩ ⟨ 15 16 17 ⟩ ⟩ ⟨ ⟨ 18 19 20 ⟩ ⟨ 21 22 23 ⟩ ⟩  
+  ⟨ ⟨ 0 1 2 ⟩ ⟨ 3 4 5 ⟩ ⟩       ⟨ ⟨ 6 7 8 ⟩ ⟨ 9 10 11 ⟩ ⟩      
+                                                              ┘
 

Depth ¯1 is equivalent to Each, and reverses the larger lists, while depth ¯2 applies Each twice to reverse the smaller lists:

↗️
    ¯1 n
-┌─                                                                         
-╵ ⟨ ⟨ 2 3 ⟩ ⟨ 0 1 ⟩ ⟩     ⟨ ⟨ 6 7 ⟩ ⟨ 4 5 ⟩ ⟩     ⟨ ⟨ 10 11 ⟩ ⟨ 8 9 ⟩ ⟩    
-  ⟨ ⟨ 14 15 ⟩ ⟨ 12 13 ⟩ ⟩ ⟨ ⟨ 18 19 ⟩ ⟨ 16 17 ⟩ ⟩ ⟨ ⟨ 22 23 ⟩ ⟨ 20 21 ⟩ ⟩  
-  ⟨ ⟨ 26 27 ⟩ ⟨ 24 25 ⟩ ⟩ ⟨ ⟨ 30 31 ⟩ ⟨ 28 29 ⟩ ⟩ ⟨ ⟨ 34 35 ⟩ ⟨ 32 33 ⟩ ⟩  
-  ⟨ ⟨ 38 39 ⟩ ⟨ 36 37 ⟩ ⟩ ⟨ ⟨ 42 43 ⟩ ⟨ 40 41 ⟩ ⟩ ⟨ ⟨ 46 47 ⟩ ⟨ 44 45 ⟩ ⟩  
-                                                                          ┘
+┌─                                                             
+╵ ⟨ ⟨ 3 4 5 ⟩ ⟨ 0 1 2 ⟩ ⟩       ⟨ ⟨ 9 10 11 ⟩ ⟨ 6 7 8 ⟩ ⟩      
+  ⟨ ⟨ 15 16 17 ⟩ ⟨ 12 13 14 ⟩ ⟩ ⟨ ⟨ 21 22 23 ⟩ ⟨ 18 19 20 ⟩ ⟩  
+  ⟨ ⟨ 27 28 29 ⟩ ⟨ 24 25 26 ⟩ ⟩ ⟨ ⟨ 33 34 35 ⟩ ⟨ 30 31 32 ⟩ ⟩  
+  ⟨ ⟨ 39 40 41 ⟩ ⟨ 36 37 38 ⟩ ⟩ ⟨ ⟨ 45 46 47 ⟩ ⟨ 42 43 44 ⟩ ⟩  
+                                                              ┘
     ¯2 n
-┌─                                                                         
-╵ ⟨ ⟨ 1 0 ⟩ ⟨ 3 2 ⟩ ⟩     ⟨ ⟨ 5 4 ⟩ ⟨ 7 6 ⟩ ⟩     ⟨ ⟨ 9 8 ⟩ ⟨ 11 10 ⟩ ⟩    
-  ⟨ ⟨ 13 12 ⟩ ⟨ 15 14 ⟩ ⟩ ⟨ ⟨ 17 16 ⟩ ⟨ 19 18 ⟩ ⟩ ⟨ ⟨ 21 20 ⟩ ⟨ 23 22 ⟩ ⟩  
-  ⟨ ⟨ 25 24 ⟩ ⟨ 27 26 ⟩ ⟩ ⟨ ⟨ 29 28 ⟩ ⟨ 31 30 ⟩ ⟩ ⟨ ⟨ 33 32 ⟩ ⟨ 35 34 ⟩ ⟩  
-  ⟨ ⟨ 37 36 ⟩ ⟨ 39 38 ⟩ ⟩ ⟨ ⟨ 41 40 ⟩ ⟨ 43 42 ⟩ ⟩ ⟨ ⟨ 45 44 ⟩ ⟨ 47 46 ⟩ ⟩  
-                                                                          ┘
+┌─                                                             
+╵ ⟨ ⟨ 2 1 0 ⟩ ⟨ 5 4 3 ⟩ ⟩       ⟨ ⟨ 8 7 6 ⟩ ⟨ 11 10 9 ⟩ ⟩      
+  ⟨ ⟨ 14 13 12 ⟩ ⟨ 17 16 15 ⟩ ⟩ ⟨ ⟨ 20 19 18 ⟩ ⟨ 23 22 21 ⟩ ⟩  
+  ⟨ ⟨ 26 25 24 ⟩ ⟨ 29 28 27 ⟩ ⟩ ⟨ ⟨ 32 31 30 ⟩ ⟨ 35 34 33 ⟩ ⟩  
+  ⟨ ⟨ 38 37 36 ⟩ ⟨ 41 40 39 ⟩ ⟩ ⟨ ⟨ 44 43 42 ⟩ ⟨ 47 46 45 ⟩ ⟩  
+                                                              ┘
 

While a negative depth tells how many levels to go down, a non-negative depth gives the maximum depth of the argument before applying the left operand. On a depth-3 array like above, depth 2 is equivalent to ¯1 and depth 1 is equivalent to ¯2. A depth of 0 means to descend all the way to the level of atoms, that is, apply pervasively, like an arithmetic function.

↗️
    'a',"bc" 0 23,4
-- 
cgit v1.2.3