diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/primitive.md | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/primitive.md b/spec/primitive.md index b2d9b6ff..15d1cf14 100644 --- a/spec/primitive.md +++ b/spec/primitive.md @@ -144,3 +144,21 @@ Modifiers for iteration are defined in layers 1, 2, and 4. Two 2-modifiers, `ā **Deshape** (`ā„`) 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. **Reshape** (`ā„`) 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; `š©` 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 `š©` is empty but the result is not, then the result consists of fill elements for `š©`. Furthermore, at most one element of `šØ` can be a "length code": one of the primitives `āāā½ā`. In this case, a target length is computed from the number of elements in `š©` divided by the product of the other elements of `šØ` (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 `ā`, and the target length is rounded down if the code is `ā` and up if it's `ā½` or `ā`. With code `ā½`, elements are repeated cyclically as usual, but with code `ā`, the extra elements after each argument element is used are fill values for `š©`. **Transpose** (`ā`) reorders axes of its argument to place the first axis last; if the argument has one or fewer axes then it's returned unchanged. **Reorder Axes** (`ā`) 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 `1āæ3āæ0āæ0`, `2` 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 "sent to" the specified result axis: in terms of indices, `iāšØāš©` is `(šØāi)āš©` if `šØ` 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. While Transpose does not enclose an atom right argument, Reorder Axes does, so that its result is always an array. + +### Searching + +**Match** (`ā”`) indicates whether two values are considered equivalent. It always returns 0 or 1, and never causes an error. If both arguments are atoms then it is identical to `=`, and if one is an atom and the other an array then it returns 0. If both arguments are arrays then it returns 1 only if they have the same shape and all pairs of corresponding elements match. Fill elements aren't taken into account, so that arrays that match might still differ in behavior. **Not Match** simply returns the complement of Match, `¬ā”`. + +Monadic search functions compare the major cells of `š©` to each other. `š©` must have rank at least 1. Except for Unique (`ā·`), the result is a list of numbers with the same length as `š©`. + +- **Unique Mask** (`ā`) returns 1 for a cell if it doesn't match any earlier cell and 0 if it does. +- **Deduplicate** (`ā·`) filters major cells to remove duplicates, retaining the ordering given by the first appearance of each unique cell. +- **Classify** (`ā`) returns, for each cell, the smallest index of a cell that matches it (it's necessarily less than or equal to `āā š©` element-wise, since each cell matches itself). +- **Occurrence Count** (`ā`) returns the number of earlier cells matching each cell. + +Dyadic search functions check whether major cells of the *principal argument* (which must have rank at least 1) match cells of the *non-principal argument* of the same rank. The rank of the non-principal argument can't be less than the major cell rank (rank minus one) of the principal argument. However, the non-principal argument can be an atom, in which case it will be automatically enclosed. The principal argument is `šØ` for `ā` and `ā` and `š©` for `ā`. The result is an array containing one number for each cell of the non-principal argument. The value of this number depends on the function: +- **Member of** (`ā`) indicates whether any cell of the principal argument matches the cell in question. +- **Index of** (`ā`) gives the smallest index of a principal argument cell that matches the cell, or `ā šØ` if there is no such cell. +- **Progressive Index of** (`ā`) processes non-principal cells in ravel order, and gives the smallest index of a principal argument cell that matches the cell that hasn't already been included in the result. Again `ā šØ` is returned for a given cell if there is no valid cell. + +**Find** (`ā·`) indicates positions where `šØ` appears as a contiguous subarray of a `=šØ`-cell of `š©`. It has one result element for each such subarray of `š©`, whose value is 1 if that subarray matches `š©` and 0 otherwise. |
