diff options
Diffstat (limited to 'docs/doc/rank.html')
| -rw-r--r-- | docs/doc/rank.html | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/docs/doc/rank.html b/docs/doc/rank.html index 631693cf..409fee4b 100644 --- a/docs/doc/rank.html +++ b/docs/doc/rank.html @@ -104,7 +104,7 @@ </pre> <p>What's it mean for Nudge to shift the "entire table"? The block above shows that it shifts downward, but what's really happening is that Nudge treats <code><span class='Value'>𝕩</span></code> as a collection of major cells—its rows—and shifts these. So it adds an entire row and moves the rest of the rows downwards. Nudge Cells appears similar, but it's acting independently on each row, and the values that it moves around are major cells of the row, that is, rank-0 units.</p> <p>Here's an example showing how Cells can be used to shift each row independently, even though it's not possible to shift columns like this (in fact the best way to do that would be to <a href="transpose.html">transpose</a> in order to work on rows). It uses the not-yet-introduced dyadic form of Cells, so you might want to come back to it after reading the next section.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KOKGkSLiiJjiiJgiKSDiipHiirjCu8uYIGE=">↗️</a><pre> <span class='Paren'>(</span><span class='Function'>↑</span><span class='String'>"∘∘"</span><span class='Paren'>)</span> <span class='Function'>⊑</span><span class='Modifier2'>⊸</span><span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDihpAgJ2EnICsgM+KAv+KImCDipYog4oaVMjQgICMgQSBjaGFyYWN0ZXIgYXJyYXkKKOKGkSLiiJjiiJgiKSDiipHiirjCu8uYIGE=">↗️</a><pre> <span class='Paren'>(</span><span class='Function'>↑</span><span class='String'>"∘∘"</span><span class='Paren'>)</span> <span class='Function'>⊑</span><span class='Modifier2'>⊸</span><span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> ┌─ ╵"abcdefgh ∘ijklmno @@ -112,7 +112,7 @@ ┘ </pre> <p>You can also see how Cells splits its argument into rows using a less array-oriented primitive: <a href="enclose.html">Enclose</a> just wraps each row up so that it appears as a separate element in the final result.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=PMuYIGE=">↗️</a><pre> <span class='Function'><</span><span class='Modifier'>˘</span> <span class='Value'>a</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDihpAgJ2EnICsgM+KAv+KImCDipYog4oaVMjQgICMgQSBjaGFyYWN0ZXIgYXJyYXkKPMuYIGE=">↗️</a><pre> <span class='Function'><</span><span class='Modifier'>˘</span> <span class='Value'>a</span> ⟨ "abcdefgh" "ijklmnop" "qrstuvwx" ⟩ </pre> <p>Enclose also comes in handy for the following task: join the rows in an array of lists, resulting in an array where each element is a joined row. The obvious guess would be "join cells", <code><span class='Function'>∾</span><span class='Modifier'>˘</span></code>, but it doesn't work, because each <code><span class='Function'>∾</span></code> can return a result with a different length. Cells tries to make each result of <code><span class='Function'>∾</span></code> into a <em>cell</em>, when the problem was to use it as an <em>element</em>. But a 0-cell is an enclosed element, so we can close the gap by applying <code><span class='Function'><</span></code> to a joined list: <code><span class='Function'><</span><span class='Modifier2'>∘</span><span class='Function'>∾</span></code>.</p> @@ -131,7 +131,7 @@ <p>This approach can apply to more complicated functions as well. And because the result of <code><span class='Function'><</span></code> always has the same shape, <code><span class='Bracket'>⟨⟩</span></code>, the function <code><span class='Function'><</span><span class='Modifier2'>∘</span><span class='Function'>𝔽</span><span class='Modifier'>˘</span></code> can never have a shape agreement error. So if <code><span class='Function'>𝔽</span><span class='Modifier'>˘</span></code> fails, it can't hurt to check <code><span class='Function'><</span><span class='Modifier2'>∘</span><span class='Function'>𝔽</span><span class='Modifier'>˘</span></code> and see what results <code><span class='Function'>𝔽</span></code> is returning.</p> <h3 id="two-arguments"><a class="header" href="#two-arguments">Two arguments</a></h3> <p>When given two arguments, Cells tries to pair their cells together. Starting simple, a unit (whether array or atom) on either side will be paired with every cell of the other argument.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=J+KImCcgwrvLmCBh">↗️</a><pre> <span class='String'>'∘'</span> <span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDihpAgJ2EnICsgM+KAv+KImCDipYog4oaVMjQgICMgQSBjaGFyYWN0ZXIgYXJyYXkKJ+KImCcgwrvLmCBh">↗️</a><pre> <span class='String'>'∘'</span> <span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> ┌─ ╵"∘abcdefg ∘ijklmno @@ -139,7 +139,7 @@ ┘ </pre> <p>If you <em>want</em> to use this one-to-many behavior with an array, it'll take more work: since you're really only mapping over one argument, <a href="hook.html">bind</a> the other inside Cells.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=IuKImOKImCIgwrvLmCBhCgoi4oiY4oiYIuKKuMK7y5ggYQ==">↗️</a><pre> <span class='String'>"∘∘"</span> <span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDihpAgJ2EnICsgM+KAv+KImCDipYog4oaVMjQgICMgQSBjaGFyYWN0ZXIgYXJyYXkKIuKImOKImCIgwrvLmCBhCgoi4oiY4oiYIuKKuMK7y5ggYQ==">↗️</a><pre> <span class='String'>"∘∘"</span> <span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> <span class='Error'>Error: ˘: Leading axis of arguments not equal (⟨2⟩ ≡ ≢𝕨, 3‿8 ≡ ≢𝕩)</span> <span class='String'>"∘∘"</span><span class='Modifier2'>⊸</span><span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> @@ -150,7 +150,7 @@ ┘ </pre> <p>This is because the general case of Cells does one-to-one matching, pairing the first axis of one argument with the other. For this to work, the two arguments need to have the same length.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oICIwMTIiIMK7y5ggYSwgICgz4oC/4oiY4qWKIlVWV1hZWiIpIMK7y5ggYSDin6k=">↗️</a><pre> <span class='Bracket'>⟨</span> <span class='String'>"012"</span> <span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span><span class='Separator'>,</span> <span class='Paren'>(</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Modifier2'>∘</span><span class='Function'>⥊</span><span class='String'>"UVWXYZ"</span><span class='Paren'>)</span> <span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> <span class='Bracket'>⟩</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDihpAgJ2EnICsgM+KAv+KImCDipYog4oaVMjQgICMgQSBjaGFyYWN0ZXIgYXJyYXkK4p+oICIwMTIiIMK7y5ggYSwgICgz4oC/4oiY4qWKIlVWV1hZWiIpIMK7y5ggYSDin6k=">↗️</a><pre> <span class='Bracket'>⟨</span> <span class='String'>"012"</span> <span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span><span class='Separator'>,</span> <span class='Paren'>(</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Modifier2'>∘</span><span class='Function'>⥊</span><span class='String'>"UVWXYZ"</span><span class='Paren'>)</span> <span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> <span class='Bracket'>⟩</span> ┌─ · ┌─ ┌─ ╵"0abcdefg ╵"UVabcdef @@ -160,7 +160,7 @@ ┘ </pre> <p>The arguments might have different ranks: for example, <code><span class='String'>"012"</span></code> has rank 1 and <code><span class='Value'>a</span></code> has rank 2 above. That's fine: it just means Cells will pass arguments of rank 0 and 1 to its operand. You can see these arguments using <a href="pair.html">Pair</a> Cells, <code><span class='Function'>⋈</span><span class='Modifier'>˘</span></code>, so that each cell of the result is just a list of the two arguments used for that call.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=IjAxMiIg4ouIy5ggYQ==">↗️</a><pre> <span class='String'>"012"</span> <span class='Function'>⋈</span><span class='Modifier'>˘</span> <span class='Value'>a</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDihpAgJ2EnICsgM+KAv+KImCDipYog4oaVMjQgICMgQSBjaGFyYWN0ZXIgYXJyYXkKIjAxMiIg4ouIy5ggYQ==">↗️</a><pre> <span class='String'>"012"</span> <span class='Function'>⋈</span><span class='Modifier'>˘</span> <span class='Value'>a</span> ┌─ ╵ ┌· "abcdefgh" ·'0' @@ -196,7 +196,7 @@ ⟨ "abc" "def" ⟩ </pre> <p>The function <code><span class='Function'>𝔽</span><span class='Modifier2'>⎉</span><span class='Value'>k</span></code>, for <code><span class='Value'>k</span><span class='Function'>≥</span><span class='Number'>0</span></code>, operates on the <code><span class='Value'>k</span></code>-cells of its arguments—that is, it maps over all <em>but</em> the last <code><span class='Value'>k</span></code> axes. For any given argument <code><span class='Value'>a</span></code>, ranks <code><span class='Value'>k</span></code> and <code><span class='Value'>k</span><span class='Function'>-=</span><span class='Value'>a</span></code> are the same, as long as <code><span class='Value'>k</span><span class='Function'>≥</span><span class='Number'>0</span></code> and <code><span class='Paren'>(</span><span class='Value'>k</span><span class='Function'>-=</span><span class='Value'>a</span><span class='Paren'>)</span><span class='Function'>≤</span><span class='Number'>¯1</span></code>. So rank 2 is rank ¯3 for a rank-5 array. The reason this option is useful is that the same rank might be applied to multiple arguments, either with multiple function calls or one call on two arguments. Let's revisit an example with Cells from before, shifting the same string into each row of a table. The function <code><span class='Function'>»</span></code> should be called on rank-1 strings, but because the argument ranks are different, a negative rank can't get down to rank 1 on both sides. Positive rank 1 does the job, allowing us to unbundle the string <code><span class='String'>"∘∘"</span></code> so that <code><span class='Function'>»</span><span class='Modifier2'>⎉</span><span class='Number'>1</span></code> is a standalone function.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=IuKImOKImCLiirjCu8uYIGEKCiLiiJjiiJgiIMK74o6JMSBh">↗️</a><pre> <span class='String'>"∘∘"</span><span class='Modifier2'>⊸</span><span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDihpAgJ2EnICsgM+KAv+KImCDipYog4oaVMjQgICMgQSBjaGFyYWN0ZXIgYXJyYXkKIuKImOKImCLiirjCu8uYIGEKCiLiiJjiiJgiIMK74o6JMSBh">↗️</a><pre> <span class='String'>"∘∘"</span><span class='Modifier2'>⊸</span><span class='Function'>»</span><span class='Modifier'>˘</span> <span class='Value'>a</span> ┌─ ╵"∘∘abcdef ∘∘ijklmn @@ -260,7 +260,7 @@ ⟨ 2 ¯1 3 ⟩ </pre> <p>But a rank of <code><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>∞</span></code> works the best because it also defines a matrix-<em>matrix</em> product. Which as shown below does the same transformation to the <em>cells</em> of the right-hand-side matrix, instead of the elements of a vector. This works because <code><span class='Function'>×</span></code> and <code><span class='Function'>+</span><span class='Modifier'>˝</span></code> work on the leading axes of their arguments. When <code><span class='Modifier2'>⎉</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>∞</span></code> is applied, these axes are the last axis of <code><span class='Value'>𝕨</span></code> and the first axis of <code><span class='Value'>𝕩</span></code>. Which… is kind of weird, but it's what a matrix product is.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K8udIDDigL8x4oC/MCDDlyAx4oC/MuKAvzPDl+KMnDHigL8xMAoKbSAry53iiJjDl+KOiTHigL/iiJ4gMeKAvzLigL8zw5fijJwx4oC/MTA=">↗️</a><pre> <span class='Function'>+</span><span class='Modifier'>˝</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span> <span class='Function'>×</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Function'>×</span><span class='Modifier'>⌜</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>10</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqiIG0g4oaQIFsw4oC/MeKAvzAsIMKvMeKAvzDigL8wLCAw4oC/MOKAvzFdCivLnSAw4oC/MeKAvzAgw5cgMeKAvzLigL8zw5fijJwx4oC/MTAKCm0gK8ud4oiYw5fijokx4oC/4oieIDHigL8y4oC/M8OX4oycMeKAvzEw">↗️</a><pre> <span class='Function'>+</span><span class='Modifier'>˝</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span> <span class='Function'>×</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Function'>×</span><span class='Modifier'>⌜</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>10</span> ⟨ 2 20 ⟩ <span class='Value'>m</span> <span class='Function'>+</span><span class='Modifier'>˝</span><span class='Modifier2'>∘</span><span class='Function'>×</span><span class='Modifier2'>⎉</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>∞</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Function'>×</span><span class='Modifier'>⌜</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>10</span> |
