diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-05-31 21:56:13 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-05-31 21:56:13 -0400 |
| commit | 6078db236e6c34788371576bb51410cf8298b583 (patch) | |
| tree | 0e62588f942289a4fef397b19c5f06c5591f9d1a /docs | |
| parent | f0d58667085fee808a59b9c9e7667ad18d074cdf (diff) | |
Define cells in the documentation
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/doc/array.html | 14 | ||||
| -rw-r--r-- | docs/doc/glossary.html | 8 | ||||
| -rw-r--r-- | docs/doc/rank.html | 4 |
3 files changed, 20 insertions, 6 deletions
diff --git a/docs/doc/array.html b/docs/doc/array.html index d941f90a..6ce906e3 100644 --- a/docs/doc/array.html +++ b/docs/doc/array.html @@ -117,6 +117,20 @@ <p>The total number of elements in an array is its <strong>bound</strong>, and can be found using <a href="reshape.html">Deshape</a> with <code><span class='Function'>≠</span><span class='Modifier2'>∘</span><span class='Function'>⥊</span></code>, or by multiplying all the lengths in the shape. An array of rank 0, which always contains exactly one element, is called a <a href="enclose.html#whats-a-unit"><strong>unit</strong></a>, while an array of rank 1 is called a <strong>list</strong> and an array of rank 2 is called a <strong>table</strong>.</p> <h2 id="elements"><a class="header" href="#elements">Elements</a></h2> <p>Any BQN value can be used as an array element, including another array (BQN, as a dynamically-typed language, doesn't restrict the types that can be used in one context without a good reason). However, BQN arrays are restricted relative to other array models. Frameworks like NumPy or Julia have mutable arrays, so that the value of an element can be changed after the array is created. This allows an array to be its own element, by creating an array and then inserting it into itself. This would be unnatural in BQN, where an array can only be formed from elements that already exist. In BQN only operations and namespaces are <a href="lexical.html#mutation">mutable</a>.</p> +<h2 id="cells"><a class="header" href="#cells">Cells</a></h2> +<p>The contents of an array are its elements, but it also makes sense to split up an array into subarrays of elements called cells. The most important kind of cell, a <strong>major cell</strong> consists of all the elements that have indices beginning with some particular index <code><span class='Value'>i</span></code>. For this to make sense, <code><span class='Value'>i</span></code> must be between <code><span class='Number'>0</span></code> and the length <code><span class='Value'>l</span></code> of the array's first axis, so that there are <code><span class='Value'>l</span></code> major cells each identified by an index.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MuKAvzPigL80IMOX4oycIDHigL814oC/OOKAvzExCgoxIOKKjyAy4oC/M+KAvzQgw5fijJwgMeKAvzXigL844oC/MTEgICMgTWFqb3IgY2VsbCAx">↗️</a><pre> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span> <span class='Function'>×</span><span class='Modifier'>⌜</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>8</span><span class='Ligature'>‿</span><span class='Number'>11</span> +┌─ +╵ 2 10 16 22 + 3 15 24 33 + 4 20 32 44 + ┘ + + <span class='Number'>1</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> <span class='Function'>×</span><span class='Modifier'>⌜</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>8</span><span class='Ligature'>‿</span><span class='Number'>11</span> <span class='Comment'># Major cell 1 +</span>⟨ 3 15 24 33 ⟩ +</pre> +<p>A major cell still has an array structure: it retains all the axes of the original array other than the first. So it has its own major cells, identified by the index <code><span class='Value'>i</span></code> of the original major cell and <code><span class='Value'>j</span></code> within it. These are also cells of the original array. Generalizing, a <strong>cell</strong> with index list <code><span class='Value'>l</span></code> is defined to be the array of all elements whose indices begin with <code><span class='Value'>l</span></code>. In an array with rank <code><span class='Value'>n</span></code>, the cell rank is <code><span class='Value'>n</span><span class='Function'>-≠</span><span class='Value'>l</span></code>, and cells grouped using this rank. An <code><span class='Value'>n</span></code>-cell mst have an empty cell index, so that it includes all elements—it's the entire array! An <code><span class='Value'>n</span><span class='Function'>-</span><span class='Number'>1</span></code> cell, also called a ¯1-cell, is a major cell. A 0-cell has an index of length <code><span class='Value'>n</span></code>, and contains a single element.</p> +<p>Cells are the center of the <a href="leading.html">leading axis model</a> used to structure many array primitives.</p> <h2 id="properties"><a class="header" href="#properties">Properties</a></h2> <p>Summarizing, the values needed to define an array are its rank (the number of axes), its shape (the number of positions along each axis), and the value of each element (that is, at each combination of positions). Two arrays <a href="match.html">match</a> when all these values match.</p> <p>If the rank is considered to be part of the shape, as it is when the shape is a BQN list, then the array is defined by its shape and element list—from <a href="reshape.html">deshape</a>.</p> diff --git a/docs/doc/glossary.html b/docs/doc/glossary.html index abf71a37..ee3cddb4 100644 --- a/docs/doc/glossary.html +++ b/docs/doc/glossary.html @@ -61,11 +61,11 @@ </ul> <ul> <li><strong>Empty</strong>: Having no elements. An array is empty if its shape contains 0.</li> -<li><strong>Cell</strong>: An array containing all elements of the original array whose indices share a particular prefix.</li> -<li><strong>k-Cell</strong>: A cell of rank <em>k</em>.</li> -<li><a href="indices.html#major-cell-indices"><strong>Major cell</strong></a>: A cell with rank one less than the original array.</li> +<li><a href="array.html#cells"><strong>Cell</strong></a>: An array containing all elements of the original array whose indices share a particular prefix.</li> +<li><a href="array.html#cells"><strong>k-Cell</strong></a>: A cell of rank <em>k</em>.</li> +<li><a href="array.html#cells"><strong>Major cell</strong></a>: A cell with rank one less than the original array.</li> <li><a href="leading.html#leading-axis-agreement"><strong>Agreement</strong></a>: The way elements are paired when a function maps over two arrays.</li> -<li><strong>Frame</strong>: A prefix of an array's shape, used for agreement with the Rank modifier.</li> +<li><a href="rank.html#frame-and-cells"><strong>Frame</strong></a>: A prefix of an array's shape, used for agreement with the Rank modifier.</li> </ul> <ul> <li><strong>Unit</strong>: An array of rank 0, or an atom.</li> diff --git a/docs/doc/rank.html b/docs/doc/rank.html index e96eacb1..d030055d 100644 --- a/docs/doc/rank.html +++ b/docs/doc/rank.html @@ -89,7 +89,7 @@ <p>The Cells modifier <code><span class='Modifier'>˘</span></code> applies a function to major cells of its argument, much like <a href="map.html">Each</a> applies to elements. Each result from <code><span class='Function'>𝔽</span></code> becomes a major cell of the result, which means they must all have the same shape.</p> <p>The Rank modifier <code><span class='Modifier2'>⎉</span></code> generalizes this concept by allowing numbers provided by <code><span class='Function'>𝔾</span></code> to specify a rank for each argument: non-negative to indicate the rank of each array passed to <code><span class='Function'>𝔽</span></code>, or negative for the number of axes that are mapped over. Cells, which maps over one axis of each argument, is identical to <code><span class='Modifier2'>⎉</span><span class='Number'>¯1</span></code>. Rank is analogous to the <a href="depth.html#the-depth-modifier">Depth modifier</a>, but the homogeneous structure of an array eliminates some tricky edge cases found in Depth.</p> <h2 id="cells"><a class="header" href="#cells">Cells</a></h2> -<p>The function Cells (<code><span class='Modifier'>˘</span></code>) is named after <em>major cells</em> in an array. A major cell is a component of an array with dimension one smaller, so that the major cells of a list are <a href="enclose.html#whats-a-unit">units</a>, the major cells of a rank-2 table are its rows (which are lists), and the major cells of a rank-3 array are tables.</p> +<p>The function Cells (<code><span class='Modifier'>˘</span></code>) is named after <em>major cells</em> in an array. A <a href="array.html#cells">major cell</a> is a component of an array with dimension one smaller, so that the major cells of a list are <a href="enclose.html#whats-a-unit">units</a>, the major cells of a rank-2 table are its rows (which are lists), and the major cells of a rank-3 array are tables.</p> <p>The function <code><span class='Function'>𝔽</span><span class='Modifier'>˘</span></code> applies <code><span class='Function'>𝔽</span></code> to the major cells of <code><span class='Value'>𝕩</span></code>. So, for example, where <a href="shift.html">Nudge</a> (<code><span class='Function'>»</span></code>) shifts an entire table, Nudge Cells shifts its major cells, or rows.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDihpAgJ2EnICsgM+KAv+KImCDipYog4oaVMjQgICMgQSBjaGFyYWN0ZXIgYXJyYXkKCuKfqCAgYSAgICAgICwgICAgIMK7YSAgICAgLCAgICDCu8uYYSDin6k=">↗️</a><pre> <span class='Value'>a</span> <span class='Gets'>←</span> <span class='String'>'a'</span> <span class='Function'>+</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Modifier2'>∘</span> <span class='Function'>⥊</span> <span class='Function'>↕</span><span class='Number'>24</span> <span class='Comment'># A character array </span> @@ -174,7 +174,7 @@ ┘ </pre> <h2 id="rank"><a class="header" href="#rank">Rank</a></h2> -<p>Rank (<code><span class='Modifier2'>⎉</span></code>) is a generalization of Cells (<code><span class='Function'>𝔽</span><span class='Modifier'>˘</span></code> is defined to be <code><span class='Function'>𝔽</span><span class='Modifier2'>⎉</span><span class='Number'>¯1</span></code>) that can apply to arbitrary—not just major—cells and combine different levels of mapping for two arguments.</p> +<p>Rank (<code><span class='Modifier2'>⎉</span></code>) is a generalization of Cells (<code><span class='Function'>𝔽</span><span class='Modifier'>˘</span></code> is defined to be <code><span class='Function'>𝔽</span><span class='Modifier2'>⎉</span><span class='Number'>¯1</span></code>) that can apply to arbitrary—not just major—<a href="array.html#cells">cells</a> and combine different levels of mapping for two arguments.</p> <p>Rank comes in handy when there are high-rank arrays with lots of exciting axes, which is a great use case for BQN but honestly isn't all that common. And to continue this trend of honesty, using Rank just never <em>feels</em> good—it's some heavy machinery that I drag out when nothing else works, only to make use of a small part of the functionality. If Cells covers your use cases, that's probably for the best!</p> <h3 id="negative-and-positive-ranks"><a class="header" href="#negative-and-positive-ranks">Negative and positive ranks</a></h3> <p>I've said that <code><span class='Function'>𝔽</span><span class='Modifier2'>⎉</span><span class='Number'>¯1</span></code> is <code><span class='Function'>𝔽</span><span class='Modifier'>˘</span></code>. And it's also the case that <code><span class='Function'>𝔽</span><span class='Modifier2'>⎉</span><span class='Number'>¯2</span></code> is <code><span class='Function'>𝔽</span><span class='Modifier'>˘˘</span></code>. And <code><span class='Function'>𝔽</span><span class='Modifier2'>⎉</span><span class='Number'>¯3</span></code> is <code><span class='Function'>𝔽</span><span class='Modifier'>˘˘˘</span></code>. And so on.</p> |
