From 666ad23844be33141f7c986de3b83f035db4b95a Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 15 Feb 2021 17:51:17 -0500 Subject: Reference implementation and commentary for Group length extension --- docs/spec/primitive.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/spec') diff --git a/docs/spec/primitive.html b/docs/spec/primitive.html index ab65ef6c..d0eb9b2f 100644 --- a/docs/spec/primitive.html +++ b/docs/spec/primitive.html @@ -127,7 +127,7 @@

First (โŠ‘) simply takes the first element of its argument in index order, or the fill element if ๐•ฉ is empty.

For Select (โŠ), ๐•จ 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 ๐•ฉ 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 ๐•จ in order, followed by the trailing (unmatched) shape of ๐•ฉ. This means that a single axis in ๐•ฉ can correspond to any number of axes in ๐•จโŠ๐•ฉ, depending on the rank of that portion of ๐•จ. More precisely, the value of the result at an index j is obtained by splitting j into one index into each array of ๐•จ followed by a partial index into ๐•ฉ. An index i for ๐•ฉ comes from selecting from each array of ๐•จ and appending the results to the partial index from j, and the value iโŠ‘๐•ฉ is jโŠ‘๐•จโŠ๐•ฉ.

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 general case is that ๐•จ 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 โ‰ ๐•จ, and each result element has rank (โ‰ ๐•จ)+(=๐•ฉ)-+ยด=ยจ๐•จ, with the initial โ‰ ๐•จ axes corresponding to elements of ๐•จ and the remainder to trailing axes of ๐•ฉ. Each atom in ๐•จ can be either a natural number or ยฏ1 (which indicates the corresponding position in ๐•ฉ will be omitted). If ยฏ1 doesn't appear, the result has the property that each cell of ๐•ฉ appears in the corresponding element of ๐•จโŠ๐•จโŠ”๐•ฉ. More concretely, the length of the result along axis a is the maximum value in aโŠ‘๐•จ plus one, or zero if aโŠ‘๐•จ is empty. Axis a corresponds to =aโŠ‘๐•จ axes in ๐•ฉ, and an element of the result at position i along this axis contains all positions in ๐•ฉ where i=aโŠ‘๐•จ. There may be multiple such positions, and they're arranged along axis a of that result element according to their index order in ๐•ฉ. Group Indices treats its argument ๐•ฉ as a left argument for Group and uses a right argument made up of indices, with the definition โŠ”โŸœ(โ†•โ‰ โš‡1).

+

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 general case is that ๐•จ 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 โ‰ ๐•จ, and each result element has rank (โ‰ ๐•จ)+(=๐•ฉ)-+ยด=ยจ๐•จ, with the initial โ‰ ๐•จ axes corresponding to elements of ๐•จ and the remainder to trailing axes of ๐•ฉ. Each atom in ๐•จ can be either a natural number or ยฏ1 (which indicates the corresponding position in ๐•ฉ will be omitted). If ยฏ1 doesn't appear, the result has the property that each cell of ๐•ฉ appears in the corresponding element of ๐•จโŠ๐•จโŠ”๐•ฉ. More concretely, the length of the result along axis a is the maximum value in aโŠ‘๐•จ plus one, or zero if aโŠ‘๐•จ is empty. Axis a corresponds to =aโŠ‘๐•จ axes in ๐•ฉ, and an element of the result at position i along this axis contains all positions in ๐•ฉ where i=aโŠ‘๐•จ. There may be multiple such positions, and they're arranged along axis a of that result element according to their index order in ๐•ฉ. The shapes of components of ๐•จ must match the corresponding axes of ๐•ฉ, except for rank-1 components of ๐•จ, which can match or have an extra element. This element, which like the others is either a natural number or ยฏ1, gives the minimum length of the result axis corresponding to the component of ๐•จ in question, but otherwise does not affect the result. 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

-- cgit v1.2.3