Variant: Difference between revisions
mNo edit summary |
No edit summary |
||
Line 24: | Line 24: | ||
<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 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>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 <apll>L×R</apll> there | <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>For example:</p> | <p>For example:</p> | ||
Line 163: | Line 163: | ||
<br /> | <br /> | ||
==Rising and Falling Factorials== | |||
<p>A falling factorial is like a normal factorial except that it subtracts the step value (by default <apll>1</apll> unless overridden) from the original number for a fixed # of iterations. That is, <apll>!6</apll> successively decrements <apll>6</apll> by <apll>1</apll> and multiplies the numbers <apll>6 5 4 3 2 1</apll> to get <apll>720</apll>. A falling factorial starting with <apll>6</apll> of length (say) <apll>3</apll> multiplies <apll>6 5 4</apll> to get <apll>120</apll>. | <p>A falling factorial is like a normal factorial except that it subtracts the step value (by default <apll>1</apll> unless overridden) from the original number for a fixed # of iterations. That is, <apll>!6</apll> successively decrements <apll>6</apll> by <apll>1</apll> and multiplies the numbers <apll>6 5 4 3 2 1</apll> to get <apll>720</apll>. A falling factorial starting with <apll>6</apll> of length (say) <apll>3</apll> multiplies <apll>6 5 4</apll> to get <apll>120</apll>. | ||
Line 249: | Line 249: | ||
</apll> | </apll> | ||
==Identities== | |||
<table border="1" cellpadding="5" cellspacing="5" rules="none" summary=""> | <table border="1" cellpadding="5" cellspacing="5" rules="none" summary=""> | ||
Line 271: | Line 271: | ||
</tr> | </tr> | ||
</table> | </table> | ||
==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. | |||
{| 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←(⌹⍠2) R</apll>||<apll>Z</apll> is a Complex floating point matrix of the Eigenvectors of <apll>R</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 | |||
|} | |||
For example, Eigenvalues and Eigenvectors can be used to calculate the factorial of a matrix: | |||
<apll><pre> M←2 2⍴1 3 2 1 | |||
M | |||
1 3 | |||
2 1 | |||
MatFact←{(Eval Evec)←(⌹⍠3) ⍵ | |||
<span style="color:blue;">➥</span>⋄ Diag←(⍴⍵)⍴0 ⋄ Diag[,¨⍨⍳⍴Eval]←!Eval ⍝ Factorial of Eigenvalues on diagonal | |||
<span style="color:blue;">➥</span>⋄ Evec+.×Diag+.×⌹Evec} | |||
MatFact M | |||
3.6274 8.8423 | |||
5.8949 3.6274 | |||
</pre></apll> | |||
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: | |||
<apll><pre> | |||
CplexFact←{(a b)←>⍵ ⍝ Split out coefficients of a Complex 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>} | |||
CplexFact 1i2 | |||
0.11229J0.32361 | |||
!1i2 | |||
0.11229J0.32361 | |||
</pre></apll> | |||
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 <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 | |||
0.0060975i¯0.0010787j¯0.001618k¯0.0021573 | |||
</pre></apll> | |||
{{Language Toolbar}} | {{Language Toolbar}} |
Revision as of 18:49, 29 July 2017
|
||||
L and R are arbitrary arrays conformable with f, and B is a simple scalar, simple or heterogeneous vector, or nested vector. | ||||
f is a function. |
The dyadic Variant operator creates a version of the function f with a set of properties bound 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', 'DQ', 'DT', 'FPC', 'IO', and 'PP' which stand for the corresponding system variable. Note that for the Variants of L×R and ⌹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.
If the left operand is a primitive function, the following shorthands may be used:
Function | Right Arg Type |
Meaning |
---|---|---|
⍳R and L⍳R | N | ⎕IO←N |
N1 N2 | ⎕IO←N1 and ⎕CT←N2 | |
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, |
N | ⎕CT←N |
L|R | N | ⎕CT←N |
C | ⎕DQ←C | |
N C | ⎕CT←N and ⎕DQ←C | |
C N | ⎕CT←N and ⎕DQ←C | |
?R and L?R | N | ⎕IO←N |
C | ⎕DT←C | |
N C | ⎕IO←N and ⎕DT←C | |
C N | ⎕IO←N and ⎕DT←C | |
!R (Pochhammer k-symbol) | N | Rising (N > 0) and Falling (N < 0) factorial of length |N, stepping by |N 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 | ⎕DQ←C |
L×R | C | where C may be either 'i' or 'e' for Interior or Exterior product where the former calculates (((L×R)+R×L)÷2 and the latter calculates (((L×R)-R×L)÷2 and L and R are non-commutative (Quaternion or Octonion) numbers — for commutative numbers, both products are trivial. |
⌹R | N | where N may be 1, 2, or 3. 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 nested two-element vector with the Eigenvalues in the first element and the Eigenvectors in the second. |
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
(!⍠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.
Z←(⌹⍠1) R | Z is a Complex floating point vector of the Eigenvalues of R |
Z←(⌹⍠2) R | Z is a Complex floating point matrix of the Eigenvectors of R, one per column |
Z←(⌹⍠3) R | Z 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 |
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←(⍴⍵)⍴0 ⋄ Diag[,¨⍨⍳⍴Eval]←!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 Complex number:
CplexFact←{(a b)←>⍵ ⍝ Split out coefficients of a Complex number ➥⋄ M←2 2⍴a (-b) b a ⍝ Matrix representation ... ➥⋄ ⎕IO←1 ⋄ <9○1⌷[2] MatFact M ⍝ Factorial ... ➥} CplexFact 1i2 0.11229J0.32361 !1i2 0.11229J0.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:
!<⍳4 0.0060975i¯0.0010787j¯0.001618k¯0.0021573
NARS 2000 Lang Tool Bar |
← | → | + | - | × | ÷ | * | ⍟ | ⌹ | ○ | ! | ? | √ | | | ⌈ | ⌊ | ⊥ | ⊤ | ⊣ | ⊢ | |||
≡ | ≢ | < | ≤ | = | ≥ | > | ≠ | ∨ | ∧ | ⍱ | ⍲ | ↑ | ↓ | ⊂ | ⊃ | ⌷ | ⍋ | ⍒ | |||||
⍳ | ∊ | ⍸ | ⍷ | ∪ | ∩ | ⊆ | ⊇ | ~ | § | π | .. | , | ⍪ | ⍴ | ⌽ | ⊖ | ⍉ | ||||||
/ | \ | ⌿ | ⍀ | ⊙ | ¨ | ⍨ | ⍤ | ⍣ | ⍡ | ⍥ | ⍦ | . | ∘ | ⍠ | ‼ | ⌻ | ∂ | ∫ | ⍞ | ⎕ | ⍎ | ⍕ | |
⋄ | ⍝ | ∇ | ∆ | ⍙ | _ | ⍺ | ⍵ | ¯ | ⍬ | ∞ | ∅ | ||||||||||||
Second Row | i j k | i j k l | g | p | r | v | x |