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/couple.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/doc/couple.html') diff --git a/docs/doc/couple.html b/docs/doc/couple.html index 8bc54ef5..03b0bf07 100644 --- a/docs/doc/couple.html +++ b/docs/doc/couple.html @@ -4,7 +4,7 @@ BQN: Couple and Merge -

Couple and Merge

+

Couple and Merge

Solo/Couple () and Merge (>) are functions that create a higher-rank array from lower-rank components. Each takes some number of inner arrays organized in an outer structure, and creates a single array combining all elements of those inner arrays. For example, let's couple two arrays of shape 23:

↗️
     p  35×3
 ┌─        
@@ -56,7 +56,7 @@
 ⟨ 2 3 5 ⟩
 

Merge is effectively 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.

-

Merge and array theory

+

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 ravels of the 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 (which, being independent elements, could be any sort of "ragged" array) can fit together in an array, and then to consider them to be such an array. For this reason, Merge (or a virtual analogue) is used to combine the result cells when calling a function with Rank into a single array.

↗️
     > a
 "ABrstABuvwABxyzCDrstCDuvwCDxyz"
@@ -74,7 +74,7 @@
 ⟨ 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

+

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 pair function, which creates a list from its arguments, can be written Pair <, while in either valence is >Pair. As an interesting consequence, ←→ ><, and the same relationship holds for Pair.

↗️
    2,3 < "abc"  # Pair two values
@@ -82,6 +82,6 @@
     < "abc"        # Pair one(?) value
 ⟨ "abc" ⟩
 
-

Definitions

+

Definitions

As discussed above, is equivalent to >{𝕩;𝕨,𝕩}. 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𝕩).

-- cgit v1.2.3