From a1e3b94d0539aed459ade2b262e9dd197dd6342c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 23 Sep 2020 16:53:07 -0400 Subject: Shift functions are better for fixed-length 2-wise reduction --- docs/doc/windows.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/doc') diff --git a/docs/doc/windows.html b/docs/doc/windows.html index 0f85eab7..7a446b90 100644 --- a/docs/doc/windows.html +++ b/docs/doc/windows.html @@ -82,13 +82,13 @@ ↗️
    +´˘3 2,6,0,1,4,3
 ⟨ 8 7 5 8 ⟩
 
-

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.

-↗️
    -˜´˘20 +` 3211
+

A common task is to act on windows with an initial or final element so the total length stays the same. When using windows of length 2, the best way to accomplish this is with shift functions like « or ». If the window length is longer or variable, then a trick with Windows works better: add the elements, and then use windows matching the original length. Here we invert +`, which requires we take pairwise differences starting at initial value 0.

+↗️
    -(0»⊢) +` 3211
 ⟨ 3 2 1 1 ⟩
     (-˜˝≠↕0∾⊢) +` 3211
 ⟨ 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.

+

With Windows, we can modify the 3-element running sum above to keep the length constant by starting with two zeros.

↗️
    (+˝≠↕(20)) 2,6,0,1,4,3
 ⟨ 2 8 8 7 5 8 ⟩
 
-- cgit v1.2.3