diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-06-20 08:10:31 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-06-20 08:10:31 -0400 |
| commit | 617d05b2cbb07e2778411b889914eecc156c6d79 (patch) | |
| tree | ab09f79fa34cde5fd6af55c8f1c67e4fe7cc6e57 | |
| parent | 7ee066159ac2a60fffc3162cd31d35ce73cfd623 (diff) | |
Use vector reduce in documentation
| -rw-r--r-- | doc/group.md | 6 | ||||
| -rw-r--r-- | doc/join.md | 2 | ||||
| -rw-r--r-- | doc/transpose.md | 4 | ||||
| -rw-r--r-- | doc/windows.md | 6 |
4 files changed, 9 insertions, 9 deletions
diff --git a/doc/group.md b/doc/group.md index 6451d678..c149716c 100644 --- a/doc/group.md +++ b/doc/group.md @@ -168,14 +168,14 @@ In other cases, we might want to split on spaces, so that words are separated by However, trailing spaces are ignored because Group never produces trailing empty groups (to get them back we would use a dummy final character in the string). To avoid empty words, we should increase the word index only once per group of spaces. We can do this by taking the prefix sum of a list that is 1 only for a space with no space before it. To make such a list, we can use the [Windows](windows.md) function. We will extend our list with an initial 1 so that leading spaces will be ignored. Then we take windows of the same length as the original list: the first includes the dummy argument followed by a shifted copy of the list, and the second is the original list. These represent whether the previous and current characters are spaces; we want positions where the previous wasn't a space and the current is. - ≍⟜(<´≠↕1∾⊢) ' '=" string with spaces " ⍝ All, then filtered, spaces + ≍⟜((<´<˘)≠↕1∾⊢) ' '=" string with spaces " ⍝ All, then filtered, spaces ┌ 1 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 - ≍⟜(⊢-˜¬×+`∘(<´≠↕1∾⊢))' '=" string with spaces " ⍝ More processing + ≍⟜(⊢-˜¬×+`∘((<´<˘)≠↕1∾⊢))' '=" string with spaces " ⍝ More processing ┌ 1 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 ¯1 ¯1 0 0 0 0 0 0 ¯1 1 1 1 1 ¯1 ¯1 2 2 2 2 2 2 ¯1 ¯1 ¯1 ┘ - ' '((⊢-˜¬×+`∘(<´≠↕1∾⊢))∘=⊔⊢)" string with spaces " ⍝ Final result + ' '((⊢-˜¬×+`∘((<´<˘)≠↕1∾⊢))∘=⊔⊢)" string with spaces " ⍝ Final result [ [ string ] [ with ] [ spaces ] ] diff --git a/doc/join.md b/doc/join.md index a89bcbd7..f11b815a 100644 --- a/doc/join.md +++ b/doc/join.md @@ -38,4 +38,4 @@ However, Join has higher-dimensional uses as well. Given a rank-`m` array of ran Join has fairly strict requirements on the shapes of its argument elements—although less strict than those of Unbox, which requires they all have identical shape. Suppose the argument to Join has rank `m`. Each of its elements must have the same rank, `n`, which is at least `m`. The trailing shapes `m↓⟜≢¨𝕩` must all be identical (the trailing shape `m↓≢∾𝕩` of the result will match these shapes as well). The other entries in the leading shapes need not be the same, but the shape of an element along a particular axis must depend only on the location of the element along that axis in the full array. For a vector argument this imposes no restriction, since the one leading shape element is allowed to depend on position along the only axis. But for higher ranks the structure quickly becomes more rigid. -To state this requirement more formally in BQN, we say that there is some vector `s` of length vectors, so that `(≢¨s)≡≢𝕩`. We require element `i⊑𝕩` to have shape `i⊑¨s`. Then the first `m` axes of the result are `>+´¨s`. +To state this requirement more formally in BQN, we say that there is some vector `s` of length vectors, so that `(≢¨s)≡≢𝕩`. We require element `i⊑𝕩` to have shape `i⊑¨s`. Then the first `m` axes of the result are `+´¨s`. diff --git a/doc/transpose.md b/doc/transpose.md index 2acb59e9..e13b6691 100644 --- a/doc/transpose.md +++ b/doc/transpose.md @@ -4,7 +4,7 @@ As in APL, Transpose (`⍉`) is a tool for rearranging the axes of an array. BQN ## Monadic Transpose -Transposing a matrix exchanges its axes, mirroring it across the diagonal. APL extends the function to any rank by reversing all axes, but this generalization isn't very natural and is almost never used. The main reason for it is to maintain the equivalence `a MP b ←→ a MP⌾⍉ b`, where `MP ← +´∘×⎉1‿∞` is the generalized matrix product. But even here APL's Transpose is suspect. It does much more work than it needs to, as we'll see. +Transposing a matrix exchanges its axes, mirroring it across the diagonal. APL extends the function to any rank by reversing all axes, but this generalization isn't very natural and is almost never used. The main reason for it is to maintain the equivalence `a MP b ←→ a MP⌾⍉ b`, where `MP ← (+´<˘)∘×⎉1‿∞` is the generalized matrix product. But even here APL's Transpose is suspect. It does much more work than it needs to, as we'll see. BQN's transpose takes the first axis of its argument and moves it to the end. @@ -108,4 +108,4 @@ A non-array right argument to Transpose is always boxed to get a scalar array be Monadic transpose is identical to `(≠∘≢-1˜)⊸⍉`, except that for scalar arguments it returns the array unchanged rather than giving an error. -In Dyadic transpose, the left argument is a number or numeric array of rank 1 or less, and `𝕨≤○≠≢𝕩`. Define the result rank `r←(≠≢𝕩)-+´¬∊𝕨` to be the argument rank minus the number of duplicate entries in the left argument. We require `∧´𝕨<r`. Bring `𝕨` to full length by appending the missing indices: `𝕨∾↩𝕨(¬∘∊˜/⊢)↕r`. Now the result shape is defined to be `>⌊´¨𝕨⊔≢𝕩`. Element `i⊑z` of the result `z` is element `(𝕨⊏i)⊑𝕩` of the argument. +In Dyadic transpose, the left argument is a number or numeric array of rank 1 or less, and `𝕨≤○≠≢𝕩`. Define the result rank `r←(≠≢𝕩)-+´¬∊𝕨` to be the argument rank minus the number of duplicate entries in the left argument. We require `∧´𝕨<r`. Bring `𝕨` to full length by appending the missing indices: `𝕨∾↩𝕨(¬∘∊˜/⊢)↕r`. Now the result shape is defined to be `⌊´¨𝕨⊔≢𝕩`. Element `i⊑z` of the result `z` is element `(𝕨⊏i)⊑𝕩` of the argument. diff --git a/doc/windows.md b/doc/windows.md index 081aa701..d4165d62 100644 --- a/doc/windows.md +++ b/doc/windows.md @@ -60,7 +60,7 @@ If the left argument has length `0`, then the argument is not sliced along any d `𝕩` is an array. `𝕨` is a number or numeric list or scalar with `𝕨≤○≠≢𝕩`. The result `z` has shape `𝕨∾¬⟜𝕨⌾((≠𝕨)⊸↑)≢𝕩`, and element `i⊑z` is `𝕩⊑˜(≠𝕨)(↑+⌾((≠𝕨)⊸↑)↓)i`. -Using [Group](group.md) we could also write `i⊑z` ←→ `𝕩⊑˜(𝕨∾○(↕∘≠)≢𝕩) (>+´¨)∘⊔ i`. +Using [Group](group.md) we could also write `i⊑z` ←→ `𝕩⊑˜(𝕨∾○(↕∘≠)≢𝕩) +´¨∘⊔ i`. ## Symmetry @@ -103,10 +103,10 @@ A common task is to pair elements, with an initial or final element so the total -˜´˘2↕0∾ +` 3‿2‿1‿1 [ 3 2 1 1 ] - (-˜´≠↕0∾⊢) +` 3‿2‿1‿1 + ((-˜´<˘)≠↕0∾⊢) +` 3‿2‿1‿1 [ 3 2 1 1 ] This method extends to any number of initial elements. We can modify the running sum above to keep the length constant by starting with two zeros. - (+´≠↕(2⥊0)⊸∾) ⟨2,6,0,1,4,3⟩ + ((+´<˘)≠↕(2⥊0)⊸∾) ⟨2,6,0,1,4,3⟩ [ 2 8 8 7 5 8 ] |
