Power: 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 valign="top"><apll>Z←{L} <i>f</i/>⍣<i>g</i> R</apll></td> <td></td> <td></td> <...") |
mNo edit summary |
||
(12 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
<td></td> | <td></td> | ||
<td></td> | <td></td> | ||
<td>successively applies the function <apll><i>f</i></apll> (or, if there is a Left argument, the function <apll>L∘<i>f</i></apll>) to <apll>R</apll> until the expression <apll>Z<sub>n</sub> <i>g</i> Z<sub>n-1</sub></apll> returns a singleton <apll>1</apll>. <apll>Z<sub>n</sub></apll> and <apll>Z<sub>n-1</sub></apll> represent two consecutive applications of <apll><i>f</i></apll> (or <apll>L∘<i>f</i></apll>) to <apll>R</apll> where <apll>Z<sub>n</sub> | <td>successively applies the function <apll><i>f</i></apll> (or, if there is a Left argument, the function <apll>L∘<i>f</i></apll>) to <apll>R</apll> until the expression <apll>Z<sub>n</sub> <i>g</i> Z<sub>n-1</sub></apll> returns a singleton <apll>1</apll>. <apll>Z<sub>n</sub></apll> and <apll>Z<sub>n-1</sub></apll> represent two consecutive applications of <apll><i>f</i></apll> (or <apll>L∘<i>f</i></apll>) to <apll>R</apll> where <apll>Z<sub>0</sub>←R</apll> and <apll>Z<sub>n</sub>←<i>f</i> Z<sub>n-1</sub></apll> (or <apll>Z<sub>n</sub>←L∘<i>f</i> Z<sub>n-1</sub></apll>).</td> | ||
</tr> | </tr> | ||
Line 11: | Line 11: | ||
<td></td> | <td></td> | ||
<td></td> | <td></td> | ||
<td>for non-negative | <td>for non-negative integer scalar <apll><i>b</i></apll>, successively applies the function <apll><i>f</i></apll> (or, if there is a Left argument, the function <apll>L∘<i>f</i></apll>) to <apll>R</apll>, <apll><i>b</i></apll> number of times;<br/> | ||
for a negative integer scalar <apll><i>b</i></apll>, successively applies the inverse of the function <apll><i>f</i></apll> (or, if there is a Left argument, the inverse to the function <apll>L∘<i>f</i></apll>), <apll>|<i>b</i></apll> number of times</td> | |||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td colspan="4"><apll>L</apll> and <apll>R</apll> are arbitrary arrays</td> | <td colspan="4"><apll>L</apll> and <apll>R</apll> are arbitrary arrays.</td> | ||
</tr> | </tr> | ||
Line 23: | Line 24: | ||
<tr> | <tr> | ||
<td colspan="4">In the second case, <apll><i>b</i></apll> must be | <td colspan="4">In the second case, <apll><i>b</i></apll> must be an integer scalar, otherwise a <apll>DOMAIN ERROR</apll> is signaled.</td> | ||
</tr> | </tr> | ||
Line 34: | Line 35: | ||
sqrt 2 | sqrt 2 | ||
1.414213562373095 | 1.414213562373095 | ||
sqrt 2<_x/> | |||
1.41421356237309504880168872420969807857 | |||
√2<_x/> | |||
1.41421356237309504880168872420969807857 | |||
fib←{⍵,+/¯2↑⍵} ⍝ Calculate a Fibonacci sequence | fib←{⍵,+/¯2↑⍵} ⍝ Calculate a Fibonacci sequence | ||
fib⍣15 | fib⍣15 1 1 | ||
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 | 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 | ||
pow←{⍵=0:,1 ⋄ ⍺+⍡×⍣(⍵-1) ⍺} ⍝ Raise a polynomial to a non-negative integer power | pow←{⍵=0:,1 ⋄ ⍺+⍡×⍣(⍵-1) ⍺} ⍝ Raise a polynomial to a non-negative integer power | ||
Line 43: | Line 48: | ||
phi | phi | ||
1.618033988749894 | 1.618033988749894 | ||
phi=0.5×1+√5 | |||
1 | |||
</pre></apll> | </pre></apll> | ||
=Inverses= | |||
<p>When the right operand to the Power Operator is a negative integer scalar, the inverse of the function left operand is applied to the right argument. If <apll>f f⍣¯1 R ←→ R</apll>, then <apll>f⍣¯1</apll> is a Right Identity Function, and if <apll>f⍣¯1 f R ←→ R</apll>, then <apll>f⍣¯1</apll> is a Left Identity Function, which all of the examples below satisfy.</p> | |||
<p>At the moment, only a few inverse functions are available as follows:</p> | |||
<table border="1" cellpadding="5" cellspacing="0" summary=""> | |||
<tr> | |||
<td>'''Function'''</td> | |||
<td>'''Meaning of Inverse'''</td> | |||
<td>'''Left/Right<br>Identity<br />Function'''</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> L⊥⍣¯1 R</apll></td> | |||
<td><apll><apll>(N⍴L)⊤R</apll> for <apll>N</apll> sufficiently large to display all digits of <apll>R</apll><br /> | |||
<div style="display: inline;"><apll> 10⊥⍣¯1 1234567890<br />1 2 3 4 5 6 7 8 9 0<br /> 10⊥10⊥⍣¯1 1234567890<br />1234567890<br /> 10⊥⍣¯1 10⊥1 2 3 4 5 6 7 8 9 0<br />1 2 3 4 5 6 7 8 9 0 </apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> ⊥⍣¯1 R</apll></td> | |||
<td><apll>2⊥⍣¯1 R</apll><br /> | |||
<div style="display: inline;"><apll> ⊥⍣¯1 19<br />1 0 0 1 1<br /> 2⊥⊥⍣¯1 19<br />19<br /> ⊥⍣¯1 2⊥1 0 0 1 1<br />1 0 0 1 1 </apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> L⊤⍣¯1 R</apll></td> | |||
<td><apll>L⊥R</apll><br /> | |||
<div style="display: inline;"><apll> 10 10 10⊤⍣¯1 2 3 4<br />234<br /> 10 10 10⊤10 10 10⊤⍣¯1 2 3 4<br />2 3 4<br /> 10 10 10⊤⍣¯1 10 10 10⊤234<br />234</apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> ×/⍣¯1 R</apll></td> | |||
<td><apll>πR</apll>, that is, factor <apll>R</apll> into primes<br /> | |||
<div style="display: inline;"><apll> ×/⍣¯1 130<br />2 5 13<br /> ×/×/⍣¯1 130<br />130<br /> ×/⍣¯1 ×/2 5 13<br />2 5 13</apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> π⍣¯1 R</apll></td> | |||
<td><apll>×/R</apll>, that is, multiply together the prime factors in <apll>R</apll><br /> | |||
<div style="display: inline;"><apll> π⍣¯1 2 5 13<br />130<br /> ππ⍣¯1 2 5 13<br />2 5 13<br /> π⍣¯1 π 130<br />130</apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> +\[X]⍣¯1 R</apll></td> | |||
<td><apll>¯2-\[X] R</apll><br /> | |||
<div style="display: inline;"><apll> +\⍣¯1 ⍳4<br />1 1 1 1<br /> +\+\⍣¯1 ⍳4<br />1 2 3 4<br /> +\⍣¯1+\ ⍳4<br />1 2 3 4</apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll>¯2-\[X]⍣¯1 R</apll></td> | |||
<td><apll>+\[X] R</apll><br /> | |||
<div style="display: inline;"><apll> ¯2-\⍣¯1 4⍴1<br />1 2 3 4<br /> ¯2-\¯2-\⍣¯1 4⍴1<br />1 1 1 1<br /> ¯2-\⍣¯1 ¯2-\4⍴1 <br />1 1 1 1</apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> -\[X]⍣¯1 R</apll></td> | |||
<td><apll>(2-\[X] R)×[X](⍴R)[X]⍴¯1 1</apll><br /> | |||
<div style="display: inline;"><apll> a←?5⍴10<br /> a<br />10 8 3 2 6<br /> -\⍣¯1 a<br />10 2 ¯5 1 4<br /> -\-\⍣¯1 a<br />10 8 3 2 6<br /> -\⍣¯1-\ a<br />10 8 3 2 6 </apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> ÷\[X]⍣¯1 R</apll></td> | |||
<td><apll>(2÷\[X] R)*[X](⍴R)[X]⍴¯1 1</apll><br /> | |||
<div style="display: inline;"><apll> a←?5⍴10<br /> a<br />10 8 3 2 6<br /> ÷\⍣¯1 a<br />10 1.25 0.375 1.5 3<br /> ÷\÷\⍣¯1 a<br />10 8 3 2 6<br /> ÷\⍣¯1÷\ a<br />10 8 3 2 6</apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> +∘÷/⍣¯1 R</apll></td> | |||
<td>Display the [https://en.wikipedia.org/wiki/Continued_fraction Continued Fraction] expansion of <apll>R</apll> to at most <apll>⎕PP</apll> terms<br />This function is best used on Multiple Precision numbers<br /> | |||
<div style="display: inline;"><apll> +∘÷/⍣¯1 449<_r/>303<br />1 2 13 3 1 2<br /> +∘÷/+∘÷/⍣¯1 449<_r/>303<br />449<_r/>303<br /> +∘÷/⍣¯1 +∘÷/1 2 13 3 1 2<_x/><br />1 2 13 3 1 2</apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
<tr> | |||
<td valign="top"><apll> L+∘÷/⍣¯1 R</apll></td> | |||
<td>Display the [https://en.wikipedia.org/wiki/Continued_fraction Continued Fraction] expansion of <apll>R</apll> to at most <apll>L</apll> terms<br />This function is best used on Multiple Precision numbers<br /> | |||
<div style="display: inline;"><apll> phi←1+∘÷⍣=1 ⍝ Phi -- the Golden Ratio<br /> 20 +∘÷/⍣¯1 phi<br />1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1<br /> 20 +∘÷/⍣¯1 √2<br />1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2<br /> 20 +∘÷/⍣¯1 *1<_x/><br />2 1 2 1 1 4 1 1 6 1 1 8 1 1 10 1 1 12 1 1<br /> 20 +∘÷/⍣¯1 ○1<_x/><br />3 7 15 1 292 1 1 1 2 1 3 1 14 2 1 1 2 2 2 2<br /> +∘÷/35 +∘÷/⍣¯1 ○1<_x/><br />3.141592653589793238462643383279502884197<br /> ○1<_x/><br />3.141592653589793238462643383279502884197<br /> 4 +∘÷/⍣¯1 +∘÷/○1<_x/><br />3 7 15 1<br /> +∘÷\4 +∘÷/⍣¯1 'r' ⎕DC ○1<_x/> ⍝ Convergents to Pi<br />3 22<_r/>7 333<_r/>106 355<_r/>113</apll></div></td> | |||
<td>L and R</td> | |||
</tr> | |||
</table> |
Latest revision as of 17:17, 12 February 2024
Z←{L} f⍣g R | successively applies the function f (or, if there is a Left argument, the function L∘f) to R until the expression Zn g Zn-1 returns a singleton 1. Zn and Zn-1 represent two consecutive applications of f (or L∘f) to R where Z0←R and Zn←f Zn-1 (or Zn←L∘f Zn-1). | ||
Z←{L} f⍣b R | for non-negative integer scalar b, successively applies the function f (or, if there is a Left argument, the function L∘f) to R, b number of times; for a negative integer scalar b, successively applies the inverse of the function f (or, if there is a Left argument, the inverse to the function L∘f), |b number of times |
||
L and R are arbitrary arrays. | |||
In the first case, Zn g Zn-1 must return a Boolean-valued singleton; otherwise a DOMAIN ERROR is signaled. | |||
In the second case, b must be an integer scalar, otherwise a DOMAIN ERROR is signaled. |
For example,
sqrt←{{0.5×⍵+⍺÷⍵}⍣=⍨⍵} ⍝ Calculate square root using Newton's method sqrt 2 1.414213562373095 sqrt 2x 1.41421356237309504880168872420969807857 √2x 1.41421356237309504880168872420969807857 fib←{⍵,+/¯2↑⍵} ⍝ Calculate a Fibonacci sequence fib⍣15 1 1 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 pow←{⍵=0:,1 ⋄ ⍺+⍡×⍣(⍵-1) ⍺} ⍝ Raise a polynomial to a non-negative integer power 1 ¯1 pow 5 1 ¯5 10 ¯10 5 ¯1 phi←1+∘÷⍣=1 ⍝ Calculate the Golden Ratio phi 1.618033988749894 phi=0.5×1+√5 1
Inverses
When the right operand to the Power Operator is a negative integer scalar, the inverse of the function left operand is applied to the right argument. If f f⍣¯1 R ←→ R, then f⍣¯1 is a Right Identity Function, and if f⍣¯1 f R ←→ R, then f⍣¯1 is a Left Identity Function, which all of the examples below satisfy.
At the moment, only a few inverse functions are available as follows:
Function | Meaning of Inverse | Left/Right Identity Function |
L⊥⍣¯1 R | 10⊥⍣¯1 1234567890 1 2 3 4 5 6 7 8 9 0 10⊥10⊥⍣¯1 1234567890 1234567890 10⊥⍣¯1 10⊥1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
L and R |
⊥⍣¯1 R | 2⊥⍣¯1 R ⊥⍣¯1 19 1 0 0 1 1 2⊥⊥⍣¯1 19 19 ⊥⍣¯1 2⊥1 0 0 1 1 1 0 0 1 1 |
L and R |
L⊤⍣¯1 R | L⊥R 10 10 10⊤⍣¯1 2 3 4 234 10 10 10⊤10 10 10⊤⍣¯1 2 3 4 2 3 4 10 10 10⊤⍣¯1 10 10 10⊤234 234 |
L and R |
×/⍣¯1 R | πR, that is, factor R into primes ×/⍣¯1 130 2 5 13 ×/×/⍣¯1 130 130 ×/⍣¯1 ×/2 5 13 2 5 13 |
L and R |
π⍣¯1 R | ×/R, that is, multiply together the prime factors in R π⍣¯1 2 5 13 130 ππ⍣¯1 2 5 13 2 5 13 π⍣¯1 π 130 130 |
L and R |
+\[X]⍣¯1 R | ¯2-\[X] R +\⍣¯1 ⍳4 1 1 1 1 +\+\⍣¯1 ⍳4 1 2 3 4 +\⍣¯1+\ ⍳4 1 2 3 4 |
L and R |
¯2-\[X]⍣¯1 R | +\[X] R ¯2-\⍣¯1 4⍴1 1 2 3 4 ¯2-\¯2-\⍣¯1 4⍴1 1 1 1 1 ¯2-\⍣¯1 ¯2-\4⍴1 1 1 1 1 |
L and R |
-\[X]⍣¯1 R | (2-\[X] R)×[X](⍴R)[X]⍴¯1 1 a←?5⍴10 a 10 8 3 2 6 -\⍣¯1 a 10 2 ¯5 1 4 -\-\⍣¯1 a 10 8 3 2 6 -\⍣¯1-\ a 10 8 3 2 6 |
L and R |
÷\[X]⍣¯1 R | (2÷\[X] R)*[X](⍴R)[X]⍴¯1 1 a←?5⍴10 a 10 8 3 2 6 ÷\⍣¯1 a 10 1.25 0.375 1.5 3 ÷\÷\⍣¯1 a 10 8 3 2 6 ÷\⍣¯1÷\ a 10 8 3 2 6 |
L and R |
+∘÷/⍣¯1 R | Display the Continued Fraction expansion of R to at most ⎕PP terms This function is best used on Multiple Precision numbers +∘÷/⍣¯1 449r303 1 2 13 3 1 2 +∘÷/+∘÷/⍣¯1 449r303 449r303 +∘÷/⍣¯1 +∘÷/1 2 13 3 1 2x 1 2 13 3 1 2 |
L and R |
L+∘÷/⍣¯1 R | Display the Continued Fraction expansion of R to at most L terms This function is best used on Multiple Precision numbers phi←1+∘÷⍣=1 ⍝ Phi -- the Golden Ratio 20 +∘÷/⍣¯1 phi 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 20 +∘÷/⍣¯1 √2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 20 +∘÷/⍣¯1 *1x 2 1 2 1 1 4 1 1 6 1 1 8 1 1 10 1 1 12 1 1 20 +∘÷/⍣¯1 ○1x 3 7 15 1 292 1 1 1 2 1 3 1 14 2 1 1 2 2 2 2 +∘÷/35 +∘÷/⍣¯1 ○1x 3.141592653589793238462643383279502884197 ○1x 3.141592653589793238462643383279502884197 4 +∘÷/⍣¯1 +∘÷/○1x 3 7 15 1 +∘÷\4 +∘÷/⍣¯1 'r' ⎕DC ○1x ⍝ Convergents to Pi 3 22r7 333r106 355r113 |
L and R |