From e2b07a5fd0bbaad232c717fb90a31d6c61d72bd4 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 14 Jul 2022 20:06:50 -0400 Subject: Try to include previous variable definitions in REPL links --- docs/doc/shift.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/doc/shift.html') diff --git a/docs/doc/shift.html b/docs/doc/shift.html index 84684f8a..a1e8aa25 100644 --- a/docs/doc/shift.html +++ b/docs/doc/shift.html @@ -36,7 +36,7 @@ ⟨ 1 2 2 4 3 5 6 ⟩

In this way » refers to a sequence containing the previous element at each position. By default the array's fill is used for the element before the first, and a right argument can be given to provide a different one.

-↗️
     » s
+↗️
     » s
 ⟨ ∞ 1 2 2 4 3 5 ⟩
 
     » s
@@ -44,7 +44,7 @@
 

It may appear backwards that », which typically means "go to the next item", is used to represent the previous item. In fact there is no conflict: the symbol » describes what position each cell of 𝕩 will have in the result, but in this context we are interested in knowing what argument value occurs in a particular result position. By moving all numbers into the future we ensure that a number in the present comes from the past. To keep your intuition functioning in these situations, it may help to think of the arrow point as fixed at some position in the result while the tail stretches back to land on the argument position where it comes from.

Switching the direction of the arrow, we get an operation that pulls the next value into each position:

-↗️
    s  «s
+↗️
    s  «s
 ┌─               
 ╵ 1 2 2 4 3 5 6  
   2 2 4 3 5 6 0  
@@ -53,7 +53,7 @@
 ⟨ 1 0 2 ¯1 2 1 ¯6 ⟩
 

The differences here are the same as -» s, except that they are shifted over by one, and it is the last value in the sequence that is compared with a fill value, not the first. These techniques adapt easily to more complicated operations. A symmetric difference is found by subtracting the previous element from the next, and dividing by two:

-↗️
    2÷˜ (»-«) s
+↗️
    2÷˜ (»-«) s
 ⟨ ¯1 ¯0.5 ¯1 ¯0.5 ¯0.5 ¯1.5 2.5 ⟩
 
     2÷˜ (˝» - ˝«) s  # Repeat at the ends instead of using fills
@@ -72,7 +72,7 @@
 ⟨ 1 1 0 1 1 0 0 0 ⟩
 

With a number in big-endian format, a right shift might be logical, shifting in zeros, or arithmetic, shifting in copies of the highest-order bit (for little-endian numbers, this applies to left shifts rather than right ones). The two kinds of shift can be performed with similar code, using 0 or 𝕩 for the inserted cell.

-↗️
    3 0» i    # Logical right shift
+↗️
    3 0» i    # Logical right shift
 ⟨ 0 0 0 1 0 0 1 1 ⟩
 
     3 (⊏»⊢) i  # Arithmetic right shift
-- 
cgit v1.2.3