diff options
Diffstat (limited to 'docs/doc')
| -rw-r--r-- | docs/doc/index.html | 2 | ||||
| -rw-r--r-- | docs/doc/indices.html | 2 | ||||
| -rw-r--r-- | docs/doc/leading.html | 2 | ||||
| -rw-r--r-- | docs/doc/match.html | 2 | ||||
| -rw-r--r-- | docs/doc/selfcmp.html | 16 |
5 files changed, 12 insertions, 12 deletions
diff --git a/docs/doc/index.html b/docs/doc/index.html index c1eaf56b..99a75305 100644 --- a/docs/doc/index.html +++ b/docs/doc/index.html @@ -57,7 +57,7 @@ <li><a href="scan.html">Scan</a> (<code><span class='Modifier'>`</span></code>)</li> <li><a href="search.html">Search functions</a> (<code><span class='Function'>⊐⊒∊</span></code>)</li> <li><a href="select.html">Select</a> (<code><span class='Function'>⊏</span></code>)</li> -<li><a href="selfcmp.html">Self-comparison functions</a> (<code><span class='Function'>⊐⊒∊⍷</span></code>)</li> +<li><a href="selfcmp.html">Self-search functions</a> (<code><span class='Function'>⊐⊒∊⍷</span></code>)</li> <li><a href="shift.html">Shift functions</a> (<code><span class='Function'>»«</span></code>)</li> <li><a href="couple.html">Solo, Couple, and Merge</a> (<code><span class='Function'>≍></span></code>)</li> <li><a href="transpose.html">Transpose</a> (<code><span class='Function'>⍉</span></code>)</li> diff --git a/docs/doc/indices.html b/docs/doc/indices.html index 42938172..7f342cca 100644 --- a/docs/doc/indices.html +++ b/docs/doc/indices.html @@ -92,7 +92,7 @@ <p>Unlike <code><span class='Function'>/</span></code> and <code><span class='Function'>⊔</span></code>, <code><span class='Function'>↕</span></code> and <code><span class='Function'>⊑</span></code> do use list element indices. For <code><span class='Function'>↕</span></code> this is because the output format can be controlled by the argument format: if passed a single number, the result uses atomic indices (so it's a numeric list); if passed a list, it uses list indices and the result has depth 2 (the result depth is always one greater than the argument depth). For <code><span class='Function'>⊑</span></code>, list indices are chosen because <a href="select.html">Select</a> (<code><span class='Function'>⊏</span></code>) handles atomic indices well already. When selecting multiple elements from a list, they would typically have to be placed in an array, which is equivalent to <code><span class='Function'>⊏</span></code> with a numeric list <code><span class='Value'>𝕨</span></code>. An atom <code><span class='Value'>𝕨</span></code> in Pick is converted to a list, so it can be used to select a single element if only one is wanted. To select multiple elements, <code><span class='Function'>⊑</span></code> uses each depth-1 array in <code><span class='Value'>𝕨</span></code> as an index and replaces it with that element from the right argument. Because this uses elements as elements (not cells), it is impossible to have conformability errors where elements do not fit together (invalid index errors are of course still possible). Atoms also cannot be used in this context, as it would create ambiguity: is a one-element list an index, or does it contain an index?</p> <h2 id="major-cell-indices">Major cell indices</h2> <p>One of the successes of the <a href="https://aplwiki.com/wiki/Leading_axis_theory">leading axis model</a> is to introduce a kind of index for multidimensional arrays that is easier to work with than list indices. The model introduces <a href="https://aplwiki.com/wiki/Cell">cells</a>, where a cell index is a list of any length up to the containing array's rank. General cell indices are discussed in the next section; first we introduce a special case, indices into major cells or ¯1-cells. These cells naturally form a list, so the index of a major cell is a single number. Such an index can also be considered to select along the first axis, since an index along any axis is a single number.</p> -<p><a href="order.html">Ordering</a> functions <code><span class='Function'>⍋⍒</span></code> and <a href="search.html">search</a>/<a href="selfcmp.html">self-comparison</a> functions <code><span class='Function'>⊐⊒</span></code> that depend on cell ordering only really make sense with major cell indices: while other indices have an ordering, it's not very natural. Note that <code><span class='Function'>⊐</span></code> only uses the ordering in an incidental way, because it's defined to return the <em>first</em> index where a cell in <code><span class='Value'>𝕩</span></code> is found. A mathematician would be more interested in a "pre-image" function that returns the set of all indices where a particular value appears. However, programming usefulness and consistency with the other search functions makes searching for the first index a reasonable choice.</p> +<p><a href="order.html">Ordering</a> functions <code><span class='Function'>⍋⍒</span></code> and <a href="search.html">search</a>/<a href="selfcmp.html">self-search</a> functions <code><span class='Function'>⊐⊒</span></code> that depend on cell ordering only really make sense with major cell indices: while other indices have an ordering, it's not very natural. Note that <code><span class='Function'>⊐</span></code> only uses the ordering in an incidental way, because it's defined to return the <em>first</em> index where a cell in <code><span class='Value'>𝕩</span></code> is found. A mathematician would be more interested in a "pre-image" function that returns the set of all indices where a particular value appears. However, programming usefulness and consistency with the other search functions makes searching for the first index a reasonable choice.</p> <p>Only one other function—but an important one!—deals with cells rather than elements: <a href="select.html">Select</a> (<code><span class='Function'>⊏</span></code>). Select <a href="leading.html#multiple-axes">allows</a> either a simple first-axis case where <code><span class='Value'>𝕨</span></code> has depth 1 or less (a depth-0 argument is automatically enclosed), and a multi-axis case where it is a list of depth-1 elements. In each case the depth-1 arrays index along a single axis.</p> <h2 id="general-cell-indices">General cell indices</h2> <p>BQN does not use general cell indices directly, but it is useful to consider how they might work, and how a programmer might implement functions that use them in BQN if needed. The functions <code><span class='Function'>/</span></code>, <code><span class='Function'>⊔</span></code>, and <code><span class='Function'>⊏</span></code> are the ones that can work with indices for multidimensional arrays but don't already. Here we will examine how multidimensional versions would work.</p> diff --git a/docs/doc/leading.html b/docs/doc/leading.html index 69f04d77..11e7a567 100644 --- a/docs/doc/leading.html +++ b/docs/doc/leading.html @@ -81,7 +81,7 @@ </span>⟨ 3 2 1 ⟩ </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 <a href="order.html">Grade</a> functions <code><span class='Function'>⍋⍒</span></code>, and the <a href="selfcmp.html">self-comparison</a> functions Classify (<code><span class='Function'>⊐</span></code>), Mark Firsts (<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> +<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 <a href="order.html">Grade</a> functions <code><span class='Function'>⍋⍒</span></code>, and the <a href="selfcmp.html">self-search</a> functions Classify (<code><span class='Function'>⊐</span></code>), Mark Firsts (<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> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=cyDihpAgImFicmFjYWRhYnJhIgriipIgcwriipIg4omNy5ggcwriipIgcyDiiL7ijokw4oC/MSAic3VmZml4Ig==">↗️</a><pre> <span class='Value'>s</span> <span class='Gets'>←</span> <span class='String'>"abracadabra"</span> <span class='Function'>⊒</span> <span class='Value'>s</span> ⟨ 0 0 0 1 0 2 0 3 1 1 4 ⟩ diff --git a/docs/doc/match.html b/docs/doc/match.html index 03da6ad6..dbf0b301 100644 --- a/docs/doc/match.html +++ b/docs/doc/match.html @@ -11,7 +11,7 @@ <span class='Number'>4</span> <span class='Function'>≢</span> <span class='Function'><</span><span class='Number'>4</span> 1 </pre> -<p>Match always gives the same result as <a href="arithmetic.html#comparisons">Equals</a> (<code><span class='Function'>=</span></code>) when both arguments are atoms, but the two functions are extended to arrays differently: while the pervasive Equals maps over array arguments to return an array of results, Match compares them in totality and always returns one boolean (it never gives an error). Match is the basis for BQN's <a href="search.html">search</a> and <a href="selfcmp.html">self-comparison</a> functions.</p> +<p>Match always gives the same result as <a href="arithmetic.html#comparisons">Equals</a> (<code><span class='Function'>=</span></code>) when both arguments are atoms, but the two functions are extended to arrays differently: while the pervasive Equals maps over array arguments to return an array of results, Match compares them in totality and always returns one boolean (it never gives an error). Match is the basis for BQN's <a href="search.html">search</a> and <a href="selfcmp.html">self-search</a> functions.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=ImFiYyIgPSAiYWNjIgoiYWJjIiDiiaEgImFjYyIKCiJhYmMiID0gImFiIiAgIyBNaXNtYXRjaGVkIHNoYXBlcwoiYWJjIiDiiaEgImFiIg==">↗️</a><pre> <span class='String'>"abc"</span> <span class='Function'>=</span> <span class='String'>"acc"</span> ⟨ 1 0 1 ⟩ <span class='String'>"abc"</span> <span class='Function'>≡</span> <span class='String'>"acc"</span> diff --git a/docs/doc/selfcmp.html b/docs/doc/selfcmp.html index 9188c69c..bc99ef43 100644 --- a/docs/doc/selfcmp.html +++ b/docs/doc/selfcmp.html @@ -1,10 +1,10 @@ <head> <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/> <link href="../style.css" rel="stylesheet"/> - <title>BQN: Self-comparison functions</title> + <title>BQN: Self-search functions</title> </head> <div class="nav"><a href="https://github.com/mlochbaum/BQN">BQN</a> / <a href="../index.html">main</a> / <a href="index.html">doc</a></div> -<h1 id="self-comparison-functions">Self-comparison functions</h1> +<h1 id="self-search-functions">Self-search functions</h1> <svg viewBox='-115.2 -33 676.8 299.2'> <defs> <mask id='m'> @@ -131,11 +131,11 @@ </g> </svg> -<p>BQN has four self-comparison functions, Classify (<code><span class='Function'>⊐</span></code>), Occurrence Count (<code><span class='Function'>⊒</span></code>), Mark Firsts (<code><span class='Function'>∊</span></code>), and Deduplicate (<code><span class='Function'>⍷</span></code>). Each of these is a monadic function that obtains its result by comparing each major cell of the argument (which must have rank at least 1) to the earlier major cells with <a href="match.html">match</a>. For example, Mark Firsts indicates the cells that don't match any earlier cell, making them the first of their kind.</p> +<p>BQN has four self-search functions, Classify (<code><span class='Function'>⊐</span></code>), Occurrence Count (<code><span class='Function'>⊒</span></code>), Mark Firsts (<code><span class='Function'>∊</span></code>), and Deduplicate (<code><span class='Function'>⍷</span></code>). Each of these is a monadic function that obtains its result by comparing each major cell of the argument (which must have rank at least 1) to the earlier major cells with <a href="match.html">match</a>. For example, Mark Firsts indicates the cells that don't match any earlier cell, making them the first of their kind.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oiKICJhYmFhY2Ii">↗️</a><pre> <span class='Function'>∊</span> <span class='String'>"abaacb"</span> ⟨ 1 1 0 0 1 0 ⟩ </pre> -<p>When the argument is a list, its major cells are units and thus contain one element each, so it's just as valid to say that a self-comparison function compares elements of its argument. Only with a higher-rank argument does the major cell nature become apparent.</p> +<p>When the argument is a list, its major cells are units and thus contain one element each, so it's just as valid to say that a self-search function compares elements of its argument. Only with a higher-rank argument does the major cell nature become apparent.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqiIGFyciDihpAgPiJhYmMi4oC/ImRjYiLigL8iYWJjIuKAvyJiY2Qi4oC/ImRjYiIK4oiKIGFycg==">↗️</a><pre> <span class='Function'>⊢</span> <span class='Value'>arr</span> <span class='Gets'>←</span> <span class='Function'>></span><span class='String'>"abc"</span><span class='Ligature'>‿</span><span class='String'>"dcb"</span><span class='Ligature'>‿</span><span class='String'>"abc"</span><span class='Ligature'>‿</span><span class='String'>"bcd"</span><span class='Ligature'>‿</span><span class='String'>"dcb"</span> ┌─ ╵"abc @@ -147,9 +147,9 @@ <span class='Function'>∊</span> <span class='Value'>arr</span> ⟨ 1 1 0 1 0 ⟩ </pre> -<p>The result has one number for each major cell, or in other words is a list with the same length as its argument. Three self-comparison functions follow this pattern, but Deduplicate (<code><span class='Function'>⍷</span></code>) is different: it returns an array of the same rank but possibly a shorter length than the argument.</p> +<p>The result has one number for each major cell, or in other words is a list with the same length as its argument. Three self-search functions follow this pattern, but Deduplicate (<code><span class='Function'>⍷</span></code>) is different: it returns an array of the same rank but possibly a shorter length than the argument.</p> <h2 id="classify">Classify</h2> -<p>Classify is the universal self-comparison function, in that it preserves all the self-comparison information in its argument. It gives each different cell value a natural number, ordered by first appearance.</p> +<p>Classify is the universal self-search function, in that it preserves all the self-search information in its argument. It gives each different cell value a natural number, ordered by first appearance.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqQIDXigL824oC/MuKAvzLigL814oC/MQ==">↗️</a><pre> <span class='Function'>⊐</span> <span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>6</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>1</span> ⟨ 0 1 2 2 0 3 ⟩ </pre> @@ -160,7 +160,7 @@ 0 1 2 2 0 3 ┘ </pre> -<p>Applying Classify before another self-comparison function will never change the result, except in the case of Deduplicate (<code><span class='Function'>⍷</span></code>), which constructs its result from cells in the argument. In particular, Classify is <a href="https://en.wikipedia.org/wiki/Idempotent">idempotent</a>, meaning that applying it twice is the same as applying it once.</p> +<p>Applying Classify before another self-search function will never change the result, except in the case of Deduplicate (<code><span class='Function'>⍷</span></code>), which constructs its result from cells in the argument. In particular, Classify is <a href="https://en.wikipedia.org/wiki/Idempotent">idempotent</a>, meaning that applying it twice is the same as applying it once.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oiKICAgImRiYWVkY2JjZWNiY2QiCuKIiiDiipAgImRiYWVkY2JjZWNiY2QiCgp7KPCdlY/iiaHwnZWP4oiY4oqQKSJkYmFlZGNiY2VjYmNkIn3CqCDiipDigL/iipLigL/iiIrigL/ijbc=">↗️</a><pre> <span class='Function'>∊</span> <span class='String'>"dbaedcbcecbcd"</span> ⟨ 1 1 1 1 0 1 0 0 0 0 0 0 0 ⟩ <span class='Function'>∊</span> <span class='Function'>⊐</span> <span class='String'>"dbaedcbcecbcd"</span> @@ -208,7 +208,7 @@ <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-comparison 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 filter 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 ⟩ |
