Commutator
From NARS2000
|
||||
L is an optional array. | ||||
R is an array. | ||||
f is an arbitrary ambivalent function with an inverse. | ||||
g is an arbitrary monadic function with an inverse. |
Introduction
The concept of the Commutator operator is taken from mathematical Group Theory from the 1830s.
For example, the algorithm for Partitioned Plus Scan where P is the Boolean partition vector (always with a leading 1), in modern notation looks like this:
P←1 0 0 1 0 1 0 0 0 R←1 2 3 4 5 6 7 8 9 +\R-P\¯2-\P/+\¯1↓0,R 1 3 6 4 9 6 13 21 30
An interesting observation on this one-liner is that it contains two interleaved pairs of inverses: P\ and P/ as one and ¯2-\ and +\ as the other. This interleaving of inverses exactly matches the template for the Commutator Operator:
f-1 g-1 f g
where g ←→ +\ g⍣¯1 ←→ ¯2∘(-\) f ←→ P∘/ f⍣¯1 ←→ P∘\
which can be re-written as
+\R-P∘/⍫(+\)¯1↓0,R
Implementation
This operator is implemented via the anonymous function:
{⍺←⍣0 ⋄ (⍵⍵ ⍺) ⍺⍺⍣¯1 ⍵⍵⍣¯1 (⍵⍵ ⍺) ⍺⍺ ⍵⍵ ⍵}