From bed78fe6147cb7921b7367960d406d28d37cb019 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 7 Jun 2022 22:16:01 -0400 Subject: The editing is going to end at some point isn't it? --- docs/doc/selfcmp.html | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'docs/doc/selfcmp.html') diff --git a/docs/doc/selfcmp.html b/docs/doc/selfcmp.html index e5a8aa84..05490758 100644 --- a/docs/doc/selfcmp.html +++ b/docs/doc/selfcmp.html @@ -131,7 +131,7 @@ -

BQN has four self-search functions, Classify (), Occurrence Count (), Mark Firsts (), and Deduplicate (). Each of these is a monadic function that obtains its result by comparing each major cell of the argument (which must have rank at least 1) to the earlier major cells with match. For example, Mark Firsts indicates the cells that don't match any earlier cell, making them the first of their kind.

+

BQN has four self-search functions, Classify (), Occurrence Count (), Mark Firsts (), and Deduplicate (). Each of these is a monadic function that obtains its result by comparing each major cell of the argument (which must have rank at least 1) to the earlier major cells with match. For example, Mark Firsts indicates the cells that don't match any earlier cell, which might be called the first of their kind.

↗️
     "abaacb"
 ⟨ 1 1 0 0 1 0 ⟩
 
@@ -148,6 +148,22 @@ ⟨ 1 1 0 1 0 ⟩

The result has one number for each major cell, or in other words is a list with the same length as its argument. Three self-search functions follow this pattern, but Deduplicate () is different: it returns an array of the same rank but possibly a shorter length than the argument.

+

Deduplicate

+

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.

+↗️
     >"take""drop""drop""pick""take""take"
+┌─      
+╵"take  
+  drop  
+  pick" 
+       ┘
+
+     >"take""drop""drop""pick""take""take"
+┌─      
+╵"drop  
+  pick  
+  take" 
+       ┘
+

Classify

Classify is the universal self-search function, in that it preserves all the self-search information in its argument. It gives each different cell value a natural number, ordered by first appearance.

↗️
     562251
@@ -185,7 +201,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 is a different story, and 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  
@@ -204,11 +220,10 @@
   yellow" 
          ┘
 
-

One way to view this relationship is to consider an idea from linear algebra, where an idempotent transformation is called a "projection". That means that the argument might be any value but the result is part of a smaller class of values, and any argument from that smaller class is left the same. What arrays do the two functions project to? The result of Deduplicate is an array with no repeated major cells. The result of Classify is a list of natural numbers, but it also has an additional property: each number in the list is at most one higher than the previous numbers, and the first number is zero. This comes from the way Classify numbers the cells of its argument. When it finds a cell that hasn't appeared before (at a lower index), it always chooses the next higher number for it.

-

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.

+

One way to view this relationship is from the perspective of linear algebra, where an idempotent transformation is called a "projection". That means that the argument might be any value but the result is part of a smaller class of values, and any argument from that smaller class is left the same. What arrays do the two functions project to? The result of Deduplicate is an array with no repeated major cells. The result of Classify is a list of natural numbers, but it also has an additional property: each number in the list is at most one higher than the previous numbers, and the first number is zero. This comes from the way Classify numbers the cells of its argument. When it finds a cell that hasn't appeared before (at a lower index), it always chooses the next higher number for it.

+

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. 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 numeric 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 ⟩
 
@@ -248,21 +263,3 @@
 ⟨ 0 1 0 1 2 0 1 2 3 ⟩
 

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.

-↗️
     >"take""drop""drop""pick""take""take"
-┌─      
-╵"take  
-  drop  
-  pick" 
-       ┘
-
-     >"take""drop""drop""pick""take""take"
-┌─      
-╵"drop  
-  pick  
-  take" 
-       ┘
-
-

The relationship between Classify and Deduplicate is discussed above.

-- cgit v1.2.3