Variant: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
 
(28 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
'''Caution:''' Be careful not to confuse this symbol, which is <apll>⍠</apll>, with <apll>⌹</apll> which is [[Matrix Inverse/Divide]].
<hr /><table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
<tr>
<tr>
   <td>
   <td>
     <table border="0" cellpadding="5" cellspacing="0" summary="">
     <table border="0" cellpadding="5" cellspacing="0" summary="">
     <tr>
     <tr>
       <td valign="top"><apll>Z←f⍠B R</apll> or <apll>Z←L f⍠B R</apll></td>
       <td valign="top"><apll>Z←f⍠B R</apll> &nbsp;&nbsp; or &nbsp;&nbsp; <apll>Z←L f⍠B R</apll></td>
       <td></td>
       <td></td>
       <td></td>
       <td></td>
Line 16: Line 17:
</tr>
</tr>
<tr>
<tr>
   <td><apll>f</apll> is a function.</td>
   <td><apll>f</apll> is an arbitrary function.</td>
</tr>
</tr>
</table>
</table>


<p>The dyadic Variant operator creates a version of the function <apll>f</apll> with a set of properties bound to it as specified by the array right operand.  For example, <apll>⍳⍠0</apll> is a version of <apll>⍳</apll> that executes in origin-0 independent of the current value of <apll>⎕IO</apll>.</p>
==Introduction==


<p>The array right operand to the operator may take several different forms depending upon the function left operand.  In the general case, for any kind of function left operand, the right operand may specify a single property in the form of <apll>Key Val</apll>, or multiple properties in the form of <apll>(Key1 Val1) (Key2 Val2) ...</apll>, or if the left operand is a primitive function, a shorthand notation may be used as in <apll>Val</apll> or <apll>Val1 Val2</apll>.</p>
<p>The dyadic Variant operator creates a version of the function <apll>f</apll> with a set of properties bound and localized to it as specified by the array right operand.  For example, <apll>⍳⍠0</apll> is a version of <apll></apll> that executes in origin-0 independent of the current value of <apll>⎕IO</apll>.</p>


<p>In the general case, the keys specify a property such as Index Origin as <apll>'IO'</apll> or Comparison Tolerance as <apll>'CT'</apll>, and the value part specifies a value appropriate to the property specified in the matching key.  At the moment, the keys that may be used are <apll>'CT'</apll>, <apll>'DQ'</apll>, <apll>'DT'</apll>, <apll>'FPC'</apll>, <apll>'IO'</apll>, and <apll>'PP'</apll> which stand for the corresponding system variable.  Note that for the Variants of <apll>L×R</apll> and <apll>⌹R</apll> there are no corresponding system variables as yet.</p>
<p>The array right operand to the operator may take several different forms depending upon the function left operand.  In the general case, for any kind of function left operand, the right operand may specify a single property in the form of <apll>Key Val</apll>, or multiple properties in the form of <apll>(Key1 Val1) (Key2 Val2)</apll><b>&#8230;</b>, or if the left operand is a primitive function, a shorthand notation may be used as in <apll>Val</apll> or <apll>Val1 Val2</apll> <b>&#8230;</b>.</p>
 
<p>In the general case, the keys specify a property such as Index Origin as <apll>'IO'</apll> or Comparison Tolerance as <apll>'CT'</apll>, and the value part specifies a value appropriate to the property specified in the matching key.  At the moment, the keys that may be used are <apll>'CT'</apll>, <apll>'DT'</apll>, <apll>'FPC'</apll>, <apll>'IO'</apll>, <apll>'LR'</apll>, <apll>'PP'</apll>, and <apll>'RL'</apll> which stand for the corresponding system variable.  Note that for the Variants of <apll>L×R</apll> and <apll>⌹R</apll> and the Subsequence variants such as <apll>L⍳⍠'a' R</apll> there are no corresponding system variables as yet.</p>


<p>For example:</p>
<p>For example:</p>


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 2 (3+1e¯9)&nbsp; 3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3<br />
<apll><pre>
3<br />
      1 2 (3+1e¯9)&nbsp; 3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 2 (3+1e¯10) 3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3<br />
3
2<br />
      1 2 (3+1e¯10) 3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⍳⍠('IO' 0) 3<br />
2
0 1 2<br />
      ⍳⍠('IO' 0) 3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⍳⍠('IO' 1) 3<br />
0 1 2  
1 2 3<br />
      ⍳⍠('IO' 1) 3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⍳⍠('IO' 0) ⍠('IO' 1) 3<br />
1 2 3
0 1 2<br />
      ⍳⍠('IO' 0) ⍠('IO' 1) 3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⍳⍠('IO' 1) ⍠('IO' 0) 3<br />
0 1 2  
1 2 3</apll>
      ⍳⍠('IO' 1) ⍠('IO' 0) 3  
1 2 3</pre></apll>


<p>Note that in the last two examples, the lefthand (innermost) value of <apll>⎕IO</apll> takes precedence.</p>
<p>Note that in the last two examples, the lefthand (innermost) value of <apll>⎕IO</apll> takes precedence.</p>


<p>If the left operand is a primitive function, the following shorthands may be used:</p>
==Shorthand Notation==
 
<p>If the left operand is a primitive or derived function, the following shorthand notation may be used:</p>


<table border="1" cellpadding="5" cellspacing="0" rules="all" summary="">
<table border="1" cellpadding="5" cellspacing="0" rules="all" summary="">
<tr>
<tr>
   <th>Function</th>
   <th width="20%">Function or<br />Principal Operator</th>
   <th>Right<br />Arg<br />Type</th>
   <th width="5%">Right<br />Arg<br />Type</th>
   <th>Meaning</th>
   <th width="75%">Meaning</th>
</tr>
 
<tr>
  <td><apll>⍳R</apll></td>
  <td><i>N</i></td>
  <td><apll>⎕IO←</apll><i>N</i></td>
</tr>
</tr>


<tr>
<tr>
   <td rowspan="2"><apll>⍳R</apll> and <apll>L⍳R</apll></td>
   <td rowspan="8"><apll>L⍳R</apll></td>
   <td><i>N</i></td>
   <td><i>N</i></td>
   <td><apll>⎕IO←</apll><i>N</i></td>
   <td><apll>⎕IO←</apll><i>N</i></td>
Line 61: Line 73:
   <td><i>N1&nbsp;N2</i></td>
   <td><i>N1&nbsp;N2</i></td>
   <td><apll>⎕IO←</apll><i>N1</i> and <apll>⎕CT←</apll><i>N2</i></td>
   <td><apll>⎕IO←</apll><i>N1</i> and <apll>⎕CT←</apll><i>N2</i></td>
</tr>
<tr>
  <td><i>C</i></td>
  <td>[[#Subsequences|Subsequence]] <i>C</i> (<apll>'a'</apll> for Ascending, <apll>'d'</apll> for Descending)</td>
</tr>
<tr>
  <td><i>N</i>&nbsp;<i>C</i></td>
  <td><apll>⎕IO←</apll><i>N</i> and [[#Subsequences|Subsequence]] <i>C</i> (<apll>'a'</apll> for Ascending, <apll>'d'</apll> for Descending)</td>
</tr>
<tr>
  <td><i>C</i>&nbsp;<i>N</i></td>
  <td><apll>⎕IO←</apll><i>N</i> and [[#Subsequences|Subsequence]] <i>C</i> (<apll>'a'</apll> for Ascending, <apll>'d'</apll> for Descending)</td>
</tr>
<tr>
  <td><i>N1&nbsp;N2&nbsp;C</i></td>
  <td><apll>⎕IO←</apll><i>N1</i>, <apll>⎕CT←</apll><i>N2</i>, and [[#Subsequences|Subsequence]] <i>C</i> (<apll>'a'</apll> for Ascending, <apll>'d'</apll> for Descending)</td>
</tr>
<tr>
  <td><i>N1&nbsp;C&nbsp;N2</i></td>
  <td><apll>⎕IO←</apll><i>N1</i>, <apll>⎕CT←</apll><i>N2</i>, and [[#Subsequences|Subsequence]] <i>C</i> (<apll>'a'</apll> for Ascending, <apll>'d'</apll> for Descending)</td>
</tr>
<tr>
  <td><i>C&nbsp;N1&nbsp;N2</i></td>
  <td><apll>⎕IO←</apll><i>N1</i>, <apll>⎕CT←</apll><i>N2</i>, and [[#Subsequences|Subsequence]] <i>C</i> (<apll>'a'</apll> for Ascending, <apll>'d'</apll> for Descending)</td>
</tr>
</tr>


Line 78: Line 120:
   <td><apll><apll>L&lt;R</apll>, <apll>L≤R</apll>, <apll>L=R</apll>, <apll>L≠R</apll>, <apll>L≥R</apll>, <apll>L&gt;R</apll>,<br />
   <td><apll><apll>L&lt;R</apll>, <apll>L≤R</apll>, <apll>L=R</apll>, <apll>L≠R</apll>, <apll>L≥R</apll>, <apll>L&gt;R</apll>,<br />
<apll>L∊R</apll>, <apll>L≡R</apll>, <apll>L≢R</apll>, <apll>L∪R</apll>, <apll>L∩R</apll>,<br />
<apll>L∊R</apll>, <apll>L≡R</apll>, <apll>L≢R</apll>, <apll>L∪R</apll>, <apll>L∩R</apll>,<br />
<apll>L⊆R</apll>, <apll>L⊇R</apll>, <apll>L§R</apll>, <apll>L~R</apll>, <apll>L⍷R</apll><br />
<apll>L⊆R</apll>, <apll>L⊇R</apll>, <apll>L§R</apll>, <apll>L~R</apll>, <apll>L⍷R</apll>,<br />
<apll>⌊R</apll>, <apll>⌈R</apll>, <apll>∪R</apll></td>
<apll>⌊R</apll>, <apll>⌈R</apll>, <apll>∪R</apll></td>
   <td><i>N</i></td>
   <td><i>N</i></td>
Line 85: Line 127:


<tr>
<tr>
   <td rowspan="4"><apll>L|R</apll></td>
   <td rowspan="4"><apll>L|R</apll>, <apll>f⌻R</apll>, <apll>L f⌻R</apll>, <apll>∘⌻R</apll></td>
   <td><i>N</i></td>
   <td><i>N</i></td>
   <td><apll>⎕CT←</apll><i>N</i></td>
   <td><apll>⎕CT←</apll><i>N</i></td>
Line 92: Line 134:
<tr>
<tr>
   <td><i>C</i></td>
   <td><i>C</i></td>
   <td><apll>⎕DQ←</apll><i>C</i></td>
   <td><apll>⎕LR←</apll><i>C</i></td>
</tr>
</tr>


<tr>
<tr>
   <td><i>N C</i>
   <td><i>N C</i>
   <td><apll>⎕CT←</apll><i>N</i> and <apll>⎕DQ←</apll><i>C</i></td>
   <td><apll>⎕CT←</apll><i>N</i> and <apll>⎕LR←</apll><i>C</i></td>
</tr>
</tr>


<tr>
<tr>
   <td><i>C N</i>
   <td><i>C N</i>
   <td><apll>⎕CT←</apll><i>N</i> and <apll>⎕DQ←</apll><i>C</i></td>
   <td><apll>⎕CT←</apll><i>N</i> and <apll>⎕LR←</apll><i>C</i></td>
</tr>
</tr>


<tr>
<tr>
   <td rowspan="4"><apll>?R</apll> and <apll>L?R</apll></td>
   <td rowspan="8"><apll>?R</apll> and <apll>L?R</apll></td>
   <td><i>N</i></td>
   <td><i>N</i></td>
   <td><apll>⎕IO←</apll><i>N</i></td>
   <td><apll>⎕IO←</apll><i>N</i></td>
</tr>
<tr>
  <td><i>N1&nbsp;N2</i></td>
  <td><apll>⎕IO←</apll><i>N1</i> and <apll>⎕RL←</apll><i>N2</i></td>
</tr>
</tr>


Line 124: Line 171:
   <td><i>C N</i>
   <td><i>C N</i>
   <td><apll>⎕IO←</apll><i>N</i> and <apll>⎕DT←</apll><i>C</i></td>
   <td><apll>⎕IO←</apll><i>N</i> and <apll>⎕DT←</apll><i>C</i></td>
</tr>
<tr>
  <td><i>N1&nbsp;N2&nbsp;C</i></td>
  <td><apll>⎕IO←</apll><i>N1</i>, <apll>⎕RL←</apll><i>N2</i>, and <apll>⎕DT←</apll><i>C</i></td>
</tr>
<tr>
  <td><i>N1&nbsp;C&nbsp;N2</i></td>
  <td><apll>⎕IO←</apll><i>N1</i>, <apll>⎕RL←</apll><i>N2</i>, and <apll>⎕DT←</apll><i>C</i></td>
</tr>
<tr>
  <td><i>C&nbsp;N1&nbsp;N2</i></td>
  <td><apll>⎕IO←</apll><i>N1</i>, <apll>⎕RL←</apll><i>N2</i>, and <apll>⎕DT←</apll><i>C</i></td>
</tr>
</tr>


Line 129: Line 191:
   <td rowspan="2"><apll>!R</apll> ([https://en.wikipedia.org/wiki/Pochhammer_k-symbol Pochhammer k-symbol])</td>
   <td rowspan="2"><apll>!R</apll> ([https://en.wikipedia.org/wiki/Pochhammer_k-symbol Pochhammer k-symbol])</td>
   <td><i>N</i></td>
   <td><i>N</i></td>
   <td>Rising (<i>N</i> &gt; 0) and Falling (<i>N</i> &lt; 0) factorial of length <apll>|</apll><i>N</i>, stepping by <apll>|</apll><i>N</i> in the direction of <i>N</i></td>
   <td>[[#Rising_and_Falling_Factorials|Rising (<i>N</i> &gt; 0) and Falling (<i>N</i> &lt; 0) factorial]] of length <apll>|</apll><i>N</i>, stepping by <apll>1</apll> in the direction of <i>N</i></td>
</tr>
</tr>


<tr>
<tr>
   <td><i>N1&nbsp;N2</i></td>
   <td><i>N1&nbsp;N2</i></td>
   <td>Rising (<i>N1</i> &gt; 0) and Falling (<i>N1</i> &lt; 0) factorial of length <apll>|</apll><i>N1</i>, stepping by <apll>|</apll><i>N2</i> in the direction of <i>N1</i></td>
   <td>[[#Rising_and_Falling_Factorials|Rising (<i>N1</i> &gt; 0) and Falling (<i>N1</i> &lt; 0) factorial]] of length <apll>|</apll><i>N1</i>, stepping by <apll>|</apll><i>N2</i> in the direction of <i>N1</i></td>
</tr>
</tr>


Line 146: Line 208:
   <td><apll>L÷R</apll>, <apll>L∨R</apll>, <apll>L∧R</apll>, <apll>L○R</apll>, <apll>L⊤R</apll></td>
   <td><apll>L÷R</apll>, <apll>L∨R</apll>, <apll>L∧R</apll>, <apll>L○R</apll>, <apll>L⊤R</apll></td>
   <td><i>C</i></td>
   <td><i>C</i></td>
   <td><apll>⎕DQ←</apll><i>C</i></td>
   <td><apll>⎕LR←</apll><i>C</i></td>
</tr>
</tr>


Line 152: Line 214:
   <td><apll>L×R</apll></td>
   <td><apll>L×R</apll></td>
   <td><i>C</i></td>
   <td><i>C</i></td>
   <td>where <i>C</i> may be either <apll>'i'</apll> or <apll>'e'</apll> for <b>I</b>nterior or <b>E</b>xterior product where the former calculates <apll>(((L×R)+R×L)÷2</apll> and the latter calculates <apll>(((L×R)-R×L)÷2</apll> and <apll>L</apll> and <apll>R</apll> are non-commutative (Quaternion or Octonion) numbers &mdash; for commutative numbers, both products are trivial.</td>
   <td>Except for <b>Dot Product</b>, these variants are non-trivial only when multiplying <b>Non-commutative</b> numbers.<br />The following definitions on scalar <apll>L</apll> and <apll>R</apll> extend to higher rank arrays in the usual way.<br /><br />
    <table border="1" cellpadding="10" cellspacing="0" rules="all" summary="">
      <tr>
        <th><i>C</i></th>
        <th>Name</th>
        <th>Quaternion/Octonion &mdash; Non-commutative</th>
        <th>Real/Complex &mdash; Commutative</th>
      </tr>
      <tr>
      <td><apll>'i'</apll></td>
      <td><b>I</b>nterior product</td>
      <td><apll>((L×R)+R×L)÷2</apll></td>
      <td><apll>L×R</apll></td>
      </tr>
      <tr>
        <td><apll>'e'</apll></td>
        <td><b>E</b>xterior product</td>
        <td><apll>((L×R)-R×L)÷2</apll></td>
        <td><apll>0</apll></td>
      </tr>
      <tr>
        <td><apll>'x'</apll></td>
        <td><b>Cross</b> product</td>
        <td><apll>¯9○&lt;(∘⌻¯9○L)+.×&gt;¯9○R</apll>&nbsp;&nbsp;&nbsp;<b>Quaternions only</b><br />where <apll>¯9○R</apll> returns <apll>(R-+R)÷2</apll>, i.e. as a pure imaginary number</td>
        <td><apll>0</apll></td>
      </tr>
      <tr>
        <td><apll>'d'</apll></td>
        <td><b>D</b>ot product</td>
        <td><apll>(&gt;L)+.×&gt;R</apll></td>
        <td>(same)</td>
      </tr>
      <tr>
        <td><apll>'c'</apll></td>
        <td><b>C</b>onjugation product</td>
        <td><apll>L×R÷L</apll></td>
        <td><apll>R</apll></td>
      </tr>
    </table>
  </td>
</tr>
</tr>


Line 158: Line 259:
   <td><apll>⌹R</apll></td>
   <td><apll>⌹R</apll></td>
   <td><i>N</i></td>
   <td><i>N</i></td>
   <td>where <i>N</i> may be <apll>1</apll>, <apll>2</apll>, or <apll>3</apll>.  <apll>R</apll> must be a square simple Real numeric matrix.  If <i>N</i> is <apll>1</apll>, the result is a Complex floating point vector of the [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors Eigenvalues] of <apll>R</apll>.  If <i>N</i> is 2, the result is a Complex floating point matrix of the [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors Eigenvectors] of <apll>R</apll>, one per column.  If <i>N</i> is <apll>3</apll>, the result is a nested two-element vector with the Eigenvalues in the first element and the Eigenvectors in the second.</td>
   <td>where <i>N</i> may be <apll>1</apll>, <apll>2</apll>, <apll>3</apll>, or <apll>4</apll>.  <apll>R</apll> must be a square simple Real numeric matrix.  If <i>N</i> is <apll>1</apll>, the result is a Complex floating point vector of the [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors Eigenvalues] of <apll>R</apll>.  If <i>N</i> is 2, the result is a Complex floating point matrix of the [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors Eigenvectors] of <apll>R</apll>, one per column.  If <i>N</i> is <apll>3</apll>, the result is a two-element nested vector with a Complex vector of the Eigenvalues in the first element and a Complex matrix of the Eigenvectors in the second.  If <i>N</i> is <apll>4</apll>, the result is a three-element nested vector with a Complex vector of the Eigenvalues in the first element, a Complex matrix of the Eigenvectors in the second, and a Real matrix of the Schur vectors in the third.  For more details see [[#Eigenvalues_and_Eigenvectors|Eigenvalues and Eigenvectors]].</td>
</tr>
 
<tr>
  <td><apll><i>f</i>.<i>g</i>/0⍴⊂R</apll></td>
  <td><i>C</i></td>
  <td><apll>⎕LR←</apll><i>C</i> &mdash; this value is used only when the identity function for inner product is called so as to distinguish the Left identity element from the Right.  For example, with <apll>R←3 4⍴⍳12</apll>, the expression <apll>⊃+.×⍠'l'/0⍴⊂R</apll> produces the Left identity element (which is a <apll>3</apll> by <apll>3</apll> identity matix) and <apll>⊃+.×⍠'r'/0⍴⊂R</apll> produces the Right identity element (which is a <apll>4</apll> by <apll>4</apll> identity matrix).  The actual values in the result are dependent on the functions <i>f</i> and <i>g</i>.</td>
</tr>
</tr>
</table>
</table>
<br />
<br />
==Subsequences==
===Ascending===
<p>An Ascending subsequence of one vector in another (<apll>L⍳⍠'a' R</apll>) is a set of indices of <apll>L</apll> (barring items Not Found) such that <apll>R≡L[L⍳⍠'a' R]</apll> and <apll>∧/2&lt;/L⍳⍠'a' R</apll>, that is the indices are monotonically increasing.  This primitive is written such that it returns the smallest values that satisfy the above conditions.  All datatypes are valid for the left and right arguments; the result is always an integer vector of the same length as <apll>R</apll>.</p>
<p>For example:</p>
<apll><pre>
      L←2 7 1 5 7 1 2 1 7 1
      R←5 2 7 1
      L⍳⍠'a' R
4 7 9 10
      L[L⍳⍠'a' R]
5 2 7 1
</pre></apll>
<p>If an element in <apll>R</apll> is Not Found, the corresponding value in the result is <apll>⎕IO+⍴L</apll>.  Moreover, if an element in <apll>R</apll> is Not Found, then all following elements in <apll>R</apll> are also Not Found.</p>
<p>Continuing the above example:</p>
<apll><pre>
      LL←L,3
      RR←R,9 3
      LL⍳⍠'a' RR
4 7 9 10 12 12
      (LL,'?')[LL⍳⍠'a' RR]
5 2 7 1 ??
</pre></apll>
===Descending===
<p>A Descending subsequence of one vector in another (<apll>L⍳⍠'d' R</apll>) is a set of indices of <apll>L</apll> (barring items Not Found) such that <apll>R≡L[L⍳⍠'d' R]</apll> and <apll>∧/2&gt;/L⍳⍠'d' R</apll>, that is the indices are monotonically decreasing.  This primitive is written such that it returns the largest values that satisfy the above conditions.  All datatypes are valid for the left and right arguments; the result is always an integer vector of the same length as <apll>R</apll>.</p>
<p>For example:</p>
<apll><pre>
      L←1 2 5 7 2 1 5 7 1 2 5 5 1 2 7
      R←5 2 7 1
      L⍳⍠'d' R
12 10 8 6
      L[L⍳⍠'d' R]
5 2 7 1
</pre></apll>
<p>If an element in <apll>R</apll> is Not Found, the corresponding value in the result is <apll>⎕IO-1</apll>.  Moreover, if an element in <apll>R</apll> is Not Found, then all following elements in <apll>R</apll> are also Not Found.</p>
<p>Continuing the above example:</p>
<apll><pre>
      LL←3,L
      RR←R,9 3
      LL⍳⍠'d' RR
13 11 9 7 0 0
      ('?',LL)[1+LL⍳⍠'d' RR]
5 2 7 1 ??
</pre></apll>
===Combining Variants===
<p>Dyadic Iota allows several other Variants such as setting the Index Origin and Comparison Tolerance.  They may be combined into one right operand, for example, any of the following expressions</p>
<apll>      L⍳⍠(0 1<_E/>¯10 'd') R</apll>&nbsp;&nbsp; or<br />
<apll>      L⍳⍠(0 'd' 1<_E/>¯10) R</apll>&nbsp;&nbsp; or<br />
<apll>      L⍳⍠('d' 0 1<_E/>¯10) R</apll><br />
<p>may be used to find a Descending Subsequence in origin-0 using a Comparison Tolerance of <apll>1<_E/>¯10</apll>.</p>
<p>The order of the two numeric values is important:  if there is only one number in the right operand, it is applied to the Index Origin; if there are two numbers, the first is applied to the Index Origin and the second to the Comparison Tolerance.  The character value may appear anywhere in the right operand &mdash; however if a second character-valued Variant were defined for Dyadic Iota, then the two character values would also be order-dependent.</p>
===Identities For Subsequences===
<p>The following identities hold in either Index Origin even if there are Not Found values in the result:</p>
<apll>      (L⍳⍠'a' R)≡(1 ¯1[1]+⍴L)-(⌽L)⍳⍠'d' R</apll><br />
<apll>      (L⍳⍠'d' R)≡(1 ¯1[1]+⍴L)-(⌽L)⍳⍠'a' R</apll>


==Rising and Falling Factorials==
==Rising and Falling Factorials==
Line 173: Line 357:
<p>Here are some examples of the falling factorial</p>
<p>Here are some examples of the falling factorial</p>


<apll>
<apll><pre>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!6<br />
      !6  
720<br />
720  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯6)6 ⍝ ×/6 5 4 3 2 1<br />
      (!⍠¯6)6 ⍝ ×/6 5 4 3 2 1  
720<br />
720  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯5)6 ⍝ ×/6 5 4 3 2<br />
      (!⍠¯5)6 ⍝ ×/6 5 4 3 2  
720<br />
720  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯4)6 ⍝ ×/6 5 4 3<br />
      (!⍠¯4)6 ⍝ ×/6 5 4 3  
360<br />
360  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯3)6 ⍝ ×/6 5 4<br />
      (!⍠¯3)6 ⍝ ×/6 5 4  
120<br />
120  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯2)6 ⍝ ×/6 5<br />
      (!⍠¯2)6 ⍝ ×/6 5
30<br />
30  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯1)6 ⍝ ×/6<br />
      (!⍠¯1)6 ⍝ ×/6  
6<br />
6  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯0)6 ⍝ ×/⍬<br />
      (!⍠¯0)6 ⍝ ×/⍬  
1<br />
1  
</apll>
</pre></apll>


<p>and now falling by <apll>2</apll></p>
<p>and now falling by <apll>2</apll></p>


<apll>
<apll><pre>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯6 2)6 ⍝ ×/6 4 2 0 ¯2 ¯4<br />
      (!⍠(¯6 2))6 ⍝ ×/6 4 2 0 ¯2 ¯4  
0<br />
0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯5 2)6 ⍝ ×/6 4 2 0 ¯2<br />
      (!⍠(¯5 2))6 ⍝ ×/6 4 2 0 ¯2  
0<br />
0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯4 2)6 ⍝ ×/6 4 2 0<br />
      (!⍠(¯4 2))6 ⍝ ×/6 4 2 0  
0<br />
0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯3 2)6 ⍝ ×/6 4 2<br />
      (!⍠(¯3 2))6 ⍝ ×/6 4 2  
48<br />
48  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯2 2)6 ⍝ ×/6 4<br />
      (!⍠(¯2 2))6 ⍝ ×/6 4  
24<br />
24  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯1 2)6 ⍝ ×/6<br />
      (!⍠(¯1 2))6 ⍝ ×/6  
6<br />
6  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠¯0 2)6 ⍝ ×/⍬<br />
      (!⍠(¯0 2))6 ⍝ ×/⍬  
1<br />
1  
</apll>
</pre></apll>


<p>and here are some examples of the rising factorial</p>
<p>and here are some examples of the rising factorial</p>


<apll>
<apll><pre>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠6)6 ⍝ ×/6 7 8 9 10 11<br />
      (!⍠6)6 ⍝ ×/6 7 8 9 10 11  
332640<br />
332640  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠5)6 ⍝ ×/6 7 8 9 10<br />
      (!⍠5)6 ⍝ ×/6 7 8 9 10  
30240<br />
30240  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠4)6 ⍝ ×/6 7 8 9<br />
      (!⍠4)6 ⍝ ×/6 7 8 9  
3024<br />
3024  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠3)6 ⍝ ×/6 7 8<br />
      (!⍠3)6 ⍝ ×/6 7 8  
336<br />
336  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠2)6 ⍝ ×/6 7<br />
      (!⍠2)6 ⍝ ×/6 7
42<br />
42
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠1)6 ⍝ ×/6<br />
      (!⍠1)6 ⍝ ×/6
6<br />
6
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠0)6 ⍝ ×/⍬<br />
      (!⍠0)6 ⍝ ×/⍬
1<br />
1  
</apll>
</pre></apll>


<p>and now rising by <apll>2</apll></p>
<p>and now rising by <apll>2</apll></p>


<apll>
<apll><pre>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠6 2)6 ⍝ ×/6 8 10 12 14 16<br />
      (!⍠(6 2))6 ⍝ ×/6 8 10 12 14 16  
1290240<br />
1290240  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠5 2)6 ⍝ ×/6 8 10 12 14<br />
      (!⍠(5 2))6 ⍝ ×/6 8 10 12 14  
80640<br />
80640  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠4 2)6 ⍝ ×/6 8 10 12<br />
      (!⍠(4 2))6 ⍝ ×/6 8 10 12  
5760<br />
5760  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠3 2)6 ⍝ ×/6 8 10<br />
      (!⍠(3 2))6 ⍝ ×/6 8 10  
480<br />
480  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠2 2)6 ⍝ ×/6 8<br />
      (!⍠(2 2))6 ⍝ ×/6 8  
48<br />
48  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠1 2)6 ⍝ ×/6<br />
      (!⍠(1 2))6 ⍝ ×/6  
6<br />
6  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(!⍠0 2)6 ⍝ ×/⍬<br />
      (!⍠(0 2))6 ⍝ ×/⍬  
1<br />
1  
</apll>
</pre></apll>


==Identities==
===Identities For Rising and Falling Factorials===


<table border="1" cellpadding="5" cellspacing="5" rules="none" summary="">
<table border="1" cellpadding="5" cellspacing="5" rules="none" summary="">
Line 271: Line 455:
</tr>
</tr>
</table>
</table>


==Eigenvalues and Eigenvectors==
==Eigenvalues and Eigenvectors==


These [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors concepts] from Linear Algebra and Matrix Theory define the characteristic values and vectors of the linear transformation represented by a matrix.  Every square simple Real numeric matrix has Eigenvalues and Eigenvectors.  To calculate these objects, use the Variant operator with a left operand of the Domino function and a right operand of an integer scalar.
These [https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors concepts] from Linear Algebra and Matrix Theory define the characteristic values and vectors of the linear transformation represented by a matrix.  Every square simple Real numeric matrix has Eigenvalues and Eigenvectors.  To calculate these objects, use the Variant operator with a left operand of the Domino function and a right operand of an integer scalar according to the following table:




{| border="1" cellpadding="5" cellspacing="5" rules="all" summary="" style=""border:1px solid black;"
{| border="1" cellpadding="5" cellspacing="5" rules="all" summary="" style=""border:1px solid black;"
|<apll>Z←(⌹⍠1) R</apll>||<apll>Z</apll> is a Complex floating point vector of the Eigenvalues of <apll>R</apll>
|<apll>Z←⌹⍠1 RA</apll>||<apll>Z</apll> is a Complex floating point vector of the Eigenvalues of <apll>RA</apll>
|-
|-
|<apll>Z←(⌹⍠2) R</apll>||<apll>Z</apll> is a Complex floating point matrix of the Eigenvectors of <apll>R</apll>, one per column
|<apll>Z←⌹⍠2 RA</apll>||<apll>Z</apll> is a Complex floating point matrix of the Eigenvectors of <apll>RA</apll>, one per column
|-
|-
|<apll>Z←(⌹⍠3) R</apll>||<apll>Z</apll> is a Nested two-element vector with a Complex floating point vector of the Eigenvalues in the first element and a Complex floating point matrix of the Eigenvectors in the second
|<apll>Z←⌹⍠3 RA</apll>||<apll>Z</apll> is a two-element nested vector with a Complex floating point vector of the Eigenvalues (<apll>⌹⍠1 RA</apll>) in the first element and a Complex floating point matrix of the Eigenvectors (<apll>⌹⍠2 RA</apll>) in the second
|-
|<apll>Z←⌹⍠4 RA</apll>||<apll>Z</apll> is a three-element nested vector with a Complex floating point vector of the Eigenvalues (<apll>⌹⍠1 RA</apll>) in the first element, a Complex floating point matrix of the Eigenvectors (<apll>⌹⍠2 RA</apll>) in the second, and a Real matrix of the Schur vectors in the third
|-
|<apll>Z←⌹⍠5 RA</apll>||<apll>Z</apll> is a two-element nested vector consisting of the QR Decomposition of <apll>RA</apll>; the first element is <apll>Q</apll>, an orthonormal matrix (<apll>Q≡⍉⌹Q</apll>) and the second element is <apll>R</apll>, an upper-triangular matrix, which, together, satisfy the identity <apll>RA≡Q+.×R</apll>.
|}
|}


Line 289: Line 476:
For example, Eigenvalues and Eigenvectors can be used to calculate the factorial of a matrix:
For example, Eigenvalues and Eigenvectors can be used to calculate the factorial of a matrix:


<apll><pre>      M←2 2⍴1 3 2 1
<apll><pre>
      M
&ensp;       M←2 2⍴1 3 2 1
1 3
&ensp;      M
2 1
&ensp; 1 3
      MatFact←{(Eval Evec)←(⌹⍠3)
&ensp; 2 1
<span style="color:blue;">➥</span>⋄ Diag←(⍴⍵)⍴0 ⋄ Diag[,¨⍨⍳⍴Eval]←!Eval ⍝ Factorial of Eigenvalues on diagonal
&ensp;      MatFact←{(Eval Evec)←⌹⍠3
<span style="color:blue;">➥</span>⋄ Diag←∘⌻!Eval ⍝ Factorial of Eigenvalues on diagonal
<span style="color:blue;">➥</span>⋄ Evec+.×Diag+.×⌹Evec}
<span style="color:blue;">➥</span>⋄ Evec+.×Diag+.×⌹Evec}
      MatFact M
&ensp;      MatFact M
3.6274 8.8423
&ensp; 3.6274 8.8423
5.8949 3.6274
&ensp; 5.8949 3.6274
</pre></apll>
</pre></apll>


Note that if we delete the Shriek function in <apll>MatFact</apll>, the result is the original matrix argument.
Note that if we delete the Shriek function in <apll>MatFact</apll>, the result is the original matrix argument.


In turn, the function <apll>MatFact</apll> can be used to calculate the Factorial of a Complex number:
In turn, the function <apll>MatFact</apll> can be used to calculate the Factorial of a HyperComplex number:


<apll><pre>
<apll><pre>
       CplexFact←{(a b)←>⍵      Split out coefficients of a Complex number
&ensp;       HyperFact←{M←∘⌻⍵        Matrix representation of a HyperComplex number
<span style="color:blue;">➥</span>⋄ M←2 2⍴a (-b) b a            ⍝ Matrix representation ...
<span style="color:blue;">➥</span>⋄ ⎕IO←1 ⋄ <9○1⌷[2] MatFact M  ⍝ Factorial ...
<span style="color:blue;">➥</span>⋄ ⎕IO←1 ⋄ <9○1⌷[2] MatFact M  ⍝ Factorial ...
<span style="color:blue;">➥</span>}
<span style="color:blue;">➥</span>}
       CplexFact 1i2
&ensp;       HyperFact 1<_i/>2
0.11229J0.32361
&ensp; 0.11229<_i/>0.32361
       !1i2
&ensp;       !1<_i/>2
0.11229J0.32361
&ensp; 0.11229<_i/>0.32361
</pre></apll>
</pre></apll>


Line 320: Line 507:
In a similar manner, using the appropriate <apll>4×4</apll> matrix representation of a Quaternion, its Factorial can be calculated which is the algorithm used in the implementation:
In a similar manner, using the appropriate <apll>4×4</apll> matrix representation of a Quaternion, its Factorial can be calculated which is the algorithm used in the implementation:


<apll><pre>     !<⍳4
<apll><pre>
0.0060975i¯0.0010787j¯0.001618k¯0.0021573
&ensp;      HyperFact <⍳4
&ensp; 0.0060975<_i/>¯0.0010787<_j/>¯0.001618<_k/>¯0.0021573
&ensp;      !<⍳4
&ensp; 0.0060975<_i/>¯0.0010787<_j/>¯0.001618<_k/>¯0.0021573
</pre></apll>
</pre></apll>


{{Language Toolbar}}
{{Article footer|9|Variant}}
[[Category:Operators]]

Latest revision as of 19:45, 18 February 2024

Caution: Be careful not to confuse this symbol, which is , with which is Matrix Inverse/Divide.


Z←f⍠B R    or    Z←L f⍠B R evaluates f R or L f R in the context described by B.
L and R are arbitrary arrays conformable with f, and B is a simple scalar, simple or heterogeneous vector, or nested vector.
f is an arbitrary function.

Introduction

The dyadic Variant operator creates a version of the function f with a set of properties bound and localized to it as specified by the array right operand. For example, ⍳⍠0 is a version of that executes in origin-0 independent of the current value of ⎕IO.

The array right operand to the operator may take several different forms depending upon the function left operand. In the general case, for any kind of function left operand, the right operand may specify a single property in the form of Key Val, or multiple properties in the form of (Key1 Val1) (Key2 Val2), or if the left operand is a primitive function, a shorthand notation may be used as in Val or Val1 Val2 .

In the general case, the keys specify a property such as Index Origin as 'IO' or Comparison Tolerance as 'CT', and the value part specifies a value appropriate to the property specified in the matching key. At the moment, the keys that may be used are 'CT', 'DT', 'FPC', 'IO', 'LR', 'PP', and 'RL' which stand for the corresponding system variable. Note that for the Variants of L×R and ⌹R and the Subsequence variants such as L⍳⍠'a' R there are no corresponding system variables as yet.

For example:

      1 2 (3+1e¯9)  3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3
3
      1 2 (3+1e¯10) 3⍳⍠(('IO' 0) ('CT' 1e¯10)) 3
2
      ⍳⍠('IO' 0) 3 
0 1 2 
      ⍳⍠('IO' 1) 3 
1 2 3
      ⍳⍠('IO' 0) ⍠('IO' 1) 3 
0 1 2 
      ⍳⍠('IO' 1) ⍠('IO' 0) 3 
1 2 3

Note that in the last two examples, the lefthand (innermost) value of ⎕IO takes precedence.

Shorthand Notation

If the left operand is a primitive or derived function, the following shorthand notation may be used:

Function or
Principal Operator
Right
Arg
Type
Meaning
⍳R N ⎕IO←N
L⍳R N ⎕IO←N
N1 N2 ⎕IO←N1 and ⎕CT←N2
C Subsequence C ('a' for Ascending, 'd' for Descending)
N C ⎕IO←N and Subsequence C ('a' for Ascending, 'd' for Descending)
C N ⎕IO←N and Subsequence C ('a' for Ascending, 'd' for Descending)
N1 N2 C ⎕IO←N1, ⎕CT←N2, and Subsequence C ('a' for Ascending, 'd' for Descending)
N1 C N2 ⎕IO←N1, ⎕CT←N2, and Subsequence C ('a' for Ascending, 'd' for Descending)
C N1 N2 ⎕IO←N1, ⎕CT←N2, and Subsequence C ('a' for Ascending, 'd' for Descending)
L⌷R, L⍉R, ⍋R, L⍋R, ⍒R, L⍒R,
L⊃R, ⍸R, LπR, a‼R
N ⎕IO←N
⍕R and L⍕R N ⎕PP←N
L<R, L≤R, L=R, L≠R, L≥R, L>R,

L∊R, L≡R, L≢R, L∪R, L∩R,
L⊆R, L⊇R, L§R, L~R, L⍷R,

⌊R, ⌈R, ∪R
N ⎕CT←N
L|R, f⌻R, L f⌻R, ∘⌻R N ⎕CT←N
C ⎕LR←C
N C ⎕CT←N and ⎕LR←C
C N ⎕CT←N and ⎕LR←C
?R and L?R N ⎕IO←N
N1 N2 ⎕IO←N1 and ⎕RL←N2
C ⎕DT←C
N C ⎕IO←N and ⎕DT←C
C N ⎕IO←N and ⎕DT←C
N1 N2 C ⎕IO←N1, ⎕RL←N2, and ⎕DT←C
N1 C N2 ⎕IO←N1, ⎕RL←N2, and ⎕DT←C
C N1 N2 ⎕IO←N1, ⎕RL←N2, and ⎕DT←C
!R (Pochhammer k-symbol) N Rising (N > 0) and Falling (N < 0) factorial of length |N, stepping by 1 in the direction of N
N1 N2 Rising (N1 > 0) and Falling (N1 < 0) factorial of length |N1, stepping by |N2 in the direction of N1
⍎R N ⎕FPC←N
L÷R, L∨R, L∧R, L○R, L⊤R C ⎕LR←C
L×R C Except for Dot Product, these variants are non-trivial only when multiplying Non-commutative numbers.
The following definitions on scalar L and R extend to higher rank arrays in the usual way.

C Name Quaternion/Octonion — Non-commutative Real/Complex — Commutative
'i' Interior product ((L×R)+R×L)÷2 L×R
'e' Exterior product ((L×R)-R×L)÷2 0
'x' Cross product ¯9○<(∘⌻¯9○L)+.×>¯9○R   Quaternions only
where ¯9○R returns (R-+R)÷2, i.e. as a pure imaginary number
0
'd' Dot product (>L)+.×>R (same)
'c' Conjugation product L×R÷L R
⌹R N where N may be 1, 2, 3, or 4. R must be a square simple Real numeric matrix. If N is 1, the result is a Complex floating point vector of the Eigenvalues of R. If N is 2, the result is a Complex floating point matrix of the Eigenvectors of R, one per column. If N is 3, the result is a two-element nested vector with a Complex vector of the Eigenvalues in the first element and a Complex matrix of the Eigenvectors in the second. If N is 4, the result is a three-element nested vector with a Complex vector of the Eigenvalues in the first element, a Complex matrix of the Eigenvectors in the second, and a Real matrix of the Schur vectors in the third. For more details see Eigenvalues and Eigenvectors.
f.g/0⍴⊂R C ⎕LR←C — this value is used only when the identity function for inner product is called so as to distinguish the Left identity element from the Right. For example, with R←3 4⍴⍳12, the expression ⊃+.×⍠'l'/0⍴⊂R produces the Left identity element (which is a 3 by 3 identity matix) and ⊃+.×⍠'r'/0⍴⊂R produces the Right identity element (which is a 4 by 4 identity matrix). The actual values in the result are dependent on the functions f and g.


Subsequences

Ascending

An Ascending subsequence of one vector in another (L⍳⍠'a' R) is a set of indices of L (barring items Not Found) such that R≡L[L⍳⍠'a' R] and ∧/2</L⍳⍠'a' R, that is the indices are monotonically increasing. This primitive is written such that it returns the smallest values that satisfy the above conditions. All datatypes are valid for the left and right arguments; the result is always an integer vector of the same length as R.

For example:

      L←2 7 1 5 7 1 2 1 7 1
      R←5 2 7 1
      L⍳⍠'a' R
4 7 9 10
      L[L⍳⍠'a' R]
5 2 7 1

If an element in R is Not Found, the corresponding value in the result is ⎕IO+⍴L. Moreover, if an element in R is Not Found, then all following elements in R are also Not Found.

Continuing the above example:

      LL←L,3
      RR←R,9 3
      LL⍳⍠'a' RR
4 7 9 10 12 12
      (LL,'?')[LL⍳⍠'a' RR]
5 2 7 1 ??

Descending

A Descending subsequence of one vector in another (L⍳⍠'d' R) is a set of indices of L (barring items Not Found) such that R≡L[L⍳⍠'d' R] and ∧/2>/L⍳⍠'d' R, that is the indices are monotonically decreasing. This primitive is written such that it returns the largest values that satisfy the above conditions. All datatypes are valid for the left and right arguments; the result is always an integer vector of the same length as R.

For example:

      L←1 2 5 7 2 1 5 7 1 2 5 5 1 2 7
      R←5 2 7 1
      L⍳⍠'d' R
12 10 8 6
      L[L⍳⍠'d' R]
5 2 7 1

If an element in R is Not Found, the corresponding value in the result is ⎕IO-1. Moreover, if an element in R is Not Found, then all following elements in R are also Not Found.

Continuing the above example:

      LL←3,L
      RR←R,9 3
      LL⍳⍠'d' RR
13 11 9 7 0 0
      ('?',LL)[1+LL⍳⍠'d' RR]
5 2 7 1 ??

Combining Variants

Dyadic Iota allows several other Variants such as setting the Index Origin and Comparison Tolerance. They may be combined into one right operand, for example, any of the following expressions

L⍳⍠(0 1E¯10 'd') R   or
L⍳⍠(0 'd' 1E¯10) R   or
L⍳⍠('d' 0 1E¯10) R

may be used to find a Descending Subsequence in origin-0 using a Comparison Tolerance of 1E¯10.

The order of the two numeric values is important: if there is only one number in the right operand, it is applied to the Index Origin; if there are two numbers, the first is applied to the Index Origin and the second to the Comparison Tolerance. The character value may appear anywhere in the right operand — however if a second character-valued Variant were defined for Dyadic Iota, then the two character values would also be order-dependent.

Identities For Subsequences

The following identities hold in either Index Origin even if there are Not Found values in the result:

(L⍳⍠'a' R)≡(1 ¯1[1]+⍴L)-(⌽L)⍳⍠'d' R
(L⍳⍠'d' R)≡(1 ¯1[1]+⍴L)-(⌽L)⍳⍠'a' R

Rising and Falling Factorials

A falling factorial is like a normal factorial except that it subtracts the step value (by default 1 unless overridden) from the original number for a fixed # of iterations. That is, !6 successively decrements 6 by 1 and multiplies the numbers 6 5 4 3 2 1 to get 720. A falling factorial starting with 6 of length (say) 3 multiplies 6 5 4 to get 120.

A rising factorial is like a falling factorial except it adds the step value (by default 1 unless overridden) instead of subtracting it. A rising factorial starting with 6 of length (say) 3 multiplies 6 7 8 to get 336.

Here are some examples of the falling factorial

      !6 
720 
      (!⍠¯6)6 ⍝ ×/6 5 4 3 2 1 
720 
      (!⍠¯5)6 ⍝ ×/6 5 4 3 2 
720 
      (!⍠¯4)6 ⍝ ×/6 5 4 3 
360 
      (!⍠¯3)6 ⍝ ×/6 5 4 
120 
      (!⍠¯2)6 ⍝ ×/6 5
30 
      (!⍠¯1)6 ⍝ ×/6 
6 
      (!⍠¯0)6 ⍝ ×/⍬ 
1 

and now falling by 2

      (!⍠(¯6 2))6 ⍝ ×/6 4 2 0 ¯2 ¯4 
0 
      (!⍠(¯5 2))6 ⍝ ×/6 4 2 0 ¯2 
0 
      (!⍠(¯4 2))6 ⍝ ×/6 4 2 0 
0 
      (!⍠(¯3 2))6 ⍝ ×/6 4 2 
48 
      (!⍠(¯2 2))6 ⍝ ×/6 4 
24 
      (!⍠(¯1 2))6 ⍝ ×/6 
6 
      (!⍠(¯0 2))6 ⍝ ×/⍬ 
1 

and here are some examples of the rising factorial

      (!⍠6)6 ⍝ ×/6 7 8 9 10 11 
332640 
      (!⍠5)6 ⍝ ×/6 7 8 9 10 
30240 
      (!⍠4)6 ⍝ ×/6 7 8 9 
3024 
      (!⍠3)6 ⍝ ×/6 7 8 
336 
      (!⍠2)6 ⍝ ×/6 7
42
      (!⍠1)6 ⍝ ×/6
6
      (!⍠0)6 ⍝ ×/⍬
1 

and now rising by 2

      (!⍠(6 2))6 ⍝ ×/6 8 10 12 14 16 
1290240 
      (!⍠(5 2))6 ⍝ ×/6 8 10 12 14 
80640 
      (!⍠(4 2))6 ⍝ ×/6 8 10 12 
5760 
      (!⍠(3 2))6 ⍝ ×/6 8 10 
480 
      (!⍠(2 2))6 ⍝ ×/6 8 
48 
      (!⍠(1 2))6 ⍝ ×/6 
6 
      (!⍠(0 2))6 ⍝ ×/⍬ 
1 

Identities For Rising and Falling Factorials

(!⍠N)R   ←→   (!⍠(N 1))R
(!⍠(N 0))R   ←→   R*N
(!⍠(N1,N2))R   ←→   (!⍠(N1,|N2))R   (the sign of N2 is ignored)

Eigenvalues and Eigenvectors

These concepts from Linear Algebra and Matrix Theory define the characteristic values and vectors of the linear transformation represented by a matrix. Every square simple Real numeric matrix has Eigenvalues and Eigenvectors. To calculate these objects, use the Variant operator with a left operand of the Domino function and a right operand of an integer scalar according to the following table:


Z←⌹⍠1 RA Z is a Complex floating point vector of the Eigenvalues of RA
Z←⌹⍠2 RA Z is a Complex floating point matrix of the Eigenvectors of RA, one per column
Z←⌹⍠3 RA Z is a two-element nested vector with a Complex floating point vector of the Eigenvalues (⌹⍠1 RA) in the first element and a Complex floating point matrix of the Eigenvectors (⌹⍠2 RA) in the second
Z←⌹⍠4 RA Z is a three-element nested vector with a Complex floating point vector of the Eigenvalues (⌹⍠1 RA) in the first element, a Complex floating point matrix of the Eigenvectors (⌹⍠2 RA) in the second, and a Real matrix of the Schur vectors in the third
Z←⌹⍠5 RA Z is a two-element nested vector consisting of the QR Decomposition of RA; the first element is Q, an orthonormal matrix (Q≡⍉⌹Q) and the second element is R, an upper-triangular matrix, which, together, satisfy the identity RA≡Q+.×R.


For example, Eigenvalues and Eigenvectors can be used to calculate the factorial of a matrix:

        M←2 2⍴1 3 2 1
        M
  1 3
  2 1
        MatFact←{(Eval Evec)←⌹⍠3 ⍵
⋄ Diag←∘⌻!Eval ⍝ Factorial of Eigenvalues on diagonal
⋄ Evec+.×Diag+.×⌹Evec}
        MatFact M
  3.6274 8.8423
  5.8949 3.6274

Note that if we delete the Shriek function in MatFact, the result is the original matrix argument.

In turn, the function MatFact can be used to calculate the Factorial of a HyperComplex number:

        HyperFact←{M←∘⌻⍵        ⍝ Matrix representation of a HyperComplex number
⋄ ⎕IO←1 ⋄ <9○1⌷[2] MatFact M  ⍝ Factorial ...
}
        HyperFact 1i2
  0.11229i0.32361
        !1i2
  0.11229i0.32361

where the latter expression uses the Gnu Scientific Library Complex number routines to calculate the Factorial of a Complex number.

In a similar manner, using the appropriate 4×4 matrix representation of a Quaternion, its Factorial can be calculated which is the algorithm used in the implementation:

        HyperFact <⍳4
  0.0060975i¯0.0010787j¯0.001618k¯0.0021573
        !<⍳4
  0.0060975i¯0.0010787j¯0.001618k¯0.0021573


See Also
System Commands System Variables and Functions Operators


Keyboard
Alt+Shift
Alt ¨ ¯ < > × ÷
Shift ~ ! @ # $ % ^ & * ( ) _ +
Key ` 1 2 3 4 5 6 7 8 9 0 - =
Alt+Shift
Alt ? § π
Shift Q W E R T Y U I O P { } |
Key q w e r t y u i o p [ ] \
Alt+Shift
Alt
Shift A S D F G H J K L : "
Key a s d f g h j k l ; '
Alt+Shift χ
Alt
Shift Z X C V B N M < > ?
Key z x c v b n m , . /
NARS 2000 Lang
Tool
Bar
+ - × ÷ * ! ? |
< = >
~ § π .. ,
/ \ ¨ .
_ ¯
Second Row i j k i j k l g p r v x