diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-15 17:51:17 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-15 17:51:17 -0500 |
| commit | 666ad23844be33141f7c986de3b83f035db4b95a (patch) | |
| tree | ba698088b9473d387f0db3d0f61414a8aa7a48bf /spec | |
| parent | 9ca6a97ade483d5cc6dfbffc3af35b88385381e8 (diff) | |
Reference implementation and commentary for Group length extension
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/primitive.md | 2 | ||||
| -rw-r--r-- | spec/reference.bqn | 13 |
2 files changed, 10 insertions, 5 deletions
diff --git a/spec/primitive.md b/spec/primitive.md index fca283d5..2662f8c4 100644 --- a/spec/primitive.md +++ b/spec/primitive.md @@ -161,7 +161,7 @@ For **Select** (`β`), `π¨` is an array of natural numbers, or a list of such **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<π©`. diff --git a/spec/reference.bqn b/spec/reference.bqn index 288fdc39..988bfb51 100644 --- a/spec/reference.bqn +++ b/spec/reference.bqn @@ -383,11 +383,16 @@ Groupβ{ π¨β©PairβToArrayβ(2>β‘)π¨ ! 1==π¨ {!β§Β΄IntΒ¨π©β!β§Β΄Β―1β€π©}ββ₯Β¨π¨ - nβ+Β΄=Β¨π¨ + nβ+Β΄rβ=Β¨π¨ ! nβ€=π© - ! (βΎβ’βπ¨)β‘nββ’π© - π¨β©β₯Β¨π¨ β π©β©((β Β¨π¨)βΎnββ’π©)β₯π© - (π¨βΈ=/π©Λ)Β¨β1+Β―1β´¨π¨ + ldβ(βΎβ’βπ¨)-nββ’π© + ! β§Β΄(0βΈβ€β§β€β(r/1=r))ld + drβrβ(0Β»+`r)βldβΎβ¨0β© + sβdrβ£βΆβ¨0,Β―1βΈββ©Β¨π¨ + π¨β©dr(β₯Β―1βΈβββ£)Β¨π¨ + sββ©1+Β―1β´¨π¨ + π©β©((β Β¨π¨)βΎnββ’π©)β₯π© + (π¨βΈ=/π©Λ)Β¨βs } GroupIndsβ{ ! 1==π© |
