From 7fa325f583a59a1999cd8ce093a49f8048a3e05c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 8 Jul 2022 22:06:05 -0400 Subject: Simplify and update Couple/Merge docs --- docs/doc/arrayrepr.html | 2 +- docs/doc/couple.html | 15 ++++++++------- docs/doc/rank.html | 2 +- docs/doc/syntax.html | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) (limited to 'docs/doc') diff --git a/docs/doc/arrayrepr.html b/docs/doc/arrayrepr.html index 5218009e..b2335438 100644 --- a/docs/doc/arrayrepr.html +++ b/docs/doc/arrayrepr.html @@ -193,7 +193,7 @@

High-rank arrays

-

Higher-rank arrays can be written with [], an array notation that indicates each element is to be used as a cell of its result. It's identical to forming a list and applying Merge ([] is the same as >).

+

Higher-rank arrays can be written with [], an array notation that indicates each element is to be used as a cell of its result. It's identical to forming a list and applying Merge ([] is the same as >).

↗️
    [23, 41, 05]
 ┌─     
 ╵ 2 3  
diff --git a/docs/doc/couple.html b/docs/doc/couple.html
index d5325de5..86d8434a 100644
--- a/docs/doc/couple.html
+++ b/docs/doc/couple.html
@@ -59,7 +59,11 @@
      > a
 ⟨ 2 3 5 ⟩
 
-

Merge serves as a generalization of Solo and Couple, since Solo is {>𝕩} and Couple is {>𝕨,𝕩}. Since works on the "list" of arguments, it can only add one dimension, but > can take any number of dimensions as its input.

+

If 𝕩 is empty, but has a fill element, then its shape is used for the inner shape. If it doesn't have a fill, the inner shape is assumed to be empty, so that the result is 𝕩 with no changes.

+

Merge serves as a generalization of Solo and Couple, since Solo is {>𝕩} and Couple is {>𝕨,𝕩}. These can be combined with Pair, giving >⋈ for both. Since the result of has rank 1, it can only add one dimension, but > can take any number of dimensions as its input.

+

Coupling units

+

A note on the topic of Solo and Couple applied to units. As always, one axis will be added, so that the result is a list (strangely, J's laminate differs from Couple in this one case, as it adds an axis to get a shape 21 result). Solo on a unit is interchangeable with Deshape (), and either primitive might be chosen for stylistic reasons. Couple on units is equivalent to Join-to (), but this is an irregular form of Join-to because it is the only case where Join-to adds an axis to both arguments instead of just one. Couple should be preferred in this case.

+

As a consequence, Pair () can be written <, while is > as discussed above. This gives the neat (but not useful) identities ←→ ><, and ←→ ><, which have the same form because adding < commutes with adding >.

Merge and array theory

In all cases, what these functions do is more like reinterpreting existing data than creating new information. In fact, if we ignore the shape and look at the deshaped arrays involved in a call to Merge, we find that it just joins them together. Essentially, Merge is a request to ensure that the inner arrays make up a homogeneous (not "ragged") array, and then to consider them to be such an array. It's the same thing Rank does to combine the result cells from its operand into a single array.

↗️
     > a
@@ -70,7 +74,7 @@
       ¨ a
 "ABrstABuvwABxyzCDrstCDuvwCDxyz"
 
-

Somewhat like Table , Merge might be considered a fundamental way to build up multidimensional arrays from lists. In both cases rank-0 or unit arrays are somewhat special. They are the identity value of a function with Table, and Enclose (<), which creates a unit, is a right inverse to Merge. Enclose is needed because Merge can't produce a rank 0 array on its own. Merge has another catch as well: it can't produce arrays with a 0 in the shape, except at the end, without relying on a fill element.

+

Somewhat like Table , Merge might be considered a fundamental way to build up multidimensional arrays from lists. In both cases rank-0 or unit arrays are somewhat special. They are the identity value of a function with Table, and Enclose (<), which creates a unit, is a right inverse to Merge. Enclose is needed because Merge can't produce a rank 0 array on its own. Merge has another catch as well: it can't produce arrays with a 0 in the shape, except at the end, without relying on a fill element.

↗️
     e  ⟨⟩¨ 3
 ⟨ ⟨⟩ ⟨⟩ ⟨⟩ ⟩
      > e
@@ -79,9 +83,6 @@
 ⟨ 3 0 ⟩
 

Above we start with a list of three empty arrays. After merging once we get a shape 30 array, sure, but what happens next? The shape added by another merge is the shared shape of that array's elements—and there aren't any! If the nested list kept some type information around then we might know, but extra type information is essentially how lists pretend to be arrays. True dynamic lists simply can't represent multidimensional arrays with a 0 in the middle of the shape. In this sense, arrays are a richer model than nested lists.

-

Coupling units

-

A note on the topic of Solo and Couple applied to units. As always, one axis will be added, so that the result is a list (strangely, J's laminate differs from Couple in this one case, as it will add an axis to get a shape 21 result). For Solo, this is interchangeable with Deshape (), and either primitive might be chosen for stylistic reasons. For Couple, it is equivalent to Join-to (), but this is an irregular form of Join-to because it is the only case where Join-to adds an axis to both arguments instead of just one. Couple should be preferred in this case.

-

The function Pair () can be written <, while in either valence is >. As an interesting consequence, ←→ ><, and ←→ ><. These two identities have the same form because adding < commutes with adding >.

Definitions

-

As discussed above, is equivalent to >{𝕩;𝕨,𝕩} or >⋈. To complete the picture we should describe Merge fully. Merge is defined on an array argument 𝕩 such that there's some shape s satisfying ´(s≡≢)¨𝕩. If 𝕩 is empty then any shape satisfies this expression; s should be chosen based on known type information for 𝕩 or otherwise assumed to be ⟨⟩. If s is empty then 𝕩 is allowed to contain atoms as well as unit arrays, and these will be implicitly promoted to arrays by the indexing used later. We construct the result by combining the outer and inner axes of the argument with Table; since the outer axes come first they must correspond to the left argument and the inner axes must correspond to the right argument. 𝕩 is a natural choice of left argument, and because no concrete array can be used, the right argument will be s, the array of indices into any element of 𝕩. To get the appropriate element corresponding to a particular choice of index and element of 𝕩 we should select using that index. The result of Merge is 𝕩˜⌜s.

-

Given this definition we can also describe Rank () in terms of Each (¨) and the simpler monadic function Enclose-Rank <k. We assume effective ranks j for 𝕨 (if present) and k for 𝕩 have been computed. Then the correspondence is 𝕨Fk𝕩 ←→ >(<j𝕨)F¨(<k𝕩).

+

We can define as >⋈. To complete the picture we should describe Merge fully. Merge is defined on an array argument 𝕩 such that there's some shape s satisfying ´(s≡≢)¨𝕩. If 𝕩 is empty then any shape satisfies this expression; s is then the shape of the fill if there is one, or otherwise ⟨⟩.

+

Then the result of Merge is 𝕩˜⌜s. Here, Table is a nice way of combining outer and inner axes to produce the result; since the outer axes come first they should go on the left and the inner axes on the right. 𝕩 is a natural choice of left argument, and because no concrete array can be used, the right argument is s, the array of indices into any element of 𝕩. Then Pick selects all the elements. If s is empty, then 𝕩 is allowed to contain atoms as well as unit arrays. Pick will implicitly treat them as arrays.

diff --git a/docs/doc/rank.html b/docs/doc/rank.html index 8cf63ad2..631693cf 100644 --- a/docs/doc/rank.html +++ b/docs/doc/rank.html @@ -219,7 +219,7 @@ <2 43210 ⟨ 1 0 ⟩ -

We can build a frame array using <2, as shown above. In the general case, the frame remains conceptual: the actual array <2 x is never created, and the result might also not have the shape 432. But the result shape does always have 432 as a prefix. Rank maps over these axes, leaving them intact. And it can be defined in terms of the cell-splitting function <k, and its inverse Merge (>).

+

We can build a frame array using <2, as shown above. In the general case, the frame remains conceptual: the actual array <2 x is never created, and the result might also not have the shape 432. But the result shape does always have 432 as a prefix. Rank maps over these axes, leaving them intact. And it can be defined in terms of the cell-splitting function <k, and its inverse Merge (>).

Fk x  ←→  >F¨<k x
 

That is, Fk splits its argument into k-cells, applies F to each of these (in index order, of course), then merges the results into a single array.

diff --git a/docs/doc/syntax.html b/docs/doc/syntax.html index 26af7c42..23f1a3a2 100644 --- a/docs/doc/syntax.html +++ b/docs/doc/syntax.html @@ -258,7 +258,7 @@

List and array notation

Full documentation

Lists (1-dimensional arrays) are enclosed in angle brackets ⟨⟩, with the results of the expressions in between being the list's elements. Lists of two elements or more can also be written with the ligature character . This character has higher binding strength than any part of an expression except . for namespace field access. If one of the elements is a compound expression, then it will need to be enclosed in parentheses.

-

Arrays, or at least non-empty ones with rank 1 or more, can be written with square brackets []. These work just like angle brackets but merge the elements so that they form cells of the result.

+

Arrays, or at least non-empty ones with rank 1 or more, can be written with square brackets []. These work just like angle brackets but merge the elements so that they form cells of the result.

Blocks

Full documentation

Blocks are written with curly braces {} and can have a subject, function, or modifier role. The contents are any number of bodies separated by ;. Each body is a sequence of expressions to be evaluated in order, possibly with a header, followed by :, that sets the type and describes expected inputs. A body runs in its own environment according to the rules of lexical scoping. The result is either a namespace, if the body used , or the result of the last expression.

-- cgit v1.2.3