From eb01eb415a5304d98c55f844188bb0defac90c67 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 17 Jul 2020 12:04:34 -0400 Subject: Character entity escaping for "&<> --- docs/windows.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'docs/windows.html') diff --git a/docs/windows.html b/docs/windows.html index f7cc8a6b..a599d634 100644 --- a/docs/windows.html +++ b/docs/windows.html @@ -4,7 +4,7 @@

The Window function replaces APL's Windowed Reduction, J's more general Infix operator, and Dyalog's Stencil, which is adapted from one case of J's Cut operator.

Definition

We'll start with the one-axis case. Here Window's left argument is a number between 0 and 1+≠𝕩. The result is composed of slices of 𝕩 (contiguous sections of major cells) with length 𝕨, starting at each possible index in order.

-
    5↕"abcdefg"
+
    5↕"abcdefg"
 β”Œ
   abcde
   bcdef
@@ -13,15 +13,15 @@
 

There are 1+(≠𝕩)-𝕨, or (≠𝕩)¬𝕨, of these sections, because the starting index must be at least 0 and at most (≠𝕩)-𝕨. Another way to find this result is to look at the number of cells in or before a given slice: there are always 𝕨 in the slice and there are only ≠𝕩 in total, so the number of slices is the range spanned by these two endpoints.

You can take a slice of an array 𝕩 that has length l and starts at index i using l↑i↓𝕩 or l↑iβŒ½π•©. The Prefixes function returns all the slices that end at the end of the array ((≠𝕩)=i+l), and Suffixes gives the slices that start at the beginning (i=0). Windows gives yet another collection of slices: the ones that have a fixed length l=𝕨. Selecting one cell from its result gives you the slice starting at that cell's index:

-
    2⊏5↕"abcdefg"
+
    2⊏5↕"abcdefg"
 [ cdefg ]
-    5↑2↓"abcdefg"
+    5↑2↓"abcdefg"
 [ cdefg ]
 

Windows differs from Prefixes and Suffixes in that it doesn't add a layer of nesting (it doesn't box each slice). This is possible because the slices have a fixed size.

Multiple dimensions

The above description applies to a higher-rank right argument. As an example, we'll look at two-row slices of a shape 3β€Ώ4 array. For convenience, we will box each slice. Note that slices always have the same rank as the argument array.

-
    <βŽ‰2 2↕"0123"∾"abcd"≍"ABCD"
+
    <βŽ‰2 2↕"0123"∾"abcd"≍"ABCD"
 β”Œ
   β”Œ        β”Œ
     0123     abcd
@@ -30,7 +30,7 @@
                     β”˜
 

Passing a list as the left argument to Windows takes slices along any number of leading axes. Here are all the shape 2β€Ώ2 slices:

-
    <βŽ‰2 2β€Ώ2↕"0123"∾"abcd"≍"ABCD"
+
    <βŽ‰2 2β€Ώ2↕"0123"∾"abcd"≍"ABCD"
 β”Œ
   β”Œ      β”Œ      β”Œ
     01     12     23
@@ -49,7 +49,7 @@
 

Using Group we could also write iβŠ‘z ←→ π•©βŠ‘Λœ(π•¨βˆΎβ—‹(β†•βˆ˜β‰ )≒𝕩) +Β΄Β¨βˆ˜βŠ” i.

Symmetry

Let's look at an earlier example, along with its transpose.

-
    {βŸ¨π•©,β‰π•©βŸ©}5↕"abcdefg"
+
    {βŸ¨π•©,β‰π•©βŸ©}5↕"abcdefg"
 β”Œ
   β”Œ         β”Œ
     abcde     abc
@@ -61,11 +61,11 @@
                     β”˜
 

Although the two arrays have different shapes, they are identical where they overlap.

-
    ≑○(3β€Ώ3βŠΈβ†‘)βŸœβ‰5↕"abcdefg"
+
    ≑○(3β€Ώ3βŠΈβ†‘)βŸœβ‰5↕"abcdefg"
 1
 

In other words, the i'th element of slice j is the same as the j'th element of slice i: it is the i+j'th element of the argument. So transposing still gives a possible result of Windows, but with a different slice length.

-
    {(5↕𝕩)≑⍉(3↕𝕩)}"abcdefg"
+
    {(5↕𝕩)≑⍉(3↕𝕩)}"abcdefg"
 1
 

In general, we need a more complicated transposeβ€”swapping the first set of ≠𝕨 axes with the second set. Note again the use of Span, our slice-length to slice-number converter.

@@ -80,11 +80,11 @@

A common task is to pair elements, with an initial or final element so the total length stays the same. This can also be done with a pairwise reduction, but another good way (and more performant without special support in the interpreter) is to add the element and then use windows matching the original length. Here both methods are used to invert +`, which requires we take pairwise differences starting at initial value 0.

    -˜´˘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 ]
 
-- cgit v1.2.3