diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-07-16 18:23:52 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-07-16 18:24:01 -0400 |
| commit | 2010e8b2897a5741e211980c9f8ec9177299c939 (patch) | |
| tree | 4b3476744be928724da2fd5d83b0bf2e9a8ba502 /docs/doc/selfcmp.html | |
| parent | e3366f9e18a8791c43110e080b9ea45cfceefed8 (diff) | |
Finish links and editing documentation pass
Diffstat (limited to 'docs/doc/selfcmp.html')
| -rw-r--r-- | docs/doc/selfcmp.html | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/docs/doc/selfcmp.html b/docs/doc/selfcmp.html index bc99ef43..8e9540f2 100644 --- a/docs/doc/selfcmp.html +++ b/docs/doc/selfcmp.html @@ -185,7 +185,7 @@ <span class='Function'>⊐</span> <span class='Function'>⍷</span> <span class='Value'>c</span> ⟨ 0 1 2 ⟩ </pre> -<p>Applying both separately, in contrast, gives completely interesting results. These results contain all information from the original argument, as <code><span class='Function'>⍷</span></code> indicates which cells it contained and <code><span class='Function'>⊐</span></code> indicates where they were located. The function Select (<code><span class='Function'>⊏</span></code>) reconstructs the argument from the two values.</p> +<p>Applying both separately, in contrast, gives completely interesting results. These results contain all information from the original argument, as <code><span class='Function'>⍷</span></code> indicates which cells it contained and <code><span class='Function'>⊐</span></code> indicates where they were located. The function <a href="select.html">Select</a> (<code><span class='Function'>⊏</span></code>) reconstructs the argument from the two values.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4o23IGMK4oqQIGMKKOKKkGMpIOKKjyAo4o23Yyk=">↗️</a><pre> <span class='Function'>⍷</span> <span class='Value'>c</span> ┌─ ╵"yellow @@ -208,15 +208,15 @@ <p>Applying both Classify and Deduplicate gives an array that has both properties (this isn't the case for all pairs of projections—we need to know that Classify maintains the uniqueness property for Deduplicate and vice-versa). It has no duplicate major cells, <em>and</em> it's a list of natural numbers that starts with 0 and never goes up by more than one. Taken together, these are a tight constraint! The first element of the argument has to be 0. The next can't be 0 because it's already appeared, but it can't be more than one higher—it has to be 1. The next can't be 0 or 1, and has to be 2. And so on. So the result is always <code><span class='Function'>↕</span><span class='Value'>n</span></code> for some <code><span class='Value'>n</span></code>. In fact it's possible to determine the length as well, by noting that each function preserves the number of unique major cells in its argument. Classify does this because distinct numbers in the output correspond exactly to distinct major cells in the input; Deduplicate does this because it only removes duplicate cells, not distinct ones. So the final result is <code><span class='Function'>↕</span><span class='Value'>n</span></code>, where <code><span class='Value'>n</span></code> is the number of unique major cells in the argument.</p> <h3 id="mark-firsts">Mark Firsts</h3> <p><em>See the <a href="https://aplwiki.com/wiki/Unique_Mask">APL Wiki page</a> on this function as well.</em></p> -<p>Mark Firsts (<code><span class='Function'>∊</span></code>) is the simplest self-search function: it returns <code><span class='Number'>0</span></code> for any major cell of the argument that is a duplicate of an earlier cell and <code><span class='Number'>1</span></code> for a major cell that's the first with its value. To implement <a href="#deduplicate">Deduplicate</a> in terms of Mark Firsts, just filter out the duplicates with <code><span class='Function'>∊</span><span class='Modifier2'>⊸</span><span class='Function'>/</span></code>.</p> +<p>Mark Firsts (<code><span class='Function'>∊</span></code>) is the simplest self-search function: it returns <code><span class='Number'>0</span></code> for any major cell of the argument that is a duplicate of an earlier cell and <code><span class='Number'>1</span></code> for a major cell that's the first with its value. To implement <a href="#deduplicate">Deduplicate</a> in terms of Mark Firsts, just <a href="replicate.html">filter</a> out the duplicates with <code><span class='Function'>∊</span><span class='Modifier2'>⊸</span><span class='Function'>/</span></code>.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oiKICAgM+KAvzHigL804oC/MeKAvzXigL854oC/MuKAvzbigL81CgriiIriirgvIDPigL8x4oC/NOKAvzHigL814oC/OeKAvzLigL824oC/NQ==">↗️</a><pre> <span class='Function'>∊</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>9</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>6</span><span class='Ligature'>‿</span><span class='Number'>5</span> ⟨ 1 1 1 0 1 1 1 1 0 ⟩ <span class='Function'>∊</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>9</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>6</span><span class='Ligature'>‿</span><span class='Number'>5</span> ⟨ 3 1 4 5 9 2 6 ⟩ </pre> -<p>Mark Firsts has other uses, of course. Instead of keeping the unique values, you might remove the first of each value with <code><span class='Function'>¬</span><span class='Modifier2'>∘</span><span class='Function'>∊</span><span class='Modifier2'>⊸</span><span class='Function'>/</span></code>. You can use <code><span class='Function'>∧</span><span class='Modifier'>´</span><span class='Function'>∊</span></code> to check that an array has no duplicate major cells, or <code><span class='Function'>+</span><span class='Modifier'>´</span><span class='Modifier2'>∘</span><span class='Function'>∊</span></code> to count the number of unique ones.</p> -<p>What about marking the elements that appear exactly once? There's a trick for this: find the cells that are firsts running both forwards (<code><span class='Function'>∊</span></code>) and backwards (<code><span class='Function'>∊</span><span class='Modifier2'>⌾</span><span class='Function'>⌽</span></code>). Such a cell has no equal before it, nor after it, so it's unique in the entire array.</p> +<p>Mark Firsts has other uses, of course. Instead of keeping the unique values, you might remove the first of each value with <code><span class='Function'>¬</span><span class='Modifier2'>∘</span><span class='Function'>∊</span><span class='Modifier2'>⊸</span><span class='Function'>/</span></code>. You can use <code><span class='Function'>∧</span><span class='Modifier'>´</span><span class='Function'>∊</span></code> to check that an array has no duplicate major cells, or <code><span class='Function'>+</span><span class='Modifier'>´</span><span class='Function'>∊</span></code> to count the number of unique ones.</p> +<p>What about marking the elements that appear exactly once? There's a trick for this: find the cells that are firsts running both forwards (<code><span class='Function'>∊</span></code>) and <a href="reverse.html">backwards</a> (<code><span class='Function'>∊</span><span class='Modifier2'>⌾</span><span class='Function'>⌽</span></code>). Such a cell has no equal before it, nor after it, so it's unique in the entire array.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KOKIiuKIp+KIiuKMvuKMvSkgImR1Y2si4oC/ImR1Y2si4oC/InRlYWwi4oC/ImR1Y2si4oC/Imdvb3NlIg==">↗️</a><pre> <span class='Paren'>(</span><span class='Function'>∊∧∊</span><span class='Modifier2'>⌾</span><span class='Function'>⌽</span><span class='Paren'>)</span> <span class='String'>"duck"</span><span class='Ligature'>‿</span><span class='String'>"duck"</span><span class='Ligature'>‿</span><span class='String'>"teal"</span><span class='Ligature'>‿</span><span class='String'>"duck"</span><span class='Ligature'>‿</span><span class='String'>"goose"</span> ⟨ 0 0 1 0 1 ⟩ </pre> @@ -243,11 +243,11 @@ <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KDE94oqSKeKKuC8gImFhYWFiY2RkY2Mi">↗️</a><pre> <span class='Paren'>(</span><span class='Number'>1</span><span class='Function'>=⊒</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='String'>"aaaabcddcc"</span> "adc" </pre> -<p>An interesting combination is Occurrence Count applied to the result of Indices (<code><span class='Function'>/</span></code>). The result counts up to each number from the argument in turn; in other symbols, it's <code><span class='Function'>∾↕</span><span class='Modifier'>¨</span></code>. This version is interesting because it doesn't create any nested arrays, just lists of natural numbers.</p> +<p>An interesting combination is Occurrence Count applied to the result of <a href="replicate.html#indices">Indices</a> (<code><span class='Function'>/</span></code>). The result counts up to each number from the argument in turn; in other symbols, it's <code><span class='Function'>∾↕</span><span class='Modifier'>¨</span></code>. This version is interesting because it doesn't create any nested arrays, just lists of natural numbers.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqSIC8gMuKAvzPigL80">↗️</a><pre> <span class='Function'>⊒</span> <span class='Function'>/</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span> ⟨ 0 1 0 1 2 0 1 2 3 ⟩ </pre> -<p>A more efficient way when the interpreter doesn't optimize <code><span class='Function'>⊒</span></code> here is <code><span class='Function'>/</span><span class='Paren'>(</span><span class='Number'>¯1</span><span class='Modifier2'>⊸</span><span class='Function'>⊑↕</span><span class='Modifier2'>⊸</span><span class='Function'>-⊏</span><span class='Modifier2'>⟜</span><span class='Function'>»</span><span class='Paren'>)</span><span class='Function'>+</span><span class='Modifier'>`</span></code>, but that's clearly quite a bit more complicated.</p> +<p>A more efficient way when <code><span class='Function'>⊒</span></code> doesn't have a fast implementation is <code><span class='Function'>/</span><span class='Paren'>(</span><span class='Number'>¯1</span><span class='Modifier2'>⊸</span><span class='Function'>⊑↕</span><span class='Modifier2'>⊸</span><span class='Function'>-⊏</span><span class='Modifier2'>⟜</span><span class='Function'>»</span><span class='Paren'>)</span><span class='Function'>+</span><span class='Modifier'>`</span></code>, but that's clearly quite a bit more complicated.</p> <h3 id="deduplicate">Deduplicate</h3> <p><em>There's also an <a href="https://aplwiki.com/wiki/Unique">APL Wiki page</a> on this function.</em></p> <p>Deduplicate removes every major cell from the argument that matches an earlier cell, resulting in an array with the same rank but possibly a shorter length. It might also be described as returning the unique major cells of the argument, ordered by first occurrence. Deduplicate Under Reverse (<code><span class='Function'>⍷</span><span class='Modifier2'>⌾</span><span class='Function'>⌽</span></code>) orders by last occurrence instead.</p> |
