http://wiki.nars2000.org/index.php?title=Special:NewPages&feed=atom&hidebots=1&hideredirs=1&limit=50&offset=&namespace=0&username=&tagfilter=&size-mode=max&size=0NARS2000 - New pages [en]2024-03-28T17:49:48ZFrom NARS2000MediaWiki 1.38.4http://wiki.nars2000.org/index.php?title=CommutatorCommutator2024-02-07T14:31:52Z<p>WikiSysop: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←{L} <i>f</i>⍫<i>g</i> R</apll></td><br />
<td></td><br />
<td></td><br />
<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><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is an optional array.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an array.</td><br />
</tr><br />
<tr><br />
<td><apll><i>f</i></apll> is an arbitrary ambivalent function with an inverse.</td><br />
</tr><br />
<tr><br />
<td><apll><i>g</i></apll> is an arbitrary monadic function with an inverse.</td><br />
</tr><br />
</table><br />
<br />
==Notation==<br />
<br />
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).<br />
<br />
==Introduction==<br />
<br />
<p>The concept of the Commutator operator is taken from mathematical [https://en.wikipedia.org/wiki/Commutator Group Theory] from the 1830s.</p><br />
<br />
<p>For example, the algorithm for [https://dl.acm.org/doi/pdf/10.1145/800136.804488 Partitioned Plus Scan] where <apll>P</apll> is the Boolean partition vector (always with a leading 1), in modern notation looks like this:</p><br />
<br />
<apll><pre><br />
P←1 0 0 1 0 1 0 0 0<br />
R←1 2 3 4 5 6 7 8 9 <br />
+\R- P\ ¯2-\ P/ +\ ¯1↓0,R<br />
1 3 6 4 9 6 13 21 30<br />
</pre></apll><br />
<br />
<p>An interesting observation on this one-liner is that it contains two interleaved pairs of inverses: <apll>P\</apll> and <apll>P/</apll> as one and <apll>¯2-\</apll> and <apll>+\</apll> as the other. This interleaving of inverses exactly matches the template for the Commutator Operator:</p><br />
<br />
<apll>f<sup>-1</sup> g<sup>-1</sup> f g</apll><br />
<br />
<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><br />
<br />
<p>which can be re-written as</p><br />
<br />
<apll><pre> +\R- P∘/⍫(+\) ¯1↓0,R<br />
1 3 6 4 9 6 13 21 30<br />
</pre></apll><br />
<br />
<p>For more information about inverses, see the [[Power#Inverses|Power Operator]].<br />
<br />
==Implementation==<br />
<br />
<p>This operator is implemented via the anonymous function:</p><br />
<br />
<apll><pre><br />
{⍺←⍣0 ⋄ (⍵⍵ ⍺) ⍺⍺⍣¯1 ⍵⍵⍣¯1 (⍵⍵ ⍺) ⍺⍺ ⍵⍵ ⍵}<br />
</pre></apll></div>WikiSysophttp://wiki.nars2000.org/index.php?title=DualDual2024-02-06T22:06:15Z<p>WikiSysop: </p>
<hr />
<div><table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←{L} <i>f</i>⍢<i>g</i> R</apll></td><br />
<td></td><br />
<td></td><br />
<td>applies the function <apll><i>g</i></apll> then <apll><i>f</i></apll> and then <apll><i>g</i>⍣¯1</apll> to or between the arguments.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td><apll>L</apll> is an optional array.</td><br />
</tr><br />
<tr><br />
<td><apll>R</apll> is an array.</td><br />
</tr><br />
<tr><br />
<td><apll><i>f</i></apll> is an arbitrary ambivalent function.</td><br />
</tr><br />
<tr><br />
<td><apll><i>g</i></apll> is an arbitrary monadic function with an inverse.</td><br />
</tr><br />
</table><br />
<br />
==Introduction==<br />
<br />
<p>The concept of the Dual operator was described in Ken Iverson's paper on [https://www.jsoftware.com/papers/opfns.htm Operators and Functions].</p><br />
<br />
<br />
<br />
<br />
==Implementation==<br />
<br />
<p>This operator is implemented via the anonymous function:</p><br />
<br />
<apll><pre><br />
{⍺←⍣0 ⋄ ⍵⍵⍣¯1 (⍵⍵ ⍺) ⍺⍺ ⍵⍵ ⍵}<br />
</pre></apll></div>WikiSysophttp://wiki.nars2000.org/index.php?title=AtAt2023-11-28T02:24:21Z<p>WikiSysop: /* Variable v. Jot */</p>
<hr />
<div>==At Derived Functions==<br />
<br />
<p>The dyadic At operator is used to index assign into an array <apll>R</apll>, returning as the result the changed array. There are four separate cases, depending upon whether the two operands are Variables or Functions. The design of this operator is taken directly from the corresponding feature in Dyalog APL.</p><br />
<br />
===Variable v. Variable===<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←<i>a</i>@<i>b</i> R</apll></td><br />
</tr><br />
<tr><br />
<td>Replaces the <apll><i>b</i></apll> items of <apll>R</apll> with <apll><i>a</i></apll>, where <apll><i>a</i></apll> and <apll><i>b</i></apll> are variables.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td>For example:<br />
Replace the 1st and last characters in a string with a string:<br />
<apll><pre><br />
(⊂'abra')@(1 5)'scads!'<br />
abra cad abra !</pre></apll><br />
</td><br />
</tr><br />
<tr><br />
<td>Replace the diagonal elements of a matrix:<br />
<apll><pre><br />
'abcd'@(2/¨⍳4)4 4⍴⍳16<br />
a 2 3 4<br />
5 b 7 8<br />
9 10 c 12<br />
13 14 15 d<br />
</pre></apll><br />
</td><br />
</tr><br />
<tr><br />
<td><p>This case is implemented via the anonymous function <apll>{A←⍵ ⋄ 1≥≡A:A⊣A[⊃⍵⍵⌷¨⊂⍳⍴A]←⍺⍺ ⋄ A[⍵⍵]←⍺⍺ ⋄ A}</apll>.</p></td><br />
</tr><br />
</table><br />
&nbsp;<br />
===Variable v. Function===<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←<i>a</i>@<i>g</i> R</apll></td><br />
</tr><br />
<tr><br />
<td>When the Boolean-valued result of <apll><i>g R</i></apll> is <apll>1</apll>, replace the corresponding element of <apll>R</apll> with the corresponding element of <apll><i>a</i></apll>, where <apll><i>a</i></apll> is a variable and <apll><i>g</i></apll> is a function.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td>For example:<br />
Replace the prime numbers in R with a character:<br />
<apll><pre><br />
'π'@{0π⍵}4 4⍴⍳16<br />
1 π π 4<br />
π 6 π 8<br />
9 10 π 12<br />
π 14 15 16</pre></apll></td><br />
</tr><br />
<tr><br />
<td><p>This case is implemented via the anonymous function <apll>{A←⍵ ⋄ A[⍸⍵⍵ A]←⍺⍺ ⋄ A}</apll>.</p></td><br />
</tr><br />
</table><br />
&nbsp;<br />
===Variable v. Jot===<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←<i>a</i>@∘ R</apll></td><br />
</tr><br />
<tr><br />
<td>Replaces all of the items of <apll>R</apll> with <apll><i>a</i></apll>, where <apll><i>a</i></apll> is a variable.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td>For example:<br />
Replace all of the items of <apll>R</apll> with <apll>¯1</apll>:<br />
<apll><pre><br />
¯1@∘⍳2 3<br />
¯1 ¯1 ¯1<br />
¯1 ¯1 ¯1<br />
</pre></apll><br />
</td><br />
</tr><br />
<tr><br />
<td><p>This case is implemented via the anonymous function <apll>{A←⍵ ⋄ A[]←⍺⍺ ⋄ A}</apll>.</p></td><br />
</tr><br />
</table><br />
&nbsp;<br />
<br />
===Function v. Variable===<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←{L} <i>f</i>@<i>b</i> R</apll></td><br />
</tr><br />
<tr><br />
<td>Replaces the <apll><i>b</i></apll> items of <apll>R</apll> with <apll><i>f</i></apll> applied to each replaced item, where <apll>{L}</apll> is an optional left argument to <apll><i>f</i></apll>, <apll><i>f</i></apll> is a function, and <apll><i>b</i></apll> is a variable.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td>For example:<br />
Replace the diagonal elements of a matrix with their reciprocals:<br />
<apll><pre><br />
÷@(2/¨⍳4)4 4⍴⍳16<_x/><br />
1 2 3 4<br />
5 1<_r/>6 7 8<br />
9 10 1<_r/>11 12<br />
13 14 15 1<_r/>16<br />
</pre></apll><br />
</td><br />
</tr><br />
<tr><br />
<td>Replace the diagonal elements of a matrix with their duplicates:<br />
<apll><pre><br />
2/¨@(2/¨⍳4)4 4⍴⍳16<br />
1 1 2 3 4 <br />
5 6 6 7 8 <br />
9 10 11 11 12 <br />
13 14 15 16 16<br />
</pre</apll></td><br />
</tr><br />
<tr><br />
<td><p>This case is implemented via the anonymous function <apll>{⍺←⊢ ⋄ A←⍵ ⋄ 1≥≡A:A⊣A[B]←⍺ ⍺⍺ A[B]⊣B←⊃⍵⍵⌷¨⊂⍳⍴A ⋄ A[⍵⍵]←⍺ ⍺⍺ A[⍵⍵] ⋄ A}</apll>.</p></td><br />
</tr><br />
</table><br />
&nbsp;<br />
===Function v. Function===<br />
<br />
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""><br />
<tr><br />
<td><br />
<table border="0" cellpadding="5" cellspacing="0" summary=""><br />
<tr><br />
<td valign="top"><apll>Z←{L} <i>f</i>@<i>g</i> R</apll></td><br />
</tr><br />
<tr><br />
<td>When the Boolean-valued result of <apll><i>g</i> R</apll> is <apll>1</apll>, replace the corresponding element of <apll>R</apll> with <apll><i>f</i></apll> applied to the same element, where <apll>{L}</apll> is an optional left argument to <apll><i>f</i></apll>, <apll><i>f</i></apll> and <apll><i>g</i></apll> are functions.</td><br />
</tr><br />
</table><br />
</td><br />
</tr><br />
<tr><br />
<td>For example:<br />
Replace composite numbers with their factors:<br />
<apll><pre><br />
π¨@{~0π⍵}4 4⍴⍳16<br />
1 2 3 2 2 <br />
5 2 3 7 2 2 2 <br />
3 3 2 5 11 2 2 3 <br />
13 2 7 3 5 2 2 2 2<br />
</pre></apll></td><br />
</tr><br />
<tr><br />
<td><p>This case is implemented via the anonymous function <apll>{⍺←⊢ ⋄ A←⍵ ⋄ B←⍸⍵⍵ A ⋄ A[B]←⍺ ⍺⍺ A[B] ⋄ A}</apll>.</p></td><br />
</tr><br />
</table></div>WikiSysop