aboutsummaryrefslogtreecommitdiff
path: root/docs/spec/primitive.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/spec/primitive.html')
-rw-r--r--docs/spec/primitive.html4
1 files changed, 2 insertions, 2 deletions
diff --git a/docs/spec/primitive.html b/docs/spec/primitive.html
index fc60460d..b2e127c6 100644
--- a/docs/spec/primitive.html
+++ b/docs/spec/primitive.html
@@ -122,13 +122,13 @@
<p><strong>Enclose</strong> (<code><span class='Function'>&lt;</span></code>) forms a unit array that contains its argument.</p>
<p><strong>Merge</strong> (<code><span class='Function'>&gt;</span></code>) combines the outer axes of an array of arrays with inner axes: it requires that all elements of its argument have the same shape, and creates an array such that <code><span class='Paren'>(</span><span class='Value'>i</span><span class='Function'>โˆพ</span><span class='Value'>j</span><span class='Paren'>)</span><span class='Function'>โŠ‘&gt;</span><span class='Value'>๐•ฉ</span></code> is <code><span class='Value'>i</span><span class='Function'>โŠ‘</span><span class='Value'>j</span><span class='Function'>โŠ‘</span><span class='Value'>๐•ฉ</span></code>. It also accepts atom elements of <code><span class='Value'>๐•ฉ</span></code>, converting them to unit arrays, or an atom argument, which is returned unchanged. <strong>Solo</strong> and <strong>Couple</strong> (<code><span class='Function'>โ‰</span></code>) turn one or two arguments into major cells of the result and can be defined easily in terms of Merge.</p>
<p><strong>Join To</strong> (<code><span class='Function'>โˆพ</span></code>) combines its two arguments along an existing initial axis, unless both arguments are units, in which case it creates an axis and is identical to Couple (<code><span class='Function'>โ‰</span></code>). The arguments must differ in rank by at most 1, and the result rank is equal to the maximum of 1 and the higher argument rank. Each argument with rank less than the result, and each major cell of an argument with rank equal to it, becomes a major cell of the result, with cells from the left argument placed before those from the right. <strong>Join</strong> (<code><span class='Function'>โˆพ</span></code>) generalizes the equal-rank subset of this behavior to an array of values instead of just two. The argument must be an array (unlike Merge), and its elements must all the same rank, which is at least the argument rank. Atom elements are treated as unit arrays. Then &quot;outer&quot; argument axes are matched up with leading &quot;inner&quot; element axes, and elements are joined along these axes. In order to allow this, the length of an element along a particular axis must depend only on the position along the corresponding axis in the argument. An empty argument to Join is return unchanged, as though the element rank is equal to the argument rank.</p>
-<p><strong>Deshape</strong> (<code><span class='Function'>โฅŠ</span></code>) differs from the provided function (which returns the element list of an array) only in that it accepts an atom, returning a one-element list containing it. <strong>Reshape</strong> (<code><span class='Function'>โฅŠ</span></code>) is extended in numerous ways. It accepts any list of natural numbers (including as a unit array or atom) for the left argument and any right argument; <code><span class='Value'>๐•ฉ</span></code> is deshaped first so that it is treated as a list of elements. These elements are repeated cyclically to fill the result array in ravel order. If <code><span class='Value'>๐•ฉ</span></code> is empty but the result is not, then the result consists of fill elements for <code><span class='Value'>๐•ฉ</span></code>. Furthermore, at most one element of <code><span class='Value'>๐•จ</span></code> can be a &quot;length code&quot;: one of the primitives <code><span class='Modifier2'>โˆ˜</span><span class='Function'>โŒŠโŒฝโ†‘</span></code>. In this case, a target length is computed from the number of elements in <code><span class='Value'>๐•ฉ</span></code> divided by the product of the other elements of <code><span class='Value'>๐•จ</span></code> (which must not be zero). If the target length is an integer then it is used directly for the length code. Otherwise, an error is given if the length code is <code><span class='Modifier2'>โˆ˜</span></code>, and the target length is rounded down if the code is <code><span class='Function'>โŒŠ</span></code> and up if it's <code><span class='Function'>โŒฝ</span></code> or <code><span class='Function'>โ†‘</span></code>. With code <code><span class='Function'>โŒฝ</span></code>, elements are repeated cyclically as usual, but with code <code><span class='Function'>โ†‘</span></code>, the extra elements after each argument element is used are fill values for <code><span class='Value'>๐•ฉ</span></code>.</p>
+<p><strong>Deshape</strong> (<code><span class='Function'>โฅŠ</span></code>) differs from the provided function (which returns the element list of an array) only in that it accepts an atom, returning a one-element list containing it. <strong>Reshape</strong> (<code><span class='Function'>โฅŠ</span></code>) is extended in numerous ways. It accepts any list of natural numbers (including as a unit array or atom) for the left argument and any right argument; <code><span class='Value'>๐•ฉ</span></code> is deshaped first so that it is treated as a list of elements. These elements are repeated cyclically to fill the result array in ravel order. If <code><span class='Value'>๐•ฉ</span></code> is empty then a non-empty requested result shape causes an error. Furthermore, at most one element of <code><span class='Value'>๐•จ</span></code> can be a &quot;length code&quot;: one of the primitives <code><span class='Modifier2'>โˆ˜</span><span class='Function'>โŒŠโŒฝโ†‘</span></code>. In this case, a target length is computed from the number of elements in <code><span class='Value'>๐•ฉ</span></code> divided by the product of the other elements of <code><span class='Value'>๐•จ</span></code> (which must not be zero). If the target length is an integer then it is used directly for the length code. Otherwise, an error is given if the length code is <code><span class='Modifier2'>โˆ˜</span></code>, and the target length is rounded down if the code is <code><span class='Function'>โŒŠ</span></code> and up if it's <code><span class='Function'>โŒฝ</span></code> or <code><span class='Function'>โ†‘</span></code>. With code <code><span class='Function'>โŒฝ</span></code>, elements are repeated cyclically as usual, but with code <code><span class='Function'>โ†‘</span></code>, the extra elements after each argument element is used are fill values for <code><span class='Value'>๐•ฉ</span></code>.</p>
<p><strong>Transpose</strong> (<code><span class='Function'>โ‰</span></code>) reorders axes of its argument to place the first axis last; if the argument has one or fewer axes then it's enclosed if it's an atom and otherwise returned unchanged. <strong>Reorder Axes</strong> (<code><span class='Function'>โ‰</span></code>) requires the left argument to be a list or unit of natural numbers, with length at most the rank of the right argument. This list is extended to match the right argument rank exactly by repeatedly appending the least unused natural number (for example, given <code><span class='Number'>1</span><span class='Ligature'>โ€ฟ</span><span class='Number'>3</span><span class='Ligature'>โ€ฟ</span><span class='Number'>0</span><span class='Ligature'>โ€ฟ</span><span class='Number'>0</span></code>, <code><span class='Number'>2</span></code> is appended). After extension, it specifies a result axis for each axis of the right argument. There must be no gaps in the list: that is, with the result rank equal to one plus the greatest value present, every result axis must appear at least once. Now each argument axis is &quot;sent to&quot; the specified result axis: in terms of indices, <code><span class='Value'>i</span><span class='Function'>โŠ‘</span><span class='Value'>๐•จ</span><span class='Function'>โ‰</span><span class='Value'>๐•ฉ</span></code> is <code><span class='Paren'>(</span><span class='Value'>๐•จ</span><span class='Function'>โŠ</span><span class='Value'>i</span><span class='Paren'>)</span><span class='Function'>โŠ‘</span><span class='Value'>๐•ฉ</span></code> if <code><span class='Value'>๐•จ</span></code> is complete. If multiple argument axes correspond to the same result axis, then a diagonal is taken, and it's as long as the shortest of those argument axes. Like Transpose, Reorder Axes encloses <code><span class='Value'>๐•ฉ</span></code> if it's an atom, so that its result is always an array.</p>
<h3 id="indices-and-selection">Indices and selection</h3>
<p>Each element in an array <code><span class='Value'>s</span><span class='Function'>โฅŠ</span><span class='Value'>e</span></code> is associated with an <em>index</em>, which is a list of natural numbers <code><span class='Value'>i</span></code> such that <code><span class='Function'>โˆง</span><span class='Modifier'>ยด</span><span class='Value'>i</span><span class='Function'>&lt;</span><span class='Value'>s</span></code>. The list of all indices, which corresponds to the element list <code><span class='Value'>e</span></code>, contains all such lists <code><span class='Value'>i</span></code> in lexicographic order. That is, index <code><span class='Value'>i</span></code> comes before <code><span class='Value'>j</span></code> exactly when the two indices are not the same, and <code><span class='Value'>i</span></code> has the smaller value at the first position where they are unequal. The index of an element along a particular axis <code><span class='Value'>a</span></code> is the value <code><span class='Value'>a</span><span class='Function'>โŠ‘</span><span class='Value'>i</span></code>.</p>
<p><strong>Range</strong> (<code><span class='Function'>โ†•</span></code>) is extended to apply to a list of natural numbers, in addition to the provided case of a single natural number (an enclosed natural number <code><span class='Value'>๐•ฉ</span></code> should still result in an error). For a list <code><span class='Value'>๐•ฉ</span></code>, the result is an array of shape <code><span class='Value'>๐•ฉ</span></code> in which the value at a given index is that index, as a list of natural numbers. That is, <code><span class='Value'>i</span><span class='Function'>โ‰ก</span><span class='Value'>i</span><span class='Function'>โŠ‘โ†•</span><span class='Value'>๐•ฉ</span></code> for any list of natural numbers <code><span class='Value'>i</span></code> with <code><span class='Function'>โˆง</span><span class='Modifier'>ยด</span><span class='Value'>i</span><span class='Function'>&lt;</span><span class='Value'>๐•ฉ</span></code>.</p>
<p><strong>Pick</strong> (<code><span class='Function'>โŠ‘</span></code>) is extended to array left arguments. In this case, it requires every depth-1 array in the nested structure of <code><span class='Value'>๐•จ</span></code> to be a valid index list for <code><span class='Value'>๐•ฉ</span></code>, and every atom to be contained in one of these lists. The result is <code><span class='Value'>๐•จ</span></code> with each index list replaced by the element of <code><span class='Value'>๐•ฉ</span></code> at that index. In the simple case where <code><span class='Value'>๐•จ</span></code> itself is an index list, the result is the element of <code><span class='Value'>๐•ฉ</span></code> at index <code><span class='Value'>๐•จ</span></code>.</p>
-<p><strong>First</strong> (<code><span class='Function'>โŠ‘</span></code>) simply takes the first element of its argument in index order, or the fill element if <code><span class='Value'>๐•ฉ</span></code> is empty.</p>
+<p><strong>First</strong> (<code><span class='Function'>โŠ‘</span></code>) simply takes the first element of its argument in index order, with an error if <code><span class='Value'>๐•ฉ</span></code> is empty.</p>
<p>For <strong>Select</strong> (<code><span class='Function'>โŠ</span></code>), <code><span class='Value'>๐•จ</span></code> is an array of natural numbers, or a list of such arrays; if it's an empty list, it's interpreted as the former. The given arrays are matched with leading axes of <code><span class='Value'>๐•ฉ</span></code> and used to select from those axes. Their shape is retained, so that the final shape is the combined shapes of each array of natural numbers in <code><span class='Value'>๐•จ</span></code> in order, followed by the trailing (unmatched) shape of <code><span class='Value'>๐•ฉ</span></code>. This means that a single axis in <code><span class='Value'>๐•ฉ</span></code> can correspond to any number of axes in <code><span class='Value'>๐•จ</span><span class='Function'>โŠ</span><span class='Value'>๐•ฉ</span></code>, depending on the rank of that portion of <code><span class='Value'>๐•จ</span></code>. More precisely, the value of the result at an index <code><span class='Value'>j</span></code> is obtained by splitting <code><span class='Value'>j</span></code> into one index into each array of <code><span class='Value'>๐•จ</span></code> followed by a partial index into <code><span class='Value'>๐•ฉ</span></code>. An index <code><span class='Value'>i</span></code> for <code><span class='Value'>๐•ฉ</span></code> comes from selecting from each array of <code><span class='Value'>๐•จ</span></code> and appending the results to the partial index from <code><span class='Value'>j</span></code>, and the value <code><span class='Value'>i</span><span class='Function'>โŠ‘</span><span class='Value'>๐•ฉ</span></code> is <code><span class='Value'>j</span><span class='Function'>โŠ‘</span><span class='Value'>๐•จ</span><span class='Function'>โŠ</span><span class='Value'>๐•ฉ</span></code>.</p>
<p><strong>First Cell</strong> (<code><span class='Function'>โŠ</span></code>) selects the initial major cell of <code><span class='Value'>๐•ฉ</span></code>, giving an error if <code><span class='Value'>๐•ฉ</span></code> has rank 0 or length 0.</p>
<p><strong>Group</strong> (<code><span class='Function'>โŠ”</span></code>) performs an opposite operation to Select, so that <code><span class='Value'>๐•จ</span></code> specifies not the argument index that result values come from, but the result index that argument values go to. The general case is that <code><span class='Value'>๐•จ</span></code> is a list of arrays of numbers; if it has depth less than 2 it's converted to this form by first enclosing it if it's an atom, then placing it in a length-1 list. After this transformation, the result rank is <code><span class='Function'>โ‰ </span><span class='Value'>๐•จ</span></code>, and each result element has rank <code><span class='Paren'>(</span><span class='Function'>โ‰ </span><span class='Value'>๐•จ</span><span class='Paren'>)</span><span class='Function'>+</span><span class='Paren'>(</span><span class='Function'>=</span><span class='Value'>๐•ฉ</span><span class='Paren'>)</span><span class='Function'>-+</span><span class='Modifier'>ยด</span><span class='Function'>=</span><span class='Modifier'>ยจ</span><span class='Value'>๐•จ</span></code>, with the initial <code><span class='Function'>โ‰ </span><span class='Value'>๐•จ</span></code> axes corresponding to elements of <code><span class='Value'>๐•จ</span></code> and the remainder to trailing axes of <code><span class='Value'>๐•ฉ</span></code>. Each atom in <code><span class='Value'>๐•จ</span></code> can be either a natural number or <code><span class='Number'>ยฏ1</span></code> (which indicates the corresponding position in <code><span class='Value'>๐•ฉ</span></code> will be omitted). If <code><span class='Number'>ยฏ1</span></code> doesn't appear, the result has the property that each cell of <code><span class='Value'>๐•ฉ</span></code> appears in the corresponding element of <code><span class='Value'>๐•จ</span><span class='Function'>โŠ</span><span class='Value'>๐•จ</span><span class='Function'>โŠ”</span><span class='Value'>๐•ฉ</span></code>. More concretely, the length of the result along axis <code><span class='Value'>a</span></code> is the maximum value in <code><span class='Value'>a</span><span class='Function'>โŠ‘</span><span class='Value'>๐•จ</span></code> plus one, or zero if <code><span class='Value'>a</span><span class='Function'>โŠ‘</span><span class='Value'>๐•จ</span></code> is empty. Axis <code><span class='Value'>a</span></code> corresponds to <code><span class='Function'>=</span><span class='Value'>a</span><span class='Function'>โŠ‘</span><span class='Value'>๐•จ</span></code> axes in <code><span class='Value'>๐•ฉ</span></code>, and an element of the result at position <code><span class='Value'>i</span></code> along this axis contains all positions in <code><span class='Value'>๐•ฉ</span></code> where <code><span class='Value'>i</span><span class='Function'>=</span><span class='Value'>a</span><span class='Function'>โŠ‘</span><span class='Value'>๐•จ</span></code>. There may be multiple such positions, and they're arranged along axis <code><span class='Value'>a</span></code> of that result element according to their index order in <code><span class='Value'>๐•ฉ</span></code>. The shapes of components of <code><span class='Value'>๐•จ</span></code> must match the corresponding axes of <code><span class='Value'>๐•ฉ</span></code>, except for rank-1 components of <code><span class='Value'>๐•จ</span></code>, which can match or have an extra element. This element, which like the others is either a natural number or <code><span class='Number'>ยฏ1</span></code>, gives the minimum length of the result axis corresponding to the component of <code><span class='Value'>๐•จ</span></code> in question, but otherwise does not affect the result. <strong>Group Indices</strong> treats its argument <code><span class='Value'>๐•ฉ</span></code> as a left argument for Group and uses a right argument made up of indices, which is <code><span class='Function'>โ†•โ‰ </span><span class='Value'>๐•ฉ</span></code> if <code><span class='Value'>๐•ฉ</span></code> has depth 1 and <code><span class='Function'>โ†•โˆพโ‰ข</span><span class='Modifier'>ยจ</span><span class='Value'>๐•ฉ</span></code> if it has depth 2. Because the depth-1 case uses atomic indices, <code><span class='Value'>๐•ฉ</span></code> is required to be a list (and it can't be an atom). Much like Range, the result has depth one higher than the argument.</p>