diff options
Diffstat (limited to 'docs/doc/replicate.html')
| -rw-r--r-- | docs/doc/replicate.html | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/docs/doc/replicate.html b/docs/doc/replicate.html index 31e63228..4387373b 100644 --- a/docs/doc/replicate.html +++ b/docs/doc/replicate.html @@ -88,7 +88,7 @@ <p>The functions Indices and Replicate are used to copy or filter data. They might be described as transforming a <a href="https://en.wikipedia.org/wiki/Run-length_encoding">run-length encoding</a> into unencoded form. On the other hand, Indices might be described as giving a sparse representation of <code><span class='Value'>๐ฉ</span></code>, which is smaller if <code><span class='Value'>๐ฉ</span></code> mostly consists of zeros.</p> <p>BQN doesn't have any of the various features used in APL to add fills to the result of Replicate, like negative numbers in <code><span class='Value'>๐จ</span></code> or an Expand (<code><span class='Value'>\</span></code>) primitive. An alternative to Expand is to use Replicate with structural <a href="under.html">Under</a> (<code><span class='Modifier2'>โพ</span></code>) to insert values into an array of fills.</p> <h2 id="replicate"><a class="header" href="#replicate">Replicate</a></h2> -<p>Given a list of natural numbers <code><span class='Value'>๐จ</span></code>, Replicate repeats each major cell in <code><span class='Value'>๐ฉ</span></code> the corresponding number of times. That is, <code><span class='Value'>๐จ</span></code> and <code><span class='Value'>๐ฉ</span></code> must have the same length, and the result includes <code><span class='Value'>i</span><span class='Function'>โ</span><span class='Value'>๐จ</span></code> copies of each cell <code><span class='Value'>i</span><span class='Function'>โ</span><span class='Value'>๐ฉ</span></code>, in order.</p> +<p>Given a list of natural numbers <code><span class='Value'>๐จ</span></code>, Replicate repeats each <a href="array.html#cells">major cell</a> in <code><span class='Value'>๐ฉ</span></code> the corresponding number of times. That is, <code><span class='Value'>๐จ</span></code> and <code><span class='Value'>๐ฉ</span></code> must have the same length, and the result includes <code><span class='Value'>i</span><span class='Function'>โ</span><span class='Value'>๐จ</span></code> copies of each cell <code><span class='Value'>i</span><span class='Function'>โ</span><span class='Value'>๐ฉ</span></code>, in order.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MuKAvzHigL8w4oC/MiAvICJhYmNkIgoK4oqiIGEg4oaQID4iYWEwIuKAvyJiYjEi4oC/ImNjMiLigL8iZGQzIgoKMuKAvzHigL8w4oC/MiAvIGE=">โ๏ธ</a><pre> <span class='Number'>2</span><span class='Ligature'>โฟ</span><span class='Number'>1</span><span class='Ligature'>โฟ</span><span class='Number'>0</span><span class='Ligature'>โฟ</span><span class='Number'>2</span> <span class='Function'>/</span> <span class='String'>"abcd"</span> "aabdd" @@ -124,7 +124,7 @@ "fie" </pre> <p>Here <code><span class='Function'>โค</span><span class='Modifier2'>โ</span><span class='String'>'i'</span></code> is a pervasive function, so there's no need to add <code><span class='Modifier'>ยจ</span></code>. Similarly, to filter major cells of an array, <code><span class='Function'>Fn</span><span class='Modifier'>ห</span><span class='Modifier2'>โธ</span><span class='Function'>/</span></code> could be used, applying <code><span class='Function'>Fn</span></code> to one major cell at a time.</p> -<p>A similar pattern applies to Replicate as well. The function below tests which input characters are double quotes, but by adding one it changes the result to 1 for each non-quote character and 2 for quotes (but source code and display also double quotes here, so the input string has only two <code><span class='String'>"</span></code>s and the output has four).</p> +<p>This idea extends to Replicate as well. The function below tests which input characters are double quotes, but by adding one it changes the result to 1 for each non-quote character and 2 for quotes (but source code and display also double quotes here, so the input string has only two <code><span class='String'>"</span></code>s and the output has four).</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=ezErJyInPfCdlal94oq4LyAiZm9yICIiZXNjYXBpbmciIiBxdW90ZXMi">โ๏ธ</a><pre> <span class='Brace'>{</span><span class='Number'>1</span><span class='Function'>+</span><span class='String'>'"'</span><span class='Function'>=</span><span class='Value'>๐ฉ</span><span class='Brace'>}</span><span class='Modifier2'>โธ</span><span class='Function'>/</span> <span class='String'>"for ""escaping"" quotes"</span> "for """"escaping"""" quotes" </pre> @@ -173,7 +173,7 @@ 1 </pre> <h2 id="indices"><a class="header" href="#indices">Indices</a></h2> -<p>The monadic form of <code><span class='Function'>/</span></code> is much simpler than the dyadic one, with no multidimensional case or mismatched argument ranks. <code><span class='Value'>๐ฉ</span></code> must be a list of natural numbers, and <code><span class='Function'>/</span><span class='Value'>๐ฉ</span></code> is the list <code><span class='Value'>๐ฉ</span><span class='Function'>/โโ </span><span class='Value'>๐ฉ</span></code>. Its elements are the <a href="indices.html">indices</a> for <code><span class='Value'>๐ฉ</span></code>, with index <code><span class='Value'>i</span></code> repeated <code><span class='Value'>i</span><span class='Function'>โ</span><span class='Value'>๐ฉ</span></code> times.</p> +<p>The monadic form of <code><span class='Function'>/</span></code> is much simpler than the dyadic one, with no multidimensional case or mismatched argument ranks. <code><span class='Value'>๐ฉ</span></code> has to be a list of natural numbers, and <code><span class='Function'>/</span><span class='Value'>๐ฉ</span></code> is the list <code><span class='Value'>๐ฉ</span><span class='Function'>/โโ </span><span class='Value'>๐ฉ</span></code>. Its elements are the <a href="indices.html">indices</a> for <code><span class='Value'>๐ฉ</span></code>, with index <code><span class='Value'>i</span></code> repeated <code><span class='Value'>i</span><span class='Function'>โ</span><span class='Value'>๐ฉ</span></code> times.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=LyAz4oC/MOKAvzHigL8y">โ๏ธ</a><pre> <span class='Function'>/</span> <span class='Number'>3</span><span class='Ligature'>โฟ</span><span class='Number'>0</span><span class='Ligature'>โฟ</span><span class='Number'>1</span><span class='Ligature'>โฟ</span><span class='Number'>2</span> โจ 0 0 0 2 3 3 โฉ </pre> @@ -211,7 +211,7 @@ 8 2 โ </pre> -<p>This means the transitions can be grouped exactly in pairs, the beginning and end of each group. Reshape with a <a href="reshape.html#computed-lengths">computed length</a> <code><span class='Modifier2'>โ</span><span class='Ligature'>โฟ</span><span class='Number'>2</span></code> groups these pairs, and then a scan <code><span class='Function'>-</span><span class='Modifier'>ห`ห</span></code> can be used to convert the start/end format to start/length if wanted.</p> +<p>This means the transitions can be grouped exactly in pairs, the beginning and end of each group. Reshape with a <a href="reshape.html#computed-lengths">computed length</a> <code><span class='Modifier2'>โ</span><span class='Ligature'>โฟ</span><span class='Number'>2</span></code> groups these pairs, and then a <a href="scan.html">scan</a> <code><span class='Function'>-</span><span class='Modifier'>ห`ห</span></code> can be used to convert the start/end format to start/length if wanted.</p> <h3 id="inverse"><a class="header" href="#inverse">Inverse</a></h3> <p>The result of Indices <code><span class='Function'>/</span><span class='Value'>n</span></code> is an ordered list of natural numbers, where the number <code><span class='Value'>i</span></code> appears <code><span class='Value'>i</span><span class='Function'>โ</span><span class='Value'>n</span></code> times. Given an ordered list of natural numbers <code><span class='Value'>k</span></code>, the <a href="undo.html"><em>inverse</em></a> of indices returns a corresponding <code><span class='Value'>n</span></code>: one where the value <code><span class='Value'>i</span><span class='Function'>โ</span><span class='Value'>n</span></code> is the number of times <code><span class='Value'>i</span></code> appears in <code><span class='Value'>k</span></code>.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=LyAz4oC/MuKAvzEKCi/igbwgMOKAvzDigL8w4oC/MeKAvzHigL8y">โ๏ธ</a><pre> <span class='Function'>/</span> <span class='Number'>3</span><span class='Ligature'>โฟ</span><span class='Number'>2</span><span class='Ligature'>โฟ</span><span class='Number'>1</span> |
