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 Zn g Zn-1 returns a singleton 1. Zn and Zn-1 represent two consecutive applications of f (or L∘f) to R where Zn ←→ f Zn-1 (or Zn ←→ L∘f Zn-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, Zn g Zn-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