From 2afb23928e1984d475cc460e1672e8f6fa0e4dbe Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 11 Aug 2021 17:21:31 -0400 Subject: Allow clicking on header to get fragment link --- docs/doc/shift.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/doc/shift.html') diff --git a/docs/doc/shift.html b/docs/doc/shift.html index 012dfb0d..5b72e865 100644 --- a/docs/doc/shift.html +++ b/docs/doc/shift.html @@ -4,7 +4,7 @@ BQN: Shift functions -

Shift functions

+

Shift functions

The shift functions « and » add major cells to one side an array, displacing cells on the opposite side and moving those in between. Shifts resemble but are more general than the bit-based shift operations used in low-level languages. They replace the APL pattern of a 2-wise reduction after appending or prepending an element (APL's 2≠/0,v translates to »v), one of the more common uses of 2-wise reduction.

The result of a shift function always has the same shape as 𝕩. The function adds major cells to the beginning (») or end («) of 𝕩, moving the cells already in 𝕩 to accomodate them. Some cells on the opposite side from those added will "fall off" and not be included in the result.

↗️
    00 » 321             # Shift Before
@@ -19,7 +19,7 @@
 ⟨ 2 3 0 ⟩
 

If 𝕨 is longer than 𝕩, some cells from 𝕨 will be discarded, as well as all of 𝕩. In this case 𝕨»𝕩 is (𝕩)𝕨 and 𝕨«𝕩 is (-≠𝕩)𝕨. For similar reasons, nudging an array of length 0 returns it unchanged.

-

Sequence processing with shifts

+

Sequence processing with shifts

When working with a sequence of data such as text, daily measurements, or audio data, shift functions are generally the best way to handle the concept of "next" or "previous". In the following example s is shown alongside the shifted-right data »s, and each element is compared to the previous with -», which we see is the inverse of Plus Scan +`.

↗️
    s  1224356
     s  »s
@@ -58,7 +58,7 @@
 ⟨ ¯0.5 ¯0.5 ¯1 ¯0.5 ¯0.5 ¯1.5 ¯0.5 ⟩
 

A feature these examples all share is that they maintain the length of s. This is a common condition in sequence processing, particularly when the processed sequence needs to be combined or compared with the original in some way. However, it's not always the case. In some instances, for example when searching s to see if there is any value less than the previous, the list should get shorter during processing. In these cases, Windows () is usually a better choice.

-

Arithmetic and logical shifts

+

Arithmetic and logical shifts

The glyphs « and », suggesting movement, were chosen for the same reasons as the digraphs << and >>, and can be used to implement the same operations on boolean lists.

↗️
     i  "10011011"-'0'
 ⟨ 1 0 0 1 1 0 1 1 ⟩
@@ -76,7 +76,7 @@
     3 (⊏»⊢) i  # Arithmetic right shift
 ⟨ 1 1 1 1 0 0 1 1 ⟩
 
-

Other examples

+

Other examples

In Take (), there's no way to specify the fill element when the result is longer than the argument. To take along the first axis with a specified, constant fill value, you can use Shift Before instead, where the right argument is an array of fills with the desired final shape.

↗️
    "abc" » 5'F'
 "abcFF"
@@ -95,7 +95,7 @@
 ↗️
    (×`1»⊢) 5243
 ⟨ 24 12 3 1 ⟩
 
-

Higher rank

+

Higher rank

Shifting always works on the first axis of 𝕩 (which must have rank 1 or more), and shifts in major cells. A left argument can have rank equal to 𝕩, or one less than it, in which case it becomes a single cell of the result. With no left argument, a cell of fills 10𝕩 is nudged in.

↗️
     a  (↕×´) 43
 ┌─         
@@ -129,7 +129,7 @@
   'c' 'e' 'l'  
               ┘
 
-

Definition

+

Definition

In any instance of » or «, 𝕩 must have rank at least 1.

For a dyadic shift function, 𝕨 must be Join-compatible with 𝕩 (that is, 𝕨𝕩 completes without error) and cannot have greater rank than 𝕩. Then Shift Before (») is {(𝕩)𝕨𝕩} and Shift After («) is {(-≠𝕩)𝕩𝕨}

When called monadically, the default argument is a cell of fills 10𝕩. That is, Nudge (») is (10↑⊢)» and Nudge Back («) is (10↑⊢)«. This default argument always satisfies the compatibility requirement above and so the only conditions for nudge are that 𝕩 has rank at least 1 and has a fill element.

-- cgit v1.2.3