Commutator: Difference between revisions

From NARS2000
Jump to navigationJump to search
(Created page with "<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""> <tr> <td> <table border="0" cellpadding="5" cellspacing="0" summary=""> <tr> <td valign="top"><apll>Z←{L} <i>f</i>⍫<i>g</i> R</apll></td> <td></td> <td></td> <td>applies the function <apll><i>g</i></apll> then <apll><i>f</i></apll> then <apll><i>g</i>⍣¯1</apll> and then <apll><i>f</i>⍣¯1</apll> to or between the arguments.</td> </tr> </table> <...")
 
No edit summary
 
Line 25: Line 25:
</tr>
</tr>
</table>
</table>
==Notation==
The symbol chosen for this operator is the Del overstruck with Tilde (<apl>⍫</apl>), entered from the keyboard as Alt-’K’ or Alt-Shift-'k' (U+236B).


==Introduction==
==Introduction==
Line 35: Line 39:
       P←1 0 0 1 0 1 0 0 0
       P←1 0 0 1 0 1 0 0 0
       R←1 2 3 4 5 6 7 8 9  
       R←1 2 3 4 5 6 7 8 9  
       +\R-P\¯2-\P/+\¯1↓0,R
       +\R- P\ ¯2-\ P/ +\ ¯1↓0,R
1 3 6 4 9 6 13 21 30
1 3 6 4 9 6 13 21 30
</pre></apll>
</pre></apll>
Line 43: Line 47:
<apll>f<sup>-1</sup> g<sup>-1</sup> f g</apll>
<apll>f<sup>-1</sup> g<sup>-1</sup> f g</apll>


<p>where <apll>g ←→ +\</apll>   <apll>g⍣¯1 ←→ ¯2∘(-\)</apll>   <apll>f ←→ P∘/   f⍣¯1 ←→ P∘\</apll></p>
<p>where <apll>f⍣¯1 ←→ P∘\</apll> &nbsp;&nbsp;&nbsp; <apll>g⍣¯1 ←→ ¯2∘(-\)</apll> &nbsp;&nbsp;&nbsp; <apll>f ←→ P∘/</apll> &nbsp;&nbsp;&nbsp; <apll>g ←→ +\</apll></p>


<p>which can be re-written as</p>
<p>which can be re-written as</p>


<apll>+\R-P∘/⍫(+\)¯1↓0,R</apll>
<apll><pre>      +\R- P∘/⍫(+\) ¯1↓0,R
1 3 6 4 9 6 13 21 30
</pre></apll>
 
<p>For more information about inverses, see the [[Power#Inverses|Power Operator]].


==Implementation==
==Implementation==

Latest revision as of 15:57, 9 February 2024

Z←{L} fg R applies the function g then f then g⍣¯1 and then f⍣¯1 to or between the arguments.
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.

Notation

The symbol chosen for this operator is the Del overstruck with Tilde (), entered from the keyboard as Alt-’K’ or Alt-Shift-'k' (U+236B).

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 f⍣¯1 ←→ P∘\     g⍣¯1 ←→ ¯2∘(-\)     f ←→ P∘/     g ←→ +\

which can be re-written as

      +\R- P∘/⍫(+\) ¯1↓0,R
1 3 6 4 9 6 13 21 30

For more information about inverses, see the Power Operator.

Implementation

This operator is implemented via the anonymous function:

{⍺←⍣0 ⋄ (⍵⍵ ⍺) ⍺⍺⍣¯1 ⍵⍵⍣¯1 (⍵⍵ ⍺) ⍺⍺ ⍵⍵ ⍵}