aboutsummaryrefslogtreecommitdiff
path: root/docs/doc/leading.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/doc/leading.html')
-rw-r--r--docs/doc/leading.html18
1 files changed, 9 insertions, 9 deletions
diff --git a/docs/doc/leading.html b/docs/doc/leading.html
index e86c57f7..92200f77 100644
--- a/docs/doc/leading.html
+++ b/docs/doc/leading.html
@@ -5,7 +5,7 @@
<h2 id="monadic-functions">Monadic functions</h2>
<h3 id="manipulating-cells">Manipulating cells</h3>
<p>Most non-scalar monadic functions work only on the first axis of the argument—that is, they treat it as a list of its major cells. The function Length (<code><span class='Function'>≠</span></code>) counts these major cells, while Prefixes (<code><span class='Function'>↑</span></code>), Suffixes (<code><span class='Function'>↓</span></code>), Reverse (<code><span class='Function'>⌽</span></code>), and First Cell (<code><span class='Function'>⊏</span></code>) move them around. The Insert (<code><span class='Modifier'>˝</span></code>) and Scan (<code><span class='Modifier'>`</span></code>) modifiers also yield functions that work along the first axis; in contrast, Reduce (<code><span class='Modifier'>´</span></code>) requires its argument to be a list, as it works on elements.</p>
-<pre> <span class='Function'>⊢</span> <span class='Value'>a</span> <span class='Gets'>←</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span> <span class='Function'>⥊</span> <span class='String'>&quot;abcdef&quot;</span> <span class='Comment'># An array with three major cells
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqiIGEg4oaQIDPigL8yIOKliiAiYWJjZGVmIiAgIyBBbiBhcnJheSB3aXRoIHRocmVlIG1ham9yIGNlbGxzCuKKjyBhICAgICAgICAgICAgICAgICAgICMgR2V0IHRoZSBmaXJzdCBtYWpvciBjZWxsCuKMvSBhICAgICAgICAgICAgICAgICAgICMgUmV2ZXJzZSB0aGUgY2VsbHMK4oqjYCBhICAgICAgICAgICAgICAgICAgIyBSZXBsaWNhdGUgdGhlIGZpcnN0IGNlbGw=&run">↗️</a><pre> <span class='Function'>⊢</span> <span class='Value'>a</span> <span class='Gets'>←</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span> <span class='Function'>⥊</span> <span class='String'>&quot;abcdef&quot;</span> <span class='Comment'># An array with three major cells
</span>┌─
╵"ab
cd
@@ -27,7 +27,7 @@
</pre>
<p>To use these functions on another axis, use the Rank (<code><span class='Modifier2'>⎉</span></code>) or Cells (<code><span class='Modifier'>˘</span></code>) modifier to find the one you want. For a rank 2 array like <code><span class='Value'>a</span></code>, the most you'll ever need is a single <code><span class='Modifier'>˘</span></code>, because a function works on axis 0 by default, and there's only one other axis.</p>
-<pre> <span class='Function'>⊏</span><span class='Modifier'>˘</span> <span class='Value'>a</span> <span class='Comment'># First column
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqPy5ggYSAgICAgICAgICAgICAgICAgICMgRmlyc3QgY29sdW1uCuKMvcuYIGEgICAgICAgICAgICAgICAgICAjIFN3YXAgdGhlIGNvbHVtbnMK4oqjYMuYIGEgICAgICAgICAgICAgICAgICMgUmVwbGljYXRlIGFsb25nIHJvd3M=&run">↗️</a><pre> <span class='Function'>⊏</span><span class='Modifier'>˘</span> <span class='Value'>a</span> <span class='Comment'># First column
</span>"ace"
<span class='Function'>⌽</span><span class='Modifier'>˘</span> <span class='Value'>a</span> <span class='Comment'># Swap the columns
</span>┌─
@@ -43,7 +43,7 @@
</pre>
<p>In these three cases above, the results are the same as you would get from transposing before and after (this has no effect on the result of <code><span class='Function'>⊏</span><span class='Modifier'>˘</span></code>, since it has rank 1). But in the following cases, the structure is quite different: <code><span class='Function'>↑</span><span class='Value'>a</span></code> is a list of matrices while <code><span class='Function'>↑</span><span class='Modifier'>˘</span><span class='Value'>a</span></code> is a matrix of lists. This is because the functions <code><span class='Function'>⊏</span></code>, <code><span class='Function'>⌽</span></code>, and <code><span class='Function'>⊣</span><span class='Modifier'>`</span></code> leave the trailing axis structure intact (<code><span class='Function'>⊏</span></code> removes one axis); taking into account that Rank or Cells always preserves the leading or frame axes, all axes are preserved (except the one removed by <code><span class='Function'>⊏</span></code>). In contrast, Prefixes or Suffixes pushes some axes down in depth, and the number of axes that are pushed down in this way changes with the rank of application. More precisely, these functions move axes after the first from the argument itself to result elements, and create two axes from the first axis, with one of them forming the sole result axis and the other joining the rest as an element axis.</p>
-<pre> <span class='Function'>↑</span> <span class='Value'>a</span> <span class='Comment'># Prefixes of a: ranks 1|2
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oaRIGEgICAgICAgICAgICAgICAgICAgIyBQcmVmaXhlcyBvZiBhOiAgICByYW5rcyAxfDIK4oaRy5ggYSAgICAgICAgICAgICAgICAgICMgUHJlZml4ZXMgb2Ygcm93czogcmFua3MgMnwxCuKIvsudIGEgICAgICAgICAgICAgICAgICAjIEpvaW4gdGhlIGNlbGxzCuKIvsudy5ggYSAgICAgICAgICAgICAgICAgIyBKb2luLWluc2VydCBpcyBhIG5vLW9wIG9uIGxpc3Rz&run">↗️</a><pre> <span class='Function'>↑</span> <span class='Value'>a</span> <span class='Comment'># Prefixes of a: ranks 1|2
</span>┌─
· 0‿2⥊⟨⟩ ┌─ ┌─ ┌─
╵"ab" ╵"ab ╵"ab
@@ -67,7 +67,7 @@
</pre>
<p><a href="couple.html">Solo</a> (<code><span class='Function'>≍</span></code>), something of a maverick, manages to act on <em>zero</em> leading axes of its argument by creating the first axis of the <em>result</em> instead. Because it doesn't need any axis to work, it can go in front of either axis but also past the last one by working with rank 0, a case where most array functions would give an error.</p>
-<pre> <span class='Function'>≢</span> <span class='Function'>≍</span> <span class='Value'>a</span> <span class='Comment'># Solo adds a length-1 axis
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omiIOKJjSBhICAgICAgICAgICAgICAgICAjIFNvbG8gYWRkcyBhIGxlbmd0aC0xIGF4aXMKYSDiiaEg4oqPIOKJjSBhICAgICAgICAgICAgICMgRmlyc3QgQ2VsbCB1bmRvZXMgdGhpcwriiaIg4omNy5ggYSAgICAgICAgICAgICAgICAjIFNvbG8gY2FuIGluc2VydCB0aGUgYXhpcyBkZWVwZXLigKYK4omiIOKJjeKOiTAgYSAgICAgICAgICAgICAgICMg4oCmb3IgZGVlcGVyIHN0aWxsLg==&run">↗️</a><pre> <span class='Function'>≢</span> <span class='Function'>≍</span> <span class='Value'>a</span> <span class='Comment'># Solo adds a length-1 axis
</span>⟨ 1 3 2 ⟩
<span class='Value'>a</span> <span class='Function'>≡</span> <span class='Function'>⊏</span> <span class='Function'>≍</span> <span class='Value'>a</span> <span class='Comment'># First Cell undoes this
</span>1
@@ -78,7 +78,7 @@
</pre>
<h3 id="comparing-cells">Comparing cells</h3>
<p>The functions in the last section manipulate cells in the same way regardless of what data they contain. Other functions compare cells to each other, either testing whether they match or how they are ordered relative to one another. The two Grade functions <code><span class='Function'>⍋⍒</span></code>, and the self-comparison functions Unique Mask (<code><span class='Function'>∊</span></code>) and Occurrence Count (<code><span class='Function'>⊒</span></code>), each give a list result, with one number for each cell. We can see below that Occurrence Count returns the same results even as we make the argument cells more complicated, because the changes made preserve the matching of cells.</p>
-<pre> <span class='Value'>s</span> <span class='Gets'>←</span> <span class='String'>&quot;abracadabra&quot;</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=cyDihpAgImFicmFjYWRhYnJhIgriipIgcwriipIg4omNy5ggcwriipIgcyDiiL7ijokw4oC/MSAic3VmZml4Ig==&run">↗️</a><pre> <span class='Value'>s</span> <span class='Gets'>←</span> <span class='String'>&quot;abracadabra&quot;</span>
<span class='Function'>⊒</span> <span class='Value'>s</span>
⟨ 0 0 0 1 0 2 0 3 1 1 4 ⟩
<span class='Function'>⊒</span> <span class='Function'>≍</span><span class='Modifier'>˘</span> <span class='Value'>s</span>
@@ -87,7 +87,7 @@
⟨ 0 0 0 1 0 2 0 3 1 1 4 ⟩
</pre>
<p>The two Sort functions <code><span class='Function'>∧∨</span></code> and Deduplicate (<code><span class='Function'>⍷</span></code>) move cells around based on their ordering. The length of Deduplicate's result depends on how many unique cells the argument has, so you'd better be careful if you want to apply it to argument cells! However, the result of sorting has the same shape as the argument, so it can always safely be applied at any rank, for example to the rows of an array.</p>
-<pre> <span class='Function'>⊢</span> <span class='Value'>b</span> <span class='Gets'>←</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>5</span> <span class='Function'>⥊</span> <span class='Function'>↕</span><span class='Number'>4</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqiIGIg4oaQIDTigL81IOKliiDihpU0CuKIqMuYIGI=&run">↗️</a><pre> <span class='Function'>⊢</span> <span class='Value'>b</span> <span class='Gets'>←</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>5</span> <span class='Function'>⥊</span> <span class='Function'>↕</span><span class='Number'>4</span>
┌─
╵ 0 1 2 3 0
1 2 3 0 1
@@ -129,7 +129,7 @@
</tbody>
</table>
<p>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. Observing the operation of Rotate on the result of Range is instructive:</p>
-<pre> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span> <span class='Function'>⌽</span> <span class='Function'>↕</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>5</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MuKAvzEg4oy9IOKGlTPigL81&run">↗️</a><pre> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span> <span class='Function'>⌽</span> <span class='Function'>↕</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>5</span>
┌─
╵ ⟨ 2 1 ⟩ ⟨ 2 2 ⟩ ⟨ 2 3 ⟩ ⟨ 2 4 ⟩ ⟨ 2 0 ⟩
⟨ 0 1 ⟩ ⟨ 0 2 ⟩ ⟨ 0 3 ⟩ ⟨ 0 4 ⟩ ⟨ 0 0 ⟩
@@ -137,13 +137,13 @@
</pre>
<p>The array is shifted once to the left and twice upward, so that the first index (by ravel order) is now <code><span class='Function'>⊑</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Function'>⌽↕</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>5</span> <span class='Gets'>←→</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span></code>. To see how values are matched to leading axes, we can look at how Drop changes the shape of its argument:</p>
-<pre> <span class='Function'>≢</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span> <span class='Function'>↓</span> <span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Function'>⥊</span><span class='String'>&quot;abc&quot;</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omiIDPigL8yIOKGkyA34oC/N+KAvzfigL834qWKImFiYyI=&run">↗️</a><pre> <span class='Function'>≢</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span> <span class='Function'>↓</span> <span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Function'>⥊</span><span class='String'>&quot;abc&quot;</span>
⟨ 4 5 7 7 ⟩
</pre>
<p>Functions with single-axis depth 1 tend to be more complicated; see for example <a href="group.html#multidimensional-grouping">Group</a>.</p>
<h3 id="leading-axis-agreement">Leading axis agreement</h3>
<p>Scalar functions, and the Each (<code><span class='Modifier'>¨</span></code>) and Depth (<code><span class='Modifier2'>⚇</span></code>) modifiers, use leading axis agreement to match their arguments together. All axes of the lower-rank argument are matched with the leading axes of the higher-rank one, and axes matched together must have the same length. After pairing axes in this way, a single element of the lower-rank argument might correspond to any number of elements of the higher-rank one. It's reused for each of those corresponding elements.</p>
-<pre> <span class='Function'>⊢</span> <span class='Value'>x</span> <span class='Gets'>←</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>4</span> <span class='Function'>⥊</span> <span class='Function'>↕</span><span class='Number'>60</span> <span class='Comment'># A rank-3 array
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqiIHgg4oaQIDPigL8y4oC/NCDipYog4oaVNjAgICAgICMgQSByYW5rLTMgYXJyYXkKMTAw4oC/MOKAvzIwMCArIHggICAgICAgICAjIDAtY2VsbHMgcGFpcmVkIHdpdGggMi1jZWxscwriiqIgYyDihpAgMTAwIMOXIDMgPeKMnOKXi+KGlSAyICAjIEEgcmFuay0yIGFycmF5IHRvIGFkZApjICsgeCAgICAgICAgICAgICAgICAgIyAwLWNlbGxzIHBhaXJlZCB3aXRoIDEtY2VsbHMKeCArIHggICAgICAgICAgICAgICAgICMgUGFpcndpc2UgYWRkaXRpb24=&run">↗️</a><pre> <span class='Function'>⊢</span> <span class='Value'>x</span> <span class='Gets'>←</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>4</span> <span class='Function'>⥊</span> <span class='Function'>↕</span><span class='Number'>60</span> <span class='Comment'># A rank-3 array
</span>┌─
╎ 0 1 2 3
4 5 6 7