From e2b07a5fd0bbaad232c717fb90a31d6c61d72bd4 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 14 Jul 2022 20:06:50 -0400 Subject: Try to include previous variable definitions in REPL links --- docs/doc/transpose.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'docs/doc/transpose.html') diff --git a/docs/doc/transpose.html b/docs/doc/transpose.html index 8c9841b3..998840b8 100644 --- a/docs/doc/transpose.html +++ b/docs/doc/transpose.html @@ -21,7 +21,7 @@ ┘

Transpose is named this way because it exchanges the two axes of the matrix. Above you can see that while mat has shape 23, mat has shape 32, and we can also check that the element at index ij in mat is the same as the one at ji in mat:

-↗️
    10  mat
+↗️
    10  mat
 3
     01   mat
 3
@@ -53,7 +53,7 @@
                        ┘
 

But, ignoring the whitespace and going in reading order, the argument and result have exactly the same element ordering as for the rank 2 matrix ˘ a322:

-↗️
     ˘ a322
+↗️
     ˘ a322
 ┌─                          
 · ┌─            ┌─          
   ╵ 0 1  2  3   ╵ 0 4  8    
@@ -64,7 +64,7 @@
                            ┘
 

To exchange multiple axes, use the Repeat modifier. A negative power moves axes in the other direction, just like how Rotate handles negative left arguments. In particular, to move the last axis to the front, use Undo (as you might expect, this exactly inverts ).

-↗️
     3 a23456
+↗️
     3 a23456
 ⟨ 5 6 2 3 4 ⟩
 
       a23456
@@ -72,11 +72,11 @@
 

In fact, we have ≢⍉k a ←→ k⌽≢a for any whole number k and array a.

To move axes other than the first, use the Rank modifier in order to leave initial axes untouched. A rank of k>0 transposes only the last k axes while a rank of k<0 ignores the first |k axes.

-↗️
     3 a23456
+↗️
     3 a23456
 ⟨ 2 3 5 6 4 ⟩
 

And of course, Rank and Repeat can be combined to do more complicated transpositions: move a set of contiguous axes with any starting point and length to the end.

-↗️
     ¯1 a23456
+↗️
     ¯1 a23456
 ⟨ 2 6 3 4 5 ⟩
 

Using these forms (and the Rank function), we can state BQN's generalized matrix product swapping rule:

@@ -84,28 +84,28 @@

Certainly not as concise as APL's version, but not a horror either. BQN's rule is actually more parsimonious in that it only performs the axis exchanges necessary for the computation: it moves the two axes that will be paired with the matrix product into place before the product, and directly exchanges all axes afterwards. Each of these steps is equivalent in terms of data movement to a matrix transpose, the simplest nontrivial transpose to perform. Also remember that for two-dimensional matrices both kinds of transposition are the same, so that APL's simpler rule MP MP˜ holds in BQN on rank 2.

Axis permutations of the types we've shown generate the complete permutation group on any number of axes, so you could produce any transposition you want with the right sequence of monadic transpositions with Rank. However, this can be unintuitive and tedious. What if you want to transpose the first three axes, leaving the rest alone? With monadic Transpose you have to send some axes to the end, then bring them back to the beginning. For example [following four or five failed tries]:

-↗️
     ¯2  a23456  # Restrict Transpose to the first three axes
+↗️
     ¯2  a23456  # Restrict Transpose to the first three axes
 ⟨ 3 4 2 5 6 ⟩
 

In a case like this the dyadic version of , called Reorder Axes, is much easier.

Reorder Axes

Transpose also allows a left argument that specifies a permutation of 𝕩's axes. For each index pi𝕨 in the left argument, axis i of 𝕩 is used for axis p of the result. Multiple argument axes can be sent to the same result axis, in which case that axis goes along a diagonal of 𝕩, and the result will have a lower rank than 𝕩 (see the next section).

-↗️
     13204  a23456
+↗️
     13204  a23456
 ⟨ 5 2 4 3 6 ⟩
 
      12200  a23456  # Don't worry too much about this case though
 ⟨ 5 2 3 ⟩
 

Since this kind of rearrangement can be counterintuitive, it's often easier to use when specifying all axes. If p≠≢a, then we have pa ←→ p⊏≢a.

-↗️
     13204  a23456
+↗️
     13204  a23456
 ⟨ 3 5 4 2 6 ⟩
 

BQN makes one further extension, which is to allow only some axes to be specified (this is the only difference in dyadic relative to APL). Then 𝕨 will be matched up with leading axes of 𝕩. Those axes are moved according to 𝕨, and remaining axes are placed in order into the gaps between them.

-↗️
     024  a23456
+↗️
     024  a23456
 ⟨ 2 5 3 6 4 ⟩
 

In particular, the case with only one axis specified is interesting. Here, the first axis ends up at the given location. This gives us a much better solution to the problem at the end of the last section.

-↗️
     2  a23456  # Restrict Transpose to the first three axes
+↗️
     2  a23456  # Restrict Transpose to the first three axes
 ⟨ 3 4 2 5 6 ⟩
 

Finally, it's worth noting that, as monadic Transpose moves the first axis to the end, it's equivalent to Reorder Axes with a "default" left argument: (=-1˙).

-- cgit v1.2.3