# Power

From NARS2000

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 Z_{n} g Z_{n-1} returns a singleton 1. Z_{n} and Z_{n-1} represent two consecutive applications of f (or L∘f) to R where Z_{0}←R and Z_{n}←f Z_{n-1} (or Z_{n}←L∘f Z_{n-1}). |
||

Z←{L} f⍣b R |
for non-negative singleton integer b, successively applies the function f (or, if there is a Left argument, the function L∘f) to R, b number of times. |
||

L and R are arbitrary arrays. | |||

In the first case, Z_{n} g Z_{n-1} must return a Boolean-valued singleton; otherwise a DOMAIN ERROR is signaled. |
|||

In the second case, b must be a non-negative integer singleton. If b is a negative integer singleton, a NONCE ERROR is signaled as Function Inverses haven't been implemented as yet; otherwise a DOMAIN ERROR is signaled. |

For example,

sqrt←{{0.5×⍵+⍺÷⍵}⍣=⍨⍵} ⍝ Calculate square root using Newton's method sqrt 2 1.414213562373095 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