From 47bbd4513fac56d4eb36940fcc186e718799ad6d Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 9 Feb 2021 22:17:01 -0500 Subject: Finish primitive commentary with section on structural manipulation --- docs/spec/primitive.html | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'docs/spec/primitive.html') diff --git a/docs/spec/primitive.html b/docs/spec/primitive.html index 30549201..02b856be 100644 --- a/docs/spec/primitive.html +++ b/docs/spec/primitive.html @@ -128,6 +128,14 @@

First Cell (⊏) selects the initial major cell of 𝕩, giving an error if 𝕩 has rank 0 or length 0.

Group (βŠ”) performs an opposite operation to Select, so that 𝕨 specifies not the argument index that result values come from, but the result index that argument values go to. The result rank is ≠𝕨, and each result element has rank 1+(=𝕩)-+Β΄=¨𝕨. The result element contains the minimal list of cells so that each cell of 𝕩 appears in the corresponding element of π•¨βŠπ•¨βŠ”π•©, in index order. Group Indices treats its argument 𝕩 as a left argument for Group and uses a right argument made up of indices, with the definition βŠ”βŸœ(β†•β‰ βš‡1).

Range (↕) 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 𝕩 should still result in an error). For a list 𝕩, the result is an array of shape 𝕩 in which the value at a given index is that index, as a list of natural numbers. That is, i≑iβŠ‘β†•π•© for any list of natural numbers i with ∧´i<𝕩.

+

Indices (/) applies to a list of natural numbers, and returns a list of natural numbers. The result contains iβŠ‘π•© copies of each natural number index i for 𝕩, in increasing order.

+

Structural manipulation

+

Monadic structural functions work on the first axis of the argument, so they require it to have rank at least 1. Reverse (⌽) reverses the ordering of the major cells of 𝕩. Nudge (Β») shifts them forward, removing the last and placing a major cell made up of fill elements at the beginning, while Nudge Back (Β«) does the same in the reverse direction, so it removes the first cell and places fills at the end. Prefixes (↑) and Suffixes (↓) each return lists with length one higher than 𝕩, whose elements are arrays with the same rank as 𝕩. For Prefixes, the element of the result at index i contains the first i major cells of 𝕩 in order, and for Suffixes, it contains all but these major cells.

+

The remainder of the functions discussed in this section are dyadic. There are four functions for which 𝕨 is a list of whole numbersβ€”but an atomic number or enclosed number is also permitted, and treated as a 1-element listβ€”and its elements are matched with leading axes of 𝕩. These functions independently manipulate each axis: one way to define such a process is to consider lists running along the axis, where every element of the index is fixed except one. A change to this axis retains the fixed indices, but can move elements from one location to another along the variable index, add fill elements, or split the axis into two axes. A change to a different axis can rearrange these lists along the original axis, but can't affect the placement of elements within them. In the reference implementations, working on leading axes is accomplished using the Cells (˘) modifier recursively, so that action on the first axes doesn't use Cells, on the next is affected by Cells once, then twice, and so on.

+

Rotate (⌽) is the simplest of these four functions: each element of 𝕨 gives an amount to rotate the corresponding axis, where a rotation of r moves the element at index i+r to i when all indices are taken modulo the length of the axis. Windows (↕) splits each axis of 𝕩 that corresponds to an element of 𝕨 in two, so that the result has one set of axes corresponding to elements of 𝕨, then another, then the unchanged trailing axes. The second set of axes has lengths given by 𝕨 (which must consist of natural numbers), while the first has lengths s¬𝕨, where s contains the lengths of leading axes of 𝕩. Position i in the first set of axes and j in the second corresponds to i+j in the argument, so that fixing one of these positions and varying the other gives a slice of the argument. In both Rotate and Windows, the length of 𝕨 is at most the rank of 𝕩.

+

Take (↑) offers several possibilities. The absolute value of 𝕨 gives the final lengths of the axes in the result. It may be positive to indicate that the axis aligns with 𝕩 at the beginning, or negative to indicate it aligns at the end. A zero value gives no result elements, so there is no need to consider alignment. If the absolute value of an element of 𝕨 is smaller than or equal to the corresponding length in 𝕩, then the first or last few elements are taken along that axis. If it is larger, then instead fill elements are added to the end (if positive) or beginning (if negative) to make up the difference in length. Drop (↓) gives 𝕨 a similar meaning, but excludes all elements that Take includes (maintaining the order of the retained ones). The result of Drop never uses fill elements. In a case where Take would use fill elements, it would include all positions from 𝕩, so Drop should include none of them, and the result will have length 0 for that axis. Take and Drop are extended to allow an argument with length greater than the rank of 𝕩. In this case leading length-1 axes are added to 𝕩 so that its rank matches 𝕨 before taking or dropping. If 𝕩 is an atom, it is always enclosed to an array first, even if 𝕨 is empty.

+

Replicate (/) is similar to the four dyadic structural functions above, but 𝕨 gives a list of containing lists of natural numbers, or plain or enclosed natural numbers, instead of a simple list. If 𝕨 has depth less than 2, it's considered to be a single value corresponding to one axis of 𝕩, while if it has depth 2 then it's a list of values. If 𝕨 is the empty list ⟨⟩ then it is defined to be in the second case despite having a depth of 1. On a single axis of 𝕩 the corresponding value r from 𝕨 is either a list or a unit: if it's a unit then it is repeated to match the length of that axis of 𝕩, and if it's a list it must already have the same length as that axis. Each number in r now specifies the number of times to repeat the corresponding position in 𝕩. This is equivalent to calling Indices on r and using the result for selection.

+

Shift Before (Β») and Shift After (Β«) are derived from Join To and share most of its behavior. The difference is that only a portion of the result of Join To is returned, matching the length of 𝕩. This portion comes from the beginning for Shift Before and the end for Shift After. The only difference in conditions between the shift functions and Join To is that Join To allows 𝕩 to have smaller rank than 𝕨 while for shifting it must have the same or greater rank.

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 Deduplicate (⍷), the result is a list of numbers with the same length as 𝕩.

-- cgit v1.2.3