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/selfcmp.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/doc/selfcmp.html') diff --git a/docs/doc/selfcmp.html b/docs/doc/selfcmp.html index bc99ef43..8e9540f2 100644 --- a/docs/doc/selfcmp.html +++ b/docs/doc/selfcmp.html @@ -185,7 +185,7 @@ c ⟨ 0 1 2 ⟩ -

Applying both separately, in contrast, gives completely interesting results. These results contain all information from the original argument, as indicates which cells it contained and indicates where they were located. The function Select () reconstructs the argument from the two values.

+

Applying both separately, in contrast, gives completely interesting results. These results contain all information from the original argument, as indicates which cells it contained and indicates where they were located. The function Select () reconstructs the argument from the two values.

↗️
     c
 ┌─        
 ╵"yellow  
@@ -208,15 +208,15 @@
 

Applying both Classify and Deduplicate gives an array that has both properties (this isn't the case for all pairs of projections—we need to know that Classify maintains the uniqueness property for Deduplicate and vice-versa). It has no duplicate major cells, and it's a list of natural numbers that starts with 0 and never goes up by more than one. Taken together, these are a tight constraint! The first element of the argument has to be 0. The next can't be 0 because it's already appeared, but it can't be more than one higher—it has to be 1. The next can't be 0 or 1, and has to be 2. And so on. So the result is always n for some n. In fact it's possible to determine the length as well, by noting that each function preserves the number of unique major cells in its argument. Classify does this because distinct numbers in the output correspond exactly to distinct major cells in the input; Deduplicate does this because it only removes duplicate cells, not distinct ones. So the final result is n, where n is the number of unique major cells in the argument.

Mark Firsts

See the APL Wiki page on this function as well.

-

Mark Firsts () is the simplest self-search function: it returns 0 for any major cell of the argument that is a duplicate of an earlier cell and 1 for a major cell that's the first with its value. To implement Deduplicate in terms of Mark Firsts, just filter out the duplicates with /.

+

Mark Firsts () is the simplest self-search function: it returns 0 for any major cell of the argument that is a duplicate of an earlier cell and 1 for a major cell that's the first with its value. To implement Deduplicate in terms of Mark Firsts, just filter out the duplicates with /.

↗️
       314159265
 ⟨ 1 1 1 0 1 1 1 1 0 ⟩
 
     / 314159265
 ⟨ 3 1 4 5 9 2 6 ⟩
 
-

Mark Firsts has other uses, of course. Instead of keeping the unique values, you might remove the first of each value with ¬/. You can use ´ to check that an array has no duplicate major cells, or +´ to count the number of unique ones.

-

What about marking the elements that appear exactly once? There's a trick for this: find the cells that are firsts running both forwards () and backwards (). Such a cell has no equal before it, nor after it, so it's unique in the entire array.

+

Mark Firsts has other uses, of course. Instead of keeping the unique values, you might remove the first of each value with ¬/. You can use ´ to check that an array has no duplicate major cells, or +´ to count the number of unique ones.

+

What about marking the elements that appear exactly once? There's a trick for this: find the cells that are firsts running both forwards () and backwards (). Such a cell has no equal before it, nor after it, so it's unique in the entire array.

↗️
    (∊∧∊) "duck""duck""teal""duck""goose"
 ⟨ 0 0 1 0 1 ⟩
 
@@ -243,11 +243,11 @@ ↗️
    (1=⊒)/ "aaaabcddcc"
 "adc"
 
-

An interesting combination is Occurrence Count applied to the result of Indices (/). The result counts up to each number from the argument in turn; in other symbols, it's ∾↕¨. This version is interesting because it doesn't create any nested arrays, just lists of natural numbers.

+

An interesting combination is Occurrence Count applied to the result of Indices (/). The result counts up to each number from the argument in turn; in other symbols, it's ∾↕¨. This version is interesting because it doesn't create any nested arrays, just lists of natural numbers.

↗️
     / 234
 ⟨ 0 1 0 1 2 0 1 2 3 ⟩
 
-

A more efficient way when the interpreter doesn't optimize here is /(¯1⊑↕-⊏»)+`, but that's clearly quite a bit more complicated.

+

A more efficient way when doesn't have a fast implementation is /(¯1⊑↕-⊏»)+`, but that's clearly quite a bit more complicated.

Deduplicate

There's also an APL Wiki page on this function.

Deduplicate removes every major cell from the argument that matches an earlier cell, resulting in an array with the same rank but possibly a shorter length. It might also be described as returning the unique major cells of the argument, ordered by first occurrence. Deduplicate Under Reverse () orders by last occurrence instead.

-- cgit v1.2.3