From 2010e8b2897a5741e211980c9f8ec9177299c939 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 16 Jul 2021 18:23:52 -0400 Subject: Finish links and editing documentation pass --- docs/doc/scan.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/doc/scan.html') diff --git a/docs/doc/scan.html b/docs/doc/scan.html index 1f572239..cc806de6 100644 --- a/docs/doc/scan.html +++ b/docs/doc/scan.html @@ -59,8 +59,8 @@

The 1-modifier Scan (`) moves along the first axis of the array 𝕩, building up an array of results by applying 𝔽 repeatedly beginning with 𝕨 or 𝕩. It's related to the fold modifiers, and most closely resembles the APL2-style reduction ¨˝, but it traverses the array in forward rather than reverse index order, and includes all intermediate results of 𝔽 in its output instead of just the final one.

-

BQN's Scan is ordered differently from Scan in APL. Both include one result for each non-empty prefix of 𝕩. In BQN this is a left-to-right fold, so that each new result requires one application of 𝔽. APL uses a right-to-left ordering, which matches with reduction, but requires starting over at the end for each new prefix, except in special cases. If needed, this definition can be obtained with a fold on each prefix except the first (which is empty). In the particular case of -, that nested solution isn't needed: negate odd-indexed elements and then apply +`.

-

Scan also differs from Fold or Insert in that it never depends on 𝔽's identity element, because scanning over an empty array simply returns that array.

+

BQN's Scan is ordered differently from Scan in APL. Both include one result for each non-empty prefix of 𝕩. In BQN this is a left-to-right fold, so that each new result requires one application of 𝔽. APL uses right-to-left folds, which matches with reduction, but requires starting over at the end for each new prefix, except in special cases. If needed, this definition can be obtained with a fold on each prefix except the first (which is empty). In the particular case of -, that nested solution isn't needed: negate odd-indexed elements and then apply +`.

+

Scan also differs from Fold or Insert in that it never depends on 𝔽's identity value, because scanning over an empty array simply returns that array.

Lists

The best-known use of Scan is the prefix sum of a list, in which each element of the result is the sum of that element and all the ones before it. With a shift this can be modified to sum the previous elements only.

↗️
    +` 2431
@@ -69,7 +69,7 @@
     +`»2431  # Exclusive prefix sum
 ⟨ 0 2 6 9 ⟩
 
-

The pattern is generalized to any function 𝔽. With an operand of ×, it can find the first n factorials. With , it returns the largest element so far.

+

The pattern is generalized to any function 𝔽. With an operand of ×, it can find the first n factorials. With Maximum (), it returns the largest element so far.

↗️
    ×` 1+↕6
 ⟨ 1 2 6 24 120 720 ⟩
 
@@ -94,7 +94,7 @@
     c
 9
 
-

Some other useful scans apply to boolean lists. The function ` tests whether this or any previous element is 1, so that the result starts at 0 but permanently switches to 1 as soon as the first 1 is found. Similarly, ` turns all instances of 1 after the first 0 to 0.

+

Some other useful scans apply to boolean lists. The function ` (with Or) tests whether this or any previous element is 1, so that the result starts at 0 but permanently switches to 1 as soon as the first 1 is found. Similarly, ` turns all instances of 1 after the first 0 to 0.

↗️
    ` 00100101
 ⟨ 0 0 1 1 1 1 1 1 ⟩
 
@@ -109,7 +109,7 @@
 "ab\rs\\"
 

Reverse scan

-

We've discussed how the scan moves forward along 𝕩, so that each time 𝔽 takes an old result as 𝕨 and a new value as 𝕩. This means that results correspond to prefixes and go left to right on each one. Since the most important scans have associative, commutative operands, the left-to-right ordering often doesn't make a difference. But sometimes a suffix rather than prefix scan is wanted. For these cases, Scan Under Reverse (`) does the trick.

+

We've discussed how the scan moves forward along 𝕩, so that each time 𝔽 takes an old result as 𝕨 and a new value as 𝕩. This means that results correspond to prefixes and go left to right on each one. Since the most important scans have associative, commutative operands, the left-to-right ordering often doesn't make a difference. But sometimes a suffix rather than prefix scan is wanted. For these cases, Scan Under Reverse (`) does the trick.

↗️
    `   0010010
 ⟨ 0 0 1 1 1 1 1 ⟩
 
-- 
cgit v1.2.3